@ocap/chain-node 0.0.0-stage → 1.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -2
- package/esm/access-log.d.mts +34 -0
- package/esm/access-log.mjs +71 -0
- package/esm/config-consistency.d.mts +59 -0
- package/esm/config-consistency.mjs +220 -0
- package/esm/env.d.mts +32 -0
- package/esm/env.mjs +218 -0
- package/esm/follower-config.d.mts +25 -0
- package/esm/follower-config.mjs +57 -0
- package/esm/index.d.mts +7 -0
- package/esm/index.mjs +7 -0
- package/esm/standalone-env.d.mts +92 -0
- package/esm/standalone-env.mjs +152 -0
- package/esm/start-chain-node.d.mts +14 -0
- package/esm/start-chain-node.mjs +1107 -0
- package/esm/test-hooks-token.d.mts +12 -0
- package/esm/test-hooks-token.mjs +21 -0
- package/esm/testing.d.mts +13 -0
- package/esm/testing.mjs +23 -0
- package/esm/types.d.mts +310 -0
- package/esm/types.mjs +1 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/access-log.cjs +73 -0
- package/lib/access-log.d.cts +34 -0
- package/lib/config-consistency.cjs +227 -0
- package/lib/config-consistency.d.cts +59 -0
- package/lib/env.cjs +221 -0
- package/lib/env.d.cts +32 -0
- package/lib/follower-config.cjs +63 -0
- package/lib/follower-config.d.cts +25 -0
- package/lib/index.cjs +32 -0
- package/lib/index.d.cts +7 -0
- package/lib/standalone-env.cjs +165 -0
- package/lib/standalone-env.d.cts +92 -0
- package/lib/start-chain-node.cjs +1116 -0
- package/lib/start-chain-node.d.cts +14 -0
- package/lib/test-hooks-token.cjs +24 -0
- package/lib/test-hooks-token.d.cts +12 -0
- package/lib/testing.cjs +23 -0
- package/lib/testing.d.cts +13 -0
- package/lib/types.cjs +0 -0
- package/lib/types.d.cts +310 -0
- package/package.json +78 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/test-hooks-token.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Private non-global symbol guarding `ChainNodeTestHooks` (P3-2).
|
|
4
|
+
*
|
|
5
|
+
* Intentionally created via `Symbol(...)` (NEVER `Symbol.for(...)`) and unexported from the
|
|
6
|
+
* `@ocap/chain-node` barrel so JSON/CLI/env payloads and untrusted callers cannot forge it.
|
|
7
|
+
*/
|
|
8
|
+
declare const CHAIN_NODE_TEST_HOOKS_TOKEN: unique symbol;
|
|
9
|
+
declare function assertNotProductionForTestHooks(): void;
|
|
10
|
+
declare function assertValidChainNodeTestHooks(candidate: unknown): void;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CHAIN_NODE_TEST_HOOKS_TOKEN, assertNotProductionForTestHooks, assertValidChainNodeTestHooks };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
+
|
|
3
|
+
//#region src/test-hooks-token.ts
|
|
4
|
+
/**
|
|
5
|
+
* Private non-global symbol guarding `ChainNodeTestHooks` (P3-2).
|
|
6
|
+
*
|
|
7
|
+
* Intentionally created via `Symbol(...)` (NEVER `Symbol.for(...)`) and unexported from the
|
|
8
|
+
* `@ocap/chain-node` barrel so JSON/CLI/env payloads and untrusted callers cannot forge it.
|
|
9
|
+
*/
|
|
10
|
+
const CHAIN_NODE_TEST_HOOKS_TOKEN = Symbol("@ocap/chain-node/test-hooks-token");
|
|
11
|
+
function assertNotProductionForTestHooks() {
|
|
12
|
+
if (process.env.NODE_ENV === "production") throw new CustomError("FORBIDDEN_IN_PRODUCTION", "ChainNodeTestHooks cannot be enabled when NODE_ENV=production");
|
|
13
|
+
}
|
|
14
|
+
function assertValidChainNodeTestHooks(candidate) {
|
|
15
|
+
if (candidate === void 0) return;
|
|
16
|
+
assertNotProductionForTestHooks();
|
|
17
|
+
if (!candidate || typeof candidate !== "object" || candidate[CHAIN_NODE_TEST_HOOKS_TOKEN] !== true) throw new CustomError("SECURITY_VIOLATION", "Invalid ChainNodeTestHooks token: must be created via createChainNodeTestHooks from @ocap/chain-node/testing");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CHAIN_NODE_TEST_HOOKS_TOKEN, assertNotProductionForTestHooks, assertValidChainNodeTestHooks };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChainNodeTestHooks, ChainNodeTestHooksInput, FollowerSyncTestController, FollowerUpstreamInterceptorContext } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/testing.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Construct a token-stamped `ChainNodeTestHooks` object for deterministic tests (`@ocap/chain-node/testing`).
|
|
7
|
+
*
|
|
8
|
+
* Hard-blocked when `process.env.NODE_ENV === 'production'` (`FORBIDDEN_IN_PRODUCTION`), and stamped with a
|
|
9
|
+
* private non-global `Symbol` (`P3-2`) re-verified inside `startChainNode` Step 1.
|
|
10
|
+
*/
|
|
11
|
+
declare function createChainNodeTestHooks(input?: ChainNodeTestHooksInput): ChainNodeTestHooks;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { type ChainNodeTestHooks, type ChainNodeTestHooksInput, type FollowerSyncTestController, type FollowerUpstreamInterceptorContext, createChainNodeTestHooks };
|
package/esm/testing.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CHAIN_NODE_TEST_HOOKS_TOKEN, assertNotProductionForTestHooks } from "./test-hooks-token.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/testing.ts
|
|
4
|
+
/**
|
|
5
|
+
* Construct a token-stamped `ChainNodeTestHooks` object for deterministic tests (`@ocap/chain-node/testing`).
|
|
6
|
+
*
|
|
7
|
+
* Hard-blocked when `process.env.NODE_ENV === 'production'` (`FORBIDDEN_IN_PRODUCTION`), and stamped with a
|
|
8
|
+
* private non-global `Symbol` (`P3-2`) re-verified inside `startChainNode` Step 1.
|
|
9
|
+
*/
|
|
10
|
+
function createChainNodeTestHooks(input = {}) {
|
|
11
|
+
assertNotProductionForTestHooks();
|
|
12
|
+
const stamped = { ...input };
|
|
13
|
+
Object.defineProperty(stamped, CHAIN_NODE_TEST_HOOKS_TOKEN, {
|
|
14
|
+
value: true,
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: false,
|
|
17
|
+
writable: false
|
|
18
|
+
});
|
|
19
|
+
return Object.freeze(stamped);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createChainNodeTestHooks };
|
package/esm/types.d.mts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { FutureTimestampGuardConfig, TChainConfigCheckMode } from "./standalone-env.mjs";
|
|
2
|
+
import { CHAIN_NODE_TEST_HOOKS_TOKEN } from "./test-hooks-token.mjs";
|
|
3
|
+
import { AnchorPublisher, ICheckpointSignerWallet, IHotStuffRuntimeValidatorMember, ILedgerHealth, INodeRoleConfig, ISegmentArchiveStore, IWriterLeaseConfig, Ledger, LedgerConfig } from "@arcblock/ledger-core";
|
|
4
|
+
import { SqliteLedgerStorage } from "@arcblock/ledger-sqlite";
|
|
5
|
+
import SqliteIndexDB from "@ocap/indexdb-sqlite";
|
|
6
|
+
import OCAPResolver, { FollowerSyncService, HotStuffNodeRuntime, HotStuffNodeRuntimeOptions, IColdSegmentReader, INodeMaintenanceController, NodePreferencesManager, TFollowerUpstreamFetchKind } from "@ocap/resolver";
|
|
7
|
+
import SqliteStateDB from "@ocap/statedb-sqlite";
|
|
8
|
+
import { SqliteTrustedStorage } from "@ocap/trusted-storage";
|
|
9
|
+
import express from "express";
|
|
10
|
+
import { IChainConfig, IPipelineLogger, TFollowerSyncMode, TNodeWritePolicy } from "@ocap/types";
|
|
11
|
+
import http from "node:http";
|
|
12
|
+
|
|
13
|
+
//#region src/types.d.ts
|
|
14
|
+
type ILedgerLeaseOptions = IWriterLeaseConfig;
|
|
15
|
+
type ILedgerHealthStatus = ILedgerHealth;
|
|
16
|
+
type TNodeRetentionMode = INodeRoleConfig['retentionMode'];
|
|
17
|
+
type ChainNodeSegmentPublisher = NonNullable<LedgerConfig['segmentPublisher']> & {
|
|
18
|
+
getArchiveStore?: () => ISegmentArchiveStore | undefined;
|
|
19
|
+
};
|
|
20
|
+
interface TrustedAccountConfig {
|
|
21
|
+
address: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Consensus / proposer signer configuration supporting `ed25519`, standard `secp256k1` (`did:abt:z...`),
|
|
26
|
+
* and Ethereum `0x...` `secp256k1` accounts.
|
|
27
|
+
*/
|
|
28
|
+
interface ChainNodeSignerConfig {
|
|
29
|
+
address: string;
|
|
30
|
+
secretKey: string;
|
|
31
|
+
publicKey?: string;
|
|
32
|
+
keyType?: 'ed25519' | 'secp256k1' | 'eth';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Public-key-only proposer configuration for legacy single-validator chains whose moderator secretKey
|
|
36
|
+
* is held offline (e.g., Blocklet Server `BLOCKLET_APP_PPK` before `CHAIN_CONSENSUS_SK` cutover).
|
|
37
|
+
* Produces unsigned local checkpoints while `storage.trustedStorageSecretKey` signs `trusted.sqlite`.
|
|
38
|
+
*/
|
|
39
|
+
interface PublicKeyOnlyValidatorSignerConfig {
|
|
40
|
+
address: string;
|
|
41
|
+
publicKey?: string;
|
|
42
|
+
secretKey?: undefined;
|
|
43
|
+
keyType?: 'ed25519' | 'secp256k1' | 'eth';
|
|
44
|
+
}
|
|
45
|
+
type ValidatorSignerConfig = ChainNodeSignerConfig | PublicKeyOnlyValidatorSignerConfig;
|
|
46
|
+
type ChainNodeRoleConfig = ValidatorRoleConfig | FollowerRoleConfig | HotStuffValidatorRoleConfig;
|
|
47
|
+
interface ValidatorRoleConfig {
|
|
48
|
+
kind: 'validator';
|
|
49
|
+
signer: ValidatorSignerConfig;
|
|
50
|
+
retentionMode?: TNodeRetentionMode;
|
|
51
|
+
hotWindowEntries?: number;
|
|
52
|
+
hotWindowCheckpoints?: number;
|
|
53
|
+
snapshotBaseUrl?: string | null;
|
|
54
|
+
witnessQuorum?: number;
|
|
55
|
+
trustedWitnesses?: Record<string, string> | string[];
|
|
56
|
+
witnessSubmitUrls?: string[];
|
|
57
|
+
anchorWebhookUrl?: string | null;
|
|
58
|
+
}
|
|
59
|
+
interface FollowerRoleConfig {
|
|
60
|
+
kind: 'follower';
|
|
61
|
+
/** `'reject'` (`FOLLOWER_READ_ONLY`) | `'forward'` (single-hop forward to Leader via `LeaderRouter`) */
|
|
62
|
+
writePolicy: TNodeWritePolicy;
|
|
63
|
+
upstreamChainUrl: string | null;
|
|
64
|
+
clusterPeerUrls?: string[];
|
|
65
|
+
snapshotBaseUrl?: string | null;
|
|
66
|
+
snapshotPrefix?: string;
|
|
67
|
+
trustedProposer?: string | null;
|
|
68
|
+
trustedProposerPublicKey?: string | null;
|
|
69
|
+
hotstuffValidators?: IHotStuffRuntimeValidatorMember[];
|
|
70
|
+
hotstuffQuorumThreshold?: number;
|
|
71
|
+
/** Whether `127.0.0.1` / RFC1918 private peers are allowed (`false` by default for SSRF safety) */
|
|
72
|
+
allowPrivatePeers?: boolean;
|
|
73
|
+
/** Reject cascaded keyless/unsigned follower upstreams with `UPSTREAM_CASCADED_FORBIDDEN` */
|
|
74
|
+
disallowKeylessCascadedUpstream?: boolean;
|
|
75
|
+
allowUnauthenticatedBootstrap?: boolean;
|
|
76
|
+
syncMode?: TFollowerSyncMode;
|
|
77
|
+
pollIntervalMs?: number;
|
|
78
|
+
maxSyncLag?: number;
|
|
79
|
+
maxUpstreamStaleMs?: number;
|
|
80
|
+
retentionMode?: TNodeRetentionMode;
|
|
81
|
+
hotWindowEntries?: number;
|
|
82
|
+
hotWindowCheckpoints?: number;
|
|
83
|
+
witnessWallet?: ICheckpointSignerWallet;
|
|
84
|
+
witnessSubmitUrls?: string[];
|
|
85
|
+
/** Optional Standby consensus signer when running a keyed Standby node */
|
|
86
|
+
signer?: ChainNodeSignerConfig;
|
|
87
|
+
/** Optional explicit runtime role (`'follower'` default or `'standby'`) */
|
|
88
|
+
runtimeRole?: 'follower' | 'standby';
|
|
89
|
+
}
|
|
90
|
+
interface HotStuffValidatorRoleConfig {
|
|
91
|
+
kind: 'hotstuff';
|
|
92
|
+
signer: ChainNodeSignerConfig;
|
|
93
|
+
validators: IHotStuffRuntimeValidatorMember[];
|
|
94
|
+
quorumThreshold?: number;
|
|
95
|
+
consensusBindHost: string;
|
|
96
|
+
consensusPort: number;
|
|
97
|
+
allowPublicConsensusBind?: boolean;
|
|
98
|
+
writePolicy?: TNodeWritePolicy;
|
|
99
|
+
allowPrivatePeers?: boolean;
|
|
100
|
+
retentionMode?: TNodeRetentionMode;
|
|
101
|
+
hotWindowEntries?: number;
|
|
102
|
+
hotWindowCheckpoints?: number;
|
|
103
|
+
snapshotBaseUrl?: string | null;
|
|
104
|
+
witnessQuorum?: number;
|
|
105
|
+
trustedWitnesses?: Record<string, string> | string[];
|
|
106
|
+
witnessSubmitUrls?: string[];
|
|
107
|
+
}
|
|
108
|
+
interface ChainAppHookContext {
|
|
109
|
+
nodeId: string;
|
|
110
|
+
dataDir: string;
|
|
111
|
+
role: ChainNodeRoleConfig['kind'];
|
|
112
|
+
config: IChainConfig;
|
|
113
|
+
statedb: SqliteStateDB;
|
|
114
|
+
indexdb: SqliteIndexDB;
|
|
115
|
+
ledger: Ledger;
|
|
116
|
+
resolver: OCAPResolver;
|
|
117
|
+
preferencesManager: NodePreferencesManager;
|
|
118
|
+
maintenanceController: INodeMaintenanceController;
|
|
119
|
+
}
|
|
120
|
+
interface ChainProfileBase {
|
|
121
|
+
/** Optional explicit nodeId (otherwise loaded/persisted in `<dataDir>/.node-id`) */
|
|
122
|
+
nodeId?: string;
|
|
123
|
+
/** Exclusive node data directory (`statedb.sqlite`, `ledger.sqlite`, `indexdb.sqlite`, `trusted.sqlite`, `.node-id`) */
|
|
124
|
+
dataDir: string;
|
|
125
|
+
http: {
|
|
126
|
+
/** Default `'127.0.0.1'`; pass `'0.0.0.0'` explicitly to listen on all interfaces */
|
|
127
|
+
host?: string;
|
|
128
|
+
/** Pass `0` for OS-assigned ephemeral port; `restart()` reuses the bound port automatically */
|
|
129
|
+
port: number;
|
|
130
|
+
corsOrigins?: string | string[] | boolean;
|
|
131
|
+
drainTimeoutMs?: number;
|
|
132
|
+
enableDashboard?: boolean;
|
|
133
|
+
enableExplorer?: boolean;
|
|
134
|
+
explorerDistDir?: string;
|
|
135
|
+
enableAccessLog?: boolean;
|
|
136
|
+
adminEnv?: Record<string, string | undefined>;
|
|
137
|
+
onGraphqlError?: (err: Error & {
|
|
138
|
+
originalError?: Error;
|
|
139
|
+
}) => void;
|
|
140
|
+
};
|
|
141
|
+
storage?: {
|
|
142
|
+
statedbPath?: string;
|
|
143
|
+
ledgerPath?: string;
|
|
144
|
+
indexdbPath?: string;
|
|
145
|
+
trustedPath?: string;
|
|
146
|
+
entryHashV2?: 'auto' | 'activate';
|
|
147
|
+
walAutoCheckpoint?: number;
|
|
148
|
+
indexWalAutoCheckpoint?: number;
|
|
149
|
+
lease?: ILedgerLeaseOptions | false;
|
|
150
|
+
/** Defaults to `role.signer.secretKey` on Validator/HotStuff; Keyless Follower uses `.follower-trusted.key` */
|
|
151
|
+
trustedStorageSecretKey?: string;
|
|
152
|
+
legacyTrustedSecretKeys?: string[];
|
|
153
|
+
trustedRetryLimit?: number;
|
|
154
|
+
trustedAllowLegacySignatures?: boolean;
|
|
155
|
+
};
|
|
156
|
+
checkpoint?: {
|
|
157
|
+
batchSize?: number;
|
|
158
|
+
timeoutMs?: number;
|
|
159
|
+
auto?: boolean;
|
|
160
|
+
periodicTimer?: boolean;
|
|
161
|
+
timerIntervalMs?: number;
|
|
162
|
+
};
|
|
163
|
+
da?: {
|
|
164
|
+
segmentPublisher?: ChainNodeSegmentPublisher | null;
|
|
165
|
+
coldArchiveReader?: IColdSegmentReader | null;
|
|
166
|
+
anchorPublisher?: AnchorPublisher | null;
|
|
167
|
+
env?: Record<string, string | undefined>;
|
|
168
|
+
};
|
|
169
|
+
genesisTime?: string;
|
|
170
|
+
reservedSymbols?: string[];
|
|
171
|
+
blacklist?: {
|
|
172
|
+
dumpPath?: string;
|
|
173
|
+
dumpIntervalMs?: number;
|
|
174
|
+
staticBlockedAddresses?: string[];
|
|
175
|
+
getTrustedAccounts?: () => Promise<TrustedAccountConfig[]> | TrustedAccountConfig[];
|
|
176
|
+
admissionBlockedCheck?: (addr: string) => boolean;
|
|
177
|
+
admissionReservedSymbolCheck?: (sym: string) => boolean;
|
|
178
|
+
};
|
|
179
|
+
txQueue?: {
|
|
180
|
+
maxRequest?: number;
|
|
181
|
+
concurrent?: number;
|
|
182
|
+
timeoutMs?: number;
|
|
183
|
+
};
|
|
184
|
+
maintenance?: {
|
|
185
|
+
pruneIndexDbFn?: (opts: {
|
|
186
|
+
findOnly?: boolean;
|
|
187
|
+
indexdb: SqliteIndexDB;
|
|
188
|
+
statedb: SqliteStateDB;
|
|
189
|
+
}) => Promise<unknown>;
|
|
190
|
+
requireAllowUpdateTokenDistributionEnv?: boolean;
|
|
191
|
+
env?: Record<string, string | undefined>;
|
|
192
|
+
};
|
|
193
|
+
validateTokenConfig?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Follower only (#1961): before any replay, compare the consensus config this node replays with against the
|
|
196
|
+
* upstream leader's `getConfig`. Default `off` (no request). `enforce` refuses to start on a difference.
|
|
197
|
+
*/
|
|
198
|
+
configCheck?: {
|
|
199
|
+
mode: TChainConfigCheckMode;
|
|
200
|
+
/** Stub upstream for tests; defaults to `getConfig` over `<upstreamChainUrl>/api/gql`. */
|
|
201
|
+
fetchUpstreamConfig?: (upstreamUrl: string) => Promise<unknown>;
|
|
202
|
+
/** `enforce`: how long an unavailable upstream is retried before deciding (default 60 s). */
|
|
203
|
+
retryDeadlineMs?: number;
|
|
204
|
+
};
|
|
205
|
+
/** Follower only (#1961): acceptance guards on replayed ledger entries. Default: none (today's behavior). */
|
|
206
|
+
replayGuards?: {
|
|
207
|
+
/** Refuse (retryably) entries at or after `activationSequence` whose timestamp is ahead of the local clock. */
|
|
208
|
+
futureTimestamp?: FutureTimestampGuardConfig;
|
|
209
|
+
};
|
|
210
|
+
logger?: IPipelineLogger;
|
|
211
|
+
configureApp?: (app: express.Express, ctx: ChainAppHookContext) => void | Promise<void>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Validator / HotStuff profiles require a complete `chainConfig`; Keyless Follower profiles may omit it
|
|
215
|
+
* and rehydrate `IChainConfig` directly from `statedb.sqlite` after snapshot verification.
|
|
216
|
+
*/
|
|
217
|
+
type ChainProfile = (ChainProfileBase & {
|
|
218
|
+
role: ValidatorRoleConfig | HotStuffValidatorRoleConfig;
|
|
219
|
+
chainConfig: IChainConfig;
|
|
220
|
+
}) | (ChainProfileBase & {
|
|
221
|
+
role: FollowerRoleConfig;
|
|
222
|
+
chainConfig?: Partial<IChainConfig>;
|
|
223
|
+
expectedChainId?: string;
|
|
224
|
+
});
|
|
225
|
+
type ChainNodeProfile = ChainProfile;
|
|
226
|
+
interface FollowerUpstreamInterceptorContext {
|
|
227
|
+
kind: TFollowerUpstreamFetchKind;
|
|
228
|
+
url: string;
|
|
229
|
+
init?: RequestInit;
|
|
230
|
+
}
|
|
231
|
+
interface FollowerSyncTestController {
|
|
232
|
+
pause(): void;
|
|
233
|
+
resume(): void;
|
|
234
|
+
isPaused(): boolean;
|
|
235
|
+
triggerSyncOnce(): Promise<void>;
|
|
236
|
+
}
|
|
237
|
+
interface ChainNodeTestHooksInput {
|
|
238
|
+
now?: () => number;
|
|
239
|
+
initialClockOffsetMs?: number;
|
|
240
|
+
initialClockOffsetSeconds?: number;
|
|
241
|
+
checkpoint?: {
|
|
242
|
+
batchSize?: number;
|
|
243
|
+
timeoutMs?: number;
|
|
244
|
+
};
|
|
245
|
+
logger?: IPipelineLogger;
|
|
246
|
+
followerSync?: {
|
|
247
|
+
startPaused?: boolean;
|
|
248
|
+
artificialPollDelayMs?: number;
|
|
249
|
+
interceptUpstreamFetch?: (ctx: FollowerUpstreamInterceptorContext, defaultFetch: typeof fetch) => Promise<Response>;
|
|
250
|
+
onControllerReady?: (ctrl: FollowerSyncTestController) => void;
|
|
251
|
+
};
|
|
252
|
+
hotstuff?: {
|
|
253
|
+
onOutboundConsensusRequest?: HotStuffNodeRuntimeOptions['onOutboundConsensusRequest'];
|
|
254
|
+
/** @deprecated Use `onOutboundConsensusRequest` */
|
|
255
|
+
interceptOutboundRpc?: HotStuffNodeRuntimeOptions['onOutboundConsensusRequest'];
|
|
256
|
+
};
|
|
257
|
+
resolver?: {
|
|
258
|
+
beforeStateDbCommit?: (info: {
|
|
259
|
+
commitHash: string;
|
|
260
|
+
prevHash: string;
|
|
261
|
+
seq: number;
|
|
262
|
+
}) => void | Promise<void>;
|
|
263
|
+
};
|
|
264
|
+
onAfterBoot?: (handles: {
|
|
265
|
+
dataDir: string;
|
|
266
|
+
statedb: SqliteStateDB;
|
|
267
|
+
ledger: Ledger;
|
|
268
|
+
trustedStorage: SqliteTrustedStorage;
|
|
269
|
+
}) => void | Promise<void>;
|
|
270
|
+
}
|
|
271
|
+
interface ChainNodeTestHooks extends ChainNodeTestHooksInput {
|
|
272
|
+
readonly [CHAIN_NODE_TEST_HOOKS_TOKEN]: true;
|
|
273
|
+
}
|
|
274
|
+
interface StartChainNodeOptions {
|
|
275
|
+
profile: ChainProfile;
|
|
276
|
+
testHooks?: ChainNodeTestHooks;
|
|
277
|
+
}
|
|
278
|
+
interface RunningChainNode {
|
|
279
|
+
readonly endpoint: string;
|
|
280
|
+
readonly rpcUrl: string;
|
|
281
|
+
readonly wsUrl: string;
|
|
282
|
+
readonly port: number;
|
|
283
|
+
readonly host: string;
|
|
284
|
+
readonly chainId: string;
|
|
285
|
+
readonly role: ChainNodeRoleConfig['kind'];
|
|
286
|
+
readonly nodeId: string;
|
|
287
|
+
readonly dataDir: string;
|
|
288
|
+
readonly proposerDid: string | null;
|
|
289
|
+
readonly proposerPublicKey: string | null;
|
|
290
|
+
readonly signatureKeyType: 'ed25519' | 'secp256k1' | null;
|
|
291
|
+
readonly app: express.Express;
|
|
292
|
+
readonly resolver: OCAPResolver;
|
|
293
|
+
readonly ledger: Ledger;
|
|
294
|
+
readonly ledgerStorage: SqliteLedgerStorage;
|
|
295
|
+
readonly statedb: SqliteStateDB;
|
|
296
|
+
readonly indexdb: SqliteIndexDB;
|
|
297
|
+
readonly trustedStorage: SqliteTrustedStorage;
|
|
298
|
+
readonly server: http.Server;
|
|
299
|
+
readonly followerSync?: FollowerSyncService;
|
|
300
|
+
readonly hotstuffRuntime?: HotStuffNodeRuntime;
|
|
301
|
+
readonly preferencesManager: NodePreferencesManager;
|
|
302
|
+
readonly maintenanceController: INodeMaintenanceController;
|
|
303
|
+
ledgerHealth(): Promise<ILedgerHealthStatus>;
|
|
304
|
+
advanceClock?(seconds: number): number;
|
|
305
|
+
restart(nextProfile?: Partial<ChainProfile>): Promise<RunningChainNode>;
|
|
306
|
+
stop(): Promise<void>;
|
|
307
|
+
}
|
|
308
|
+
type ChainNodeHandle = RunningChainNode;
|
|
309
|
+
//#endregion
|
|
310
|
+
export { ChainAppHookContext, ChainNodeHandle, ChainNodeProfile, ChainNodeRoleConfig, ChainNodeSegmentPublisher, ChainNodeSignerConfig, ChainNodeTestHooks, ChainNodeTestHooksInput, ChainProfile, ChainProfileBase, FollowerRoleConfig, FollowerSyncTestController, FollowerUpstreamInterceptorContext, HotStuffValidatorRoleConfig, ILedgerHealthStatus, ILedgerLeaseOptions, PublicKeyOnlyValidatorSignerConfig, RunningChainNode, StartChainNodeOptions, TNodeRetentionMode, TrustedAccountConfig, ValidatorRoleConfig, ValidatorSignerConfig };
|
package/esm/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _ocap_util_lib_client_ip = require("@ocap/util/lib/client-ip");
|
|
3
|
+
|
|
4
|
+
//#region src/access-log.ts
|
|
5
|
+
const MAX_PATH = 2048;
|
|
6
|
+
const MAX_HOST = 255;
|
|
7
|
+
const MAX_CF_RAY = 64;
|
|
8
|
+
const MAX_UA = 256;
|
|
9
|
+
const pctByte = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
10
|
+
const token = (value, max) => {
|
|
11
|
+
if (!value) return "-";
|
|
12
|
+
return value.replace(/[\s"\\\u0000-\u001f\u007f]/g, pctByte).slice(0, max);
|
|
13
|
+
};
|
|
14
|
+
const quoted = (value, max) => {
|
|
15
|
+
if (!value) return "\"-\"";
|
|
16
|
+
return `"${value.slice(0, max).replace(/["\\\u0000-\u001f\u007f]/g, (c) => c === "\"" || c === "\\" ? `\\${c}` : `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`)}"`;
|
|
17
|
+
};
|
|
18
|
+
function formatAccessLogLine(f) {
|
|
19
|
+
return [
|
|
20
|
+
"[access]",
|
|
21
|
+
token(f.method, 16),
|
|
22
|
+
token(f.path, MAX_PATH),
|
|
23
|
+
String(f.status),
|
|
24
|
+
`${Math.max(0, Math.round(f.durationMs))}ms`,
|
|
25
|
+
String(f.bytes),
|
|
26
|
+
token(f.clientIp, 45),
|
|
27
|
+
token(f.host, MAX_HOST),
|
|
28
|
+
token(f.cfRay, MAX_CF_RAY),
|
|
29
|
+
quoted(f.userAgent, MAX_UA)
|
|
30
|
+
].join(" ");
|
|
31
|
+
}
|
|
32
|
+
const headerString = (v) => Array.isArray(v) ? v[0] : v;
|
|
33
|
+
const chunkBytes = (chunk, encoding) => {
|
|
34
|
+
if (chunk === void 0 || chunk === null || typeof chunk === "function") return 0;
|
|
35
|
+
if (typeof chunk === "string") return Buffer.byteLength(chunk, typeof encoding === "string" ? encoding : "utf8");
|
|
36
|
+
if (chunk instanceof Uint8Array) return chunk.byteLength;
|
|
37
|
+
return 0;
|
|
38
|
+
};
|
|
39
|
+
/** Express middleware writing one `formatAccessLogLine` per finished response through `logger.info`. */
|
|
40
|
+
function createAccessLogMiddleware(logger) {
|
|
41
|
+
return (req, res, next) => {
|
|
42
|
+
const startedAt = Date.now();
|
|
43
|
+
let bytes = 0;
|
|
44
|
+
const origWrite = res.write;
|
|
45
|
+
const origEnd = res.end;
|
|
46
|
+
res.write = function write(...args) {
|
|
47
|
+
bytes += chunkBytes(args[0], args[1]);
|
|
48
|
+
return origWrite.apply(this, args);
|
|
49
|
+
};
|
|
50
|
+
res.end = function end(...args) {
|
|
51
|
+
bytes += chunkBytes(args[0], args[1]);
|
|
52
|
+
return origEnd.apply(this, args);
|
|
53
|
+
};
|
|
54
|
+
res.once("finish", () => {
|
|
55
|
+
logger.info(formatAccessLogLine({
|
|
56
|
+
method: req.method,
|
|
57
|
+
path: req.originalUrl,
|
|
58
|
+
status: res.statusCode,
|
|
59
|
+
durationMs: Date.now() - startedAt,
|
|
60
|
+
bytes,
|
|
61
|
+
clientIp: (0, _ocap_util_lib_client_ip.resolveClientIp)(req),
|
|
62
|
+
host: headerString(req.headers.host),
|
|
63
|
+
cfRay: headerString(req.headers["cf-ray"]),
|
|
64
|
+
userAgent: headerString(req.headers["user-agent"])
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
next();
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
exports.createAccessLogMiddleware = createAccessLogMiddleware;
|
|
73
|
+
exports.formatAccessLogLine = formatAccessLogLine;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
|
|
3
|
+
//#region src/access-log.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `CHAIN_ACCESS_LOG=1` line (#1922). Behind Cloudflare Tunnel there is no nginx access log, so this line carries what
|
|
7
|
+
* slow-request analysis (#1874) needs. Fixed positional format, one request per line:
|
|
8
|
+
*
|
|
9
|
+
* [access] <method> <path> <status> <ms>ms <bytes> <clientIp> <host> <cfRay> "<userAgent>"
|
|
10
|
+
*
|
|
11
|
+
* - `bytes`: response body bytes written (like nginx `$body_bytes_sent`).
|
|
12
|
+
* - `clientIp`: `@ocap/util/lib/client-ip` (`CHAIN_CLIENT_IP_HEADERS`, default `x-real-ip`, read from a loopback peer only, else socket).
|
|
13
|
+
* - absent values are `-`. Every field except the user agent is whitespace-free (whitespace, `"`, `\` and control
|
|
14
|
+
* characters are %-encoded), so `awk '{print $7}'` is the client IP; the user agent is last, quoted, with `"`, `\`
|
|
15
|
+
* and control characters backslash-escaped, so a client cannot end the line or forge a field.
|
|
16
|
+
*/
|
|
17
|
+
interface AccessLogFields {
|
|
18
|
+
method: string;
|
|
19
|
+
path: string;
|
|
20
|
+
status: number;
|
|
21
|
+
durationMs: number;
|
|
22
|
+
bytes: number;
|
|
23
|
+
clientIp: string;
|
|
24
|
+
host?: string;
|
|
25
|
+
cfRay?: string;
|
|
26
|
+
userAgent?: string;
|
|
27
|
+
}
|
|
28
|
+
declare function formatAccessLogLine(f: AccessLogFields): string;
|
|
29
|
+
/** Express middleware writing one `formatAccessLogLine` per finished response through `logger.info`. */
|
|
30
|
+
declare function createAccessLogMiddleware(logger: {
|
|
31
|
+
info: (msg: string) => void;
|
|
32
|
+
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { AccessLogFields, createAccessLogMiddleware, formatAccessLogLine };
|