@ocap/chain-node 1.32.0 → 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/esm/config-consistency.d.mts +59 -0
- package/esm/config-consistency.mjs +220 -0
- package/esm/env.mjs +1 -1
- package/esm/follower-config.d.mts +25 -0
- package/esm/follower-config.mjs +57 -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 +17 -12
- package/esm/types.d.mts +18 -1
- package/lib/config-consistency.cjs +227 -0
- package/lib/config-consistency.d.cts +59 -0
- package/lib/env.cjs +1 -1
- package/lib/follower-config.cjs +63 -0
- package/lib/follower-config.d.cts +25 -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 +19 -15
- package/lib/types.d.cts +18 -1
- package/package.json +16 -16
package/lib/start-chain-node.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_access_log = require('./access-log.cjs');
|
|
3
|
+
const require_config_consistency = require('./config-consistency.cjs');
|
|
4
|
+
const require_follower_config = require('./follower-config.cjs');
|
|
3
5
|
const require_test_hooks_token = require('./test-hooks-token.cjs');
|
|
6
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
7
|
let _arcblock_ledger_core = require("@arcblock/ledger-core");
|
|
5
8
|
let _arcblock_ledger_sqlite = require("@arcblock/ledger-sqlite");
|
|
6
|
-
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
9
|
let node_crypto = require("node:crypto");
|
|
8
10
|
node_crypto = require_rolldown_runtime.__toESM(node_crypto);
|
|
9
11
|
let node_fs = require("node:fs");
|
|
@@ -11,8 +13,6 @@ node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
|
11
13
|
let node_path = require("node:path");
|
|
12
14
|
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
13
15
|
let _arcblock_did = require("@arcblock/did");
|
|
14
|
-
let _ocap_config = require("@ocap/config");
|
|
15
|
-
_ocap_config = require_rolldown_runtime.__toESM(_ocap_config);
|
|
16
16
|
let _ocap_gql = require("@ocap/gql");
|
|
17
17
|
let _ocap_indexdb_sqlite = require("@ocap/indexdb-sqlite");
|
|
18
18
|
_ocap_indexdb_sqlite = require_rolldown_runtime.__toESM(_ocap_indexdb_sqlite);
|
|
@@ -158,9 +158,6 @@ function adaptColdReaderToArchiveStore(reader) {
|
|
|
158
158
|
...typeof reader.getLatestHead === "function" ? { getLatestHead: reader.getLatestHead.bind(reader) } : {}
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
function isCompleteChainConfig(candidate) {
|
|
162
|
-
return Boolean(candidate && typeof candidate.chainId === "string" && candidate.chainId.trim() && candidate.moderator?.address && candidate.token?.symbol && candidate.vaults?.slashedStake);
|
|
163
|
-
}
|
|
164
161
|
function formatHttpHostForUrl(bindHost) {
|
|
165
162
|
const trimmed = bindHost.trim();
|
|
166
163
|
if (!trimmed || trimmed === "0.0.0.0" || trimmed === "::" || trimmed === "[::]") return "127.0.0.1";
|
|
@@ -188,7 +185,7 @@ async function bootChainNodeOnce(params) {
|
|
|
188
185
|
const dataDir = assertSafeNonSymlinkDirectory(profile.dataDir);
|
|
189
186
|
const { role } = profile;
|
|
190
187
|
if (!role || role.kind !== "validator" && role.kind !== "follower" && role.kind !== "hotstuff") throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", "ChainProfile.role.kind must be \"validator\", \"follower\", or \"hotstuff\"");
|
|
191
|
-
if ((role.kind === "validator" || role.kind === "hotstuff") && !isCompleteChainConfig(profile.chainConfig)) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `${role.kind} role requires a complete chainConfig`);
|
|
188
|
+
if ((role.kind === "validator" || role.kind === "hotstuff") && !require_follower_config.isCompleteChainConfig(profile.chainConfig)) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `${role.kind} role requires a complete chainConfig`);
|
|
192
189
|
if ((role.kind === "validator" || role.kind === "hotstuff") && !role.signer) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `${role.kind} role requires role.signer`);
|
|
193
190
|
if (role.kind === "hotstuff" && (!Array.isArray(role.validators) || role.validators.length === 0)) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", "HotStuff role requires a non-empty validators list");
|
|
194
191
|
const logger = testHooks?.logger ?? profile.logger ?? createDefaultLogger("chain-node");
|
|
@@ -346,20 +343,14 @@ async function bootChainNodeOnce(params) {
|
|
|
346
343
|
});
|
|
347
344
|
}
|
|
348
345
|
let chainConfig;
|
|
349
|
-
if (role.kind === "follower" && !isCompleteChainConfig(profile.chainConfig)) {
|
|
346
|
+
if (role.kind === "follower" && !require_follower_config.isCompleteChainConfig(profile.chainConfig)) {
|
|
350
347
|
const storedChain = await statedb.chain.get(CHAIN_STATE_ADDR);
|
|
351
348
|
if (!storedChain) throw new _ocap_util_lib_error.CustomError("INVALID_STATE", `Missing chain state (${CHAIN_STATE_ADDR}) in Follower statedb.sqlite (${statedbPath})`);
|
|
352
349
|
const storedChainPartial = storedChain;
|
|
353
350
|
const storedChainId = typeof storedChainPartial.chainId === "string" ? storedChainPartial.chainId.trim() : "";
|
|
354
351
|
const overrideChainId = typeof profile.chainConfig?.chainId === "string" ? profile.chainConfig.chainId.trim() : "";
|
|
355
352
|
if (storedChainId && overrideChainId && overrideChainId !== storedChainId) throw new _ocap_util_lib_error.CustomError("SNAPSHOT_CHAIN_ID_MISMATCH", `Follower profile.chainConfig.chainId (${overrideChainId}) !== statedb chain.chainId (${storedChainId})`);
|
|
356
|
-
|
|
357
|
-
const reservedSymbols = Array.from(new Set([baseSymbol, ...storedChainPartial.reservedSymbols ?? []].map((s) => String(s || "").trim().toUpperCase()).filter(Boolean)));
|
|
358
|
-
chainConfig = _ocap_config.create({
|
|
359
|
-
...storedChain,
|
|
360
|
-
...storedChainId ? { chainId: storedChainId } : {},
|
|
361
|
-
reservedSymbols
|
|
362
|
-
});
|
|
353
|
+
chainConfig = require_follower_config.rehydrateFollowerChainConfig(storedChain, profile.chainConfig);
|
|
363
354
|
} else {
|
|
364
355
|
const baseConfig = profile.chainConfig;
|
|
365
356
|
if (role.kind === "follower") {
|
|
@@ -604,6 +595,15 @@ async function bootChainNodeOnce(params) {
|
|
|
604
595
|
const initialPrefs = preferencesManager.getSnapshot();
|
|
605
596
|
if (initialPrefs.runtime.txMaxRequest !== void 0) resolver.setMaxTxRequest(initialPrefs.runtime.txMaxRequest);
|
|
606
597
|
await resolver.initialize();
|
|
598
|
+
if (role.kind === "follower") await require_config_consistency.verifyFollowerConfigAgainstUpstream({
|
|
599
|
+
mode: profile.configCheck?.mode ?? "off",
|
|
600
|
+
localConfig: resolver.config,
|
|
601
|
+
upstreamUrl: role.upstreamChainUrl ?? role.clusterPeerUrls?.[0] ?? null,
|
|
602
|
+
fetchUpstreamConfig: profile.configCheck?.fetchUpstreamConfig,
|
|
603
|
+
hasLocalState: !followerPrep?.bootstrapped && await ledger.getLatestSequence() > 0,
|
|
604
|
+
...profile.configCheck?.retryDeadlineMs !== void 0 ? { retryDeadlineMs: profile.configCheck.retryDeadlineMs } : {},
|
|
605
|
+
logger
|
|
606
|
+
});
|
|
607
607
|
let followerSync;
|
|
608
608
|
let hotstuffRuntime;
|
|
609
609
|
if (role.kind === "follower") {
|
|
@@ -645,6 +645,10 @@ async function bootChainNodeOnce(params) {
|
|
|
645
645
|
startPaused: testHooks?.followerSync?.startPaused,
|
|
646
646
|
artificialPollDelayMs: testHooks?.followerSync?.artificialPollDelayMs,
|
|
647
647
|
interceptUpstreamFetch: testHooks?.followerSync?.interceptUpstreamFetch,
|
|
648
|
+
...profile.replayGuards?.futureTimestamp ? { futureTimestampGuard: {
|
|
649
|
+
...profile.replayGuards.futureTimestamp,
|
|
650
|
+
now: clockNow
|
|
651
|
+
} } : {},
|
|
648
652
|
env: { ALLOW_PRIVATE_PEER_URLS: role.allowPrivatePeers ? "1" : "0" }
|
|
649
653
|
});
|
|
650
654
|
resolver.setNodeRuntime(followerSync);
|
package/lib/types.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { FutureTimestampGuardConfig, TChainConfigCheckMode } from "./standalone-env.cjs";
|
|
1
2
|
import { CHAIN_NODE_TEST_HOOKS_TOKEN } from "./test-hooks-token.cjs";
|
|
2
3
|
import express from "express";
|
|
4
|
+
import { IChainConfig, IPipelineLogger, TFollowerSyncMode, TNodeWritePolicy } from "@ocap/types";
|
|
3
5
|
import http from "node:http";
|
|
4
6
|
import { AnchorPublisher, ICheckpointSignerWallet, IHotStuffRuntimeValidatorMember, ILedgerHealth, INodeRoleConfig, ISegmentArchiveStore, IWriterLeaseConfig, Ledger, LedgerConfig } from "@arcblock/ledger-core";
|
|
5
7
|
import { SqliteLedgerStorage } from "@arcblock/ledger-sqlite";
|
|
@@ -7,7 +9,6 @@ import SqliteIndexDB from "@ocap/indexdb-sqlite";
|
|
|
7
9
|
import OCAPResolver, { FollowerSyncService, HotStuffNodeRuntime, HotStuffNodeRuntimeOptions, IColdSegmentReader, INodeMaintenanceController, NodePreferencesManager, TFollowerUpstreamFetchKind } from "@ocap/resolver";
|
|
8
10
|
import SqliteStateDB from "@ocap/statedb-sqlite";
|
|
9
11
|
import { SqliteTrustedStorage } from "@ocap/trusted-storage";
|
|
10
|
-
import { IChainConfig, IPipelineLogger, TFollowerSyncMode, TNodeWritePolicy } from "@ocap/types";
|
|
11
12
|
|
|
12
13
|
//#region src/types.d.ts
|
|
13
14
|
type ILedgerLeaseOptions = IWriterLeaseConfig;
|
|
@@ -190,6 +191,22 @@ interface ChainProfileBase {
|
|
|
190
191
|
env?: Record<string, string | undefined>;
|
|
191
192
|
};
|
|
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
|
+
};
|
|
193
210
|
logger?: IPipelineLogger;
|
|
194
211
|
configureApp?: (app: express.Express, ctx: ChainAppHookContext) => void | Promise<void>;
|
|
195
212
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.32.
|
|
6
|
+
"version": "1.32.1",
|
|
7
7
|
"description": "Unified OCAP chain node runtime assembly (Validator, Standby, Keyless Follower)",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -54,26 +54,26 @@
|
|
|
54
54
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@ocap/mcrypto": "1.32.
|
|
58
|
-
"@ocap/message": "1.32.
|
|
57
|
+
"@ocap/mcrypto": "1.32.1",
|
|
58
|
+
"@ocap/message": "1.32.1",
|
|
59
59
|
"@types/express": "^4.17.23",
|
|
60
60
|
"@types/node": "^20.10.0",
|
|
61
61
|
"tsdown": "^0.18.4"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@arcblock/did": "1.32.
|
|
65
|
-
"@arcblock/ledger-core": "1.32.
|
|
66
|
-
"@arcblock/ledger-sqlite": "1.32.
|
|
67
|
-
"@ocap/config": "1.32.
|
|
68
|
-
"@ocap/gql": "1.32.
|
|
69
|
-
"@ocap/indexdb-sqlite": "1.32.
|
|
70
|
-
"@ocap/resolver": "1.32.
|
|
71
|
-
"@ocap/state": "1.32.
|
|
72
|
-
"@ocap/statedb-sqlite": "1.32.
|
|
73
|
-
"@ocap/trusted-storage": "1.32.
|
|
74
|
-
"@ocap/types": "1.32.
|
|
75
|
-
"@ocap/util": "1.32.
|
|
76
|
-
"@ocap/wallet": "1.32.
|
|
64
|
+
"@arcblock/did": "1.32.1",
|
|
65
|
+
"@arcblock/ledger-core": "1.32.1",
|
|
66
|
+
"@arcblock/ledger-sqlite": "1.32.1",
|
|
67
|
+
"@ocap/config": "1.32.1",
|
|
68
|
+
"@ocap/gql": "1.32.1",
|
|
69
|
+
"@ocap/indexdb-sqlite": "1.32.1",
|
|
70
|
+
"@ocap/resolver": "1.32.1",
|
|
71
|
+
"@ocap/state": "1.32.1",
|
|
72
|
+
"@ocap/statedb-sqlite": "1.32.1",
|
|
73
|
+
"@ocap/trusted-storage": "1.32.1",
|
|
74
|
+
"@ocap/types": "1.32.1",
|
|
75
|
+
"@ocap/util": "1.32.1",
|
|
76
|
+
"@ocap/wallet": "1.32.1",
|
|
77
77
|
"cors": "^2.8.5",
|
|
78
78
|
"express": "^4.22.1"
|
|
79
79
|
}
|