hypercore 11.21.1 → 11.21.4

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 (2) hide show
  1. package/lib/replicator.js +15 -12
  2. package/package.json +1 -1
package/lib/replicator.js CHANGED
@@ -461,7 +461,7 @@ class Peer {
461
461
  this.remoteBitfield = new RemoteBitfield()
462
462
  this.missingBlocks = new RemoteBitfield()
463
463
 
464
- this.pushing = false
464
+ this.pushedLength = 0
465
465
 
466
466
  this.remoteFork = 0
467
467
  this.remoteLength = 0
@@ -909,22 +909,29 @@ class Peer {
909
909
  priority: 0
910
910
  }
911
911
 
912
+ const remoteLength = Math.max(this.remoteLength, this.pushedLength)
913
+
912
914
  msg.block = {
913
915
  index,
914
- nodes: MerkleTree.maxMissingNodes(2 * index, this.remoteLength)
916
+ nodes: MerkleTree.maxMissingNodes(2 * index, remoteLength)
915
917
  }
916
918
 
917
919
  if (index >= this.remoteLength) {
918
920
  msg.upgrade = {
919
- start: this.remoteLength,
920
- length: this.core.state.length - this.remoteLength
921
+ start: remoteLength,
922
+ length: this.core.state.length - remoteLength
921
923
  }
922
924
  }
923
925
 
926
+ let req = null
924
927
  const batch = this.core.storage.read()
925
- const req = await this._getProof(batch, msg, true)
926
- if (req === null) return
928
+ try {
929
+ req = await this._getProof(batch, msg, true)
930
+ } catch {
931
+ return
932
+ }
927
933
 
934
+ if (req === null) return
928
935
  batch.tryFlush()
929
936
 
930
937
  await this._fulfillRequest(req, true)
@@ -993,13 +1000,9 @@ class Peer {
993
1000
  this.replicator._onupload(proof.block.index, proof.block.value.byteLength, this)
994
1001
  }
995
1002
 
996
- // TODO: we should prob move to a sep length prop for this. This is just quick and dirty
997
- // to produce better push upgrade proofs as we can better predict what length the remote
998
- // is going to be at.
999
- if ((pushing || this.pushing) && proof.upgrade) {
1000
- this.pushing = true
1003
+ if (proof.upgrade) {
1001
1004
  const remoteLength = proof.upgrade.start + proof.upgrade.length
1002
- if (remoteLength > this.remoteLength) this.remoteLength = remoteLength
1005
+ if (remoteLength > this.pushedLength) this.pushedLength = remoteLength
1003
1006
  }
1004
1007
 
1005
1008
  this.wireData.send({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.21.1",
3
+ "version": "11.21.4",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {