autobee 2.0.0-rc.26 → 2.0.0-rc.27
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 +2 -6
- package/lib/system.js +2 -2
- package/lib/topo.js +16 -1
- package/lib/writers.js +16 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -177,6 +177,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
177
177
|
this._bootingAll.catch(safetyCatch)
|
|
178
178
|
|
|
179
179
|
await this.bee.ready()
|
|
180
|
+
await this._workingBee.ready()
|
|
180
181
|
await this._bootingState
|
|
181
182
|
|
|
182
183
|
this._localSystemStart = this.system.bee.context.local.length
|
|
@@ -1042,12 +1043,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1042
1043
|
|
|
1043
1044
|
this.writers.attest(witnessed)
|
|
1044
1045
|
|
|
1045
|
-
for (const { key, added
|
|
1046
|
-
if (isAnchor) {
|
|
1047
|
-
// no Writer/ActiveWriters tracking, but still wake anything linked to it
|
|
1048
|
-
this.writers.triggers.trigger(b4a.toString(key, 'hex'), 1)
|
|
1049
|
-
continue
|
|
1050
|
-
}
|
|
1046
|
+
for (const { key, added } of changed) {
|
|
1051
1047
|
if (added) await this.writers.add(key)
|
|
1052
1048
|
else await this.writers.remove(key)
|
|
1053
1049
|
}
|
package/lib/system.js
CHANGED
|
@@ -85,8 +85,8 @@ module.exports = class Systembee {
|
|
|
85
85
|
this.update(key, length, -1, 0, false, false, true, false, false, -1, false)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
addAnchor(key
|
|
89
|
-
this.update(key,
|
|
88
|
+
addAnchor(key) {
|
|
89
|
+
this.update(key, 0, -1, -1, false, true, false, false, true, -1, false)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
isGenesis() {
|
package/lib/topo.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const b4a = require('b4a')
|
|
2
2
|
const encoding = require('./encoding.js')
|
|
3
|
-
const { createNode } = require('./writers.js')
|
|
3
|
+
const { createNode, finalizeNodeBatch } = require('./writers.js')
|
|
4
4
|
const asserts = require('./asserts.js')
|
|
5
|
+
const { LEGACY_OPLOG_VERSION } = require('./constants.js')
|
|
5
6
|
|
|
6
7
|
const EMPTY_HEAD = { length: 0, key: null }
|
|
7
8
|
const INFO_LEGACY_KEY = b4a.concat([b4a.from([0, 0]), b4a.from('info')])
|
|
@@ -275,8 +276,20 @@ async function getOplogBatch(undo, core, length, weight, index, opts = null) {
|
|
|
275
276
|
const seq = length - 1
|
|
276
277
|
const block = await core.get(seq, opts)
|
|
277
278
|
if (block === null) return null
|
|
279
|
+
|
|
278
280
|
const oplog = encoding.decodeOplog(block)
|
|
279
281
|
const head = createNode(core, length, weight, oplog)
|
|
282
|
+
const legacy = oplog.version <= LEGACY_OPLOG_VERSION
|
|
283
|
+
|
|
284
|
+
// if this is legacy the start pointer is always 0, fix
|
|
285
|
+
if (legacy) {
|
|
286
|
+
for (let i = length - 1; i > 0; i--) {
|
|
287
|
+
const block = await core.get(i - 1, opts)
|
|
288
|
+
const oplog = encoding.decodeOplog(block)
|
|
289
|
+
if (oplog.batch.end === 0) break
|
|
290
|
+
head.batch.start++
|
|
291
|
+
}
|
|
292
|
+
}
|
|
280
293
|
|
|
281
294
|
const batch = []
|
|
282
295
|
const result = { undo, batch, index }
|
|
@@ -304,6 +317,8 @@ async function getOplogBatch(undo, core, length, weight, index, opts = null) {
|
|
|
304
317
|
}
|
|
305
318
|
|
|
306
319
|
batch.push(head)
|
|
320
|
+
finalizeNodeBatch(batch)
|
|
321
|
+
|
|
307
322
|
return result
|
|
308
323
|
}
|
|
309
324
|
|
package/lib/writers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const b4a = require('b4a')
|
|
2
2
|
const encoding = require('./encoding.js')
|
|
3
3
|
const Triggers = require('./triggers.js')
|
|
4
|
+
const { LEGACY_OPLOG_VERSION } = require('./constants.js')
|
|
4
5
|
const { signAttestation, resolveWeight } = require('./witness.js')
|
|
5
6
|
const { WriterEncryption } = require('autobee-encryption')
|
|
6
7
|
|
|
@@ -62,9 +63,6 @@ class ActiveWriters {
|
|
|
62
63
|
|
|
63
64
|
let added = false
|
|
64
65
|
if (!w) {
|
|
65
|
-
// anchors are local-only and never replicated - nothing to fetch
|
|
66
|
-
const info = await this.auto.system.get(key, { unflushed: true })
|
|
67
|
-
if (info && info.isAnchor) return
|
|
68
66
|
w = await this.add(key)
|
|
69
67
|
if (!w) return
|
|
70
68
|
added = true
|
|
@@ -453,7 +451,9 @@ class Writer {
|
|
|
453
451
|
async update() {
|
|
454
452
|
const info = await this.system.get(this.core.key)
|
|
455
453
|
|
|
456
|
-
|
|
454
|
+
// an anchor core is prologue-only, so once its single node has applied
|
|
455
|
+
// nothing more can ever come - retire the writer
|
|
456
|
+
if (info && info.isAnchor && info.length > 0 && this !== this.writers.localWriter) {
|
|
457
457
|
await this.detachAndClose()
|
|
458
458
|
return info.length
|
|
459
459
|
}
|
|
@@ -572,7 +572,7 @@ class Writer {
|
|
|
572
572
|
}
|
|
573
573
|
|
|
574
574
|
batch.push(node)
|
|
575
|
-
if (b.end === 0) return batch
|
|
575
|
+
if (b.end === 0) return finalizeNodeBatch(batch)
|
|
576
576
|
|
|
577
577
|
// TODO: mark as dead
|
|
578
578
|
if (batch.length >= BATCH_WRITER_SANITY) return null
|
|
@@ -763,6 +763,7 @@ function sortsBefore(a, b) {
|
|
|
763
763
|
exports.ActiveWriters = ActiveWriters
|
|
764
764
|
exports.Writer = Writer
|
|
765
765
|
exports.createNode = createNode
|
|
766
|
+
exports.finalizeNodeBatch = finalizeNodeBatch
|
|
766
767
|
|
|
767
768
|
function createNode(core, length, weight, oplog) {
|
|
768
769
|
return {
|
|
@@ -784,4 +785,14 @@ function createNode(core, length, weight, oplog) {
|
|
|
784
785
|
}
|
|
785
786
|
}
|
|
786
787
|
|
|
788
|
+
function finalizeNodeBatch(batch) {
|
|
789
|
+
if (batch.length === 0 || batch[0].version > LEGACY_OPLOG_VERSION) return batch
|
|
790
|
+
|
|
791
|
+
for (let i = 0; i < batch.length; i++) {
|
|
792
|
+
batch[i].batch.start = i
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return batch
|
|
796
|
+
}
|
|
797
|
+
|
|
787
798
|
function noop() {}
|