hypercore 11.40.1 → 11.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/fully-remote-proof.js +8 -1
- package/lib/merkle-tree.js +6 -2
- package/lib/receiver-queue.js +1 -1
- package/lib/remote-bitfield.js +3 -1
- package/lib/replicator.js +26 -10
- package/package.json +1 -1
|
@@ -72,7 +72,14 @@ async function verify(storage, buffer, { referrer = null } = {}) {
|
|
|
72
72
|
|
|
73
73
|
if (!auth.manifest || !auth.manifest.signers.length) return null
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
let batch = null
|
|
76
|
+
try {
|
|
77
|
+
batch = MerkleTree.verifyFullyRemote(new SlimSession(core, auth, head, roots), proof)
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err.code !== 'INVALID_PROOF') throw err
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
|
|
76
83
|
const publicKey = auth.manifest.signers[0].publicKey
|
|
77
84
|
|
|
78
85
|
let signable = null
|
package/lib/merkle-tree.js
CHANGED
|
@@ -556,7 +556,7 @@ class TreeProof {
|
|
|
556
556
|
if (from >= to || to > head) {
|
|
557
557
|
throw INVALID_OPERATION('Invalid upgrade')
|
|
558
558
|
}
|
|
559
|
-
if (seek && upgrade && node !== null && node.
|
|
559
|
+
if (seek && upgrade && node !== null && node.lastIndex >= upgrade.start) {
|
|
560
560
|
throw INVALID_OPERATION('Cannot both do a seek and block/hash request when upgrading')
|
|
561
561
|
}
|
|
562
562
|
|
|
@@ -825,6 +825,8 @@ class MerkleTree {
|
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
827
|
|
|
828
|
+
if (unverified) throw INVALID_PROOF('Proof not covered by the upgrade')
|
|
829
|
+
|
|
828
830
|
return batch
|
|
829
831
|
}
|
|
830
832
|
|
|
@@ -1076,6 +1078,8 @@ function verifyTree({ block, hash, seek }, nodes) {
|
|
|
1076
1078
|
}
|
|
1077
1079
|
|
|
1078
1080
|
function verifyUpgrade({ fork, upgrade }, blockRoot, batch) {
|
|
1081
|
+
if (upgrade.length === 0) throw INVALID_OPERATION('Invalid upgrade')
|
|
1082
|
+
|
|
1079
1083
|
const prologue = batch.prologue
|
|
1080
1084
|
|
|
1081
1085
|
if (prologue) {
|
|
@@ -1152,7 +1156,7 @@ async function seekFromHead(session, head, bytes, padding) {
|
|
|
1152
1156
|
|
|
1153
1157
|
for (let i = 0; i < roots.length; i++) {
|
|
1154
1158
|
const root = roots[i]
|
|
1155
|
-
const node = await
|
|
1159
|
+
const node = await getTreeNodeFromStorageOrError(session.storage, root)
|
|
1156
1160
|
const size = getUnpaddedSize(node, padding, null)
|
|
1157
1161
|
|
|
1158
1162
|
if (bytes === size) return root
|
package/lib/receiver-queue.js
CHANGED
package/lib/remote-bitfield.js
CHANGED
|
@@ -116,7 +116,9 @@ class RemoteBitfieldSegment {
|
|
|
116
116
|
i++
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
return val || this.pagesLength === PAGES_PER_SEGMENT
|
|
119
|
+
return val || this.pagesLength === PAGES_PER_SEGMENT
|
|
120
|
+
? -1
|
|
121
|
+
: Math.max(position, this.pagesLength * BITS_PER_PAGE)
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
findLast(val, position) {
|
package/lib/replicator.js
CHANGED
|
@@ -1337,6 +1337,7 @@ class Peer {
|
|
|
1337
1337
|
if (start < this._remoteContiguousLength) this._remoteContiguousLength = start // bitfield is always the truth
|
|
1338
1338
|
this.remoteBitfield.insert(start, bitfield)
|
|
1339
1339
|
this.missingBlocks.insert(start, bitfield)
|
|
1340
|
+
this._remoteContiguousLength = this.remoteContiguousLength
|
|
1340
1341
|
this._clearLocalRange(start, bitfield.byteLength * 8)
|
|
1341
1342
|
this._update()
|
|
1342
1343
|
}
|
|
@@ -1385,7 +1386,7 @@ class Peer {
|
|
|
1385
1386
|
return
|
|
1386
1387
|
}
|
|
1387
1388
|
|
|
1388
|
-
const rem = start & (RemoteBitfield.
|
|
1389
|
+
const rem = start & (RemoteBitfield.BITS_PER_PAGE - 1)
|
|
1389
1390
|
if (rem > 0) {
|
|
1390
1391
|
start -= rem
|
|
1391
1392
|
length += rem
|
|
@@ -1400,7 +1401,7 @@ class Peer {
|
|
|
1400
1401
|
this.missingBlocks.insert(start, remote.bitfield)
|
|
1401
1402
|
}
|
|
1402
1403
|
|
|
1403
|
-
start += RemoteBitfield.
|
|
1404
|
+
start += RemoteBitfield.BITS_PER_PAGE
|
|
1404
1405
|
}
|
|
1405
1406
|
|
|
1406
1407
|
this._clearLocalRange(fixedStart, length)
|
|
@@ -1422,12 +1423,13 @@ class Peer {
|
|
|
1422
1423
|
if (start === 0 && drop === false) {
|
|
1423
1424
|
if (length > this._remoteContiguousLength) {
|
|
1424
1425
|
this._remoteContiguousLength = length
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
if (
|
|
1429
|
+
this.remoteFork === this.core.state.fork &&
|
|
1430
|
+
length > this.core.header.hints.remoteContiguousLength
|
|
1431
|
+
) {
|
|
1432
|
+
this.core.updateRemoteContiguousLength(length)
|
|
1431
1433
|
}
|
|
1432
1434
|
} else if (length === 1) {
|
|
1433
1435
|
const bitfield = this.core.skipBitfield === null ? this.core.bitfield : this.core.skipBitfield
|
|
@@ -1441,9 +1443,21 @@ class Peer {
|
|
|
1441
1443
|
this.remoteBitfield.setRange(rangeStart, rangeEnd, has)
|
|
1442
1444
|
this.missingBlocks.setRange(rangeStart, rangeEnd, has)
|
|
1443
1445
|
if (has) this._clearLocalRange(rangeStart, rangeEnd - rangeStart)
|
|
1446
|
+
|
|
1447
|
+
if (
|
|
1448
|
+
has &&
|
|
1449
|
+
start <= this._remoteContiguousLength &&
|
|
1450
|
+
this._remoteContiguousLength < rangeEnd
|
|
1451
|
+
) {
|
|
1452
|
+
this._remoteContiguousLength = rangeEnd
|
|
1453
|
+
}
|
|
1444
1454
|
}
|
|
1445
1455
|
}
|
|
1446
1456
|
|
|
1457
|
+
if (has && start <= this._remoteContiguousLength) {
|
|
1458
|
+
this._remoteContiguousLength = this.remoteContiguousLength
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1447
1461
|
if (this.core.hintsChanged) await this.core.flushHints()
|
|
1448
1462
|
if (drop === false) this._update()
|
|
1449
1463
|
|
|
@@ -1582,7 +1596,7 @@ class Peer {
|
|
|
1582
1596
|
|
|
1583
1597
|
for (let i = 0; i < len; i++) {
|
|
1584
1598
|
let index = off + i
|
|
1585
|
-
if (index
|
|
1599
|
+
if (index >= s.seeker.end) index -= len
|
|
1586
1600
|
|
|
1587
1601
|
if (this._remoteHasBlock(index) === false) continue
|
|
1588
1602
|
if (this.core.bitfield.get(index) === true) continue
|
|
@@ -2178,7 +2192,9 @@ module.exports = class Replicator {
|
|
|
2178
2192
|
}
|
|
2179
2193
|
|
|
2180
2194
|
for (const blk of notify) {
|
|
2181
|
-
|
|
2195
|
+
// detach swaps the last ref into the removed slot, so walk backwards
|
|
2196
|
+
for (let i = blk.refs.length - 1; i >= 0; i--) {
|
|
2197
|
+
const r = blk.refs[i]
|
|
2182
2198
|
if (r.snapshot === false) continue
|
|
2183
2199
|
blk.detach(r, SNAPSHOT_NOT_AVAILABLE())
|
|
2184
2200
|
}
|