Skip to content

Commit

Permalink
Unslab downloaded blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Jul 24, 2024
1 parent 925fb43 commit cccf908
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
The Peer uses this information to decide which blocks to request form the peer in response to _requestRange requests and the like.
*/

const unslab = require('unslab')
const b4a = require('b4a')
const safetyCatch = require('safety-catch')
const RandomIterator = require('random-array-iterator')
Expand Down Expand Up @@ -1779,6 +1780,8 @@ module.exports = class Replicator {
}

_resolveBlockRequest (tracker, index, value, req) {
if (value !== null) value = unslab(value)

const b = tracker.remove(index)
if (b === null) return false

Expand Down
15 changes: 15 additions & 0 deletions test/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,21 @@ test('download available blocks on non-sparse update', async function (t) {
t.is(b.contiguousLength, b.length)
})

test('downloaded blocks are unslabbed', async function (t) {
const a = await create()

await a.append(Buffer.alloc(1))

const b = await create(a.key)

replicate(a, b, t)

t.is(b.contiguousLength, 0, 'sanity check: we want to receive the downloaded buffer (not from fs)')
const block = await b.get(0)

t.is(block.buffer.byteLength, 1, 'unslabbed block')
})

test('sparse replication without gossiping', async function (t) {
t.plan(4)

Expand Down

0 comments on commit cccf908

Please sign in to comment.