autobee 2.9.5 → 2.9.6

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/migrations.js +26 -7
  2. package/package.json +1 -1
package/lib/migrations.js CHANGED
@@ -84,7 +84,7 @@ async function checkAutobaseMigration(store, local, bootstrap) {
84
84
  let catchup
85
85
 
86
86
  try {
87
- length = await findLocalSystemLength(core, session, systemLength)
87
+ length = await findLocalSystemLength(store, core, session, systemLength)
88
88
  catchup = await getCatchupHeads(session, length)
89
89
  } finally {
90
90
  await session.close()
@@ -205,18 +205,14 @@ function deriveNamespace(name, bootstrap, entropy, encryptionKey) {
205
205
  // scan back for the newest block the signed core actually has locally
206
206
  // the newest INFO the signed core holds that the batch session agrees with -
207
207
  // past its dependency the batch is speculative and may have diverged
208
- async function findLocalSystemLength(core, session, systemLength) {
208
+ async function findLocalSystemLength(store, core, session, systemLength) {
209
209
  let length = Math.min(core.length, systemLength)
210
210
 
211
211
  while (length > 0) {
212
212
  const seq = length - 1
213
213
  const node = await core.get(seq, { wait: false })
214
214
 
215
- if (node) {
216
- const blk = decodeBlock(node)
217
- const entry = blk.keys[0]
218
- if (b4a.equals(entry.key, INFO) && (await sameTree(core, session, length))) return length
219
- }
215
+ if (node && (await isReachableInfo(store, core, session, node, length))) return length
220
216
 
221
217
  length--
222
218
  }
@@ -224,6 +220,15 @@ async function findLocalSystemLength(core, session, systemLength) {
224
220
  return 0
225
221
  }
226
222
 
223
+ // an INFO block the batch agrees with whose views the store has caught up to -
224
+ // otherwise the migrated view would be ahead of what the system can prove
225
+ async function isReachableInfo(store, core, session, node, length) {
226
+ const entry = decodeBlock(node).keys[0]
227
+ if (!b4a.equals(entry.key, INFO)) return false
228
+ if (!(await sameTree(core, session, length))) return false
229
+ return viewsReached(store, decodeLegacySystemInfo(entry.value))
230
+ }
231
+
227
232
  async function sameTree(core, session, length) {
228
233
  if (length <= session.signedLength) return true
229
234
  if (length > session.length) return false
@@ -358,3 +363,17 @@ async function getWriterBatch(store, head, key, encryptionKey, nodes = []) {
358
363
 
359
364
  return batch
360
365
  }
366
+
367
+ async function viewsReached(store, info) {
368
+ for (const v of info.views) {
369
+ if (!v.length) continue
370
+ const core = store.get({ key: v.key, active: false })
371
+ try {
372
+ await core.ready()
373
+ if (core.length < v.length) return false
374
+ } finally {
375
+ await core.close()
376
+ }
377
+ }
378
+ return true
379
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.9.5",
3
+ "version": "2.9.6",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",