@cero-base/core 3.2.0 → 3.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.
package/package.json
CHANGED
package/src/database/index.js
CHANGED
|
@@ -265,8 +265,8 @@ export class Database extends ReadyResource {
|
|
|
265
265
|
const known = !!this.key
|
|
266
266
|
try {
|
|
267
267
|
await this._boot()
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
268
|
+
const heads = await this._replay()
|
|
269
|
+
if (heads) await this._boot({ heads })
|
|
270
270
|
|
|
271
271
|
// before replication can deliver blocks at epochs we haven't learned yet
|
|
272
272
|
await this.rotation.hydrate()
|
|
@@ -1149,7 +1149,7 @@ export class Database extends ReadyResource {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
|
|
1151
1151
|
/** @private */
|
|
1152
|
-
async _boot({ land = true } = {}) {
|
|
1152
|
+
async _boot({ land = true, heads = null } = {}) {
|
|
1153
1153
|
const bee = new EpochAutobee(this.store.namespace(this.namespace), this.key, {
|
|
1154
1154
|
keyPair: this.keyPair,
|
|
1155
1155
|
encryptionKey: this.encryptionKey,
|
|
@@ -1169,17 +1169,22 @@ export class Database extends ReadyResource {
|
|
|
1169
1169
|
await bee.ready()
|
|
1170
1170
|
this.key = bee.key
|
|
1171
1171
|
await bee.update()
|
|
1172
|
+
if (!heads) return
|
|
1173
|
+
// a view wiped to apply its log again: nothing this device wrote names what the others wrote
|
|
1174
|
+
// last, and peers announce their writers once, as they connect. It looks where they stood, and
|
|
1175
|
+
// answers once that is applied
|
|
1176
|
+
bee.hintWakeup(heads)
|
|
1177
|
+
await bee.update()
|
|
1172
1178
|
}
|
|
1173
1179
|
|
|
1174
1180
|
// a view another build applied, one with ops skipped this build now reaches among them, fills
|
|
1175
|
-
// from the log
|
|
1181
|
+
// from the log: wiped, it hands back where its writers stood
|
|
1176
1182
|
/** @private */
|
|
1177
1183
|
async _replay() {
|
|
1178
1184
|
// an empty view names no build: what was skipped and is now reached still has to be applied
|
|
1179
1185
|
const caught = this._skipped !== null && this._skipped <= this.version
|
|
1180
|
-
if (!caught && !(await this._foreign(this.view))) return
|
|
1181
|
-
|
|
1182
|
-
return true
|
|
1186
|
+
if (!caught && !(await this._foreign(this.view))) return null
|
|
1187
|
+
return this._wipe()
|
|
1183
1188
|
}
|
|
1184
1189
|
|
|
1185
1190
|
// only an admin's or an owner's device hands over a view: anyone else holding the key could serve
|
|
@@ -1448,27 +1453,26 @@ export class Database extends ReadyResource {
|
|
|
1448
1453
|
// a view again
|
|
1449
1454
|
/** @private */
|
|
1450
1455
|
async _rebuild() {
|
|
1451
|
-
// peers announce their writers once, as they connect: the writers of the view it leaves are
|
|
1452
|
-
// where the new bee starts looking
|
|
1453
|
-
const heads = []
|
|
1454
|
-
for await (const { key, length } of this.bee.system.list()) heads.push({ key, length })
|
|
1455
1456
|
await Promise.allSettled(this._writes)
|
|
1456
|
-
await this._wipe()
|
|
1457
|
+
const heads = await this._wipe()
|
|
1457
1458
|
if (this.closing) return
|
|
1458
|
-
await this._boot({ land: false })
|
|
1459
|
-
this.bee.hintWakeup(heads)
|
|
1459
|
+
await this._boot({ land: false, heads })
|
|
1460
1460
|
this._wire()
|
|
1461
1461
|
}
|
|
1462
1462
|
|
|
1463
|
-
// the bee closes first: open, a batch it applied meanwhile would store what it applied again
|
|
1463
|
+
// the bee closes first: open, a batch it applied meanwhile would store what it applied again.
|
|
1464
|
+
// Where its writers stood goes to the bee that applies the log again
|
|
1464
1465
|
/** @private */
|
|
1465
1466
|
async _wipe() {
|
|
1467
|
+
const heads = []
|
|
1468
|
+
for await (const { key, length } of this.bee.system.list()) heads.push({ key, length })
|
|
1466
1469
|
await this.bee.close()
|
|
1467
1470
|
await this._onWriter(async (writer) => {
|
|
1468
1471
|
await writer.setUserData('autobee/head', null)
|
|
1469
1472
|
await writer.setUserData('cero/skipped', null)
|
|
1470
1473
|
})
|
|
1471
1474
|
this._skipped = null
|
|
1475
|
+
return heads
|
|
1472
1476
|
}
|
|
1473
1477
|
|
|
1474
1478
|
// the lowest version skipped: the replay runs once this device reaches it, whoever sent the highest
|
package/src/database/rotation.js
CHANGED
|
@@ -71,6 +71,14 @@ export class Rotation {
|
|
|
71
71
|
return this._queued(() => this._carry(ops))
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @returns {Promise<void>} Once every rotation asked of this device so far has ended: one asked
|
|
76
|
+
* after is sealed to the devices as they stand by then.
|
|
77
|
+
*/
|
|
78
|
+
async settled() {
|
|
79
|
+
await this._queue.catch(() => {})
|
|
80
|
+
}
|
|
81
|
+
|
|
74
82
|
/** @private */
|
|
75
83
|
_queued(fn) {
|
|
76
84
|
const run = this._queue.catch(() => {}).then(fn)
|
|
@@ -44,6 +44,11 @@ export declare class Rotation {
|
|
|
44
44
|
* @returns {Promise<number | undefined>} What the removal's write resolves.
|
|
45
45
|
*/
|
|
46
46
|
carry(ops: Array<[string, unknown]>): Promise<number | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* @returns {Promise<void>} Once every rotation asked of this device so far has ended: one asked
|
|
49
|
+
* after is sealed to the devices as they stand by then.
|
|
50
|
+
*/
|
|
51
|
+
settled(): Promise<void>;
|
|
47
52
|
/** @private */
|
|
48
53
|
private _queued;
|
|
49
54
|
/**
|