hypercore 11.27.15 → 11.27.17

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.
Files changed (3) hide show
  1. package/index.js +2 -0
  2. package/lib/core.js +6 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -962,6 +962,7 @@ class Hypercore extends EventEmitter {
962
962
 
963
963
  async truncate(newLength = 0, opts = {}) {
964
964
  if (this.opened === false) await this.opening
965
+ if (this.closing) throw SESSION_CLOSED('Cannot append to a closed session', this.discoveryKey)
965
966
 
966
967
  const {
967
968
  fork = this.state.fork + 1,
@@ -983,6 +984,7 @@ class Hypercore extends EventEmitter {
983
984
 
984
985
  async append(blocks, opts = {}) {
985
986
  if (this.opened === false) await this.opening
987
+ if (this.closing) throw SESSION_CLOSED('Cannot append to a closed session', this.discoveryKey)
986
988
 
987
989
  const isDefault = this.state === this.core.state
988
990
  const defaultKeyPair = this.state.name === null ? this.keyPair : null
package/lib/core.js CHANGED
@@ -682,7 +682,9 @@ module.exports = class Core {
682
682
  }
683
683
 
684
684
  // Attempt to repair local merkle tree with remote roots
685
- const tx = this.storage.write()
685
+ const atom = this.storage.createAtom()
686
+ const atomized = this.storage.atomize(atom)
687
+ const tx = atomized.write()
686
688
  for (const node of proof.upgrade.nodes) {
687
689
  tx.putTreeNode(node)
688
690
  }
@@ -690,7 +692,7 @@ module.exports = class Core {
690
692
 
691
693
  // Try local proof again
692
694
  try {
693
- const rx = this.state.storage.read()
695
+ const rx = atomized.read()
694
696
  const treeProofPromise = MerkleTree.proof(this.state, rx, {
695
697
  block: null,
696
698
  hash: null,
@@ -715,6 +717,8 @@ module.exports = class Core {
715
717
  return false
716
718
  }
717
719
 
720
+ await atom.flush()
721
+
718
722
  for (let i = this.monitors.length - 1; i >= 0; i--) {
719
723
  this.monitors[i].emit('repaired', proof)
720
724
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.27.15",
3
+ "version": "11.27.17",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {