@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.
Files changed (42) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +7 -0
  2. package/esm/api.d.mts +33 -5
  3. package/esm/api.mjs +939 -53
  4. package/esm/dashboard.d.mts +199 -0
  5. package/esm/dashboard.mjs +2481 -0
  6. package/esm/explorer.d.mts +29 -0
  7. package/esm/explorer.mjs +227 -0
  8. package/esm/follower.d.mts +277 -0
  9. package/esm/follower.mjs +2428 -0
  10. package/esm/hooks.mjs +1 -1
  11. package/esm/hotstuff-runtime.d.mts +271 -0
  12. package/esm/hotstuff-runtime.mjs +2668 -0
  13. package/esm/index.d.mts +79 -4
  14. package/esm/index.mjs +911 -174
  15. package/esm/node-preferences.d.mts +203 -0
  16. package/esm/node-preferences.mjs +1021 -0
  17. package/esm/replayer.d.mts +74 -0
  18. package/esm/replayer.mjs +394 -0
  19. package/esm/token-distribution.mjs +2 -2
  20. package/esm/token-flow.mjs +1 -1
  21. package/esm/types.d.mts +25 -2
  22. package/lib/api.cjs +941 -52
  23. package/lib/api.d.cts +33 -5
  24. package/lib/dashboard.cjs +2491 -0
  25. package/lib/dashboard.d.cts +199 -0
  26. package/lib/explorer.cjs +227 -0
  27. package/lib/explorer.d.cts +29 -0
  28. package/lib/follower.cjs +2434 -0
  29. package/lib/follower.d.cts +277 -0
  30. package/lib/hooks.cjs +1 -1
  31. package/lib/hotstuff-runtime.cjs +2671 -0
  32. package/lib/hotstuff-runtime.d.cts +271 -0
  33. package/lib/index.cjs +945 -174
  34. package/lib/index.d.cts +79 -4
  35. package/lib/node-preferences.cjs +1043 -0
  36. package/lib/node-preferences.d.cts +203 -0
  37. package/lib/replayer.cjs +395 -0
  38. package/lib/replayer.d.cts +74 -0
  39. package/lib/token-distribution.cjs +2 -2
  40. package/lib/token-flow.cjs +1 -1
  41. package/lib/types.d.cts +25 -2
  42. package/package.json +20 -14
