hypercore 11.0.6 → 11.0.8

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/bitfield.js CHANGED
@@ -330,14 +330,15 @@ module.exports = class Bitfield {
330
330
  p = this._pages.set(i, new BitfieldPage(i, s))
331
331
  }
332
332
 
333
- const last = Math.min(end, BITS_PER_PAGE)
333
+ const offset = p.index * BITS_PER_PAGE
334
+ const last = Math.min(end - offset, BITS_PER_PAGE)
334
335
  const range = last - j
335
336
 
336
337
  if (p) p.setRange(j, last, val)
337
338
 
338
339
  j = 0
339
340
  i++
340
- end -= range
341
+ start += range
341
342
  }
342
343
  }
343
344
 
package/lib/core.js CHANGED
@@ -649,8 +649,8 @@ module.exports = class Core {
649
649
  this.updateContiguousLength({ start, length, drop: true })
650
650
  }
651
651
 
652
- async _onconflict (proof, from) {
653
- await this.replicator.onconflict(from)
652
+ async _onconflict (proof) {
653
+ await this.replicator.onconflict()
654
654
 
655
655
  for (let i = this.monitors.length - 1; i >= 0; i--) {
656
656
  const s = this.monitors[i]
package/lib/replicator.js CHANGED
@@ -1578,7 +1578,7 @@ module.exports = class Replicator {
1578
1578
  }
1579
1579
 
1580
1580
  // Called externally when a conflict has been detected and verified
1581
- async onconflict (from) {
1581
+ async onconflict () {
1582
1582
  const all = []
1583
1583
  for (const peer of this.peers) {
1584
1584
  all.push(peer._onconflict())
@@ -233,6 +233,7 @@ module.exports = class SessionState {
233
233
  }
234
234
 
235
235
  if (src.dependencyLength > this.dependencyLength) {
236
+ this.dependencyLength = src.dependencyLength
236
237
  this.storage.updateDependencyLength(src.dependencyLength)
237
238
  }
238
239
 
@@ -638,12 +639,21 @@ module.exports = class SessionState {
638
639
  const firstPage = getBitfieldPage(treeLength)
639
640
  const lastPage = getBitfieldPage(totalLength)
640
641
 
642
+ const srx = this.storage.read()
643
+ const bitfieldPagePromise = srx.getBitfieldPage(firstPage)
644
+ srx.tryFlush()
645
+
646
+ const bitfieldPage = await bitfieldPagePromise
647
+
641
648
  let index = treeLength
642
649
 
643
650
  for (let i = firstPage; i <= lastPage; i++) {
644
651
  const page = b4a.alloc(Bitfield.BYTES_PER_PAGE)
645
652
  tx.putBitfieldPage(i, page)
646
653
 
654
+ // copy existing bits in
655
+ if (i === firstPage && bitfieldPage) page.set(bitfieldPage)
656
+
647
657
  if (index < length) {
648
658
  index = fillBitfieldPage(page, index, length, i, true)
649
659
  if (index < length) continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.0.6",
3
+ "version": "11.0.8",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {