autobee 2.11.7 → 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
@@ -1612,10 +1612,11 @@ module.exports = class Autobee extends ReadyResource {
1612
1612
  if (!this._bootGuard.opened) await this._bootGuard.ready()
1613
1613
  if (this.closing) throw new Error('Autobee closed')
1614
1614
 
1615
- 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 })
1616
1617
  if (ff === null) return null
1617
1618
 
1618
- if (!(await this._runFastForward(ff, { force: true }))) return null
1619
+ if (!(await this._runFastForward(ff, { force: true, rewind: true }))) return null
1619
1620
 
1620
1621
  return this.ff.promise
1621
1622
  }
@@ -1681,7 +1682,7 @@ module.exports = class Autobee extends ReadyResource {
1681
1682
  }
1682
1683
  }
1683
1684
 
1684
- async _runFastForward(ff, { force = false } = {}) {
1685
+ async _runFastForward(ff, { force = false, rewind = false } = {}) {
1685
1686
  if (this.fastForwardTo !== null || this.fastForwarding !== null) {
1686
1687
  await ff.close()
1687
1688
  return false
@@ -1697,6 +1698,9 @@ module.exports = class Autobee extends ReadyResource {
1697
1698
 
1698
1699
  if (!result) return false
1699
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
+
1700
1704
  // apply ran while we searched, only drop it if it no longer moves us forward
1701
1705
  if (!force && flushes <= this.system.flushes) return false
1702
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.7",
3
+ "version": "2.11.8",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",