@optimystic/db-core 0.14.1 → 0.16.2
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/dist/src/blocks/block-store.d.ts +18 -1
- package/dist/src/blocks/block-store.d.ts.map +1 -1
- package/dist/src/blocks/helpers.d.ts +2 -2
- package/dist/src/blocks/helpers.d.ts.map +1 -1
- package/dist/src/blocks/helpers.js +2 -2
- package/dist/src/blocks/helpers.js.map +1 -1
- package/dist/src/btree/btree.d.ts +27 -6
- package/dist/src/btree/btree.d.ts.map +1 -1
- package/dist/src/btree/btree.js +104 -61
- package/dist/src/btree/btree.js.map +1 -1
- package/dist/src/chain/chain.d.ts.map +1 -1
- package/dist/src/chain/chain.js +11 -1
- package/dist/src/chain/chain.js.map +1 -1
- package/dist/src/cluster/index.d.ts +1 -0
- package/dist/src/cluster/index.d.ts.map +1 -1
- package/dist/src/cluster/index.js +1 -0
- package/dist/src/cluster/index.js.map +1 -1
- package/dist/src/cluster/membership.d.ts +49 -0
- package/dist/src/cluster/membership.d.ts.map +1 -0
- package/dist/src/cluster/membership.js +75 -0
- package/dist/src/cluster/membership.js.map +1 -0
- package/dist/src/cluster/structs.d.ts +50 -1
- package/dist/src/cluster/structs.d.ts.map +1 -1
- package/dist/src/cluster/structs.js +9 -1
- package/dist/src/cluster/structs.js.map +1 -1
- package/dist/src/cohort-topic/addressing.d.ts +8 -2
- package/dist/src/cohort-topic/addressing.d.ts.map +1 -1
- package/dist/src/cohort-topic/addressing.js +11 -3
- package/dist/src/cohort-topic/addressing.js.map +1 -1
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts +13 -7
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts.map +1 -1
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.js +17 -6
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.js.map +1 -1
- package/dist/src/cohort-topic/antidos/replay-guard.d.ts +17 -0
- package/dist/src/cohort-topic/antidos/replay-guard.d.ts.map +1 -1
- package/dist/src/cohort-topic/antidos/replay-guard.js +33 -0
- package/dist/src/cohort-topic/antidos/replay-guard.js.map +1 -1
- package/dist/src/cohort-topic/antidos/topic-budget.d.ts +7 -0
- package/dist/src/cohort-topic/antidos/topic-budget.d.ts.map +1 -1
- package/dist/src/cohort-topic/antidos/topic-budget.js +8 -2
- package/dist/src/cohort-topic/antidos/topic-budget.js.map +1 -1
- package/dist/src/cohort-topic/coldstart.d.ts +34 -14
- package/dist/src/cohort-topic/coldstart.d.ts.map +1 -1
- package/dist/src/cohort-topic/coldstart.js +25 -11
- package/dist/src/cohort-topic/coldstart.js.map +1 -1
- package/dist/src/cohort-topic/gossip/bus.d.ts +12 -1
- package/dist/src/cohort-topic/gossip/bus.d.ts.map +1 -1
- package/dist/src/cohort-topic/gossip/bus.js +27 -1
- package/dist/src/cohort-topic/gossip/bus.js.map +1 -1
- package/dist/src/cohort-topic/gossip/view.d.ts +8 -0
- package/dist/src/cohort-topic/gossip/view.d.ts.map +1 -1
- package/dist/src/cohort-topic/gossip/view.js +17 -1
- package/dist/src/cohort-topic/gossip/view.js.map +1 -1
- package/dist/src/cohort-topic/member-engine.d.ts +10 -3
- package/dist/src/cohort-topic/member-engine.d.ts.map +1 -1
- package/dist/src/cohort-topic/member-engine.js +29 -14
- package/dist/src/cohort-topic/member-engine.js.map +1 -1
- package/dist/src/cohort-topic/membership/publisher.d.ts +14 -7
- package/dist/src/cohort-topic/membership/publisher.d.ts.map +1 -1
- package/dist/src/cohort-topic/membership/publisher.js +15 -27
- package/dist/src/cohort-topic/membership/publisher.js.map +1 -1
- package/dist/src/cohort-topic/membership/verifier.d.ts +35 -0
- package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -1
- package/dist/src/cohort-topic/membership/verifier.js +88 -3
- package/dist/src/cohort-topic/membership/verifier.js.map +1 -1
- package/dist/src/cohort-topic/promotion.d.ts +7 -0
- package/dist/src/cohort-topic/promotion.d.ts.map +1 -1
- package/dist/src/cohort-topic/promotion.js +16 -2
- package/dist/src/cohort-topic/promotion.js.map +1 -1
- package/dist/src/cohort-topic/registration/renewal.d.ts +18 -0
- package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -1
- package/dist/src/cohort-topic/registration/renewal.js +54 -0
- package/dist/src/cohort-topic/registration/renewal.js.map +1 -1
- package/dist/src/cohort-topic/registration/types.d.ts +12 -0
- package/dist/src/cohort-topic/registration/types.d.ts.map +1 -1
- package/dist/src/cohort-topic/registration/types.js +14 -0
- package/dist/src/cohort-topic/registration/types.js.map +1 -1
- package/dist/src/cohort-topic/service.d.ts +4 -3
- package/dist/src/cohort-topic/service.d.ts.map +1 -1
- package/dist/src/cohort-topic/service.js +38 -12
- package/dist/src/cohort-topic/service.js.map +1 -1
- package/dist/src/cohort-topic/sig/payloads.d.ts +23 -7
- package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -1
- package/dist/src/cohort-topic/sig/payloads.js +22 -6
- package/dist/src/cohort-topic/sig/payloads.js.map +1 -1
- package/dist/src/cohort-topic/traffic.d.ts +6 -0
- package/dist/src/cohort-topic/traffic.d.ts.map +1 -1
- package/dist/src/cohort-topic/traffic.js +16 -1
- package/dist/src/cohort-topic/traffic.js.map +1 -1
- package/dist/src/cohort-topic/walk.d.ts +22 -7
- package/dist/src/cohort-topic/walk.d.ts.map +1 -1
- package/dist/src/cohort-topic/walk.js +78 -18
- package/dist/src/cohort-topic/walk.js.map +1 -1
- package/dist/src/cohort-topic/wire/codec.d.ts +3 -1
- package/dist/src/cohort-topic/wire/codec.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/codec.js +7 -1
- package/dist/src/cohort-topic/wire/codec.js.map +1 -1
- package/dist/src/cohort-topic/wire/index.d.ts +1 -1
- package/dist/src/cohort-topic/wire/index.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/index.js +1 -1
- package/dist/src/cohort-topic/wire/index.js.map +1 -1
- package/dist/src/cohort-topic/wire/payloads.d.ts +5 -4
- package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/payloads.js +14 -5
- package/dist/src/cohort-topic/wire/payloads.js.map +1 -1
- package/dist/src/cohort-topic/wire/primitives.d.ts +65 -0
- package/dist/src/cohort-topic/wire/primitives.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/primitives.js +173 -0
- package/dist/src/cohort-topic/wire/primitives.js.map +1 -0
- package/dist/src/cohort-topic/wire/types.d.ts +132 -5
- package/dist/src/cohort-topic/wire/types.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/validate.d.ts +15 -5
- package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -1
- package/dist/src/cohort-topic/wire/validate.js +146 -123
- package/dist/src/cohort-topic/wire/validate.js.map +1 -1
- package/dist/src/collection/collection.d.ts +23 -12
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +111 -35
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collection/struct.d.ts +37 -2
- package/dist/src/collection/struct.d.ts.map +1 -1
- package/dist/src/collection/struct.js +16 -1
- package/dist/src/collection/struct.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts +18 -1
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +36 -6
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/log/log.d.ts +26 -3
- package/dist/src/log/log.d.ts.map +1 -1
- package/dist/src/log/log.js +34 -7
- package/dist/src/log/log.js.map +1 -1
- package/dist/src/log/struct.d.ts +5 -4
- package/dist/src/log/struct.d.ts.map +1 -1
- package/dist/src/log/struct.js.map +1 -1
- package/dist/src/matchmaking/wire.d.ts +2 -1
- package/dist/src/matchmaking/wire.d.ts.map +1 -1
- package/dist/src/matchmaking/wire.js +13 -92
- package/dist/src/matchmaking/wire.js.map +1 -1
- package/dist/src/network/i-key-network.d.ts +9 -0
- package/dist/src/network/i-key-network.d.ts.map +1 -1
- package/dist/src/network/i-repo.d.ts +8 -0
- package/dist/src/network/i-repo.d.ts.map +1 -1
- package/dist/src/network/struct.d.ts +10 -0
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/reactivity/push-state.d.ts.map +1 -1
- package/dist/src/reactivity/push-state.js +4 -33
- package/dist/src/reactivity/push-state.js.map +1 -1
- package/dist/src/reactivity/wire-validate.d.ts +7 -22
- package/dist/src/reactivity/wire-validate.d.ts.map +1 -1
- package/dist/src/reactivity/wire-validate.js +7 -73
- package/dist/src/reactivity/wire-validate.js.map +1 -1
- package/dist/src/reactivity/wire.js +3 -3
- package/dist/src/reactivity/wire.js.map +1 -1
- package/dist/src/testing/async-wait.d.ts +23 -0
- package/dist/src/testing/async-wait.d.ts.map +1 -0
- package/dist/src/testing/async-wait.js +42 -0
- package/dist/src/testing/async-wait.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +3 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/test-transactor.d.ts +44 -0
- package/dist/src/testing/test-transactor.d.ts.map +1 -0
- package/dist/src/testing/test-transactor.js +423 -0
- package/dist/src/testing/test-transactor.js.map +1 -0
- package/dist/src/transaction/actions-engine.d.ts +6 -3
- package/dist/src/transaction/actions-engine.d.ts.map +1 -1
- package/dist/src/transaction/actions-engine.js +8 -7
- package/dist/src/transaction/actions-engine.js.map +1 -1
- package/dist/src/transaction/coordinator.d.ts +43 -22
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +443 -178
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transaction/errors.d.ts +82 -0
- package/dist/src/transaction/errors.d.ts.map +1 -0
- package/dist/src/transaction/errors.js +93 -0
- package/dist/src/transaction/errors.js.map +1 -0
- package/dist/src/transaction/index.d.ts +6 -3
- package/dist/src/transaction/index.d.ts.map +1 -1
- package/dist/src/transaction/index.js +4 -2
- package/dist/src/transaction/index.js.map +1 -1
- package/dist/src/transaction/operations-hash.d.ts +119 -0
- package/dist/src/transaction/operations-hash.d.ts.map +1 -0
- package/dist/src/transaction/operations-hash.js +180 -0
- package/dist/src/transaction/operations-hash.js.map +1 -0
- package/dist/src/transaction/read-dependency-collector.d.ts +43 -0
- package/dist/src/transaction/read-dependency-collector.d.ts.map +1 -0
- package/dist/src/transaction/read-dependency-collector.js +69 -0
- package/dist/src/transaction/read-dependency-collector.js.map +1 -0
- package/dist/src/transaction/session.d.ts +12 -3
- package/dist/src/transaction/session.d.ts.map +1 -1
- package/dist/src/transaction/session.js +35 -9
- package/dist/src/transaction/session.js.map +1 -1
- package/dist/src/transaction/transaction.d.ts +162 -1
- package/dist/src/transaction/transaction.d.ts.map +1 -1
- package/dist/src/transaction/transaction.js +85 -3
- package/dist/src/transaction/transaction.js.map +1 -1
- package/dist/src/transaction/validator.d.ts +3 -11
- package/dist/src/transaction/validator.d.ts.map +1 -1
- package/dist/src/transaction/validator.js +69 -28
- package/dist/src/transaction/validator.js.map +1 -1
- package/dist/src/transactor/network-transactor.d.ts +35 -0
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +146 -40
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/dist/src/transactor/transactor-source.d.ts +19 -5
- package/dist/src/transactor/transactor-source.d.ts.map +1 -1
- package/dist/src/transactor/transactor-source.js +43 -11
- package/dist/src/transactor/transactor-source.js.map +1 -1
- package/dist/src/transform/atomic-proxy.d.ts +35 -5
- package/dist/src/transform/atomic-proxy.d.ts.map +1 -1
- package/dist/src/transform/atomic-proxy.js +39 -7
- package/dist/src/transform/atomic-proxy.js.map +1 -1
- package/dist/src/transform/cache-source.d.ts +36 -5
- package/dist/src/transform/cache-source.d.ts.map +1 -1
- package/dist/src/transform/cache-source.js +84 -8
- package/dist/src/transform/cache-source.js.map +1 -1
- package/dist/src/transform/helpers.d.ts.map +1 -1
- package/dist/src/transform/helpers.js +8 -2
- package/dist/src/transform/helpers.js.map +1 -1
- package/dist/src/transform/tracker.d.ts +17 -2
- package/dist/src/transform/tracker.d.ts.map +1 -1
- package/dist/src/transform/tracker.js +66 -11
- package/dist/src/transform/tracker.js.map +1 -1
- package/dist/src/utility/backoff.d.ts +48 -0
- package/dist/src/utility/backoff.d.ts.map +1 -0
- package/dist/src/utility/backoff.js +60 -0
- package/dist/src/utility/backoff.js.map +1 -0
- package/dist/src/utility/pending.d.ts +1 -0
- package/dist/src/utility/pending.d.ts.map +1 -1
- package/dist/src/utility/pending.js +3 -1
- package/dist/src/utility/pending.js.map +1 -1
- package/package.json +4 -4
- package/src/blocks/block-store.ts +19 -1
- package/src/blocks/helpers.ts +3 -3
- package/src/btree/btree.ts +108 -63
- package/src/chain/chain.ts +11 -1
- package/src/cluster/index.ts +1 -0
- package/src/cluster/membership.ts +85 -0
- package/src/cluster/structs.ts +51 -1
- package/src/cohort-topic/addressing.ts +12 -4
- package/src/cohort-topic/antidos/bootstrap-evidence.ts +21 -9
- package/src/cohort-topic/antidos/replay-guard.ts +37 -0
- package/src/cohort-topic/antidos/topic-budget.ts +17 -2
- package/src/cohort-topic/coldstart.ts +48 -15
- package/src/cohort-topic/gossip/bus.ts +39 -2
- package/src/cohort-topic/gossip/view.ts +26 -1
- package/src/cohort-topic/member-engine.ts +36 -15
- package/src/cohort-topic/membership/publisher.ts +25 -33
- package/src/cohort-topic/membership/verifier.ts +119 -3
- package/src/cohort-topic/promotion.ts +23 -2
- package/src/cohort-topic/registration/renewal.ts +73 -1
- package/src/cohort-topic/registration/types.ts +15 -0
- package/src/cohort-topic/service.ts +41 -15
- package/src/cohort-topic/sig/payloads.ts +29 -9
- package/src/cohort-topic/traffic.ts +23 -1
- package/src/cohort-topic/walk.ts +95 -24
- package/src/cohort-topic/wire/codec.ts +12 -0
- package/src/cohort-topic/wire/index.ts +2 -0
- package/src/cohort-topic/wire/payloads.ts +14 -5
- package/src/cohort-topic/wire/primitives.ts +188 -0
- package/src/cohort-topic/wire/types.ts +136 -4
- package/src/cohort-topic/wire/validate.ts +168 -134
- package/src/collection/collection.ts +123 -40
- package/src/collection/struct.ts +44 -2
- package/src/collections/tree/tree.ts +42 -5
- package/src/index.ts +1 -0
- package/src/log/log.ts +37 -9
- package/src/log/struct.ts +5 -4
- package/src/matchmaking/wire.ts +25 -102
- package/src/network/i-key-network.ts +10 -0
- package/src/network/i-repo.ts +8 -0
- package/src/network/struct.ts +10 -0
- package/src/reactivity/push-state.ts +4 -37
- package/src/reactivity/wire-validate.ts +7 -81
- package/src/reactivity/wire.ts +3 -3
- package/src/testing/async-wait.ts +65 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/test-transactor.ts +468 -0
- package/src/transaction/actions-engine.ts +8 -6
- package/src/transaction/coordinator.ts +498 -229
- package/src/transaction/errors.ts +91 -0
- package/src/transaction/index.ts +23 -3
- package/src/transaction/operations-hash.ts +196 -0
- package/src/transaction/read-dependency-collector.ts +78 -0
- package/src/transaction/session.ts +37 -9
- package/src/transaction/transaction.ts +211 -4
- package/src/transaction/validator.ts +73 -48
- package/src/transactor/network-transactor.ts +164 -49
- package/src/transactor/transactor-source.ts +47 -12
- package/src/transform/atomic-proxy.ts +92 -49
- package/src/transform/cache-source.ts +87 -9
- package/src/transform/helpers.ts +8 -2
- package/src/transform/tracker.ts +69 -11
- package/src/utility/backoff.ts +95 -0
- package/src/utility/pending.ts +3 -1
- package/src/transaction/context.ts +0 -103
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { Log, Atomic, Tracker, copyTransforms, CacheSource, isTransformsEmpty, TransactorSource } from "../index.js";
|
|
2
|
+
import { SyncRetryExhaustedError } from "./index.js";
|
|
3
|
+
import { clampPriority } from "../transaction/transaction.js";
|
|
4
|
+
import { ReadDependencyCollector } from "../transaction/read-dependency-collector.js";
|
|
2
5
|
import { randomBytes } from '@noble/hashes/utils.js';
|
|
3
6
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
4
7
|
import { Latches } from "../utility/latches.js";
|
|
8
|
+
import { jitteredBackoffMs, abortableDelay, makeAbortError } from "../utility/backoff.js";
|
|
9
|
+
/** Default base backoff (and historical fixed delay) between sync retries, in ms. */
|
|
5
10
|
const PendingRetryDelayMs = 100;
|
|
11
|
+
/** Default max consecutive no-progress stale-failure retries before {@link Collection.sync} gives up. */
|
|
12
|
+
const DefaultMaxAttempts = 10;
|
|
13
|
+
/** Default ceiling on a single exponential-backoff sleep, in ms. */
|
|
14
|
+
const DefaultMaxBackoffMs = 5000;
|
|
6
15
|
export class Collection {
|
|
7
16
|
id;
|
|
8
17
|
transactor;
|
|
@@ -28,9 +37,12 @@ export class Collection {
|
|
|
28
37
|
this.latchId = `Collection:${this.id}`;
|
|
29
38
|
}
|
|
30
39
|
static async createOrOpen(transactor, id, init) {
|
|
31
|
-
// Start with a context that has an infinite revision number to ensure that we always fetch the latest log information
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
// Start with a context that has an infinite revision number to ensure that we always fetch the latest log information.
|
|
41
|
+
// One shared read-dependency collector feeds both the source (direct structural reads) and the cache (every
|
|
42
|
+
// cache hit/miss), so a block read from either layer records a dependency — cache hits included.
|
|
43
|
+
const collector = new ReadDependencyCollector();
|
|
44
|
+
const source = new TransactorSource(id, transactor, undefined, collector);
|
|
45
|
+
const sourceCache = new CacheSource(source, undefined, collector);
|
|
34
46
|
const tracker = new Tracker(sourceCache);
|
|
35
47
|
const header = await source.tryGet(id);
|
|
36
48
|
if (header) { // Collection already exists
|
|
@@ -99,11 +111,22 @@ export class Collection {
|
|
|
99
111
|
// Process the entries and track the blocks they affect
|
|
100
112
|
let anyConflicts = false;
|
|
101
113
|
for (const entry of latest?.entries ?? []) {
|
|
102
|
-
// Filter any pending actions that conflict with the remote actions
|
|
103
|
-
|
|
104
|
-
|
|
114
|
+
// Filter any pending actions that conflict with the remote actions. Each pending
|
|
115
|
+
// action maps to its effective form: the original, a replacement, or dropped.
|
|
116
|
+
const before = this.pending;
|
|
117
|
+
const after = before
|
|
118
|
+
.map(p => this.doFilterConflict(p, entry.actions))
|
|
119
|
+
.filter((a) => a !== undefined);
|
|
120
|
+
// A replacement or a discard changes the pending set; the tracker still holds the
|
|
121
|
+
// pre-filter transforms, so force a replay to re-stage against the effective actions.
|
|
122
|
+
// Identity comparison per the contract: keep => same instance, replace => new instance.
|
|
123
|
+
// NOTE: a filterConflict hook that always allocates a fresh (but equal) instance instead
|
|
124
|
+
// of returning the same one forces a replay on every update — if that ever shows up as a
|
|
125
|
+
// hot path, compare by value/id here instead of by reference.
|
|
126
|
+
const mutated = after.length !== before.length || after.some((a, i) => a !== before[i]);
|
|
127
|
+
this.pending = after;
|
|
105
128
|
this.sourceCache.clear(entry.blockIds);
|
|
106
|
-
anyConflicts = anyConflicts || this.tracker.conflicts(new Set(entry.blockIds)).length > 0;
|
|
129
|
+
anyConflicts = anyConflicts || mutated || this.tracker.conflicts(new Set(entry.blockIds)).length > 0;
|
|
107
130
|
}
|
|
108
131
|
// React to durable invalidations that landed since we last synced. getFrom intentionally skips
|
|
109
132
|
// invalidation entries (they are not pending/committed actions), so surface them separately: an
|
|
@@ -184,24 +207,60 @@ export class Collection {
|
|
|
184
207
|
* this, a collection that already had committed state (e.g. a pre-synced index
|
|
185
208
|
* tree, or any collection on its second commit) keeps serving the stale prior
|
|
186
209
|
* revision because {@link update} sees its rev is already current and refetches
|
|
187
|
-
* nothing. Call BEFORE resetting the tracker (the transforms are read live).
|
|
188
|
-
|
|
189
|
-
|
|
210
|
+
* nothing. Call BEFORE resetting the tracker (the transforms are read live).
|
|
211
|
+
*
|
|
212
|
+
* @param revision - the committed revision these transforms land at (from
|
|
213
|
+
* {@link recordCommitted}), so cached read-dependency revisions advance to it. */
|
|
214
|
+
applyCommittedToCache(transforms, revision) {
|
|
215
|
+
this.sourceCache.transformCache(transforms, revision);
|
|
216
|
+
}
|
|
217
|
+
/** Next revision this collection would commit at (current committed rev + 1). */
|
|
218
|
+
getNextRev() {
|
|
219
|
+
return (this.source.actionContext?.rev ?? 0) + 1;
|
|
220
|
+
}
|
|
221
|
+
/** Record a just-committed action: append its ActionRev to the committed list
|
|
222
|
+
* and advance the revision. Returns the new revision. Mirrors the inline bump
|
|
223
|
+
* in {@link syncInternal}. */
|
|
224
|
+
recordCommitted(actionId) {
|
|
225
|
+
const rev = this.getNextRev();
|
|
226
|
+
this.source.actionContext = {
|
|
227
|
+
committed: [...(this.source.actionContext?.committed ?? []), { actionId, rev }],
|
|
228
|
+
rev,
|
|
229
|
+
};
|
|
230
|
+
return rev;
|
|
190
231
|
}
|
|
191
232
|
/** Push our pending actions to the transactor */
|
|
192
|
-
async sync() {
|
|
233
|
+
async sync(options) {
|
|
193
234
|
const release = await Latches.acquire(this.latchId);
|
|
194
235
|
try {
|
|
195
|
-
await this.syncInternal();
|
|
236
|
+
await this.syncInternal(options);
|
|
196
237
|
}
|
|
197
238
|
finally {
|
|
198
239
|
release();
|
|
199
240
|
}
|
|
200
241
|
}
|
|
201
|
-
async syncInternal() {
|
|
242
|
+
async syncInternal(options) {
|
|
202
243
|
const bytes = randomBytes(16);
|
|
203
244
|
const actionId = uint8ArrayToString(bytes, 'base64url');
|
|
245
|
+
const maxAttempts = options?.maxAttempts ?? DefaultMaxAttempts;
|
|
246
|
+
const baseBackoffMs = options?.baseBackoffMs ?? PendingRetryDelayMs;
|
|
247
|
+
const maxBackoffMs = options?.maxBackoffMs ?? DefaultMaxBackoffMs;
|
|
248
|
+
const deadlineMs = options?.deadlineMs;
|
|
249
|
+
const signal = options?.signal;
|
|
250
|
+
const startedAt = Date.now();
|
|
251
|
+
// Count of consecutive stale failures that made no forward progress. Reset to 0 on every
|
|
252
|
+
// successful transact, so the cap bounds only a persistently-failing sync — a legitimate
|
|
253
|
+
// large multi-batch sync (which iterates many times committing progress) never trips it.
|
|
254
|
+
let consecutiveFailures = 0;
|
|
255
|
+
let lastReason;
|
|
204
256
|
while (this.pending.length || !isTransformsEmpty(this.tracker.transforms)) {
|
|
257
|
+
if (signal?.aborted) {
|
|
258
|
+
throw makeAbortError(signal);
|
|
259
|
+
}
|
|
260
|
+
// Progress-agnostic ceiling: give up if the wall-clock deadline passed.
|
|
261
|
+
if (deadlineMs !== undefined && Date.now() - startedAt >= deadlineMs) {
|
|
262
|
+
throw new SyncRetryExhaustedError(this.id, consecutiveFailures, lastReason ?? 'deadline exceeded');
|
|
263
|
+
}
|
|
205
264
|
// Snapshot the pending actions so that any new actions aren't assumed to be part of this action
|
|
206
265
|
const pending = [...this.pending];
|
|
207
266
|
// Create a snapshot tracker for the action, so that we can ditch the log changes if we have to retry the action
|
|
@@ -214,34 +273,58 @@ export class Collection {
|
|
|
214
273
|
}
|
|
215
274
|
const newRev = (this.source.actionContext?.rev ?? 0) + 1;
|
|
216
275
|
const addResult = await log.addActions(pending, actionId, newRev, () => tracker.transformedBlockIds());
|
|
217
|
-
// Commit the action to the transactor
|
|
218
|
-
|
|
276
|
+
// Commit the action to the transactor. Carry the aged retry priority derived from the
|
|
277
|
+
// consecutive-failure count so a sync that keeps losing concurrent races out-ranks fresh
|
|
278
|
+
// (priority-0) rivals in the cluster's resolveRace (fairness-only; capped at MaxPriority).
|
|
279
|
+
// First attempt has consecutiveFailures == 0, so priority 0 — the common pend is unchanged.
|
|
280
|
+
const staleFailure = await this.source.transact(tracker.transforms, actionId, newRev, this.id, addResult.tailPath.block.header.id, clampPriority(consecutiveFailures));
|
|
219
281
|
if (staleFailure) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
282
|
+
consecutiveFailures++;
|
|
283
|
+
lastReason = staleFailure.reason ?? lastReason;
|
|
284
|
+
// Give up once the consecutive no-progress budget is exhausted, so a transactor that
|
|
285
|
+
// persistently rejects the sync can no longer hold the collection latch forever.
|
|
286
|
+
// NOTE: this also bounds the legitimate `pending`-wait case (retrying the same action
|
|
287
|
+
// while another commit is in flight), which used to retry indefinitely. Default 10
|
|
288
|
+
// attempts ≈ 21s of exponential backoff. If a high-contention workload legitimately
|
|
289
|
+
// needs to wait longer for a pending commit to clear, raise maxAttempts for that caller.
|
|
290
|
+
if (consecutiveFailures >= maxAttempts) {
|
|
291
|
+
throw new SyncRetryExhaustedError(this.id, consecutiveFailures, lastReason);
|
|
223
292
|
}
|
|
293
|
+
// Back off before every retry (any stale failure — reason/missing/pending), growing
|
|
294
|
+
// exponentially from the base delay up to the cap, with proportional random jitter so a
|
|
295
|
+
// herd of clients that lost the same race does not re-collide on the next tick (see
|
|
296
|
+
// utility/backoff.ts). The abortable sleep lets an aborted sync reject promptly instead
|
|
297
|
+
// of finishing the sleep.
|
|
298
|
+
// NOTE: the `missing`/`reason` conflict paths now pay this backoff too (they previously
|
|
299
|
+
// retried with zero delay); that is what stops the persistent-`reason` hot spin. If a
|
|
300
|
+
// high-contention workload ever shows this base delay as recovery latency, lower
|
|
301
|
+
// baseBackoffMs for that caller rather than reintroducing the zero-delay retry.
|
|
302
|
+
const delay = jitteredBackoffMs(consecutiveFailures - 1, { baseMs: baseBackoffMs, capMs: maxBackoffMs }, options?.rand);
|
|
303
|
+
await abortableDelay(delay, signal);
|
|
224
304
|
// Fetch latest state - updateInternal() will call replayActions() if there are conflicts
|
|
225
305
|
await this.updateInternal();
|
|
226
306
|
}
|
|
227
307
|
else {
|
|
308
|
+
// Forward progress: reset the no-progress budget.
|
|
309
|
+
consecutiveFailures = 0;
|
|
310
|
+
lastReason = undefined;
|
|
228
311
|
// Clear the pending actions that were part of this action
|
|
229
312
|
this.pending = this.pending.slice(pending.length);
|
|
230
313
|
// Reset cache and replay any actions that were added during the action
|
|
231
314
|
const transforms = tracker.reset();
|
|
232
315
|
await this.replayActions();
|
|
233
|
-
this.sourceCache.transformCache(transforms);
|
|
316
|
+
this.sourceCache.transformCache(transforms, newRev);
|
|
234
317
|
this.source.actionContext = this.source.actionContext
|
|
235
318
|
? { committed: [...this.source.actionContext.committed, { actionId, rev: newRev }], rev: newRev }
|
|
236
319
|
: { committed: [{ actionId, rev: newRev }], rev: newRev };
|
|
237
320
|
}
|
|
238
321
|
}
|
|
239
322
|
}
|
|
240
|
-
async updateAndSync() {
|
|
323
|
+
async updateAndSync(options) {
|
|
241
324
|
const release = await Latches.acquire(this.latchId);
|
|
242
325
|
try {
|
|
243
326
|
await this.updateInternal();
|
|
244
|
-
await this.syncInternal();
|
|
327
|
+
await this.syncInternal(options);
|
|
245
328
|
}
|
|
246
329
|
finally {
|
|
247
330
|
release();
|
|
@@ -254,7 +337,9 @@ export class Collection {
|
|
|
254
337
|
}
|
|
255
338
|
for await (const entry of log.select(undefined, forward)) {
|
|
256
339
|
if (entry.action) {
|
|
257
|
-
|
|
340
|
+
// NOTE: copy-then-reverse to avoid mutating the stored log entry array.
|
|
341
|
+
// Once tsconfig targets ES2023, `entry.action.actions.toReversed()` is cleaner.
|
|
342
|
+
yield* forward ? entry.action.actions : [...entry.action.actions].reverse();
|
|
258
343
|
}
|
|
259
344
|
}
|
|
260
345
|
}
|
|
@@ -273,21 +358,12 @@ export class Collection {
|
|
|
273
358
|
}
|
|
274
359
|
/** Called for each local action that may be in conflict with a remote action (always called under latch).
|
|
275
360
|
* @param action - The local action to check
|
|
276
|
-
* @param potential - The remote
|
|
277
|
-
* @returns
|
|
361
|
+
* @param potential - The remote actions that are potentially in conflict
|
|
362
|
+
* @returns The effective action to keep: the original (unchanged), a replacement
|
|
363
|
+
* instance (applied instead of the original), or undefined to discard it.
|
|
278
364
|
*/
|
|
279
365
|
doFilterConflict(action, potential) {
|
|
280
|
-
|
|
281
|
-
const replacement = this.filterConflict(action, potential);
|
|
282
|
-
if (!replacement) {
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
else if (replacement !== action) {
|
|
286
|
-
// Queue replacement - it will be applied in replayActions()
|
|
287
|
-
this.pending.push(replacement);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return true;
|
|
366
|
+
return this.filterConflict ? this.filterConflict(action, potential) : action;
|
|
291
367
|
}
|
|
292
368
|
/** Bootstrap ActionContext from the committed tail block's state.
|
|
293
369
|
* The tail is always committed first (commit protocol guarantee), so it's readable
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../src/collection/collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGrH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAuBhC,MAAM,OAAO,UAAU;IAKL;IACA;IACC;IACA;IAEA;IAED;IACC;IAZV,OAAO,GAAsB,EAAE,CAAC;IACvB,OAAO,CAAS;IAEjC,YACiB,EAAgB,EAChB,UAAuB,EACtB,QAAoD,EACpD,MAAgC;IACjD,iDAAiD;IAChC,WAAgC;IACjD,sBAAsB;IACN,OAAwB,EACvB,cAAuG;QARxG,OAAE,GAAF,EAAE,CAAc;QAChB,eAAU,GAAV,UAAU,CAAa;QACtB,aAAQ,GAAR,QAAQ,CAA4C;QACpD,WAAM,GAAN,MAAM,CAA0B;QAEhC,gBAAW,GAAX,WAAW,CAAqB;QAEjC,YAAO,GAAP,OAAO,CAAiB;QACvB,mBAAc,GAAd,cAAc,CAAyF;QAExH,IAAI,CAAC,OAAO,GAAG,cAAc,IAAI,CAAC,EAAE,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAU,UAAuB,EAAE,EAAgB,EAAE,IAAoC;QACjH,sHAAsH;QACtH,MAAM,MAAM,GAAG,IAAI,gBAAgB,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,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9E,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,KAAK,CAAC,gBAAgB,CACpC,MAAgC,EAChC,UAAuB,EACvB,MAA6B;QAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAChE,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;YAC9C,IAAI,SAAS,EAAE,MAAM,EAAE,CAAC;gBACvB,MAAM,CAAC,aAAa,GAAG;oBACtB,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;oBAC/E,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG;iBACzB,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
import type { IBlock, BlockId, Action } from "../index.js";
|
|
2
2
|
import type { IChainHeader } from "../chain/chain-nodes.js";
|
|
3
|
+
import type { RandFn } from "../utility/backoff.js";
|
|
3
4
|
export type CollectionId = BlockId;
|
|
4
5
|
export type CollectionHeaderBlock = IBlock & Partial<IChainHeader>;
|
|
6
|
+
/** Bounds the retry loop inside {@link ICollection.sync} / {@link ICollection.updateAndSync}
|
|
7
|
+
* so a transactor that keeps rejecting the sync can no longer spin the collection latch forever.
|
|
8
|
+
* All fields are optional; unset fields fall back to conservative defaults. */
|
|
9
|
+
export interface SyncOptions {
|
|
10
|
+
/** Max consecutive stale-failure retries that make no progress before giving up.
|
|
11
|
+
* The counter resets to 0 on every successful commit, so a legitimate large multi-batch
|
|
12
|
+
* sync (which iterates many times making forward progress) is never falsely tripped.
|
|
13
|
+
* Default 10. */
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
/** Optional wall-clock deadline in ms measured from the start of the sync call. Independent
|
|
16
|
+
* of the attempt count — a progress-agnostic ceiling. Unset means no deadline. */
|
|
17
|
+
deadlineMs?: number;
|
|
18
|
+
/** Base backoff delay in ms applied before the first retry; subsequent retries grow the delay
|
|
19
|
+
* exponentially up to {@link maxBackoffMs}. Default 100. */
|
|
20
|
+
baseBackoffMs?: number;
|
|
21
|
+
/** Upper bound on any single backoff sleep, in ms. Default 5000. */
|
|
22
|
+
maxBackoffMs?: number;
|
|
23
|
+
/** Optional abort signal. Checked at the top of each loop iteration and raced against the
|
|
24
|
+
* backoff sleep, so an aborted sync rejects promptly (with an AbortError) rather than finishing
|
|
25
|
+
* the current sleep. */
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
/** Advanced/testing hook: source of uniform [0,1) randomness for the backoff jitter. Defaults to
|
|
28
|
+
* the package CSPRNG; inject a deterministic sequence to assert exact retry delays. */
|
|
29
|
+
rand?: RandFn;
|
|
30
|
+
}
|
|
31
|
+
/** Thrown by {@link ICollection.sync} / {@link ICollection.updateAndSync} when the retry budget
|
|
32
|
+
* (attempt count or deadline) is exhausted while the transactor keeps returning stale failures.
|
|
33
|
+
* Catchable so callers can surface a clear "gave up syncing" condition instead of hanging. */
|
|
34
|
+
export declare class SyncRetryExhaustedError extends Error {
|
|
35
|
+
readonly collectionId: CollectionId;
|
|
36
|
+
readonly attempts: number;
|
|
37
|
+
readonly lastReason?: string | undefined;
|
|
38
|
+
constructor(collectionId: CollectionId, attempts: number, lastReason?: string | undefined);
|
|
39
|
+
}
|
|
5
40
|
export interface ICollection<TAction> {
|
|
6
41
|
readonly id: CollectionId;
|
|
7
42
|
act(...actions: Action<TAction>[]): Promise<void>;
|
|
8
43
|
update(): Promise<void>;
|
|
9
|
-
sync(): Promise<void>;
|
|
10
|
-
updateAndSync(): Promise<void>;
|
|
44
|
+
sync(options?: SyncOptions): Promise<void>;
|
|
45
|
+
updateAndSync(options?: SyncOptions): Promise<void>;
|
|
11
46
|
selectLog(forward?: boolean): AsyncIterableIterator<Action<TAction>>;
|
|
12
47
|
}
|
|
13
48
|
export type CreateCollectionAction = Action<void> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"struct.d.ts","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEnE;;+EAE+E;AAC/E,MAAM,WAAW,WAAW;IAC3B;;;qBAGiB;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;sFACkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;gEAC4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;4BAEwB;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;2FACuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;8FAE8F;AAC9F,qBAAa,uBAAwB,SAAQ,KAAK;IAEhD,QAAQ,CAAC,YAAY,EAAE,YAAY;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;gBAFnB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,YAAA;CAM7B;AAED,MAAM,WAAW,WAAW,CAAC,OAAO;IACnC,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;IAC1B,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;CACrE;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG;IACnD,IAAI,EAAE,QAAQ,CAAC;CACf,CAAC"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/** Thrown by {@link ICollection.sync} / {@link ICollection.updateAndSync} when the retry budget
|
|
2
|
+
* (attempt count or deadline) is exhausted while the transactor keeps returning stale failures.
|
|
3
|
+
* Catchable so callers can surface a clear "gave up syncing" condition instead of hanging. */
|
|
4
|
+
export class SyncRetryExhaustedError extends Error {
|
|
5
|
+
collectionId;
|
|
6
|
+
attempts;
|
|
7
|
+
lastReason;
|
|
8
|
+
constructor(collectionId, attempts, lastReason) {
|
|
9
|
+
super(`sync for collection ${collectionId} exhausted ${attempts} retries` +
|
|
10
|
+
(lastReason ? `: ${lastReason}` : ''));
|
|
11
|
+
this.collectionId = collectionId;
|
|
12
|
+
this.attempts = attempts;
|
|
13
|
+
this.lastReason = lastReason;
|
|
14
|
+
this.name = 'SyncRetryExhaustedError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
2
17
|
//# sourceMappingURL=struct.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"struct.js","sourceRoot":"","sources":["../../../src/collection/struct.ts"],"names":[],"mappings":"AAkCA;;8FAE8F;AAC9F,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAEvC;IACA;IACA;IAHV,YACU,YAA0B,EAC1B,QAAgB,EAChB,UAAmB;QAE5B,KAAK,CAAC,uBAAuB,YAAY,cAAc,QAAQ,UAAU;YACxE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAL/B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAS;QAI5B,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD"}
|
|
@@ -24,7 +24,19 @@ export declare class Tree<TKey, TEntry> implements TreeReadView<TKey, TEntry> {
|
|
|
24
24
|
private readonly keyFromEntry;
|
|
25
25
|
private readonly compare;
|
|
26
26
|
private constructor();
|
|
27
|
-
static createOrOpen<TKey, TEntry>(network: ITransactor, id: CollectionId, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => 0 | 1 | -1
|
|
27
|
+
static createOrOpen<TKey, TEntry>(network: ITransactor, id: CollectionId, keyFromEntry?: (entry: TEntry) => TKey, compare?: (a: TKey, b: TKey) => 0 | 1 | -1,
|
|
28
|
+
/** B-tree node fan-out. Defaults to the BTree default (64). Exposed mainly so tests can
|
|
29
|
+
* force a multi-level tree with few entries (a small capacity), which is what exercises the
|
|
30
|
+
* interior-navigation read-exclusion path — with the default you would need thousands of
|
|
31
|
+
* entries before a descent has any interior branch between root and leaf.
|
|
32
|
+
*
|
|
33
|
+
* NOTE: fan-out is NOT persisted in the collection header — it is a per-call construction
|
|
34
|
+
* param. Creating a tree with a non-default capacity and later reopening it (a separate
|
|
35
|
+
* createOrOpen call) without the SAME capacity silently uses 64, so subsequent writes split
|
|
36
|
+
* at a fan-out the existing nodes were not built for. Fine today (only tests pass it, and
|
|
37
|
+
* they pass it consistently); if a persisted tree ever needs a custom fan-out, persist it in
|
|
38
|
+
* the header and read it back on reopen rather than trusting the caller to re-supply it. */
|
|
39
|
+
nodeCapacity?: number): Promise<Tree<TKey, TEntry>>;
|
|
28
40
|
replace(data: TreeReplaceAction<TKey, TEntry>): Promise<void>;
|
|
29
41
|
/** Stage a mutation into the collection's tracker WITHOUT flushing it to the
|
|
30
42
|
* transactor. Reads through this same Tree instance see the staged change;
|
|
@@ -64,6 +76,11 @@ export declare class Tree<TKey, TEntry> implements TreeReadView<TKey, TEntry> {
|
|
|
64
76
|
* map must hold the same instance the tree stages into. Prefer this accessor
|
|
65
77
|
* over reaching through `tree['collection']`. */
|
|
66
78
|
getCollection(): Collection<TreeReplaceAction<TKey, TEntry>>;
|
|
79
|
+
/** This tree's collection id, as a plain string. Used by consumers that flush
|
|
80
|
+
* several trees together (e.g. the Quereus adapter's legacy commit sweep) to
|
|
81
|
+
* name a specific tree in diagnostics when a partial flush leaves trees out of
|
|
82
|
+
* sync. Structurally satisfies the adapter's `DirtyTree.describe()`. */
|
|
83
|
+
describe(): string;
|
|
67
84
|
/**
|
|
68
85
|
* Update the local state from the network.
|
|
69
86
|
* Call this before reading to ensure you have the latest data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../../src/collections/tree/tree.ts"],"names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;QAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAInF,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAI3D,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAI5D,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO;CAG1C"}
|
|
@@ -15,21 +15,44 @@ export class Tree {
|
|
|
15
15
|
this.keyFromEntry = keyFromEntry;
|
|
16
16
|
this.compare = compare;
|
|
17
17
|
}
|
|
18
|
-
static async createOrOpen(network, id, keyFromEntry = (entry) => entry, compare = (a, b) => a < b ? -1 : a > b ? 1 : 0
|
|
18
|
+
static async createOrOpen(network, id, keyFromEntry = (entry) => entry, compare = (a, b) => a < b ? -1 : a > b ? 1 : 0,
|
|
19
|
+
/** B-tree node fan-out. Defaults to the BTree default (64). Exposed mainly so tests can
|
|
20
|
+
* force a multi-level tree with few entries (a small capacity), which is what exercises the
|
|
21
|
+
* interior-navigation read-exclusion path — with the default you would need thousands of
|
|
22
|
+
* entries before a descent has any interior branch between root and leaf.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: fan-out is NOT persisted in the collection header — it is a per-call construction
|
|
25
|
+
* param. Creating a tree with a non-default capacity and later reopening it (a separate
|
|
26
|
+
* createOrOpen call) without the SAME capacity silently uses 64, so subsequent writes split
|
|
27
|
+
* at a fan-out the existing nodes were not built for. Fine today (only tests pass it, and
|
|
28
|
+
* they pass it consistently); if a persisted tree ever needs a custom fan-out, persist it in
|
|
29
|
+
* the header and read it back on reopen rather than trusting the caller to re-supply it. */
|
|
30
|
+
nodeCapacity) {
|
|
19
31
|
// Tricky bootstrapping here:
|
|
20
32
|
// We need the root id to initialize the collection header, so we create the btree in the create collection header callback.
|
|
21
33
|
let btree;
|
|
22
34
|
const init = {
|
|
23
35
|
modules: {
|
|
24
|
-
"replace": async ({ data: actions },
|
|
36
|
+
"replace": async ({ data: actions }, trx) => {
|
|
37
|
+
// Write through the Atomic store the handler is handed (`trx`), NOT the captured
|
|
38
|
+
// read btree, so `internalTransact`'s all-or-nothing wrapper actually governs this
|
|
39
|
+
// action: if any entry throws, `atomic.commit()` is skipped and every staged node
|
|
40
|
+
// write from this action is discarded (whole-action rollback) — identically for
|
|
41
|
+
// freshly created and reopened trees. Binding a throwaway BTree to `trx` reuses the
|
|
42
|
+
// public constructor; no btree API change needed.
|
|
43
|
+
const actionTree = new BTree(trx, new CollectionTrunk(trx, id), keyFromEntry, compare, nodeCapacity);
|
|
25
44
|
for (const [key, entry] of actions) {
|
|
26
45
|
if (entry) {
|
|
27
|
-
await
|
|
46
|
+
await actionTree.upsert(entry);
|
|
28
47
|
}
|
|
29
48
|
else {
|
|
30
|
-
await
|
|
49
|
+
await actionTree.deleteAt((await actionTree.find(key)));
|
|
31
50
|
}
|
|
32
51
|
}
|
|
52
|
+
// Mutations landed in `trx`, not the read btree, so its version counter never moved.
|
|
53
|
+
// Bump it to invalidate any Path a caller still holds — preserving the path-invalidation
|
|
54
|
+
// the previous in-place handler gave for free.
|
|
55
|
+
btree?.invalidatePaths();
|
|
33
56
|
}
|
|
34
57
|
},
|
|
35
58
|
createHeaderBlock: (id, store) => {
|
|
@@ -37,7 +60,7 @@ export class Tree {
|
|
|
37
60
|
btree = BTree.create(store, (_s, r) => {
|
|
38
61
|
rootId = r;
|
|
39
62
|
return new CollectionTrunk(store, id);
|
|
40
|
-
}, keyFromEntry, compare);
|
|
63
|
+
}, keyFromEntry, compare, nodeCapacity);
|
|
41
64
|
return {
|
|
42
65
|
header: store.createBlockHeader(TreeHeaderBlockType, id),
|
|
43
66
|
rootId: rootId,
|
|
@@ -45,7 +68,7 @@ export class Tree {
|
|
|
45
68
|
}
|
|
46
69
|
};
|
|
47
70
|
const collection = await Collection.createOrOpen(network, id, init);
|
|
48
|
-
btree = btree ?? new BTree(collection.tracker, new CollectionTrunk(collection.tracker, collection.id), keyFromEntry, compare);
|
|
71
|
+
btree = btree ?? new BTree(collection.tracker, new CollectionTrunk(collection.tracker, collection.id), keyFromEntry, compare, nodeCapacity);
|
|
49
72
|
return new Tree(collection, btree, keyFromEntry, compare);
|
|
50
73
|
}
|
|
51
74
|
async replace(data) {
|
|
@@ -103,6 +126,13 @@ export class Tree {
|
|
|
103
126
|
getCollection() {
|
|
104
127
|
return this.collection;
|
|
105
128
|
}
|
|
129
|
+
/** This tree's collection id, as a plain string. Used by consumers that flush
|
|
130
|
+
* several trees together (e.g. the Quereus adapter's legacy commit sweep) to
|
|
131
|
+
* name a specific tree in diagnostics when a partial flush leaves trees out of
|
|
132
|
+
* sync. Structurally satisfies the adapter's `DirtyTree.describe()`. */
|
|
133
|
+
describe() {
|
|
134
|
+
return String(this.collection.id);
|
|
135
|
+
}
|
|
106
136
|
/**
|
|
107
137
|
* Update the local state from the network.
|
|
108
138
|
* Call this before reading to ensure you have the latest data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../../src/collections/tree/tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0E,MAAM,2BAA2B,CAAC;AAE/H,OAAO,EAAE,KAAK,EAA4B,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,u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":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC"}
|
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC"}
|
package/dist/src/log/log.d.ts
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { Chain } from "../index.js";
|
|
2
|
-
import type { IBlock, BlockId, ActionId, CollectionId, ChainPath, ActionRev, ActionContext, BlockStore, ReadDependency } from "../index.js";
|
|
2
|
+
import type { IBlock, BlockId, ActionId, CollectionId, ChainPath, ActionRev, ActionContext, ChainInitOptions, BlockStore, ReadDependency } from "../index.js";
|
|
3
3
|
import type { ChainDataNode } from '../chain/chain-nodes.js';
|
|
4
4
|
import type { LogEntry, DisputeResolutionProof, InvalidationEntry, RevertedBlock } from "./index.js";
|
|
5
5
|
import type { GetFromResult } from './struct.js';
|
|
6
6
|
export type LogBlock<TAction> = ChainDataNode<LogEntry<TAction>> & {
|
|
7
|
-
/** Base64url encoded Sha256 hash of the
|
|
7
|
+
/** Base64url encoded Sha256 hash of the prior (predecessor) block - present on every block except the head */
|
|
8
8
|
priorHash?: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const priorHash$: string;
|
|
11
|
+
/**
|
|
12
|
+
* Canonical byte payload covered by {@link LogBlock.priorHash}: every field of a log block EXCEPT
|
|
13
|
+
* the mutable structural links (`nextId`/`priorId`). Those links are rewritten *after* the hash is
|
|
14
|
+
* taken — `nextId` when the following block is appended ({@link Chain.add}), and `priorId`/`nextId`
|
|
15
|
+
* when blocks are removed ({@link Chain.pop}/{@link Chain.dequeue}) — so hashing the raw block would
|
|
16
|
+
* not match the bytes that end up stored. The content-bearing fields (`header`, `entries`,
|
|
17
|
+
* `priorHash`) are covered. Any verifier that re-hashes a stored block to check `priorHash` MUST
|
|
18
|
+
* reproduce exactly this payload (strip `nextId` and `priorId`; hash the rest).
|
|
19
|
+
*
|
|
20
|
+
* NOTE: the caller hashes `JSON.stringify` of this object, which is key-order dependent and not a
|
|
21
|
+
* canonical encoding. Fine today (blocks are built with a stable key order and the in-process store
|
|
22
|
+
* preserves it), but if a block is ever re-serialized by a store/codec that reorders keys or drops
|
|
23
|
+
* `undefined`s differently, a re-hash won't match the recorded priorHash — switch to a canonical
|
|
24
|
+
* encoding (sorted keys / dag-cbor) before that happens.
|
|
25
|
+
*/
|
|
26
|
+
export declare function logBlockHashPayload<TAction>(block: LogBlock<TAction>): {
|
|
27
|
+
header: import("../index.js").BlockHeader;
|
|
28
|
+
entries: LogEntry<TAction>[];
|
|
29
|
+
/** Base64url encoded Sha256 hash of the prior (predecessor) block - present on every block except the head */
|
|
30
|
+
priorHash?: string;
|
|
31
|
+
};
|
|
11
32
|
export declare class Log<TAction> {
|
|
12
33
|
private readonly chain;
|
|
13
34
|
protected constructor(chain: Chain<LogEntry<TAction>>);
|
|
@@ -93,6 +114,8 @@ export declare class Log<TAction> {
|
|
|
93
114
|
private findCheckpoint;
|
|
94
115
|
/** Returns the set of pending actions following, the given checkpoint path. */
|
|
95
116
|
private pendingFrom;
|
|
96
|
-
|
|
117
|
+
/** Chain options used by every log: block type factories plus the priorHash `newBlock` hook.
|
|
118
|
+
* Exposed (not private) so tests can drive a raw {@link Chain} through the exact same hook. */
|
|
119
|
+
static getChainOptions<TAction>(store: BlockStore<IBlock>): ChainInitOptions<LogEntry<TAction>>;
|
|
97
120
|
}
|
|
98
121
|
//# sourceMappingURL=log.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/log/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAW,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAA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