autobee 2.11.6 → 2.11.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/index.js CHANGED
@@ -732,7 +732,8 @@ module.exports = class Autobee extends ReadyResource {
732
732
  }
733
733
 
734
734
  async _shouldReindex(key, { unknown = false, length = 0, timeout = 0 } = {}) {
735
- const core = this.store.get({ key, active: false })
735
+ // an inactive session never attaches to a peer, so fetching needs an active one
736
+ const core = this.store.get({ key, active: unknown && length > 0 })
736
737
 
737
738
  try {
738
739
  await core.ready()
@@ -1611,10 +1612,11 @@ module.exports = class Autobee extends ReadyResource {
1611
1612
  if (!this._bootGuard.opened) await this._bootGuard.ready()
1612
1613
  if (this.closing) throw new Error('Autobee closed')
1613
1614
 
1614
- const ff = await FastForward.fromHead(this, head, null, { force: true, timeout })
1615
+ // an explicit move goes wherever it is pointed, backwards included
1616
+ const ff = await FastForward.fromHead(this, head, null, { force: true, rewind: true, timeout })
1615
1617
  if (ff === null) return null
1616
1618
 
1617
- if (!(await this._runFastForward(ff, { force: true }))) return null
1619
+ if (!(await this._runFastForward(ff, { force: true, rewind: true }))) return null
1618
1620
 
1619
1621
  return this.ff.promise
1620
1622
  }
@@ -1680,7 +1682,7 @@ module.exports = class Autobee extends ReadyResource {
1680
1682
  }
1681
1683
  }
1682
1684
 
1683
- async _runFastForward(ff, { force = false } = {}) {
1685
+ async _runFastForward(ff, { force = false, rewind = false } = {}) {
1684
1686
  if (this.fastForwardTo !== null || this.fastForwarding !== null) {
1685
1687
  await ff.close()
1686
1688
  return false
@@ -1696,6 +1698,9 @@ module.exports = class Autobee extends ReadyResource {
1696
1698
 
1697
1699
  if (!result) return false
1698
1700
 
1701
+ // never move backwards, a boot head can be older than what we already have
1702
+ if (!rewind && flushes < this.system.flushes) return false
1703
+
1699
1704
  // apply ran while we searched, only drop it if it no longer moves us forward
1700
1705
  if (!force && flushes <= this.system.flushes) return false
1701
1706
 
@@ -39,7 +39,12 @@ class FastForward {
39
39
 
40
40
  static DEFAULT_TIMEOUT = DEFAULT_OP_TIMEOUT
41
41
 
42
- static async fromHead(auto, head, trusted, { force = false, skipGap = false, timeout = 0 } = {}) {
42
+ static async fromHead(
43
+ auto,
44
+ head,
45
+ trusted,
46
+ { force = false, skipGap = false, rewind = false, timeout = 0 } = {}
47
+ ) {
43
48
  const conservative = !force && auto._conservativeFF
44
49
 
45
50
  const oplog = await FastForward.flushHead(auto, head, { timeout })
@@ -51,6 +56,9 @@ class FastForward {
51
56
  // legacy nodes from non-indexers have no system info to fast-forward from
52
57
  if (!oplog.op.views || !verified.op.views) return null
53
58
 
59
+ // never move backwards, even when forced or the gap is skipped
60
+ if (!rewind && verified.op.views.flushes < auto.system.flushes) return null
61
+
54
62
  if (!force && !skipGap && verified.op.views.flushes - auto.system.flushes < MIN_FF_GAP) {
55
63
  return null
56
64
  }
@@ -86,6 +94,7 @@ class FastForward {
86
94
 
87
95
  for (let i = 0; i < ops.length; i++) {
88
96
  const res = ops[i]
97
+ if (res.op.views.flushes < auto.system.flushes) continue
89
98
  if (!force && !skipGap && res.op.views.flushes - auto.system.flushes < MIN_FF_GAP) continue
90
99
 
91
100
  if (!trust[i]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.11.6",
3
+ "version": "2.11.8",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",