hypercore 10.31.3 → 10.31.5
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/index.js +1 -2
- package/lib/core.js +11 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -985,8 +985,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
985
985
|
} = typeof opts === 'number' ? { fork: opts } : opts
|
|
986
986
|
|
|
987
987
|
const writable = !this._readonly && !!(signature || (keyPair && keyPair.secretKey))
|
|
988
|
-
|
|
989
|
-
if (writable === false) throw SESSION_NOT_WRITABLE()
|
|
988
|
+
if (writable === false && (newLength > 0 || fork !== this.core.tree.fork)) throw SESSION_NOT_WRITABLE()
|
|
990
989
|
|
|
991
990
|
await this.core.truncate(newLength, fork, { keyPair, signature })
|
|
992
991
|
|
package/lib/core.js
CHANGED
|
@@ -375,7 +375,7 @@ module.exports = class Core {
|
|
|
375
375
|
|
|
376
376
|
try {
|
|
377
377
|
const batch = await this.tree.truncate(length, fork)
|
|
378
|
-
batch.signature = signature || this.verifier.sign(batch, keyPair)
|
|
378
|
+
if (length > 0) batch.signature = signature || this.verifier.sign(batch, keyPair)
|
|
379
379
|
await this._truncate(batch, null)
|
|
380
380
|
} finally {
|
|
381
381
|
this.truncating--
|
|
@@ -473,7 +473,7 @@ module.exports = class Core {
|
|
|
473
473
|
|
|
474
474
|
const adding = batch.length - treeLength
|
|
475
475
|
|
|
476
|
-
batch.upgraded = batch.length > this.tree.length
|
|
476
|
+
batch.upgraded = !pending && batch.length > this.tree.length
|
|
477
477
|
batch.treeLength = this.tree.length
|
|
478
478
|
batch.ancestors = this.tree.length
|
|
479
479
|
if (batch.upgraded && !pending) batch.signature = signature || this.verifier.sign(batch, keyPair)
|
|
@@ -507,7 +507,15 @@ module.exports = class Core {
|
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
const status = (batch.upgraded ? 0b0001 : 0) | updateContig(this.header, entry.bitfield, this.bitfield)
|
|
510
|
-
if (!pending)
|
|
510
|
+
if (!pending) {
|
|
511
|
+
// we already commit this, and now we signed it, so tell others
|
|
512
|
+
if (entry.treeUpgrade && treeLength > batch.treeLength) {
|
|
513
|
+
entry.bitfield.start = batch.treeLength
|
|
514
|
+
entry.bitfield.length = treeLength - batch.treeLength
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
this.onupdate(status, entry.bitfield, null, null)
|
|
518
|
+
}
|
|
511
519
|
|
|
512
520
|
if (this._shouldFlush()) await this._flushOplog()
|
|
513
521
|
} finally {
|