Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,15 @@ The core will also gossip to peers it is connected to, that is no longer has the

```js
{
diff: false // Returned `cleared` bytes object is null unless you enable this
diff: false // Returned `cleared` object is null unless you enable this
}
```

`cleared` object when `diff` is `true` will look like:

```
{
blocks: Number // The number of blocks cleared
}
```

Expand Down
4 changes: 4 additions & 0 deletions lib/session-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ class SessionState {
}
}

if (cleared) {
cleared.blocks = this.core.bitfield.countSet(start, end - start)
}

if (end - start === 1) tx.deleteBlock(start)
else tx.deleteBlockRange(start, end)

Expand Down
10 changes: 4 additions & 6 deletions test/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ test('clear blocks with diff option', async function (t) {
const cleared = await core.clear(1337)
t.is(cleared, null)

// todo: reenable bytes use api
const cleared2 = await core.clear(0, { diff: true })
t.ok(cleared2.blocks > 0)

// const cleared2 = await core.clear(0, { diff: true })
// t.ok(cleared2.blocks > 0)

// const cleared3 = await core.clear(0, { diff: true })
// t.is(cleared3.blocks, 0)
const cleared3 = await core.clear(0, { diff: true })
t.is(cleared3.blocks, 0)

await core.close()
})
Expand Down
Loading