@@ -0,0 +1,271 @@
1
+ import { IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.cjs";
2
+ import { ICheckpoint, IConsensusCommitter, IConsensusProposalSlot, IFollowerStatusResponse, IHotStuffClusterConfig, ILedgerEntry, INodeRuntimeAdapter, IQuorumCertificate, IResolverContext, TNodeWritePolicy } from "@ocap/types";
3
+ import { ICheckpointSignerWallet, IHotStuffValidatorEndpoint, IHotStuffVoterLockRecord, IHotStuffVoterStateStore, ITimeoutCertificate, LeaderRouter } from "@arcblock/ledger-core";
4
+ import { CustomError } from "@ocap/util/lib/error";
5
+
6
+ //#region src/hotstuff-runtime.d.ts
7
+
8
+ type TConsensusAbortCode = 'CONSENSUS_ABORTED' | 'CONSENSUS_NOT_LEADER' | 'CONSENSUS_VIEW_CHANGING' | 'CONSENSUS_QUORUM_LOST';
9
+ declare class ConsensusAbortError extends CustomError {
10
+ readonly isConsensusAbort = true;
11
+ readonly code: TConsensusAbortCode;
12
+ constructor(code: TConsensusAbortCode, message: string);
13
+ }
14
+ interface IHotStuffRuntimeStateSnapshot {
15
+ chainId: string;
16
+ voterDid: string;
17
+ currentView: number;
18
+ lockRecord: IHotStuffVoterLockRecord | null;
19
+ lockedQC: IQuorumCertificate | null;
20
+ highQC: IQuorumCertificate | null;
21
+ lastTC: ITimeoutCertificate | null;
22
+ }
23
+ interface IHotStuffRuntimeStateStore extends IHotStuffVoterStateStore {
24
+ loadRuntimeState?(chainId: string, voterDid: string): Promise<IHotStuffRuntimeStateSnapshot | null>;
25
+ saveRuntimeState?(params: {
26
+ chainId: string;
27
+ voterDid: string;
28
+ currentView?: number;
29
+ lockedQC?: IQuorumCertificate | null;
30
+ highQC?: IQuorumCertificate | null;
31
+ lastTC?: ITimeoutCertificate | null;
32
+ pruneUncommittedUpToHeight?: number;
33
+ updatedAt?: number;
34
+ }): Promise<void>;
35
+ saveUncommittedProposalEntries?(params: {
36
+ chainId: string;
37
+ voterDid: string;
38
+ checkpointHash: string;
39
+ height: number;
40
+ entries: ILedgerEntry[];
41
+ checkpoint?: ICheckpoint;
42
+ updatedAt?: number;
43
+ }): Promise<void>;
44
+ getUncommittedProposalEntries?(chainId: string, voterDid: string, checkpointHash: string): Promise<ILedgerEntry[] | null>;
45
+ getUncommittedProposalCheckpoint?(chainId: string, voterDid: string, checkpointHash: string): Promise<ICheckpoint | null>;
46
+ }
47
+ interface IHotStuffNetworkInterceptorContext {
48
+ fromDid: string;
49
+ toDid: string;
50
+ method: string;
51
+ pathWithQuery: string;
52
+ url: string;
53
+ }
54
+ interface HotStuffNodeRuntimeOptions {
55
+ resolver: IReplayerResolverTarget & {
56
+ sendTx?: (args: {
57
+ tx: string;
58
+ extra?: Record<string, unknown> | string;
59
+ }, ctx?: IResolverContext) => Promise<{
60
+ hash: string;
61
+ warning?: unknown;
62
+ }>;
63
+ };
64
+ validatorDid: string;
65
+ validatorWallet: ICheckpointSignerWallet;
66
+ validatorPublicKey: string;
67
+ validators: IHotStuffValidatorEndpoint[];
68
+ quorumThreshold?: number;
69
+ consensusBindHost: string;
70
+ consensusPort: number;
71
+ allowPublicBind?: boolean;
72
+ allowPrivateHttpPeers?: boolean;
73
+ writePolicy?: TNodeWritePolicy;
74
+ stateStore?: IHotStuffRuntimeStateStore;
75
+ leaderRouter?: LeaderRouter;
76
+ proposalTimeoutMs?: number;
77
+ httpTimeoutMs?: number;
78
+ heartbeatIntervalMs?: number;
79
+ viewTimeoutMs?: number;
80
+ maxEmptyViewMs?: number;
81
+ quorumLeaseTimeoutMs?: number;
82
+ startupQuorumGraceMs?: number;
83
+ fetchImpl?: typeof fetch;
84
+ /** Optional deterministic fault-injection hook for multi-node chaos/partition tests */
85
+ onOutboundConsensusRequest?: (ctx: IHotStuffNetworkInterceptorContext) => void | Promise<void>;
86
+ /** Optional hook invoked after each replica Phase-1 PrepareVote arrives during leader proposal fan-out */
87
+ onLeaderReplicaVoteReceived?: (info: {
88
+ leaderDid: string;
89
+ voterDid: string;
90
+ viewNumber: number;
91
+ height: number;
92
+ voteCountIncludingSelf: number;
93
+ }) => void | Promise<void>;
94
+ /** Optional hook invoked after each replica Phase-2 CommitVote arrives during leader precommit fan-out */
95
+ onLeaderReplicaPrecommitReceived?: (info: {
96
+ leaderDid: string;
97
+ voterDid: string;
98
+ viewNumber: number;
99
+ height: number;
100
+ commitVoteCountIncludingSelf: number;
101
+ }) => void | Promise<void>;
102
+ }
103
+ declare class HotStuffNodeRuntime implements INodeRuntimeAdapter, IConsensusCommitter {
104
+ readonly role: "validator";
105
+ writePolicy: TNodeWritePolicy;
106
+ readonly replayer: LedgerEntryReplayer;
107
+ readonly clusterConfig: IHotStuffClusterConfig;
108
+ private readonly resolver;
109
+ private readonly chainId;
110
+ private readonly selfDid;
111
+ private readonly validatorWallet;
112
+ private readonly signDigest;
113
+ private readonly trustAnchorVerify;
114
+ private readonly validators;
115
+ private readonly peerValidators;
116
+ private readonly validatorMap;
117
+ private readonly consensusBindHost;
118
+ private readonly configuredConsensusPort;
119
+ private readonly stateStore;
120
+ private readonly leaderRouter;
121
+ private readonly proposalTimeoutMs;
122
+ private readonly httpTimeoutMs;
123
+ private readonly heartbeatIntervalMs;
124
+ private readonly baseViewTimeoutMs;
125
+ private readonly maxEmptyViewMs;
126
+ private readonly quorumLeaseTimeoutMs;
127
+ private readonly startupQuorumGraceMs;
128
+ private readonly fetchImpl;
129
+ private readonly onOutboundConsensusRequest?;
130
+ private readonly onLeaderReplicaVoteReceived?;
131
+ private readonly onLeaderReplicaPrecommitReceived?;
132
+ private server;
133
+ private boundPort;
134
+ private heartbeatTimer;
135
+ private viewTimer;
136
+ private mutexTail;
137
+ private inConsensusLock;
138
+ private startedAtMs;
139
+ private stopped;
140
+ private halted;
141
+ private haltReason;
142
+ private currentView;
143
+ private lastSelfVotedView;
144
+ private lastSelfPreparedView;
145
+ private currentViewEnteredAtMs;
146
+ private pendingDemandForView;
147
+ private consecutiveViewTimeouts;
148
+ private highQC;
149
+ private lockedQC;
150
+ private lastTC;
151
+ private quorumLeaseValid;
152
+ private quorumContactObserved;
153
+ private unleadableView;
154
+ private activeProposalSlot;
155
+ private pendingBroadcastSegments;
156
+ private readonly peerLastSeenAtMs;
157
+ private readonly replayCache;
158
+ private readonly collectedTimeoutsByView;
159
+ private readonly demandSendersByView;
160
+ private readonly viewAdvanceWaiters;
161
+ constructor(options: HotStuffNodeRuntimeOptions);
162
+ getConsensusMode(): 'hotstuff';
163
+ getConsensusView(): number;
164
+ getHighQC(): IQuorumCertificate | null;
165
+ getLockedQC(): IQuorumCertificate | null;
166
+ getLastTC(): ITimeoutCertificate | null;
167
+ getListeningPort(): number;
168
+ getConsensusBaseUrl(): string;
169
+ getConsensusCommitter(): IConsensusCommitter;
170
+ isHalted(): boolean;
171
+ getHaltReason(): string | null;
172
+ updateRuntimeConfig(patch: {
173
+ writePolicy?: TNodeWritePolicy;
174
+ pollIntervalMs?: number;
175
+ maxSyncLag?: number;
176
+ peerUrls?: string[];
177
+ }): void;
178
+ getRuntimeDiagnostics(options?: {
179
+ includePrivateTopology?: boolean;
180
+ }): Record<string, unknown>;
181
+ triggerSyncOrProbe(): Promise<Record<string, unknown>>;
182
+ private haltFailClosed;
183
+ private computeLivePeerCount;
184
+ private refreshQuorumLease;
185
+ private recordAuthenticatedPeerContact;
186
+ private hasSpentTurnInView;
187
+ private advanceCurrentViewTo;
188
+ private shouldSuppressHeartbeatKeepalive;
189
+ shouldHandleWriteLocally(): boolean;
190
+ isSynced(): Promise<boolean>;
191
+ getFollowerStatus(): Promise<IFollowerStatusResponse>;
192
+ private triggerClientDemandViewChange;
193
+ forwardSendTx(args: {
194
+ tx: string;
195
+ extra?: Record<string, unknown> | string;
196
+ }, ctx?: IResolverContext): Promise<{
197
+ hash: string;
198
+ warning?: unknown;
199
+ }>;
200
+ private runExclusive;
201
+ /**
202
+ * Serialized local leader execution wrapper (#1712):
203
+ * 1. Acquires `runExclusive` so `SqliteStateDB` never overlaps dry-run/replay transactions.
204
+ * 2. Catches up finalized segments if behind `highQC`, and recovers any pending `lastTC.lockedCheckpoint`
205
+ * BEFORE `executor.execute` opens `statedb.runAsLambda`.
206
+ * 3. Asserts active view leadership + valid quorum lease.
207
+ * 4. Runs `fn()` (`executor.execute`), then broadcasts `/consensus/commit` after releasing `runExclusive`.
208
+ */
209
+ executeWithConsensusLock<T>(fn: () => Promise<T>): Promise<T>;
210
+ private ensureReadyToLeadLocked;
211
+ prepareProposalSlot(): Promise<IConsensusProposalSlot>;
212
+ commitStagedEntry(params: {
213
+ txInput: {
214
+ txHash: string;
215
+ from: string;
216
+ nonce: number;
217
+ pk: string;
218
+ signature: string;
219
+ txRaw: string;
220
+ tx: Record<string, unknown>;
221
+ txType: string;
222
+ timestamp: number;
223
+ chainId: string;
224
+ txExtra?: Record<string, unknown>;
225
+ };
226
+ sequence: number;
227
+ stateCommitHash: string;
228
+ timestampMs: number;
229
+ }): Promise<ILedgerEntry>;
230
+ private collectVotesAndFormQC;
231
+ private hasValidCheckpointSegmentCommitment;
232
+ private recoverLockedCheckpointLocked;
233
+ private broadcastCommittedSegments;
234
+ private tryAbsorbRemoteQC;
235
+ private isBetterTimeoutCertificate;
236
+ private markCurrentViewUnleadableAndScheduleTimeout;
237
+ private tryAbsorbRemoteTC;
238
+ private catchUpToHeightLocked;
239
+ private reconcileCrashWindowLocked;
240
+ private signHttpEnvelope;
241
+ private isReplayKeyActive;
242
+ private pruneAndCheckReplayKey;
243
+ private precheckIncomingHttpAuthHeaders;
244
+ private verifyIncomingHttpAuth;
245
+ private sendAuthenticatedJsonResponse;
246
+ private sendConsensusJson;
247
+ private handleConsensusHttpRequest;
248
+ private buildConsensusStatus;
249
+ private readFinalizedSegmentsRange;
250
+ private handleHeartbeat;
251
+ private handleDemand;
252
+ private handlePropose;
253
+ private handlePrecommit;
254
+ private handleCommit;
255
+ private currentEffectiveViewTimeoutMs;
256
+ private scheduleViewTimeout;
257
+ private clearTimers;
258
+ private sendHeartbeatsTick;
259
+ private onViewTimerExpired;
260
+ private recordTimeoutMessageAndMaybeAggregateLocked;
261
+ private applyVerifiedTimeoutCertificateLocked;
262
+ private broadcastNewViewAndMaybeRecover;
263
+ private maybeRecoverLockedCheckpointAsNewLeader;
264
+ private handleTimeoutMessage;
265
+ private handleNewView;
266
+ private probePeersOnStartup;
267
+ start(): Promise<void>;
268
+ close(): Promise<void>;
269
+ }
270
+ //#endregion
271
+ export { ConsensusAbortError, HotStuffNodeRuntime, HotStuffNodeRuntimeOptions, IHotStuffNetworkInterceptorContext, IHotStuffRuntimeStateSnapshot, IHotStuffRuntimeStateStore, TConsensusAbortCode };