@optimystic/db-core 1.27.0 → 1.28.0
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/chain/chain.d.ts +4 -0
- package/dist/src/chain/chain.d.ts.map +1 -1
- package/dist/src/chain/chain.js +15 -3
- package/dist/src/chain/chain.js.map +1 -1
- package/dist/src/cluster/membership.d.ts +9 -2
- package/dist/src/cluster/membership.d.ts.map +1 -1
- package/dist/src/cluster/membership.js +51 -11
- package/dist/src/cluster/membership.js.map +1 -1
- package/dist/src/cluster/structs.d.ts +11 -0
- package/dist/src/cluster/structs.d.ts.map +1 -1
- package/dist/src/cohort-topic/willingness.d.ts +12 -11
- package/dist/src/cohort-topic/willingness.d.ts.map +1 -1
- package/dist/src/cohort-topic/willingness.js +21 -11
- package/dist/src/cohort-topic/willingness.js.map +1 -1
- package/dist/src/collection/collection.d.ts +46 -2
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +65 -15
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collection/segments.d.ts +16 -3
- package/dist/src/collection/segments.d.ts.map +1 -1
- package/dist/src/collection/segments.js +24 -7
- package/dist/src/collection/segments.js.map +1 -1
- package/dist/src/collection/write-attempts.d.ts +5 -3
- package/dist/src/collection/write-attempts.d.ts.map +1 -1
- package/dist/src/collection/write-attempts.js +7 -5
- package/dist/src/collection/write-attempts.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts +5 -4
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +1 -1
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/network/block-size.d.ts +30 -5
- package/dist/src/network/block-size.d.ts.map +1 -1
- package/dist/src/network/block-size.js +34 -6
- package/dist/src/network/block-size.js.map +1 -1
- package/dist/src/network/i-peer-network.d.ts +5 -0
- package/dist/src/network/i-peer-network.d.ts.map +1 -1
- package/dist/src/network/i-repo.d.ts +4 -0
- package/dist/src/network/i-repo.d.ts.map +1 -1
- package/dist/src/network/promise-shortfall-error.d.ts +5 -1
- package/dist/src/network/promise-shortfall-error.d.ts.map +1 -1
- package/dist/src/network/promise-shortfall-error.js +5 -1
- package/dist/src/network/promise-shortfall-error.js.map +1 -1
- package/dist/src/network/struct.d.ts +5 -1
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/network/struct.js.map +1 -1
- package/dist/src/network/transaction-size.d.ts +37 -8
- package/dist/src/network/transaction-size.d.ts.map +1 -1
- package/dist/src/network/transaction-size.js +36 -7
- package/dist/src/network/transaction-size.js.map +1 -1
- package/dist/src/transaction/coordinator.d.ts +5 -3
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +9 -7
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transform/helpers.d.ts +12 -2
- package/dist/src/transform/helpers.d.ts.map +1 -1
- package/dist/src/transform/helpers.js +18 -2
- package/dist/src/transform/helpers.js.map +1 -1
- package/package.json +1 -1
- package/src/chain/chain.ts +15 -3
- package/src/cluster/membership.ts +129 -87
- package/src/cluster/structs.ts +11 -0
- package/src/cohort-topic/willingness.ts +39 -22
- package/src/collection/collection.ts +78 -14
- package/src/collection/segments.ts +30 -7
- package/src/collection/write-attempts.ts +7 -5
- package/src/collections/tree/tree.ts +5 -4
- package/src/network/block-size.ts +40 -6
- package/src/network/i-peer-network.ts +6 -0
- package/src/network/i-repo.ts +4 -0
- package/src/network/promise-shortfall-error.ts +5 -1
- package/src/network/struct.ts +5 -1
- package/src/network/transaction-size.ts +35 -7
- package/src/transaction/coordinator.ts +9 -6
- package/src/transform/helpers.ts +19 -2
|
@@ -154,8 +154,9 @@ export function concatTransforms(...transforms) {
|
|
|
154
154
|
* when `updates` ride along) to affect the original Transforms.
|
|
155
155
|
* @see docs/internals.md "Shallow Copy of Transforms" pitfall
|
|
156
156
|
*
|
|
157
|
-
* NOTE: clones unconditionally, even for read-only callers (
|
|
158
|
-
*
|
|
157
|
+
* NOTE: clones unconditionally, even for read-only callers (the reservation reads in
|
|
158
|
+
* `ClusterMember.reservationRequestOf` and `CoordinatorRepo.corroborateHeldBlocks`, both in cohorts of
|
|
159
|
+
* four and up); if they ever show up in a pend profile, give them {@link sharedTransformForBlockId}.
|
|
159
160
|
*/
|
|
160
161
|
export function transformForBlockId(transform, blockId) {
|
|
161
162
|
return {
|
|
@@ -166,6 +167,21 @@ export function transformForBlockId(transform, blockId) {
|
|
|
166
167
|
...(transform.deletes?.includes(blockId) ? { delete: true } : {})
|
|
167
168
|
};
|
|
168
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The transform for one block, SHARING `transform`'s inserted block and update list rather than
|
|
172
|
+
* copying them: for a caller that only reads the result, or serializes it at once, and keeps nothing
|
|
173
|
+
* of it. `StorageRepo.pend` reads it to classify a block and hands it to storage, which encodes it to
|
|
174
|
+
* JSON before returning. Anything that applies, changes or holds on to the result takes
|
|
175
|
+
* {@link transformForBlockId}, whose copy is what makes that safe.
|
|
176
|
+
* @see docs/internals.md "Functions That Share"
|
|
177
|
+
*/
|
|
178
|
+
export function sharedTransformForBlockId(transform, blockId) {
|
|
179
|
+
return {
|
|
180
|
+
...(transform.inserts && blockId in transform.inserts ? { insert: transform.inserts[blockId] } : {}),
|
|
181
|
+
...(transform.updates && blockId in transform.updates ? { updates: transform.updates[blockId] } : {}),
|
|
182
|
+
...(transform.deletes?.includes(blockId) ? { delete: true } : {})
|
|
183
|
+
};
|
|
184
|
+
}
|
|
169
185
|
export function transformsFromTransform(transform, blockId) {
|
|
170
186
|
return {
|
|
171
187
|
inserts: transform.insert ? { [blockId]: transform.insert } : {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/transform/helpers.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,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,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,KAAK,CAAC,MAAM,CAAC,KAAU,CAAC,CAAC;IAC1B,CAAC;IACD,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QAC7E,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;YAC7B,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;AACF,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAAC,KAAyB,EAAE,SAAoB;IAC7E,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;QAChC,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,UAAsB,EAAE,OAAgB,EAAE,SAAoB;IAC7F,OAAO,eAAe,CAAC,UAAU,EAAE,uBAAuB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AACjF,CAAC"}
|
package/package.json
CHANGED
package/src/chain/chain.ts
CHANGED
|
@@ -163,6 +163,10 @@ export class Chain<TEntry> {
|
|
|
163
163
|
* new block afterwards (the log's `priorHash`) nor what a caller writes into an entry after the add
|
|
164
164
|
* (the log's `blockIds`) — both small against the gap between the target and the most a block may
|
|
165
165
|
* hold.
|
|
166
|
+
*
|
|
167
|
+
* Nothing is measured that cannot change the answer, since for a large write each measure is a
|
|
168
|
+
* whole pass over row data: a lone entry for an empty block, which takes it whatever its size, and
|
|
169
|
+
* an entry offered to a block already at the target, which takes nothing more.
|
|
166
170
|
*/
|
|
167
171
|
private takenBy(block: ChainDataNode<TEntry>, entries: readonly TEntry[], start: number): number {
|
|
168
172
|
const room = Math.max(0, Math.min(EntriesPerBlock - block.entries.length, entries.length - start));
|
|
@@ -170,13 +174,21 @@ export class Chain<TEntry> {
|
|
|
170
174
|
if (target === undefined || room === 0) {
|
|
171
175
|
return room;
|
|
172
176
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
if (block.entries.length === 0 && room === 1) {
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
// NOTE: serializes the whole tail block once per append — for a large write, usually the
|
|
181
|
+
// previous large entry — the same order of cost as the commit path's digest of every touched
|
|
182
|
+
// block. If appends to large logs ever show this in a profile, keep a running byte count for the
|
|
183
|
+
// tail instead of re-measuring it.
|
|
176
184
|
let bytes = jsonEncodedBytes(block);
|
|
177
185
|
let held = block.entries.length;
|
|
178
186
|
let taken = 0;
|
|
179
187
|
for (; taken < room; ++taken) {
|
|
188
|
+
// Any entry adds at least its separating comma, so a block holding one at the target is full.
|
|
189
|
+
if (held > 0 && bytes >= target) {
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
180
192
|
// Each entry after the first adds its own JSON plus the separating comma.
|
|
181
193
|
const grown = bytes + jsonEncodedBytes(entries[start + taken]) + (held > 0 ? 1 : 0);
|
|
182
194
|
if (held > 0 && grown > target) {
|
|
@@ -1,87 +1,129 @@
|
|
|
1
|
-
import type { RepoMessage } from "../network/repo-protocol.js";
|
|
2
|
-
import type { ClusterPeers, ClusterRecord, Signature } from "./structs.js";
|
|
3
|
-
import { sha256 } from "multiformats/hashes/sha2";
|
|
4
|
-
import { base58btc } from "multiformats/bases/base58";
|
|
5
|
-
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import type { RepoMessage } from "../network/repo-protocol.js";
|
|
2
|
+
import type { ClusterPeers, ClusterRecord, Signature } from "./structs.js";
|
|
3
|
+
import { sha256 } from "multiformats/hashes/sha2";
|
|
4
|
+
import { base58btc } from "multiformats/bases/base58";
|
|
5
|
+
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
6
|
+
import { concat } from "uint8arrays/concat";
|
|
7
|
+
import { canonicalJson } from "../utility/canonical-json.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Membership-binding version a new coordinator emits. A record at this version folds a
|
|
11
|
+
* {@link membershipDigest} of its peer set into `messageHash` / `promiseHash` / `commitHash`, so the
|
|
12
|
+
* responsible peer set is covered by every signature (see `docs/correctness.md` §2). Absent or `1` marks
|
|
13
|
+
* a legacy *unbound* record (pre-binding history) whose hashes must verify byte-identically to before
|
|
14
|
+
* this change.
|
|
15
|
+
*/
|
|
16
|
+
export const CURRENT_MEMBERSHIP_VERSION = 2 as const;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Canonical membership digest for a peer set: `base64url(SHA256(canonicalJson(sorted peer-id list)))`.
|
|
20
|
+
*
|
|
21
|
+
* Derived from the sorted peer-id list ONLY — not multiaddrs or public keys. Multiaddrs churn and a
|
|
22
|
+
* peer's public key is already a function of its id, so folding either in would make identity unstable
|
|
23
|
+
* without adding agreement value. The set of ids IS the membership. The digest is therefore independent
|
|
24
|
+
* of peer-map key insertion order and of multiaddr / pubkey contents; adding or removing one id changes
|
|
25
|
+
* it. `membershipDigest({})` (the empty set) is a fixed constant.
|
|
26
|
+
*/
|
|
27
|
+
export async function membershipDigest(peers: ClusterPeers): Promise<string> {
|
|
28
|
+
return membershipDigestFromIds(Object.keys(peers ?? {}));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Canonical membership digest for an explicit peer-id list — the same digest {@link membershipDigest}
|
|
33
|
+
* derives from a peer map's keys. ONE implementation, so a verifier reading a stored `peerIds` list
|
|
34
|
+
* (e.g. a persisted block commit proof) and a coordinator reading live `ClusterPeers` can never
|
|
35
|
+
* disagree. Sorts a copy; the caller's array is not mutated.
|
|
36
|
+
*/
|
|
37
|
+
export async function membershipDigestFromIds(ids: readonly string[]): Promise<string> {
|
|
38
|
+
const sorted = [...ids].sort();
|
|
39
|
+
const bytes = new TextEncoder().encode(canonicalJson(sorted));
|
|
40
|
+
const hash = await sha256.digest(bytes);
|
|
41
|
+
return uint8ArrayToString(hash.digest, 'base64url');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The membership digest that participates in a record's hashes, or `undefined` for a legacy (v1 /
|
|
46
|
+
* unversioned) record. `undefined` selects the pre-binding hashing (empty-string concat is a no-op), so
|
|
47
|
+
* a v1 record hashes byte-identically to before this change. A v2 record folds in its declared
|
|
48
|
+
* `membershipDigest`.
|
|
49
|
+
*/
|
|
50
|
+
export function recordMembershipDigest(record: Pick<ClusterRecord, 'membershipVersion' | 'membershipDigest'>): string | undefined {
|
|
51
|
+
return record.membershipVersion === 2 ? record.membershipDigest : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const encoder = new TextEncoder();
|
|
55
|
+
// The template literal is what keeps a hostile part hashing as the string concatenation did: a record off
|
|
56
|
+
// the wire (a dispute's `originalRecord`, a proof) may carry no `messageHash` or `promises` at all, which
|
|
57
|
+
// the old `+` spelled "undefined", where `TextEncoder.encode(undefined)` would encode nothing. (Two
|
|
58
|
+
// adjacent missing parts the old `+` added to "NaN"; no record that reaches a signer has that shape.)
|
|
59
|
+
const utf8 = (text: string | undefined): Uint8Array => encoder.encode(`${text}`);
|
|
60
|
+
|
|
61
|
+
// NOTE: the memo is sound only because no `RepoMessage` is changed once it has been hashed: a message
|
|
62
|
+
// mutated after its first hash would go on hashing as it was, and a signature would then cover content
|
|
63
|
+
// the record no longer holds. Build a new message (`{ ...message, field }`) rather than assigning into one.
|
|
64
|
+
// NOTE: holds one more copy of each message for as long as the message object lives, which on a member
|
|
65
|
+
// is as long as it keeps the record; if member memory under large writes ever matters, drop the entry
|
|
66
|
+
// once the record is decided. Weak, so it never outlives its message; and a message received off the
|
|
67
|
+
// wire was bounded by the frame cap before it was decoded, so the memo costs no more than the record.
|
|
68
|
+
const messageBytes = new WeakMap<RepoMessage, Uint8Array>();
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The UTF-8 bytes of `canonicalJson(message)`, computed once per message object. A record's `message`
|
|
72
|
+
* is the whole pend or commit, row data included, and one delivery of a record reads it several times —
|
|
73
|
+
* its message, promise and commit hashes, and `mergeRecords`' comparison — so each of those shares these
|
|
74
|
+
* bytes rather than serializing the message again. The bytes are shared: never write to them.
|
|
75
|
+
*/
|
|
76
|
+
export function canonicalMessageBytes(message: RepoMessage): Uint8Array {
|
|
77
|
+
const held = messageBytes.get(message);
|
|
78
|
+
if (held !== undefined) return held;
|
|
79
|
+
// A record off the wire is hashed before its shape is checked, so `message` may be no object at all;
|
|
80
|
+
// such a message is never memoized (a WeakMap refuses it as a key), and `utf8` spells `canonicalJson`'s
|
|
81
|
+
// `undefined` for a value JSON cannot encode as the string preimage always did.
|
|
82
|
+
const bytes = utf8(canonicalJson(message));
|
|
83
|
+
if (typeof message === 'object' && message !== null) messageBytes.set(message, bytes);
|
|
84
|
+
return bytes;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* SHA-256 over the preimage `parts` spell, joined: the same bytes as encoding the joined string, so the
|
|
89
|
+
* signed layout of `docs/correctness.md` §2 is unchanged. UTF-8 encoding commutes with concatenation
|
|
90
|
+
* except where a part ending in a high surrogate meets one starting with a low surrogate (joined they
|
|
91
|
+
* are one character, apart two replacement characters). Every boundary in these preimages has a JSON
|
|
92
|
+
* text on one side, which begins and ends with an ASCII character, so that never happens — even for a
|
|
93
|
+
* hostile record whose `messageHash` or digest is not well-formed.
|
|
94
|
+
*/
|
|
95
|
+
async function hashParts(parts: Uint8Array[]): Promise<Uint8Array> {
|
|
96
|
+
return (await sha256.digest(concat(parts))).digest;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* `messageHash` = `base58btc(SHA256(canonicalJson(message) + digest))`.
|
|
101
|
+
*
|
|
102
|
+
* `digest` `undefined` → legacy v1 preimage (`canonicalJson(message)` only); passing the membership
|
|
103
|
+
* digest folds the peer set in (v2). An absent digest contributes no bytes, so the v1 image is
|
|
104
|
+
* byte-identical to the pre-binding implementation.
|
|
105
|
+
*/
|
|
106
|
+
export async function computeClusterMessageHash(message: RepoMessage, digest?: string): Promise<string> {
|
|
107
|
+
return base58btc.encode(await hashParts([canonicalMessageBytes(message), utf8(digest ?? '')]));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* `promiseHash` = `base64url(SHA256(messageHash + canonicalJson(message) + digest))`.
|
|
112
|
+
*
|
|
113
|
+
* `digest` `undefined` → legacy v1 preimage; passing it folds the peer set in (v2).
|
|
114
|
+
*/
|
|
115
|
+
export async function computeClusterPromiseHash(messageHash: string, message: RepoMessage, digest?: string): Promise<string> {
|
|
116
|
+
const hash = await hashParts([utf8(messageHash), canonicalMessageBytes(message), utf8(digest ?? '')]);
|
|
117
|
+
return uint8ArrayToString(hash, 'base64url');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* `commitHash` = `base64url(SHA256(messageHash + canonicalJson(message) + digest + canonicalJson(promises)))`.
|
|
122
|
+
*
|
|
123
|
+
* `digest` `undefined` → legacy v1 preimage; passing it folds the peer set in (v2). The digest sits
|
|
124
|
+
* between the message and the promises image, matching the v2 layout in `docs/correctness.md`.
|
|
125
|
+
*/
|
|
126
|
+
export async function computeClusterCommitHash(messageHash: string, message: RepoMessage, promises: Record<string, Signature>, digest?: string): Promise<string> {
|
|
127
|
+
const hash = await hashParts([utf8(messageHash), canonicalMessageBytes(message), utf8(digest ?? ''), utf8(canonicalJson(promises))]);
|
|
128
|
+
return uint8ArrayToString(hash, 'base64url');
|
|
129
|
+
}
|
package/src/cluster/structs.ts
CHANGED
|
@@ -449,6 +449,17 @@ export interface ClusterConsensusConfig {
|
|
|
449
449
|
* window. On a node, set through `clusterPolicy.readRepairQuietWindowMs`.
|
|
450
450
|
*/
|
|
451
451
|
readRepairQuietWindowMs?: number;
|
|
452
|
+
/**
|
|
453
|
+
* For 'lazy' mode: how long, in milliseconds, a consult started behind a read waits for the
|
|
454
|
+
* consults started by other reads, so that all of them ask each cohort peer in one request. The
|
|
455
|
+
* shared round sends this long after its first block joins, or at once when it names 32 blocks
|
|
456
|
+
* (one request's worth). Default 250 (`DEFAULT_READ_REPAIR_COALESCE_MS` in db-p2p); `0` sends each
|
|
457
|
+
* read's background consults on their own, as before. No read waits for it: only consults the read
|
|
458
|
+
* was already answered without join the shared round. It adds up to this long to how soon what a
|
|
459
|
+
* consult learns reaches the reads after it. See docs/transactions.md § Lazy read-repair window. On
|
|
460
|
+
* a node, set through `clusterPolicy.readRepairCoalesceMs`.
|
|
461
|
+
*/
|
|
462
|
+
readRepairCoalesceMs?: number;
|
|
452
463
|
/**
|
|
453
464
|
* How long ONE cohort peer gets to answer ONE read-path request, in milliseconds (default
|
|
454
465
|
* {@link DEFAULT_COHORT_QUERY_TIMEOUT_MS} = 1000). It sets BOTH per-peer deadlines on the read
|
|
@@ -49,8 +49,8 @@ export interface UnwillingCohortOutcome {
|
|
|
49
49
|
* True iff the quorum is short only because cohort members have not gossiped yet: it would be met if
|
|
50
50
|
* every member this check holds no contribution from turned out willing. A member that has gossiped
|
|
51
51
|
* *unwilling* counts as heard, so a cohort whose answers are in and short reports `false` — as does an
|
|
52
|
-
* unserviceable tier
|
|
53
|
-
*
|
|
52
|
+
* unserviceable tier. The cohort side may hold the request briefly for those answers instead of declining
|
|
53
|
+
* (§Cold-start instantiation).
|
|
54
54
|
*/
|
|
55
55
|
readonly awaitingMembers: boolean;
|
|
56
56
|
}
|
|
@@ -130,13 +130,13 @@ export function backoffRetryMs(attempt: number, config: BackoffConfig = DEFAULT_
|
|
|
130
130
|
// --- willingness check ---
|
|
131
131
|
|
|
132
132
|
export interface WillingnessConfig {
|
|
133
|
-
/** Cohort size `k` (drives the default quorum). Default 16. */
|
|
134
|
-
cohortSize?: number;
|
|
135
133
|
/**
|
|
136
134
|
* Members that must be willing to serve a tier for the cohort to take it on (the admission quorum,
|
|
137
|
-
* `docs/cohort-topic.md` §Admission quorum). Default: strict majority of
|
|
138
|
-
*
|
|
139
|
-
*
|
|
135
|
+
* `docs/cohort-topic.md` §Admission quorum). Default: a strict majority ({@link defaultQuorum}) of the
|
|
136
|
+
* cohort as {@link WillingnessDeps.cohortMembers} lists it at each evaluation, so a cohort smaller than
|
|
137
|
+
* `wantK` — every cohort on a network of fewer machines — admits on a majority of the members it has.
|
|
138
|
+
* Deliberately not the threshold-signature `minSigs = k − x` — see the doc for why the two differ and
|
|
139
|
+
* when to revisit the default.
|
|
140
140
|
*/
|
|
141
141
|
quorum?: number;
|
|
142
142
|
/** Load bucket at/above which a tier is shed. Default {@link DEFAULT_OVERLOAD_BUCKET} (6). */
|
|
@@ -158,11 +158,12 @@ export interface WillingnessDeps {
|
|
|
158
158
|
/** This member's own id, base64url (the `fromMember` key) — excluded from the sibling scan. */
|
|
159
159
|
selfMember: string;
|
|
160
160
|
/**
|
|
161
|
-
* The cohort's current members, base64url (the form {@link selfMember} and the view keys use), read
|
|
162
|
-
*
|
|
163
|
-
*
|
|
161
|
+
* The cohort's current members, base64url (the form {@link selfMember} and the view keys use), read once
|
|
162
|
+
* per evaluation. Its size, self counted once whether listed or not, is what the default quorum is a
|
|
163
|
+
* majority of; and it tells a member that has not gossiped yet apart from one that gossiped unwilling
|
|
164
|
+
* ({@link UnwillingCohortOutcome.awaitingMembers}).
|
|
164
165
|
*/
|
|
165
|
-
cohortMembers
|
|
166
|
+
cohortMembers: () => readonly string[];
|
|
166
167
|
/** Count of topics this member is already `primary` for at `tier` (the budget gate input). */
|
|
167
168
|
primaryTopicCount: (tier: Tier) => number;
|
|
168
169
|
/**
|
|
@@ -178,8 +179,14 @@ export function defaultQuorum(cohortSize: number): number {
|
|
|
178
179
|
return Math.floor(cohortSize / 2) + 1;
|
|
179
180
|
}
|
|
180
181
|
|
|
182
|
+
/** The cohort as one evaluation sees it: every member, self included once, and those not yet heard from. */
|
|
183
|
+
interface CohortReading {
|
|
184
|
+
readonly size: number;
|
|
185
|
+
readonly unheard: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
181
188
|
class GossipWillingnessCheck implements WillingnessCheck {
|
|
182
|
-
private readonly
|
|
189
|
+
private readonly quorumOverride: number | undefined;
|
|
183
190
|
private readonly overloadBucket: number;
|
|
184
191
|
private readonly maxPrimaryTopicsPerTier: number;
|
|
185
192
|
private readonly backoff: BackoffConfig;
|
|
@@ -187,8 +194,7 @@ class GossipWillingnessCheck implements WillingnessCheck {
|
|
|
187
194
|
|
|
188
195
|
constructor(private readonly deps: WillingnessDeps) {
|
|
189
196
|
const cfg = deps.config ?? {};
|
|
190
|
-
|
|
191
|
-
this.quorum = cfg.quorum ?? defaultQuorum(cohortSize);
|
|
197
|
+
this.quorumOverride = cfg.quorum;
|
|
192
198
|
this.overloadBucket = cfg.overloadBucket ?? DEFAULT_OVERLOAD_BUCKET;
|
|
193
199
|
this.maxPrimaryTopicsPerTier = cfg.maxPrimaryTopicsPerTier ?? 2048;
|
|
194
200
|
this.backoff = cfg.backoff ?? DEFAULT_BACKOFF_CONFIG;
|
|
@@ -205,11 +211,13 @@ class GossipWillingnessCheck implements WillingnessCheck {
|
|
|
205
211
|
const selfWilling = this.selfLiveWilling(self, tier);
|
|
206
212
|
const siblings = this.willingSiblings(tier);
|
|
207
213
|
const willingCount = siblings.length + (selfWilling ? 1 : 0);
|
|
214
|
+
const cohort = this.readCohort();
|
|
215
|
+
const quorum = this.quorumOverride ?? defaultQuorum(cohort.size);
|
|
208
216
|
|
|
209
217
|
// Quorum gate (§Tier ladder): the cohort takes on tier-T duties only if a quorum of members
|
|
210
218
|
// is willing; otherwise registrations get UnwillingCohort and the caller backs off in time.
|
|
211
|
-
if (willingCount <
|
|
212
|
-
return this.declineCohort(reg, willingCount +
|
|
219
|
+
if (willingCount < quorum) {
|
|
220
|
+
return this.declineCohort(reg, willingCount + cohort.unheard >= quorum);
|
|
213
221
|
}
|
|
214
222
|
if (selfWilling) {
|
|
215
223
|
return { kind: "accepted" };
|
|
@@ -222,15 +230,21 @@ class GossipWillingnessCheck implements WillingnessCheck {
|
|
|
222
230
|
return { kind: "unwilling_cohort", retryAfterMs: backoffRetryMs(this.attempts(reg), this.backoff), awaitingMembers };
|
|
223
231
|
}
|
|
224
232
|
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Read the cohort once: its size with self counted once (a snapshot that omits self — a root group that
|
|
235
|
+
* rotated past this node — still has self deciding), and the members other than self this check holds
|
|
236
|
+
* no gossiped contribution from.
|
|
237
|
+
*/
|
|
238
|
+
private readCohort(): CohortReading {
|
|
239
|
+
const members = new Set<string>(this.deps.cohortMembers());
|
|
240
|
+
members.add(this.deps.selfMember);
|
|
241
|
+
let unheard = 0;
|
|
242
|
+
for (const member of members) {
|
|
229
243
|
if (member !== this.deps.selfMember && this.deps.view.get(member) === undefined) {
|
|
230
|
-
unheard
|
|
244
|
+
unheard++;
|
|
231
245
|
}
|
|
232
246
|
}
|
|
233
|
-
return
|
|
247
|
+
return { size: members.size, unheard };
|
|
234
248
|
}
|
|
235
249
|
|
|
236
250
|
/** Live willingness of *this* member for `tier`: profile ∧ load-under-threshold ∧ under budget. */
|
|
@@ -244,6 +258,9 @@ class GossipWillingnessCheck implements WillingnessCheck {
|
|
|
244
258
|
|
|
245
259
|
/** Sibling member keys (base64url) whose *gossiped* willingness vector serves `tier`. */
|
|
246
260
|
private willingSiblings(tier: Tier): string[] {
|
|
261
|
+
// NOTE: counts every member the view holds a contribution from, including one no longer in `cohortMembers`,
|
|
262
|
+
// against a quorum taken over `cohortMembers`; if admissions or `unwilling_member` candidates are seen resting
|
|
263
|
+
// on members that left the cohort, count only siblings in the list `readCohort` read.
|
|
247
264
|
const out: string[] = [];
|
|
248
265
|
for (const [member, contribution] of this.deps.view.all()) {
|
|
249
266
|
if (member === this.deps.selfMember) continue; // self counted via live willingness
|