hypercore 10.38.2 → 11.0.0
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/README.md +13 -30
- package/index.js +388 -444
- package/lib/audit.js +33 -41
- package/lib/bit-interlude.js +174 -0
- package/lib/bitfield.js +79 -87
- package/lib/block-store.js +12 -50
- package/lib/copy-prologue.js +236 -0
- package/lib/core.js +413 -746
- package/lib/download.js +42 -4
- package/lib/merkle-tree.js +263 -406
- package/lib/multisig.js +9 -6
- package/lib/mutex.js +4 -0
- package/lib/remote-bitfield.js +9 -9
- package/lib/replicator.js +247 -177
- package/lib/session-state.js +949 -0
- package/lib/verifier.js +20 -13
- package/package.json +2 -2
- package/lib/batch.js +0 -431
- package/lib/big-header.js +0 -55
- package/lib/oplog.js +0 -228
package/lib/multisig.js
CHANGED
|
@@ -20,9 +20,9 @@ function inflate (data) {
|
|
|
20
20
|
return c.decode(multiSignature, data)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async function partialSignature (
|
|
24
|
-
if (from > tree.length) return null
|
|
25
|
-
const nodes = to <= from ? null : await upgradeNodes(
|
|
23
|
+
async function partialSignature (core, signer, from, to = core.state.length, signature = core.state.signature) {
|
|
24
|
+
if (from > core.tree.length) return null
|
|
25
|
+
const nodes = to <= from ? null : await upgradeNodes(core, from, to)
|
|
26
26
|
|
|
27
27
|
if (signature.byteLength !== 64) signature = c.decode(multiSignature, signature).proofs[0].signature
|
|
28
28
|
|
|
@@ -34,9 +34,12 @@ async function partialSignature (tree, signer, from, to = tree.length, signature
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
async function upgradeNodes (
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
async function upgradeNodes (core, from, to) {
|
|
38
|
+
const batch = core.storage.read()
|
|
39
|
+
const treeBatch = core.state.createTreeBatch()
|
|
40
|
+
const p = await core.tree.proof(batch, treeBatch, { upgrade: { start: from, length: to - from } })
|
|
41
|
+
batch.tryFlush()
|
|
42
|
+
return (await p.settle()).upgrade.nodes
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
function signableLength (lengths, quorum) {
|
package/lib/mutex.js
CHANGED
|
@@ -9,6 +9,10 @@ module.exports = class Mutex {
|
|
|
9
9
|
this._enqueue = (resolve, reject) => this._queue.push([resolve, reject])
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
idle () {
|
|
13
|
+
return this._queue.length === 0 && this.locked === false
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
lock () {
|
|
13
17
|
if (this.destroyed) return Promise.reject(this._destroyError || new Error('Mutex has been destroyed'))
|
|
14
18
|
if (this.locked) return new Promise(this._enqueue)
|
package/lib/remote-bitfield.js
CHANGED
|
@@ -32,11 +32,11 @@ class RemoteBitfieldPage {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
setRange (start,
|
|
36
|
-
quickbit.fill(this.bitfield, val, start,
|
|
35
|
+
setRange (start, end, val) {
|
|
36
|
+
quickbit.fill(this.bitfield, val, start, end)
|
|
37
37
|
|
|
38
38
|
let i = Math.floor(start / 128)
|
|
39
|
-
const n = i + Math.ceil(
|
|
39
|
+
const n = i + Math.ceil((end - start) / 128)
|
|
40
40
|
|
|
41
41
|
while (i <= n) this.tree.update(this.offset * 8 + i++ * 128)
|
|
42
42
|
}
|
|
@@ -188,11 +188,11 @@ module.exports = class RemoteBitfield {
|
|
|
188
188
|
if (p) p.set(j, val)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
setRange (start,
|
|
191
|
+
setRange (start, end, val) {
|
|
192
192
|
let j = start & (BITS_PER_PAGE - 1)
|
|
193
193
|
let i = (start - j) / BITS_PER_PAGE
|
|
194
194
|
|
|
195
|
-
while (
|
|
195
|
+
while (start < end) {
|
|
196
196
|
let p = this._pages.get(i)
|
|
197
197
|
|
|
198
198
|
if (!p && val) {
|
|
@@ -203,14 +203,14 @@ module.exports = class RemoteBitfield {
|
|
|
203
203
|
p = this._pages.set(i, new RemoteBitfieldPage(i, new Uint32Array(WORDS_PER_PAGE), s))
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
const
|
|
207
|
-
const range =
|
|
206
|
+
const last = Math.min(end, BITS_PER_PAGE)
|
|
207
|
+
const range = last - j
|
|
208
208
|
|
|
209
|
-
if (p) p.setRange(j,
|
|
209
|
+
if (p) p.setRange(j, last, val)
|
|
210
210
|
|
|
211
211
|
j = 0
|
|
212
212
|
i++
|
|
213
|
-
|
|
213
|
+
end -= range
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|