@ocap/resolver 1.31.9 → 1.32.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/esm/_virtual/rolldown_runtime.mjs +7 -0
- package/esm/api.d.mts +33 -5
- package/esm/api.mjs +939 -53
- package/esm/dashboard.d.mts +199 -0
- package/esm/dashboard.mjs +2481 -0
- package/esm/explorer.d.mts +29 -0
- package/esm/explorer.mjs +227 -0
- package/esm/follower.d.mts +277 -0
- package/esm/follower.mjs +2428 -0
- package/esm/hooks.mjs +1 -1
- package/esm/hotstuff-runtime.d.mts +271 -0
- package/esm/hotstuff-runtime.mjs +2668 -0
- package/esm/index.d.mts +79 -4
- package/esm/index.mjs +911 -174
- package/esm/node-preferences.d.mts +203 -0
- package/esm/node-preferences.mjs +1021 -0
- package/esm/replayer.d.mts +74 -0
- package/esm/replayer.mjs +394 -0
- package/esm/token-distribution.mjs +2 -2
- package/esm/token-flow.mjs +1 -1
- package/esm/types.d.mts +25 -2
- package/lib/api.cjs +941 -52
- package/lib/api.d.cts +33 -5
- package/lib/dashboard.cjs +2491 -0
- package/lib/dashboard.d.cts +199 -0
- package/lib/explorer.cjs +227 -0
- package/lib/explorer.d.cts +29 -0
- package/lib/follower.cjs +2434 -0
- package/lib/follower.d.cts +277 -0
- package/lib/hooks.cjs +1 -1
- package/lib/hotstuff-runtime.cjs +2671 -0
- package/lib/hotstuff-runtime.d.cts +271 -0
- package/lib/index.cjs +945 -174
- package/lib/index.d.cts +79 -4
- package/lib/node-preferences.cjs +1043 -0
- package/lib/node-preferences.d.cts +203 -0
- package/lib/replayer.cjs +395 -0
- package/lib/replayer.d.cts +74 -0
- package/lib/token-distribution.cjs +2 -2
- package/lib/token-flow.cjs +1 -1
- package/lib/types.d.cts +25 -2
- package/package.json +20 -14
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { DnsLookupAllFn } from "./node-preferences.cjs";
|
|
2
|
+
import { IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.cjs";
|
|
3
|
+
import { IFollowerStatusResponse, IHotStuffClusterConfig, ILedgerArchiveHead, ILedgerSegment, INodeRuntimeAdapter, IResolverContext, TFollowerSyncMode, TNodeRetentionMode, TNodeRole, TNodeWritePolicy } from "@ocap/types";
|
|
4
|
+
import { ICheckpointSignerWallet } from "@arcblock/ledger-core";
|
|
5
|
+
|
|
6
|
+
//#region src/follower.d.ts
|
|
7
|
+
|
|
8
|
+
declare const DEFAULT_FOLLOWER_POLL_INTERVAL_MS = 500;
|
|
9
|
+
declare const DEFAULT_FOLLOWER_MAX_SYNC_LAG = 20;
|
|
10
|
+
declare const DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS = 15000;
|
|
11
|
+
declare const DEFAULT_FOLLOWER_HTTP_TIMEOUT_MS = 10000;
|
|
12
|
+
interface IColdSegmentReader {
|
|
13
|
+
getSegment(chainId: string, height: number, verifyOptions?: unknown): Promise<ILedgerSegment | null>;
|
|
14
|
+
getLatestHead?(chainId: string): Promise<ILedgerArchiveHead | null>;
|
|
15
|
+
getArchiveHead?(chainId: string): Promise<ILedgerArchiveHead | null>;
|
|
16
|
+
}
|
|
17
|
+
interface ILeaderRouterLike {
|
|
18
|
+
getActiveLeaderUrl(): string | null;
|
|
19
|
+
getCandidateUrls?(): string[];
|
|
20
|
+
updateCandidatePeerUrls?(peerUrls: string[]): void;
|
|
21
|
+
getDiagnosticsSnapshot?(): {
|
|
22
|
+
activeLeaderUrl: string | null;
|
|
23
|
+
candidateCount: number;
|
|
24
|
+
candidateUrls: string[];
|
|
25
|
+
minVerifiedCheckpointHeight: number;
|
|
26
|
+
inFlightForwards: number;
|
|
27
|
+
maxConcurrentForwards: number;
|
|
28
|
+
requireSignedForwardReceipt: boolean;
|
|
29
|
+
candidates: Array<{
|
|
30
|
+
url: string;
|
|
31
|
+
reachable: boolean;
|
|
32
|
+
writable: boolean;
|
|
33
|
+
checkpointHeight: number;
|
|
34
|
+
latestSequence: number;
|
|
35
|
+
qcView: number;
|
|
36
|
+
rttMs: number | null;
|
|
37
|
+
lastProbedAtMs: number;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
forwardSendTx(args: {
|
|
41
|
+
tx: string;
|
|
42
|
+
extra?: Record<string, unknown> | string;
|
|
43
|
+
}, ctx?: IResolverContext): Promise<{
|
|
44
|
+
hash: string;
|
|
45
|
+
warning?: unknown;
|
|
46
|
+
}>;
|
|
47
|
+
probeAndPromoteLeader?(excludeBaseUrl?: string | Iterable<string>): Promise<string | null>;
|
|
48
|
+
updateTrustAnchor?(params: {
|
|
49
|
+
proposer?: string | null;
|
|
50
|
+
proposerPublicKey?: string | null;
|
|
51
|
+
}): void;
|
|
52
|
+
advanceMinVerifiedCheckpointHeight?(height: number): void;
|
|
53
|
+
setFetchImplIfDefault?(fetchFn: typeof fetch): void;
|
|
54
|
+
}
|
|
55
|
+
type TFollowerUpstreamFetchKind = 'status' | 'entries' | 'checkpoints' | 'snapshot-manifest' | 'snapshot-archive';
|
|
56
|
+
type TFollowerUpstreamFetchInterceptor = (ctx: {
|
|
57
|
+
kind: TFollowerUpstreamFetchKind;
|
|
58
|
+
url: string;
|
|
59
|
+
init?: RequestInit;
|
|
60
|
+
}, defaultFetch: typeof fetch) => Promise<Response>;
|
|
61
|
+
interface FollowerSyncServiceOptions {
|
|
62
|
+
resolver: IReplayerResolverTarget;
|
|
63
|
+
role: TNodeRole;
|
|
64
|
+
writePolicy: TNodeWritePolicy;
|
|
65
|
+
syncMode: TFollowerSyncMode;
|
|
66
|
+
upstreamUrl?: string | null;
|
|
67
|
+
peerUrls?: string[];
|
|
68
|
+
snapshotBaseUrl?: string | null;
|
|
69
|
+
coldArchiveStore?: IColdSegmentReader;
|
|
70
|
+
leaderRouter?: ILeaderRouterLike;
|
|
71
|
+
hotstuffClusterConfig?: IHotStuffClusterConfig;
|
|
72
|
+
trustedProposer?: string | null;
|
|
73
|
+
trustedProposerPublicKey?: string | null;
|
|
74
|
+
verifier?: (data: Uint8Array, signature: string, proposer: string) => Promise<boolean> | boolean;
|
|
75
|
+
allowUnauthenticated?: boolean;
|
|
76
|
+
disallowKeylessCascadedUpstream?: boolean;
|
|
77
|
+
pollIntervalMs?: number;
|
|
78
|
+
maxSyncLag?: number;
|
|
79
|
+
maxUpstreamStaleMs?: number;
|
|
80
|
+
httpTimeoutMs?: number;
|
|
81
|
+
retentionMode?: TNodeRetentionMode;
|
|
82
|
+
hotWindowEntries?: number;
|
|
83
|
+
hotWindowCheckpoints?: number;
|
|
84
|
+
witnessWallet?: ICheckpointSignerWallet;
|
|
85
|
+
witnessAddress?: string;
|
|
86
|
+
witnessSubmitUrls?: string[];
|
|
87
|
+
startPaused?: boolean;
|
|
88
|
+
artificialPollDelayMs?: number;
|
|
89
|
+
interceptUpstreamFetch?: TFollowerUpstreamFetchInterceptor;
|
|
90
|
+
fetchImpl?: typeof fetch;
|
|
91
|
+
dnsLookup?: DnsLookupAllFn;
|
|
92
|
+
env?: Record<string, string | undefined>;
|
|
93
|
+
}
|
|
94
|
+
declare function isTransientSqliteLockError(err: unknown): boolean;
|
|
95
|
+
declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
96
|
+
readonly role: TNodeRole;
|
|
97
|
+
writePolicy: TNodeWritePolicy;
|
|
98
|
+
readonly syncMode: TFollowerSyncMode;
|
|
99
|
+
readonly replayer: LedgerEntryReplayer;
|
|
100
|
+
private readonly resolver;
|
|
101
|
+
private readonly chainId;
|
|
102
|
+
private readonly upstreamUrl;
|
|
103
|
+
private readonly allowedBaseUrls;
|
|
104
|
+
private readonly coldArchiveStore?;
|
|
105
|
+
private readonly leaderRouter?;
|
|
106
|
+
private readonly hotstuffClusterConfig?;
|
|
107
|
+
private readonly hotstuffValidatorDids;
|
|
108
|
+
private trustedProposer;
|
|
109
|
+
private trustedProposerPublicKey;
|
|
110
|
+
private readonly verifier?;
|
|
111
|
+
private readonly allowUnauthenticated;
|
|
112
|
+
private readonly disallowKeylessCascadedUpstream;
|
|
113
|
+
private pollIntervalMs;
|
|
114
|
+
private maxSyncLag;
|
|
115
|
+
private readonly maxUpstreamStaleMs;
|
|
116
|
+
private readonly httpTimeoutMs;
|
|
117
|
+
private readonly retentionMode;
|
|
118
|
+
private readonly pruneController;
|
|
119
|
+
private readonly witnessWallet?;
|
|
120
|
+
private readonly witnessAddress;
|
|
121
|
+
private readonly witnessSubmitUrls;
|
|
122
|
+
private readonly attestedHeights;
|
|
123
|
+
private readonly pendingWitnessTasks;
|
|
124
|
+
private readonly fetchImpl;
|
|
125
|
+
private readonly artificialPollDelayMs;
|
|
126
|
+
private timer;
|
|
127
|
+
private syncInFlight;
|
|
128
|
+
private paused;
|
|
129
|
+
private stopped;
|
|
130
|
+
private halted;
|
|
131
|
+
private haltReason;
|
|
132
|
+
private pendingCrashWindowReconcile;
|
|
133
|
+
private initialCrashReconcileCompleted;
|
|
134
|
+
private upstreamSequence;
|
|
135
|
+
private upstreamNodeId;
|
|
136
|
+
private upstreamNodeRole;
|
|
137
|
+
private lastUpstreamSuccessAtMs;
|
|
138
|
+
private stagnantSyncCycles;
|
|
139
|
+
private lastPeerProbeAtMs;
|
|
140
|
+
private seenSignedUpstream;
|
|
141
|
+
private seenSignedStatus;
|
|
142
|
+
private stagedTofuAnchor;
|
|
143
|
+
constructor(options: FollowerSyncServiceOptions);
|
|
144
|
+
isHalted(): boolean;
|
|
145
|
+
isReconciling(): boolean;
|
|
146
|
+
getHaltReason(): string | null;
|
|
147
|
+
getConsensusMode(): 'single' | 'hotstuff';
|
|
148
|
+
getUpstreamNodeId(): string | null;
|
|
149
|
+
getUpstreamNodeRole(): TNodeRole | null;
|
|
150
|
+
pause(): void;
|
|
151
|
+
resume(): void;
|
|
152
|
+
isPaused(): boolean;
|
|
153
|
+
updateRuntimeConfig(patch: {
|
|
154
|
+
writePolicy?: TNodeWritePolicy;
|
|
155
|
+
pollIntervalMs?: number;
|
|
156
|
+
maxSyncLag?: number;
|
|
157
|
+
peerUrls?: string[];
|
|
158
|
+
}): void;
|
|
159
|
+
getRuntimeDiagnostics(options?: {
|
|
160
|
+
includePrivateTopology?: boolean;
|
|
161
|
+
}): Record<string, unknown>;
|
|
162
|
+
triggerSyncOrProbe(): Promise<Record<string, unknown>>;
|
|
163
|
+
private haltFailClosed;
|
|
164
|
+
private resolveActiveUpstreamUrl;
|
|
165
|
+
isFollowerAuthenticated(): boolean;
|
|
166
|
+
getTrustedProposer(): string | null;
|
|
167
|
+
getTrustedProposerPublicKey(): string | null;
|
|
168
|
+
isSynced(): Promise<boolean>;
|
|
169
|
+
forwardSendTx(args: {
|
|
170
|
+
tx: string;
|
|
171
|
+
extra?: Record<string, unknown> | string;
|
|
172
|
+
}, ctx?: IResolverContext): Promise<{
|
|
173
|
+
hash: string;
|
|
174
|
+
warning?: unknown;
|
|
175
|
+
}>;
|
|
176
|
+
private readLocalStateCommitHash;
|
|
177
|
+
/**
|
|
178
|
+
* Resolve the locally verified `stateRoot` (`string` or `null` when zero state-committing entries
|
|
179
|
+
* have ever run up to this checkpoint) AFTER `LedgerEntryReplayer.replayEntry` has verified every
|
|
180
|
+
* non-orphan entry via `statedb.runAsLambda` (#1711).
|
|
181
|
+
*/
|
|
182
|
+
private resolveVerifiedWitnessStateRoot;
|
|
183
|
+
/**
|
|
184
|
+
* Resolve the local StateDB commit hash to report in an `ok: false` fraud alert without ever
|
|
185
|
+
* reading untrusted upstream `segmentEntries` (#1711).
|
|
186
|
+
*/
|
|
187
|
+
private resolveLocalFraudAlertStateRoot;
|
|
188
|
+
getFollowerStatus(): Promise<IFollowerStatusResponse>;
|
|
189
|
+
private isAllowedHotStuffValidator;
|
|
190
|
+
private hasCommittedTrustAnchor;
|
|
191
|
+
private getEffectiveTrustedProposer;
|
|
192
|
+
private getEffectiveTrustedProposerPublicKey;
|
|
193
|
+
private getEffectiveSeenSignedUpstream;
|
|
194
|
+
private getEffectiveSeenSignedStatus;
|
|
195
|
+
private markSeenSignedUpstream;
|
|
196
|
+
private markSeenSignedStatus;
|
|
197
|
+
private commitStagedTofuAnchor;
|
|
198
|
+
private rethrowIfLocalStorageOrLockError;
|
|
199
|
+
private persistTrustAnchorSafe;
|
|
200
|
+
private isCheckpointAuthenticatedByProposer;
|
|
201
|
+
/**
|
|
202
|
+
* Verify that BOTH `segment.checkpoint.signature` AND `segment.checkpoint.segmentCommitmentSignature`
|
|
203
|
+
* (covering `{ chainId: this.chainId, checkpoint, entries }`) were cryptographically signed by the
|
|
204
|
+
* trusted proposer (#1711). Prevents a corrupt/MITM cold mirror or cross-chain replay from tricking
|
|
205
|
+
* an honest Witness Follower into emitting a false-positive `ok: false` fraud alert.
|
|
206
|
+
*/
|
|
207
|
+
private isColdSegmentAuthenticatedByProposer;
|
|
208
|
+
private dispatchWitnessAttestation;
|
|
209
|
+
private enqueueWitnessAttestation;
|
|
210
|
+
private checkCheckpointEquivocationAgainstLocal;
|
|
211
|
+
private buildSegmentImportOptions;
|
|
212
|
+
private verifyAndPinTrustAnchorFromStatus;
|
|
213
|
+
private verifyDidOrAccountMatchesPublicKey;
|
|
214
|
+
/**
|
|
215
|
+
* Re-hydrate `seenSignedUpstream` and any TOFU-pinned proposer trust anchor from durable `ledger`
|
|
216
|
+
* storage on process restart so `allowUnauthenticated` cannot regress after sealing signed checkpoints
|
|
217
|
+
* or pinning a verified proposer key (#1856).
|
|
218
|
+
*/
|
|
219
|
+
private hydrateDurableTrustRatchet;
|
|
220
|
+
private tagColdTransportError;
|
|
221
|
+
private fetchColdSegment;
|
|
222
|
+
private fetchColdArchiveHead;
|
|
223
|
+
private fetchAllowlistedJson;
|
|
224
|
+
/**
|
|
225
|
+
* Stage 1B: Catch up sealed `.zst` checkpoint segments from `coldArchiveStore` when available.
|
|
226
|
+
*/
|
|
227
|
+
private catchUpFromColdSegments;
|
|
228
|
+
private sealCaughtUpCheckpoints;
|
|
229
|
+
private tryEmitHotTailReplayFraudAlert;
|
|
230
|
+
private parseStrictEntryHashV2From;
|
|
231
|
+
private verifyHotTailEntriesBatchBeforeReplay;
|
|
232
|
+
/**
|
|
233
|
+
* In multi-peer unauthenticated / TOFU buffering mode (`bufferTailBeforeCommit`), pre-verify all
|
|
234
|
+
* upstream checkpoints up to `bufferedTipSeq` against `(local entries <= localSeq) + allBufferedEntries`
|
|
235
|
+
* BEFORE mutating `statedb` or `ledger` so a rogue peer serving valid entries with a forged checkpoint
|
|
236
|
+
* `stateRoot`/`txRoot` triggers clean peer failover instead of poisoning local DB (#1856).
|
|
237
|
+
*/
|
|
238
|
+
private preVerifyBufferedCheckpointsBeforeCommit;
|
|
239
|
+
/**
|
|
240
|
+
* HotStuff BFT Follower Sync (#1712):
|
|
241
|
+
* Never replays un-QC'd hot-tail entries (`latestSequence > latestCheckpoint.sequence` or 1-of-N `batchSignature`).
|
|
242
|
+
* Instead, fetches each checkpoint height `h` with a verified `2f+1` `QuorumCertificate`, collects its
|
|
243
|
+
* finalized entries, runs `verifySegmentForImport` + `dryRunVerifyEntries` BEFORE mutating any local DB,
|
|
244
|
+
* and commits `statedb` + `ledger` atomically per QC-certified checkpoint.
|
|
245
|
+
*/
|
|
246
|
+
private catchUpHotStuffQcSegmentsFromHttp;
|
|
247
|
+
private getHotLedgerEntryBySequence;
|
|
248
|
+
private findLocalCheckpointAtSequence;
|
|
249
|
+
private resolveEffectiveCheckpointStateRoot;
|
|
250
|
+
private replayCrashWindowEntry;
|
|
251
|
+
private reconcileTrailingOrphanRange;
|
|
252
|
+
/**
|
|
253
|
+
* Reconcile any crash window where finalized `ledger.sqlite` entries were durable ahead of `statedb.sqlite`
|
|
254
|
+
* (e.g., power loss between `ledger.importSegment` and `replayer.replayEntry`) before polling upstream (#1712).
|
|
255
|
+
*/
|
|
256
|
+
private reconcileFollowerCrashWindowIfNeeded;
|
|
257
|
+
/**
|
|
258
|
+
* Run one deterministic synchronization pass (cold segments + hot-tail entries + checkpoint sealing).
|
|
259
|
+
*/
|
|
260
|
+
syncOnce(): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Execute one deterministic synchronization pass even while background polling is paused (`ChainNodeTestHooks`).
|
|
263
|
+
*/
|
|
264
|
+
triggerSyncOnce(): Promise<void>;
|
|
265
|
+
private executeSyncPass;
|
|
266
|
+
/**
|
|
267
|
+
* Start background hot-tail synchronization loop (performs an initial sync pass before returning).
|
|
268
|
+
*/
|
|
269
|
+
start(): Promise<void>;
|
|
270
|
+
flushWitnessTasks(): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Stop background polling and wait for any in-flight replay transaction to finish cleanly.
|
|
273
|
+
*/
|
|
274
|
+
close(): Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
export { DEFAULT_FOLLOWER_HTTP_TIMEOUT_MS, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FollowerSyncService, FollowerSyncServiceOptions, IColdSegmentReader, ILeaderRouterLike, TFollowerUpstreamFetchInterceptor, TFollowerUpstreamFetchKind, isTransientSqliteLockError };
|
package/lib/hooks.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_package = require('./package.cjs');
|
|
3
|
-
let _arcblock_did_util = require("@arcblock/did-util");
|
|
4
3
|
let _ocap_util = require("@ocap/util");
|
|
4
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
5
5
|
let debug = require("debug");
|
|
6
6
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
7
7
|
let lodash_merge = require("lodash/merge");
|