autobee 2.3.0 → 2.3.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.
@@ -167,15 +167,18 @@ module.exports = class FastForward {
167
167
  // ensure local key is locally available always
168
168
  promises.push(this.system.get(this.auto.local.key, { timeout: this.timeout }))
169
169
 
170
- const view = this.auto.store.get({ key: this.system.view.key, active: true })
171
- this.cores.push(view)
172
-
173
- promises.push(
174
- view.get(this.system.view.length - 1, {
175
- timeout: this.timeout,
176
- activeRequests: this.activeRequests
177
- })
178
- )
170
+ // a legacy system without the designated view migrates onto an empty view
171
+ if (this.system.view.length) {
172
+ const view = this.auto.store.get({ key: this.system.view.key, active: true })
173
+ this.cores.push(view)
174
+
175
+ promises.push(
176
+ view.get(this.system.view.length - 1, {
177
+ timeout: this.timeout,
178
+ activeRequests: this.activeRequests
179
+ })
180
+ )
181
+ }
179
182
 
180
183
  for (const head of this.system.heads) {
181
184
  promises.push(this.system.get(head.key, { timeout: this.timeout }))
package/lib/migrations.js CHANGED
@@ -25,11 +25,13 @@ module.exports = {
25
25
  coreLength
26
26
  }
27
27
 
28
- async function getCoreManifest(store, key, { timeout, wait = true } = {}) {
28
+ // a peer with a sparse copy may not hold block 0, but the recorded tail is the
29
+ // block it most likely has, so fetch the manifest through that when known
30
+ async function getCoreManifest(store, key, { timeout, wait = true, length = 0 } = {}) {
29
31
  const core = store.get(key)
30
32
  await core.ready()
31
33
  try {
32
- if (!core.manifest && core.length === 0) await core.get(0, { timeout, wait })
34
+ if (!core.manifest) await core.get(length ? length - 1 : 0, { timeout, wait })
33
35
  return core.manifest
34
36
  } finally {
35
37
  await core.close()
package/lib/system.js CHANGED
@@ -158,7 +158,7 @@ module.exports = class Systembee {
158
158
  if (!info) return EMPTY_HEAD
159
159
  const a = this.auto
160
160
 
161
- const toManifests = ({ key }) => getCoreManifest(a.store, key, { timeout })
161
+ const toManifests = ({ key, length }) => getCoreManifest(a.store, key, { timeout, length })
162
162
  const promises = [...info.indexers.map(toManifests), ...info.views.map(toManifests)]
163
163
 
164
164
  await Promise.all(promises)
@@ -168,13 +168,10 @@ module.exports = class Systembee {
168
168
  // the handler only runs once the head is locked in - see auto._runMigration
169
169
  this.migration = { views, head: this.bee.head() }
170
170
 
171
- // legacyViews is ordered by preference, so the first one that resolved wins
172
- for (const name of a.legacyViews) {
173
- const view = views.get(name)
174
- if (view) return view
175
- }
176
-
177
- return EMPTY_HEAD
171
+ // only the designated view may become the autobee view: the view bee decrypts
172
+ // with the key for its own name, so any other legacy view reads as garbage
173
+ const name = a.legacyViews.length ? a.legacyViews[0] : null
174
+ return (name && views.get(name)) || EMPTY_HEAD
178
175
  }
179
176
 
180
177
  bootRecord() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",