hypercore 11.0.36 → 11.0.37

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.
@@ -114,16 +114,19 @@ module.exports = class SessionState {
114
114
  return this.treeFork === -1 ? this.core.header.tree.fork : this.treeFork
115
115
  }
116
116
 
117
- async getFlushedTreeInfo (storage) {
117
+ async updateSnapshotStorage (storage) {
118
118
  if (!this.atomized || !this.atomized.flushing) return this.treeInfo()
119
119
  await this.atomized.flushed()
120
120
 
121
121
  let rx = storage.read()
122
122
  const headPromise = rx.getHead()
123
123
  const authPromise = rx.getAuth()
124
+ const depPromise = rx.getDependency()
124
125
 
125
126
  rx.tryFlush()
126
- const [head, auth] = await Promise.all([headPromise, authPromise])
127
+ const [head, auth, dep] = await Promise.all([headPromise, authPromise, depPromise])
128
+
129
+ storage.setDependencyHead(dep)
127
130
 
128
131
  const fork = head ? head.fork : 0
129
132
  const length = head ? head.length : 0
@@ -188,7 +191,7 @@ module.exports = class SessionState {
188
191
 
189
192
  async snapshot () {
190
193
  const storage = this.storage.snapshot()
191
- const treeInfo = await this.getFlushedTreeInfo(storage)
194
+ const treeInfo = await this.updateSnapshotStorage(storage)
192
195
 
193
196
  const s = new SessionState(
194
197
  this.core,
@@ -258,6 +261,14 @@ module.exports = class SessionState {
258
261
  try {
259
262
  const currLength = this.length
260
263
 
264
+ // load dependency into memory
265
+ const rx = this.storage.read()
266
+ const dependencyPromise = rx.getDependency()
267
+
268
+ rx.tryFlush()
269
+
270
+ const dependency = await dependencyPromise
271
+
261
272
  this.fork = src.fork
262
273
  this.length = src.length
263
274
  this.byteLength = src.byteLength
@@ -271,15 +282,7 @@ module.exports = class SessionState {
271
282
  signature: this.signature
272
283
  }
273
284
 
274
- const rx = src.storage.read()
275
- const dependencyPromise = rx.getDependency()
276
-
277
- rx.tryFlush()
278
-
279
- const dependency = await dependencyPromise
280
- if (dependency && dependency.length > this.flushedLength()) {
281
- this.storage.updateDependencyLength(dependency.length, false, true)
282
- }
285
+ if (dependency) this.storage.setDependencyHead(dependency)
283
286
 
284
287
  const truncated = bitfield ? bitfield.truncated : -1
285
288
 
@@ -398,7 +401,7 @@ module.exports = class SessionState {
398
401
  this.roots = roots
399
402
  this.signature = tree.signature
400
403
 
401
- if (dependency) this.storage.updateDependencyLength(dependency.length, true)
404
+ if (dependency) this.storage.setDependencyHead(dependency)
402
405
 
403
406
  this.ontruncate(tree, tree.length, batch.treeLength, flushed)
404
407
  } finally {
@@ -424,7 +427,7 @@ module.exports = class SessionState {
424
427
  this.roots = batch.roots
425
428
  this.signature = batch.signature
426
429
 
427
- if (dependency) this.storage.updateDependencyLength(dependency.length, true)
430
+ if (dependency) this.storage.setDependencyHead(dependency)
428
431
 
429
432
  this.ontruncate(tree, batch.ancestors, batch.treeLength, flushed)
430
433
  } finally {
@@ -481,7 +484,7 @@ module.exports = class SessionState {
481
484
 
482
485
  const flushed = await this.flush()
483
486
 
484
- if (dependency) this.storage.updateDependencyLength(dependency.length, true)
487
+ if (dependency) this.storage.setDependencyHead(dependency)
485
488
 
486
489
  // todo: atomic event handle
487
490
  if (this.isDefault() && flushed) {
@@ -658,7 +661,7 @@ module.exports = class SessionState {
658
661
  const truncating = sharedLength < origLength
659
662
 
660
663
  for (const node of roots) {
661
- if (node === null) throw new INVALID_OPERATION('Invalid catchup length, tree nodes not available')
664
+ if (node === null) throw INVALID_OPERATION('Invalid catchup length, tree nodes not available')
662
665
  }
663
666
 
664
667
  const fork = truncating ? this.fork + 1 : this.fork
@@ -685,9 +688,7 @@ module.exports = class SessionState {
685
688
 
686
689
  const flushed = await this.flush()
687
690
 
688
- // and prop a better way to do this tooo
689
- this.storage.updateDependencyLength(sharedLength, true)
690
- this.storage.updateDependencyLength(length, false)
691
+ this.storage.setDependencyHead(dep)
691
692
 
692
693
  this.fork = tree.fork
693
694
  this.roots = roots
@@ -846,7 +847,7 @@ module.exports = class SessionState {
846
847
 
847
848
  await state.flush(tx)
848
849
 
849
- if (dependency) state.storage.updateDependencyLength(dependency.length, false)
850
+ if (dependency) state.storage.setDependencyHead(dependency)
850
851
  }
851
852
 
852
853
  const bitfield = { start: treeLength, length: length - treeLength, drop: false }
@@ -953,7 +954,7 @@ module.exports = class SessionState {
953
954
  if (truncation) {
954
955
  const { dependency } = truncation
955
956
 
956
- if (dependency) this.storage.updateDependencyLength(dependency.length, true)
957
+ if (dependency) this.storage.setDependencyHead(dependency)
957
958
  truncated = { to: treeLength, fork }
958
959
  }
959
960
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.0.36",
3
+ "version": "11.0.37",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {