hypercore 11.33.5 → 11.34.1

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 +19 -5
  2. package/package.json +2 -2
package/lib/replicator.js CHANGED
@@ -1019,7 +1019,7 @@ class Peer {
1019
1019
  }
1020
1020
 
1021
1021
  let req = null
1022
- const batch = this.core.storage.read()
1022
+ const batch = this.core.storage.read(this.core.state.fork)
1023
1023
  try {
1024
1024
  req = await this._getProof(batch, msg, true)
1025
1025
  } catch (err) {
@@ -1051,7 +1051,7 @@ class Peer {
1051
1051
  }
1052
1052
 
1053
1053
  try {
1054
- const batch = this.core.storage.read()
1054
+ const batch = this.core.storage.read(this.core.state.fork)
1055
1055
 
1056
1056
  // TODO: could still be answerable if (index, fork) is an ancestor of the current fork
1057
1057
  const req =
@@ -1749,6 +1749,17 @@ class Peer {
1749
1749
  return false
1750
1750
  }
1751
1751
 
1752
+ _addLastRangeBatch(r, start, end) {
1753
+ const { WANT_BATCH } = w
1754
+
1755
+ const next = this.core.bitfield.findLast(false, end - 1)
1756
+ if (next === -1 || next < start) return false
1757
+
1758
+ const b = (next - (next & (WANT_BATCH - 1))) / WANT_BATCH
1759
+
1760
+ return r.addBatch(b)
1761
+ }
1762
+
1752
1763
  _populateRangeBatches(r) {
1753
1764
  const { WANT_BATCH } = w
1754
1765
  for (let i = r.batches.length - 1; i >= 0; i--) {
@@ -1764,10 +1775,13 @@ class Peer {
1764
1775
  r.removeBatch(b)
1765
1776
  }
1766
1777
 
1767
- while (r.batches.length < 3) {
1768
- const end = r.end === -1 ? this.core.state.length : r.end
1769
- if (end <= r.start) return
1778
+ const end = r.end === -1 ? this.core.state.length : r.end
1779
+ if (end <= r.start) return
1770
1780
 
1781
+ // always keep the last batch in the range selected
1782
+ if (r.batches.length < 3) this._addLastRangeBatch(r, r.start, end)
1783
+
1784
+ while (r.batches.length < 3) {
1771
1785
  const len = end - r.start
1772
1786
  const off = r.start + (r.linear ? 0 : Math.floor(Math.random() * len))
1773
1787
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.33.5",
3
+ "version": "11.34.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,7 +54,7 @@
54
54
  "hypercore-crypto": "^3.2.1",
55
55
  "hypercore-errors": "^1.5.0",
56
56
  "hypercore-id-encoding": "^1.2.0",
57
- "hypercore-storage": "^3.0.0",
57
+ "hypercore-storage": "^3.2.0",
58
58
  "is-options": "^1.0.1",
59
59
  "nanoassert": "^2.0.0",
60
60
  "protomux": "^3.5.0",