@ocap/chain-node 1.32.0 → 1.32.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/esm/access-log.d.mts +5 -2
- package/esm/access-log.mjs +5 -3
- package/esm/config-consistency.d.mts +59 -0
- package/esm/config-consistency.mjs +256 -0
- package/esm/env.mjs +1 -1
- package/esm/follower-config.d.mts +26 -0
- package/esm/follower-config.mjs +83 -0
- package/esm/index.d.mts +4 -2
- package/esm/index.mjs +4 -2
- package/esm/standalone-env.d.mts +54 -1
- package/esm/standalone-env.mjs +82 -1
- package/esm/start-chain-node.mjs +69 -18
- package/esm/types.d.mts +23 -1
- package/lib/access-log.cjs +4 -2
- package/lib/access-log.d.cts +5 -2
- package/lib/config-consistency.cjs +263 -0
- package/lib/config-consistency.d.cts +59 -0
- package/lib/env.cjs +1 -1
- package/lib/follower-config.cjs +90 -0
- package/lib/follower-config.d.cts +26 -0
- package/lib/index.cjs +20 -1
- package/lib/index.d.cts +4 -2
- package/lib/standalone-env.cjs +89 -0
- package/lib/standalone-env.d.cts +54 -1
- package/lib/start-chain-node.cjs +71 -21
- package/lib/types.d.cts +23 -1
- package/package.json +16 -16
package/esm/access-log.d.mts
CHANGED
|
@@ -26,9 +26,12 @@ interface AccessLogFields {
|
|
|
26
26
|
userAgent?: string;
|
|
27
27
|
}
|
|
28
28
|
declare function formatAccessLogLine(f: AccessLogFields): string;
|
|
29
|
+
interface AccessLogMiddlewareOptions {
|
|
30
|
+
env?: Record<string, string | undefined>;
|
|
31
|
+
}
|
|
29
32
|
/** Express middleware writing one `formatAccessLogLine` per finished response through `logger.info`. */
|
|
30
33
|
declare function createAccessLogMiddleware(logger: {
|
|
31
34
|
info: (msg: string) => void;
|
|
32
|
-
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
35
|
+
}, options?: AccessLogMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
33
36
|
//#endregion
|
|
34
|
-
export { AccessLogFields, createAccessLogMiddleware, formatAccessLogLine };
|
|
37
|
+
export { AccessLogFields, AccessLogMiddlewareOptions, createAccessLogMiddleware, formatAccessLogLine };
|
package/esm/access-log.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveClientIp } from "@ocap/util/lib/client-ip";
|
|
1
|
+
import { getTrustedClientIpHeaders, resolveClientIp } from "@ocap/util/lib/client-ip";
|
|
2
2
|
|
|
3
3
|
//#region src/access-log.ts
|
|
4
4
|
const MAX_PATH = 2048;
|
|
@@ -36,7 +36,8 @@ const chunkBytes = (chunk, encoding) => {
|
|
|
36
36
|
return 0;
|
|
37
37
|
};
|
|
38
38
|
/** Express middleware writing one `formatAccessLogLine` per finished response through `logger.info`. */
|
|
39
|
-
function createAccessLogMiddleware(logger) {
|
|
39
|
+
function createAccessLogMiddleware(logger, options = {}) {
|
|
40
|
+
const getHeaders = () => options.env !== void 0 ? getTrustedClientIpHeaders(options.env.CHAIN_CLIENT_IP_HEADERS) : void 0;
|
|
40
41
|
return (req, res, next) => {
|
|
41
42
|
const startedAt = Date.now();
|
|
42
43
|
let bytes = 0;
|
|
@@ -51,13 +52,14 @@ function createAccessLogMiddleware(logger) {
|
|
|
51
52
|
return origEnd.apply(this, args);
|
|
52
53
|
};
|
|
53
54
|
res.once("finish", () => {
|
|
55
|
+
const trustedHeaders = getHeaders();
|
|
54
56
|
logger.info(formatAccessLogLine({
|
|
55
57
|
method: req.method,
|
|
56
58
|
path: req.originalUrl,
|
|
57
59
|
status: res.statusCode,
|
|
58
60
|
durationMs: Date.now() - startedAt,
|
|
59
61
|
bytes,
|
|
60
|
-
clientIp: resolveClientIp(req),
|
|
62
|
+
clientIp: resolveClientIp(req, trustedHeaders !== void 0 ? { headers: trustedHeaders } : void 0),
|
|
61
63
|
host: headerString(req.headers.host),
|
|
62
64
|
cfRay: headerString(req.headers["cf-ray"]),
|
|
63
65
|
userAgent: headerString(req.headers["user-agent"])
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TChainConfigCheckMode } from "./standalone-env.mjs";
|
|
2
|
+
import { IPipelineLogger } from "@ocap/types";
|
|
3
|
+
|
|
4
|
+
//#region src/config-consistency.d.ts
|
|
5
|
+
declare const CONSENSUS_CONFIG_KEYS: readonly ["chainId", "mode", "moderator.address", "token.address", "token.symbol", "token.decimal", "vaults", "reservedSymbols", "transaction"];
|
|
6
|
+
type Plain = Record<string, unknown>;
|
|
7
|
+
/** The consensus-relevant projection of a chain config, with defaults applied identically on both sides. */
|
|
8
|
+
declare function normalizeConsensusConfig(config: unknown): Plain;
|
|
9
|
+
interface ConfigDifference {
|
|
10
|
+
path: string;
|
|
11
|
+
local: unknown;
|
|
12
|
+
upstream: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** Differences between two configs' consensus projections, by dotted path (arrays compare as a whole). */
|
|
15
|
+
declare function diffConsensusConfig(local: unknown, upstream: unknown): ConfigDifference[];
|
|
16
|
+
/** POST `{ getConfig }` to `<upstreamUrl>/api/gql` and return the parsed in-memory config of the upstream. */
|
|
17
|
+
declare function fetchUpstreamChainConfig(upstreamUrl: string, {
|
|
18
|
+
fetchImpl,
|
|
19
|
+
timeoutMs
|
|
20
|
+
}?: {
|
|
21
|
+
fetchImpl?: typeof fetch;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}): Promise<unknown>;
|
|
24
|
+
declare function formatConfigDifferences(diff: ConfigDifference[]): string;
|
|
25
|
+
interface VerifyFollowerConfigOptions {
|
|
26
|
+
mode: TChainConfigCheckMode;
|
|
27
|
+
/** The config the follower will replay with (`resolver.config`). */
|
|
28
|
+
localConfig: unknown;
|
|
29
|
+
upstreamUrl: string | null | undefined;
|
|
30
|
+
/** Defaults to `fetchUpstreamChainConfig`; tests pass a stub upstream. */
|
|
31
|
+
fetchUpstreamConfig?: (upstreamUrl: string) => Promise<unknown>;
|
|
32
|
+
logger: Pick<IPipelineLogger, 'info' | 'warn'>;
|
|
33
|
+
/**
|
|
34
|
+
* The data dir already held this node's chain state before this start (not a fresh snapshot bootstrap). With
|
|
35
|
+
* `enforce`, an upstream that stays unavailable past the deadline is then a warning, not a refusal.
|
|
36
|
+
*/
|
|
37
|
+
hasLocalState?: boolean;
|
|
38
|
+
/** `enforce` only: keep retrying an unavailable upstream this long (default 60 s, CHAIN_CONFIG_CHECK_TIMEOUT_SEC). */
|
|
39
|
+
retryDeadlineMs?: number;
|
|
40
|
+
/** First backoff delay (default 1 s), doubled per attempt up to `retryMaxDelayMs` (default 10 s). */
|
|
41
|
+
retryDelayMs?: number;
|
|
42
|
+
retryMaxDelayMs?: number;
|
|
43
|
+
now?: () => number;
|
|
44
|
+
sleep?: (ms: number) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
interface VerifyFollowerConfigResult {
|
|
47
|
+
status: 'skipped' | 'match' | 'mismatch' | 'unavailable';
|
|
48
|
+
diff: ConfigDifference[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compare the follower's replay config with the upstream leader's. `off`: no request. `warn`: one attempt, log
|
|
52
|
+
* any difference or failure and continue. `enforce`: a definite difference throws `CHAIN_CONFIG_MISMATCH` (lists
|
|
53
|
+
* every differing key). An unavailable upstream (down, HTTP error such as 429, bad body) is retried with backoff
|
|
54
|
+
* until `retryDeadlineMs`; then a node with existing local state starts with a warning, and only a fresh bootstrap
|
|
55
|
+
* throws `CHAIN_CONFIG_CHECK_UNAVAILABLE`.
|
|
56
|
+
*/
|
|
57
|
+
declare function verifyFollowerConfigAgainstUpstream(opts: VerifyFollowerConfigOptions): Promise<VerifyFollowerConfigResult>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { CONSENSUS_CONFIG_KEYS, ConfigDifference, VerifyFollowerConfigOptions, VerifyFollowerConfigResult, diffConsensusConfig, fetchUpstreamChainConfig, formatConfigDifferences, normalizeConsensusConfig, verifyFollowerConfigAgainstUpstream };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { defaultGasSecurityKnobs } from "@ocap/config";
|
|
2
|
+
import defaultConfig from "@ocap/config/lib/default";
|
|
3
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
+
|
|
5
|
+
//#region src/config-consistency.ts
|
|
6
|
+
/**
|
|
7
|
+
* Follower startup consistency check (#1961): before a follower replays anything it asks the upstream leader for
|
|
8
|
+
* its in-memory chain config (`getConfig`, core/resolver `getConfig()` returns `JSON.stringify(this.config)`) and
|
|
9
|
+
* compares every consensus-relevant key, both sides normalized with the same defaults. A follower that replays with
|
|
10
|
+
* a different config computes different state commits (e.g. `transaction.bridge.enabled` off rejects the first
|
|
11
|
+
* bridge reserve entry in `bridge-reserve-v2-gate.ts`) and halts; this check turns that into a clear startup error.
|
|
12
|
+
*
|
|
13
|
+
* Consensus-relevant keys (`CONSENSUS_CONFIG_KEYS`) are what the tx pipeline / replayer reads from `context.config`:
|
|
14
|
+
* - `chainId` every protocol (`tx.chainId` checks), replayer entry chain id
|
|
15
|
+
* - `mode` `Config.create` defaults (`ledger` zeroes fees and gas)
|
|
16
|
+
* - `moderator.address` moderator-only protocols (token / factory / rollup governance)
|
|
17
|
+
* - `token.address/symbol/decimal` official token, fee and stake units, reserved base symbol
|
|
18
|
+
* - `vaults` where fees, gas and slashed stake go (`txFee`, `txFees`, `txGas`, `slashedStake`)
|
|
19
|
+
* - `reservedSymbols` `create_token_factory` verification (compared as a case-insensitive set)
|
|
20
|
+
* - `transaction` the whole section: `txFee`, `txGas` (+ free-gas / burst knobs), `txStake`,
|
|
21
|
+
* `maxTxSize`, `maxAssetSize`, `maxListSize`, `maxMultisig`, `delegate`, `supportedTxs`,
|
|
22
|
+
* `multiSignV2Txs`, `maxWriteSetSize`, `security`, `bridge`, `rollupV1`, `exchangeV2`
|
|
23
|
+
* Not compared: `version` (software), `accounts` and token metadata/supply (genesis only: a follower never re-runs
|
|
24
|
+
* genesis, it starts from a verified snapshot), `moderator.pk` (protocols compare the address), `genesisTime`.
|
|
25
|
+
*/
|
|
26
|
+
const CONSENSUS_CONFIG_KEYS = [
|
|
27
|
+
"chainId",
|
|
28
|
+
"mode",
|
|
29
|
+
"moderator.address",
|
|
30
|
+
"token.address",
|
|
31
|
+
"token.symbol",
|
|
32
|
+
"token.decimal",
|
|
33
|
+
"vaults",
|
|
34
|
+
"reservedSymbols",
|
|
35
|
+
"transaction"
|
|
36
|
+
];
|
|
37
|
+
/** Protocol fallback of `transaction.exchangeV2.defaultTtlSeconds` (core/tx-protocols exchange-v2.ts). */
|
|
38
|
+
const DEFAULT_EXCHANGE_V2_TTL_SECONDS = 720 * 60 * 60;
|
|
39
|
+
const isPlainObject = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
40
|
+
/** JSON round trip: drops `undefined`, functions and frozen-ness, so both sides compare as the wire would. */
|
|
41
|
+
function toJsonValue(value) {
|
|
42
|
+
if (value === void 0) return void 0;
|
|
43
|
+
return JSON.parse(JSON.stringify(value));
|
|
44
|
+
}
|
|
45
|
+
function getPath(obj, dotted) {
|
|
46
|
+
let cur = obj;
|
|
47
|
+
for (const seg of dotted.split(".")) {
|
|
48
|
+
if (!isPlainObject(cur)) return void 0;
|
|
49
|
+
cur = cur[seg];
|
|
50
|
+
}
|
|
51
|
+
return cur;
|
|
52
|
+
}
|
|
53
|
+
function setPath(obj, dotted, value) {
|
|
54
|
+
const segs = dotted.split(".");
|
|
55
|
+
let cur = obj;
|
|
56
|
+
for (const seg of segs.slice(0, -1)) {
|
|
57
|
+
if (!isPlainObject(cur[seg])) cur[seg] = {};
|
|
58
|
+
cur = cur[seg];
|
|
59
|
+
}
|
|
60
|
+
cur[segs[segs.length - 1]] = value;
|
|
61
|
+
}
|
|
62
|
+
/** Fill only keys that are absent (`undefined`); present values, records and arrays are kept as they are. */
|
|
63
|
+
function fillAbsent(target, defaults) {
|
|
64
|
+
const out = { ...target };
|
|
65
|
+
for (const [k, v] of Object.entries(defaults)) if (out[k] === void 0) out[k] = toJsonValue(v);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function normalizeTransaction(raw) {
|
|
69
|
+
const tx = fillAbsent(isPlainObject(raw) ? toJsonValue(raw) : {}, defaultConfig.transaction);
|
|
70
|
+
tx.txGas = fillAbsent(isPlainObject(tx.txGas) ? tx.txGas : {}, defaultGasSecurityKnobs.txGas);
|
|
71
|
+
tx.security = fillAbsent(isPlainObject(tx.security) ? tx.security : {}, defaultGasSecurityKnobs.security);
|
|
72
|
+
tx.bridge = { enabled: isPlainObject(tx.bridge) && tx.bridge.enabled === true };
|
|
73
|
+
tx.rollupV1 = { enabled: !(isPlainObject(tx.rollupV1) && tx.rollupV1.enabled === false) };
|
|
74
|
+
const exchangeV2 = isPlainObject(tx.exchangeV2) ? tx.exchangeV2 : {};
|
|
75
|
+
tx.exchangeV2 = {
|
|
76
|
+
...exchangeV2,
|
|
77
|
+
defaultTtlSeconds: typeof exchangeV2.defaultTtlSeconds === "number" ? exchangeV2.defaultTtlSeconds : DEFAULT_EXCHANGE_V2_TTL_SECONDS
|
|
78
|
+
};
|
|
79
|
+
return tx;
|
|
80
|
+
}
|
|
81
|
+
/** The consensus-relevant projection of a chain config, with defaults applied identically on both sides. */
|
|
82
|
+
function normalizeConsensusConfig(config) {
|
|
83
|
+
const out = {};
|
|
84
|
+
for (const key of CONSENSUS_CONFIG_KEYS) {
|
|
85
|
+
const value = toJsonValue(getPath(config, key));
|
|
86
|
+
switch (key) {
|
|
87
|
+
case "mode":
|
|
88
|
+
setPath(out, key, value === "ledger" ? "ledger" : "chain");
|
|
89
|
+
break;
|
|
90
|
+
case "token.address":
|
|
91
|
+
setPath(out, key, typeof value === "string" ? value : "");
|
|
92
|
+
break;
|
|
93
|
+
case "vaults":
|
|
94
|
+
setPath(out, key, isPlainObject(value) ? value : {});
|
|
95
|
+
break;
|
|
96
|
+
case "reservedSymbols":
|
|
97
|
+
setPath(out, key, Array.from(new Set((Array.isArray(value) ? value : []).map((s) => String(s ?? "").trim().toUpperCase()).filter(Boolean))).sort());
|
|
98
|
+
break;
|
|
99
|
+
case "transaction":
|
|
100
|
+
setPath(out, key, normalizeTransaction(value));
|
|
101
|
+
break;
|
|
102
|
+
default: setPath(out, key, value === void 0 ? null : value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function collectDiff(local, upstream, prefix, out) {
|
|
108
|
+
if (isPlainObject(local) && isPlainObject(upstream)) {
|
|
109
|
+
const keys = Array.from(new Set([...Object.keys(local), ...Object.keys(upstream)])).sort();
|
|
110
|
+
for (const k of keys) collectDiff(local[k], upstream[k], prefix ? `${prefix}.${k}` : k, out);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (JSON.stringify(local) !== JSON.stringify(upstream)) out.push({
|
|
114
|
+
path: prefix,
|
|
115
|
+
local: local === void 0 ? null : local,
|
|
116
|
+
upstream: upstream === void 0 ? null : upstream
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** Differences between two configs' consensus projections, by dotted path (arrays compare as a whole). */
|
|
120
|
+
function diffConsensusConfig(local, upstream) {
|
|
121
|
+
const out = [];
|
|
122
|
+
collectDiff(normalizeConsensusConfig(local), normalizeConsensusConfig(upstream), "", out);
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
const MAX_CONFIG_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
126
|
+
const GET_CONFIG_QUERY = "{ getConfig { code config } }";
|
|
127
|
+
async function readBoundedResponseText(res, url, maxBytes) {
|
|
128
|
+
const contentLength = res.headers?.get?.("content-length");
|
|
129
|
+
if (contentLength !== null && contentLength !== void 0 && contentLength.trim() !== "") {
|
|
130
|
+
const parsedLen = Number(contentLength);
|
|
131
|
+
if (Number.isFinite(parsedLen) && parsedLen > maxBytes) {
|
|
132
|
+
try {
|
|
133
|
+
await res.body?.cancel();
|
|
134
|
+
} catch {}
|
|
135
|
+
throw new Error(`getConfig from ${url} failed: response larger than ${maxBytes} bytes`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!res.body || typeof res.body.getReader !== "function") {
|
|
139
|
+
const text$1 = await res.text();
|
|
140
|
+
if (Buffer.byteLength(text$1, "utf8") > maxBytes) throw new Error(`getConfig from ${url} failed: response larger than ${maxBytes} bytes`);
|
|
141
|
+
return text$1;
|
|
142
|
+
}
|
|
143
|
+
const reader = res.body.getReader();
|
|
144
|
+
const decoder = new TextDecoder();
|
|
145
|
+
let totalBytes = 0;
|
|
146
|
+
let text = "";
|
|
147
|
+
for (;;) {
|
|
148
|
+
const { done, value } = await reader.read();
|
|
149
|
+
if (done) break;
|
|
150
|
+
if (value) {
|
|
151
|
+
totalBytes += value.byteLength;
|
|
152
|
+
if (totalBytes > maxBytes) {
|
|
153
|
+
try {
|
|
154
|
+
await reader.cancel();
|
|
155
|
+
} catch {}
|
|
156
|
+
throw new Error(`getConfig from ${url} failed: response larger than ${maxBytes} bytes`);
|
|
157
|
+
}
|
|
158
|
+
text += decoder.decode(value, { stream: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
text += decoder.decode();
|
|
162
|
+
return text;
|
|
163
|
+
}
|
|
164
|
+
/** POST `{ getConfig }` to `<upstreamUrl>/api/gql` and return the parsed in-memory config of the upstream. */
|
|
165
|
+
async function fetchUpstreamChainConfig(upstreamUrl, { fetchImpl = fetch, timeoutMs = 1e4 } = {}) {
|
|
166
|
+
const url = `${String(upstreamUrl).trim().replace(/\/+$/, "")}/api/gql`;
|
|
167
|
+
const res = await fetchImpl(url, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: {
|
|
170
|
+
"content-type": "application/json",
|
|
171
|
+
accept: "application/json"
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify({ query: GET_CONFIG_QUERY }),
|
|
174
|
+
redirect: "error",
|
|
175
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
176
|
+
});
|
|
177
|
+
const text = await readBoundedResponseText(res, url, MAX_CONFIG_RESPONSE_BYTES);
|
|
178
|
+
if (!res.ok) throw new Error(`getConfig from ${url} failed: HTTP ${res.status}`);
|
|
179
|
+
const body = JSON.parse(text);
|
|
180
|
+
if (body.errors?.length) throw new Error(`getConfig from ${url} failed: ${body.errors.map((e) => e.message).join("; ")}`);
|
|
181
|
+
const raw = body.data?.getConfig?.config;
|
|
182
|
+
if (typeof raw !== "string" || !raw) throw new Error(`getConfig from ${url} failed: no config in the response (code=${body.data?.getConfig?.code})`);
|
|
183
|
+
return assertUpstreamConfigShape(JSON.parse(raw), url);
|
|
184
|
+
}
|
|
185
|
+
/** A response that is not a chain config is a bad body ("unavailable"), never a definite mismatch. */
|
|
186
|
+
function assertUpstreamConfigShape(parsed, source) {
|
|
187
|
+
if (!isPlainObject(parsed)) throw new Error(`getConfig from ${source} failed: config is not an object`);
|
|
188
|
+
if (typeof parsed.chainId !== "string" || !parsed.chainId.trim() || !isPlainObject(parsed.transaction)) throw new Error(`getConfig from ${source} failed: config has no chainId / transaction section`);
|
|
189
|
+
return parsed;
|
|
190
|
+
}
|
|
191
|
+
const formatValue = (v) => {
|
|
192
|
+
const s = JSON.stringify(v);
|
|
193
|
+
return s.length > 160 ? `${s.slice(0, 157)}...` : s;
|
|
194
|
+
};
|
|
195
|
+
function formatConfigDifferences(diff) {
|
|
196
|
+
return diff.map((d) => `${d.path} (local=${formatValue(d.local)}, upstream=${formatValue(d.upstream)})`).join("; ");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Compare the follower's replay config with the upstream leader's. `off`: no request. `warn`: one attempt, log
|
|
200
|
+
* any difference or failure and continue. `enforce`: a definite difference throws `CHAIN_CONFIG_MISMATCH` (lists
|
|
201
|
+
* every differing key). An unavailable upstream (down, HTTP error such as 429, bad body) is retried with backoff
|
|
202
|
+
* until `retryDeadlineMs`; then a node with existing local state starts with a warning, and only a fresh bootstrap
|
|
203
|
+
* throws `CHAIN_CONFIG_CHECK_UNAVAILABLE`.
|
|
204
|
+
*/
|
|
205
|
+
async function verifyFollowerConfigAgainstUpstream(opts) {
|
|
206
|
+
if (opts.mode === "off") return {
|
|
207
|
+
status: "skipped",
|
|
208
|
+
diff: []
|
|
209
|
+
};
|
|
210
|
+
const enforce = opts.mode === "enforce";
|
|
211
|
+
const now = opts.now ?? (() => Date.now());
|
|
212
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
213
|
+
const unavailable = (reason) => {
|
|
214
|
+
const message$1 = `Follower config check (CHAIN_CONFIG_CHECK=${opts.mode}) could not read the upstream config: ${reason}`;
|
|
215
|
+
if (enforce && !opts.hasLocalState) throw new CustomError("CHAIN_CONFIG_CHECK_UNAVAILABLE", `${message$1}; refusing to start a fresh bootstrap before replay`);
|
|
216
|
+
opts.logger.warn(`[chain-node] ${message$1}; starting without the check${enforce ? " (existing local state)" : ""}`);
|
|
217
|
+
return {
|
|
218
|
+
status: "unavailable",
|
|
219
|
+
diff: []
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
const upstreamUrl = String(opts.upstreamUrl ?? "").trim();
|
|
223
|
+
if (!upstreamUrl) return unavailable("no upstream URL (UPSTREAM_CHAIN_URL) is configured");
|
|
224
|
+
const fetchConfig = opts.fetchUpstreamConfig ?? ((u) => fetchUpstreamChainConfig(u));
|
|
225
|
+
const deadline = now() + Math.max(0, opts.retryDeadlineMs ?? 6e4);
|
|
226
|
+
const maxDelay = Math.max(0, opts.retryMaxDelayMs ?? 1e4);
|
|
227
|
+
let delay = Math.max(0, opts.retryDelayMs ?? 1e3);
|
|
228
|
+
let upstreamConfig = null;
|
|
229
|
+
while (upstreamConfig === null) try {
|
|
230
|
+
upstreamConfig = assertUpstreamConfigShape(await fetchConfig(upstreamUrl), upstreamUrl);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
233
|
+
if (!enforce || now() + delay > deadline) return unavailable(reason);
|
|
234
|
+
opts.logger.warn(`[chain-node] follower config check: upstream unavailable (${reason}); retrying in ${delay} ms`);
|
|
235
|
+
await sleep(delay);
|
|
236
|
+
delay = Math.min(maxDelay, delay * 2);
|
|
237
|
+
}
|
|
238
|
+
const diff = diffConsensusConfig(opts.localConfig, upstreamConfig);
|
|
239
|
+
if (diff.length === 0) {
|
|
240
|
+
opts.logger.info(`[chain-node] follower consensus config matches upstream ${upstreamUrl}`);
|
|
241
|
+
return {
|
|
242
|
+
status: "match",
|
|
243
|
+
diff
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const message = `Follower consensus config differs from upstream ${upstreamUrl} in ${diff.length} key(s): ${formatConfigDifferences(diff)}`;
|
|
247
|
+
if (enforce) throw new CustomError("CHAIN_CONFIG_MISMATCH", `${message}; refusing to start before replay (#1961)`);
|
|
248
|
+
opts.logger.warn(`[chain-node] ${message}`);
|
|
249
|
+
return {
|
|
250
|
+
status: "mismatch",
|
|
251
|
+
diff
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
export { CONSENSUS_CONFIG_KEYS, diffConsensusConfig, fetchUpstreamChainConfig, formatConfigDifferences, normalizeConsensusConfig, verifyFollowerConfigAgainstUpstream };
|
package/esm/env.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
1
2
|
import { normalizeDidForCompare, resolveConsensusProposer, resolveConsensusProposerFromSigner, resolveEnvWitnessWallet, resolveNodeRoleConfig } from "@arcblock/ledger-core";
|
|
2
3
|
import { resolveLedgerLeaseConfig } from "@arcblock/ledger-sqlite";
|
|
3
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
4
4
|
|
|
5
5
|
//#region src/env.ts
|
|
6
6
|
function parseOptionalPositiveInt(raw, label) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IChainConfig } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/follower-config.d.ts
|
|
4
|
+
declare const isPlainRecord: (v: unknown) => v is Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* A profile config is only "complete" with its `transaction` section (#1961): a follower profile that lacks it
|
|
7
|
+
* would otherwise replay with whatever the code defaults are (e.g. bridge off) instead of the leader's switches.
|
|
8
|
+
*/
|
|
9
|
+
declare function isCompleteChainConfig(candidate: Partial<IChainConfig> | undefined): candidate is IChainConfig;
|
|
10
|
+
/** Deep merge of plain objects (arrays and scalars of `overlay` replace); inputs are not mutated. */
|
|
11
|
+
declare function mergeTransactionOverlay(base: unknown, overlay: unknown): unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Keyless follower: the stored chain row (`statedb.chain`) plus the profile's `transaction` overlay. A keyless
|
|
14
|
+
* follower cannot rebuild the full config (no vault keys), but its profile may carry the leader's transaction
|
|
15
|
+
* variables from env (e.g. CHAIN_TX_BRIDGE_ENABLED): the stored row is not rewritten on a ledger-anchored leader
|
|
16
|
+
* restart, so it still holds the values of the last genesis/config write.
|
|
17
|
+
*/
|
|
18
|
+
declare function rehydrateFollowerChainConfig(storedChain: unknown, profileChainConfig?: Partial<IChainConfig>, extraReservedSymbols?: readonly string[]): IChainConfig;
|
|
19
|
+
/**
|
|
20
|
+
* The config a resolver actually runs with (`OCAPResolver` constructor): validated, with `token.address` set to the
|
|
21
|
+
* genesis token address. This is what the leader's `getConfig` returns and what the follower's replayer reads.
|
|
22
|
+
*/
|
|
23
|
+
declare function toResolverConfig(config: IChainConfig): IChainConfig;
|
|
24
|
+
declare function orphanIndexFromSequence(chainId: string, override?: number): number;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isCompleteChainConfig, isPlainRecord, mergeTransactionOverlay, orphanIndexFromSequence, rehydrateFollowerChainConfig, toResolverConfig };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as Config from "@ocap/config";
|
|
2
|
+
|
|
3
|
+
//#region src/follower-config.ts
|
|
4
|
+
/**
|
|
5
|
+
* How a follower obtains the chain config it replays with (#1961). Shared by `startChainNode` and the read-only
|
|
6
|
+
* `scripts/ops/chain-config-diff.mjs` dry-run, so the dry-run compares exactly what the node would replay with.
|
|
7
|
+
*/
|
|
8
|
+
const isPlainRecord = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
9
|
+
/**
|
|
10
|
+
* A profile config is only "complete" with its `transaction` section (#1961): a follower profile that lacks it
|
|
11
|
+
* would otherwise replay with whatever the code defaults are (e.g. bridge off) instead of the leader's switches.
|
|
12
|
+
*/
|
|
13
|
+
function isCompleteChainConfig(candidate) {
|
|
14
|
+
return Boolean(candidate && typeof candidate.chainId === "string" && candidate.chainId.trim() && candidate.moderator?.address && candidate.token?.symbol && candidate.vaults?.slashedStake && isPlainRecord(candidate.transaction));
|
|
15
|
+
}
|
|
16
|
+
/** Deep merge of plain objects (arrays and scalars of `overlay` replace); inputs are not mutated. */
|
|
17
|
+
function mergeTransactionOverlay(base, overlay) {
|
|
18
|
+
if (!isPlainRecord(overlay)) return overlay === void 0 ? base : overlay;
|
|
19
|
+
const out = isPlainRecord(base) ? { ...base } : {};
|
|
20
|
+
for (const [k, v] of Object.entries(overlay)) {
|
|
21
|
+
if (v === void 0) continue;
|
|
22
|
+
out[k] = mergeTransactionOverlay(out[k], v);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keyless follower: the stored chain row (`statedb.chain`) plus the profile's `transaction` overlay. A keyless
|
|
28
|
+
* follower cannot rebuild the full config (no vault keys), but its profile may carry the leader's transaction
|
|
29
|
+
* variables from env (e.g. CHAIN_TX_BRIDGE_ENABLED): the stored row is not rewritten on a ledger-anchored leader
|
|
30
|
+
* restart, so it still holds the values of the last genesis/config write.
|
|
31
|
+
*/
|
|
32
|
+
function rehydrateFollowerChainConfig(storedChain, profileChainConfig, extraReservedSymbols) {
|
|
33
|
+
const storedChainPartial = storedChain;
|
|
34
|
+
const storedChainId = typeof storedChainPartial.chainId === "string" ? storedChainPartial.chainId.trim() : "";
|
|
35
|
+
const baseSymbol = storedChainPartial.token?.symbol || "TBA";
|
|
36
|
+
const reservedSymbols = Array.from(new Set([
|
|
37
|
+
baseSymbol,
|
|
38
|
+
...storedChainPartial.reservedSymbols ?? [],
|
|
39
|
+
...profileChainConfig?.reservedSymbols ?? [],
|
|
40
|
+
...extraReservedSymbols ?? []
|
|
41
|
+
].map((s) => String(s || "").trim().toUpperCase()).filter(Boolean)));
|
|
42
|
+
const transactionOverlay = isPlainRecord(profileChainConfig?.transaction) ? profileChainConfig.transaction : void 0;
|
|
43
|
+
const storedTransaction = isPlainRecord(storedChainPartial.transaction) ? { ...storedChainPartial.transaction } : storedChainPartial.transaction;
|
|
44
|
+
if (isPlainRecord(storedTransaction)) delete storedTransaction.maxTxSize;
|
|
45
|
+
const transaction = transactionOverlay ? mergeTransactionOverlay(storedTransaction, transactionOverlay) : storedTransaction;
|
|
46
|
+
return Config.create({
|
|
47
|
+
...storedChain,
|
|
48
|
+
...storedChainId ? { chainId: storedChainId } : {},
|
|
49
|
+
...transaction !== void 0 ? { transaction } : {},
|
|
50
|
+
reservedSymbols
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The config a resolver actually runs with (`OCAPResolver` constructor): validated, with `token.address` set to the
|
|
55
|
+
* genesis token address. This is what the leader's `getConfig` returns and what the follower's replayer reads.
|
|
56
|
+
*/
|
|
57
|
+
function toResolverConfig(config) {
|
|
58
|
+
const validated = Config.validate(JSON.parse(JSON.stringify(config)));
|
|
59
|
+
const tokenItx = Config.genTokenItx(validated);
|
|
60
|
+
if (tokenItx) validated.token.address = tokenItx.address;
|
|
61
|
+
return validated;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* First ledger sequence whose orphan entries (finalized, no stateCommitHash, no statedb tx row) the chain's leader
|
|
65
|
+
* indexed. Leaders index the orphans they produce since 1.31.1 (#1387); before that they never did, and a follower
|
|
66
|
+
* index must hold exactly what the leader's holds (#1875). Values read from the leaders' indexdb: the first orphan
|
|
67
|
+
* with an index row, every earlier one without (beta: last unindexed 437972; main: last unindexed 832519). A chain
|
|
68
|
+
* started on 1.31.1+ indexed all of them.
|
|
69
|
+
*/
|
|
70
|
+
const ORPHAN_INDEX_FROM_SEQUENCE = Object.freeze({
|
|
71
|
+
beta: 437983,
|
|
72
|
+
"xenon-2020-01-15": 832598
|
|
73
|
+
});
|
|
74
|
+
function orphanIndexFromSequence(chainId, override) {
|
|
75
|
+
if (override !== void 0) {
|
|
76
|
+
if (!Number.isSafeInteger(override) || override < 1) throw new Error(`orphanIndexFromSequence must be a positive integer, got ${String(override)}`);
|
|
77
|
+
return override;
|
|
78
|
+
}
|
|
79
|
+
return Object.hasOwn(ORPHAN_INDEX_FROM_SEQUENCE, chainId) ? ORPHAN_INDEX_FROM_SEQUENCE[chainId] : 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { isCompleteChainConfig, isPlainRecord, mergeTransactionOverlay, orphanIndexFromSequence, rehydrateFollowerChainConfig, toResolverConfig };
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { BLOCKLET_ENV_CHAIN_FALLBACKS, BlockletEnvLeftovers, DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS, DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS, FutureTimestampGuardConfig, STANDALONE_ENV_MARKERS, TChainConfigCheckMode, TRANSACTION_SWITCH_ENV, TransactionSwitches, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, parseNonNegativeNumberEnv, resolveConfigCheckModeFromEnv, resolveConfigCheckTimeoutMsFromEnv, resolveFutureTimestampGuardFromEnv, resolveTransactionSwitchesFromEnv, resolveTrustedSubject } from "./standalone-env.mjs";
|
|
2
|
+
import { CONSENSUS_CONFIG_KEYS, ConfigDifference, VerifyFollowerConfigOptions, VerifyFollowerConfigResult, diffConsensusConfig, fetchUpstreamChainConfig, formatConfigDifferences, normalizeConsensusConfig, verifyFollowerConfigAgainstUpstream } from "./config-consistency.mjs";
|
|
1
3
|
import { ChainAppHookContext, ChainNodeHandle, ChainNodeProfile, ChainNodeRoleConfig, ChainNodeSegmentPublisher, ChainNodeSignerConfig, ChainNodeTestHooks, ChainNodeTestHooksInput, ChainProfile, ChainProfileBase, FollowerRoleConfig, FollowerSyncTestController, FollowerUpstreamInterceptorContext, HotStuffValidatorRoleConfig, ILedgerHealthStatus, ILedgerLeaseOptions, PublicKeyOnlyValidatorSignerConfig, RunningChainNode, StartChainNodeOptions, TNodeRetentionMode, TrustedAccountConfig, ValidatorRoleConfig, ValidatorSignerConfig } from "./types.mjs";
|
|
2
4
|
import { InstallProcessSignalHandlersOptions, installProcessSignalHandlers, leaseConfigFromEnv, roleConfigFromEnv } from "./env.mjs";
|
|
5
|
+
import { isCompleteChainConfig, rehydrateFollowerChainConfig, toResolverConfig } from "./follower-config.mjs";
|
|
3
6
|
import { startChainNode } from "./start-chain-node.mjs";
|
|
4
|
-
|
|
5
|
-
export { BLOCKLET_ENV_CHAIN_FALLBACKS, type BlockletEnvLeftovers, type ChainAppHookContext, type ChainNodeHandle, type ChainNodeProfile, type ChainNodeRoleConfig, type ChainNodeSegmentPublisher, type ChainNodeSignerConfig, type ChainNodeTestHooks, type ChainNodeTestHooksInput, type ChainProfile, type ChainProfileBase, type FollowerRoleConfig, type FollowerSyncTestController, type FollowerUpstreamInterceptorContext, type HotStuffValidatorRoleConfig, type ILedgerHealthStatus, type ILedgerLeaseOptions, type InstallProcessSignalHandlersOptions, type PublicKeyOnlyValidatorSignerConfig, type RunningChainNode, STANDALONE_ENV_MARKERS, type StartChainNodeOptions, type TNodeRetentionMode, type TrustedAccountConfig, type ValidatorRoleConfig, type ValidatorSignerConfig, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, installProcessSignalHandlers, leaseConfigFromEnv, resolveTrustedSubject, roleConfigFromEnv, startChainNode };
|
|
7
|
+
export { BLOCKLET_ENV_CHAIN_FALLBACKS, type BlockletEnvLeftovers, CONSENSUS_CONFIG_KEYS, type ChainAppHookContext, type ChainNodeHandle, type ChainNodeProfile, type ChainNodeRoleConfig, type ChainNodeSegmentPublisher, type ChainNodeSignerConfig, type ChainNodeTestHooks, type ChainNodeTestHooksInput, type ChainProfile, type ChainProfileBase, type ConfigDifference, DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS, DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS, type FollowerRoleConfig, type FollowerSyncTestController, type FollowerUpstreamInterceptorContext, type FutureTimestampGuardConfig, type HotStuffValidatorRoleConfig, type ILedgerHealthStatus, type ILedgerLeaseOptions, type InstallProcessSignalHandlersOptions, type PublicKeyOnlyValidatorSignerConfig, type RunningChainNode, STANDALONE_ENV_MARKERS, type StartChainNodeOptions, type TChainConfigCheckMode, type TNodeRetentionMode, TRANSACTION_SWITCH_ENV, type TransactionSwitches, type TrustedAccountConfig, type ValidatorRoleConfig, type ValidatorSignerConfig, type VerifyFollowerConfigOptions, type VerifyFollowerConfigResult, diffConsensusConfig, fetchUpstreamChainConfig, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, formatConfigDifferences, installProcessSignalHandlers, isCompleteChainConfig, leaseConfigFromEnv, normalizeConsensusConfig, parseNonNegativeNumberEnv, rehydrateFollowerChainConfig, resolveConfigCheckModeFromEnv, resolveConfigCheckTimeoutMsFromEnv, resolveFutureTimestampGuardFromEnv, resolveTransactionSwitchesFromEnv, resolveTrustedSubject, roleConfigFromEnv, startChainNode, toResolverConfig, verifyFollowerConfigAgainstUpstream };
|
package/esm/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CONSENSUS_CONFIG_KEYS, diffConsensusConfig, fetchUpstreamChainConfig, formatConfigDifferences, normalizeConsensusConfig, verifyFollowerConfigAgainstUpstream } from "./config-consistency.mjs";
|
|
1
2
|
import { installProcessSignalHandlers, leaseConfigFromEnv, roleConfigFromEnv } from "./env.mjs";
|
|
3
|
+
import { isCompleteChainConfig, rehydrateFollowerChainConfig, toResolverConfig } from "./follower-config.mjs";
|
|
2
4
|
import { startChainNode } from "./start-chain-node.mjs";
|
|
3
|
-
import { BLOCKLET_ENV_CHAIN_FALLBACKS, STANDALONE_ENV_MARKERS, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, resolveTrustedSubject } from "./standalone-env.mjs";
|
|
5
|
+
import { BLOCKLET_ENV_CHAIN_FALLBACKS, DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS, DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS, STANDALONE_ENV_MARKERS, TRANSACTION_SWITCH_ENV, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, parseNonNegativeNumberEnv, resolveConfigCheckModeFromEnv, resolveConfigCheckTimeoutMsFromEnv, resolveFutureTimestampGuardFromEnv, resolveTransactionSwitchesFromEnv, resolveTrustedSubject } from "./standalone-env.mjs";
|
|
4
6
|
|
|
5
|
-
export { BLOCKLET_ENV_CHAIN_FALLBACKS, STANDALONE_ENV_MARKERS, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, installProcessSignalHandlers, leaseConfigFromEnv, resolveTrustedSubject, roleConfigFromEnv, startChainNode };
|
|
7
|
+
export { BLOCKLET_ENV_CHAIN_FALLBACKS, CONSENSUS_CONFIG_KEYS, DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS, DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS, STANDALONE_ENV_MARKERS, TRANSACTION_SWITCH_ENV, diffConsensusConfig, fetchUpstreamChainConfig, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, formatConfigDifferences, installProcessSignalHandlers, isCompleteChainConfig, leaseConfigFromEnv, normalizeConsensusConfig, parseNonNegativeNumberEnv, rehydrateFollowerChainConfig, resolveConfigCheckModeFromEnv, resolveConfigCheckTimeoutMsFromEnv, resolveFutureTimestampGuardFromEnv, resolveTransactionSwitchesFromEnv, resolveTrustedSubject, roleConfigFromEnv, startChainNode, toResolverConfig, verifyFollowerConfigAgainstUpstream };
|
package/esm/standalone-env.d.mts
CHANGED
|
@@ -35,5 +35,58 @@ declare function formatBlockletEnvLeftoversWarning({
|
|
|
35
35
|
leftovers,
|
|
36
36
|
readByChain
|
|
37
37
|
}: BlockletEnvLeftovers): string;
|
|
38
|
+
/** Env names of the `transaction.*` master switches a chain app maps into its chain config. */
|
|
39
|
+
declare const TRANSACTION_SWITCH_ENV: {
|
|
40
|
+
readonly bridge: "CHAIN_TX_BRIDGE_ENABLED";
|
|
41
|
+
readonly rollupV1: "CHAIN_TX_ROLLUP_V1_ENABLED";
|
|
42
|
+
};
|
|
43
|
+
interface TransactionSwitches {
|
|
44
|
+
bridge?: {
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
};
|
|
47
|
+
rollupV1?: {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `transaction.bridge` / `transaction.rollupV1` from env. Only explicitly set switches are returned, so an env
|
|
53
|
+
* without them leaves the chain config exactly as before (bridge absent = disabled, rollupV1 absent = enabled).
|
|
54
|
+
*/
|
|
55
|
+
declare function resolveTransactionSwitchesFromEnv(env?: Env): TransactionSwitches;
|
|
56
|
+
type TChainConfigCheckMode = 'off' | 'warn' | 'enforce';
|
|
57
|
+
/**
|
|
58
|
+
* `CHAIN_CONFIG_CHECK`: what a follower does with the startup comparison of its consensus config against the
|
|
59
|
+
* upstream leader's `getConfig` (`off` default: no request at all; `warn`: log differences and start; `enforce`:
|
|
60
|
+
* refuse to start on any difference or when the upstream cannot be asked).
|
|
61
|
+
*/
|
|
62
|
+
declare function resolveConfigCheckModeFromEnv(env?: Env): TChainConfigCheckMode;
|
|
63
|
+
declare const DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS = 60;
|
|
64
|
+
/**
|
|
65
|
+
* `CHAIN_CONFIG_CHECK_TIMEOUT_SEC` (non-negative integer seconds, default 60): how long `enforce` keeps retrying an
|
|
66
|
+
* unreachable / bad upstream before it decides (start with a warning on existing local state, refuse when fresh).
|
|
67
|
+
*/
|
|
68
|
+
declare function resolveConfigCheckTimeoutMsFromEnv(env?: Env): number;
|
|
69
|
+
/**
|
|
70
|
+
* A fee / gas env value (`CHAIN_GAS_PRICE`, `CREATE_*_TX_FEE`), parsed identically on leader and follower:
|
|
71
|
+
* unset or empty -> undefined (the caller's default / no overlay); otherwise a plain non-negative decimal
|
|
72
|
+
* (`integer`: digits only). Whitespace, NaN, negatives, exponents and hex fail startup instead of becoming `0`.
|
|
73
|
+
*/
|
|
74
|
+
declare function parseNonNegativeNumberEnv(env: Env, name: string, {
|
|
75
|
+
integer
|
|
76
|
+
}?: {
|
|
77
|
+
integer?: boolean;
|
|
78
|
+
}): number | undefined;
|
|
79
|
+
/** Default clock skew a replayed entry's timestamp may be ahead of the local clock (#1961; #1965 owns the value). */
|
|
80
|
+
declare const DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS = 300;
|
|
81
|
+
interface FutureTimestampGuardConfig {
|
|
82
|
+
/** Entries with `sequence >= activationSequence` are checked; earlier history is always accepted. */
|
|
83
|
+
activationSequence: number;
|
|
84
|
+
maxSkewMs: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* `LEDGER_FUTURE_TIMESTAMP_FROM_SEQ` (positive integer; unset = guard disabled, today's behavior) and
|
|
88
|
+
* `LEDGER_FUTURE_TIMESTAMP_SKEW_SEC` (non-negative integer seconds, default 300; ignored while the guard is off).
|
|
89
|
+
*/
|
|
90
|
+
declare function resolveFutureTimestampGuardFromEnv(env?: Env): FutureTimestampGuardConfig | undefined;
|
|
38
91
|
//#endregion
|
|
39
|
-
export { BLOCKLET_ENV_CHAIN_FALLBACKS, BlockletEnvLeftovers, STANDALONE_ENV_MARKERS, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, resolveTrustedSubject };
|
|
92
|
+
export { BLOCKLET_ENV_CHAIN_FALLBACKS, BlockletEnvLeftovers, DEFAULT_CONFIG_CHECK_TIMEOUT_SECONDS, DEFAULT_FUTURE_TIMESTAMP_SKEW_SECONDS, FutureTimestampGuardConfig, STANDALONE_ENV_MARKERS, TChainConfigCheckMode, TRANSACTION_SWITCH_ENV, TransactionSwitches, findBlockletEnvLeftovers, formatBlockletEnvLeftoversWarning, parseNonNegativeNumberEnv, resolveConfigCheckModeFromEnv, resolveConfigCheckTimeoutMsFromEnv, resolveFutureTimestampGuardFromEnv, resolveTransactionSwitchesFromEnv, resolveTrustedSubject };
|