@ocap/resolver 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/follower.d.mts +18 -1
- package/esm/follower.mjs +30 -6
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/replayer.d.mts +44 -4
- package/esm/replayer.mjs +41 -5
- package/lib/follower.cjs +29 -5
- package/lib/follower.d.cts +18 -1
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +2 -2
- package/lib/replayer.cjs +41 -4
- package/lib/replayer.d.cts +44 -4
- package/package.json +15 -15
package/esm/follower.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DnsLookupAllFn } from "./node-preferences.mjs";
|
|
2
|
-
import { IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.mjs";
|
|
2
|
+
import { IFutureTimestampRejection, IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.mjs";
|
|
3
3
|
import { ICheckpointSignerWallet } from "@arcblock/ledger-core";
|
|
4
4
|
import { IFollowerStatusResponse, IHotStuffClusterConfig, ILedgerArchiveHead, ILedgerSegment, INodeRuntimeAdapter, IResolverContext, TFollowerSyncMode, TNodeRetentionMode, TNodeRole, TNodeWritePolicy } from "@ocap/types";
|
|
5
5
|
|
|
@@ -90,6 +90,15 @@ interface FollowerSyncServiceOptions {
|
|
|
90
90
|
fetchImpl?: typeof fetch;
|
|
91
91
|
dnsLookup?: DnsLookupAllFn;
|
|
92
92
|
env?: Record<string, string | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* #1961: refuse (retryably) peer entries with `sequence >= activationSequence` whose timestamp is more than
|
|
95
|
+
* `maxSkewMs` ahead of `now()`. Unset (default): no guard, today's behavior.
|
|
96
|
+
*/
|
|
97
|
+
futureTimestampGuard?: {
|
|
98
|
+
activationSequence: number;
|
|
99
|
+
maxSkewMs: number;
|
|
100
|
+
now?: () => number;
|
|
101
|
+
};
|
|
93
102
|
}
|
|
94
103
|
declare function isTransientSqliteLockError(err: unknown): boolean;
|
|
95
104
|
declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
@@ -129,6 +138,8 @@ declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
|
129
138
|
private stopped;
|
|
130
139
|
private halted;
|
|
131
140
|
private haltReason;
|
|
141
|
+
private futureTimestampRejections;
|
|
142
|
+
private lastFutureTimestampRejection;
|
|
132
143
|
private pendingCrashWindowReconcile;
|
|
133
144
|
private initialCrashReconcileCompleted;
|
|
134
145
|
private upstreamSequence;
|
|
@@ -185,6 +196,12 @@ declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
|
185
196
|
* reading untrusted upstream `segmentEntries` (#1711).
|
|
186
197
|
*/
|
|
187
198
|
private resolveLocalFraudAlertStateRoot;
|
|
199
|
+
private recordFutureTimestampRejection;
|
|
200
|
+
/** #1961: how many peer entries were refused for a future timestamp, and the last one (for alerting/tests). */
|
|
201
|
+
getFutureTimestampRejections(): {
|
|
202
|
+
count: number;
|
|
203
|
+
last: IFutureTimestampRejection | null;
|
|
204
|
+
};
|
|
188
205
|
getFollowerStatus(): Promise<IFollowerStatusResponse>;
|
|
189
206
|
private isAllowedHotStuffValidator;
|
|
190
207
|
private hasCommittedTrustAnchor;
|
package/esm/follower.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFollowerPeerFetchGuard } from "./node-preferences.mjs";
|
|
2
|
-
import { LedgerEntryReplayer } from "./replayer.mjs";
|
|
2
|
+
import { FUTURE_LEDGER_ENTRY_TIMESTAMP, LedgerEntryReplayer } from "./replayer.mjs";
|
|
3
3
|
import { ArchivePayloadDecodeError, EntryHashRunVerifier, HotWindowPruneController, IncrementalMerkleTree, assertValidSegment, computeCheckpointHash, computeEntryHash, computeHotTailEntryCommitment, computeSegmentContentHash, createHotStuffTrustAnchor, createWitnessAttestation, deriveSegmentStateRoot, normalizeHttpBaseUrl, resolveTrustAnchor, verifyCheckpointQuorumCertificate, verifyCheckpointSignature, verifyDidMatchesMultiCurvePublicKey, verifyHotTailBatchSignature, verifyHotTailStatusSignature, verifySegmentCommitmentSignature } from "@arcblock/ledger-core";
|
|
4
4
|
import { toBuffer } from "@ocap/util";
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
@@ -144,7 +144,8 @@ const UPSTREAM_OR_TRANSPORT_ERROR_CODES = new Set([
|
|
|
144
144
|
"COLD_SEGMENT_CHAIN_MISMATCH",
|
|
145
145
|
"INVALID_LEDGER_ENTRY",
|
|
146
146
|
"UNFINALIZED_LEDGER_ENTRY",
|
|
147
|
-
"HTTP_ARCHIVE_ERROR"
|
|
147
|
+
"HTTP_ARCHIVE_ERROR",
|
|
148
|
+
FUTURE_LEDGER_ENTRY_TIMESTAMP
|
|
148
149
|
]);
|
|
149
150
|
function sanitizeUntrustedWireToken(value, maxLen = 128) {
|
|
150
151
|
return String(value ?? "").replace(/[\r\n\t\x00-\x1f\x7f]+/g, " ").trim().slice(0, maxLen);
|
|
@@ -237,6 +238,8 @@ var FollowerSyncService = class {
|
|
|
237
238
|
this.stopped = false;
|
|
238
239
|
this.halted = false;
|
|
239
240
|
this.haltReason = null;
|
|
241
|
+
this.futureTimestampRejections = 0;
|
|
242
|
+
this.lastFutureTimestampRejection = null;
|
|
240
243
|
this.pendingCrashWindowReconcile = false;
|
|
241
244
|
this.initialCrashReconcileCompleted = false;
|
|
242
245
|
this.upstreamSequence = null;
|
|
@@ -253,7 +256,10 @@ var FollowerSyncService = class {
|
|
|
253
256
|
this.writePolicy = options.writePolicy;
|
|
254
257
|
this.syncMode = options.syncMode;
|
|
255
258
|
this.chainId = options.resolver.config.chainId || options.resolver.ledger.chainId;
|
|
256
|
-
this.replayer = new LedgerEntryReplayer(options.resolver
|
|
259
|
+
this.replayer = new LedgerEntryReplayer(options.resolver, options.futureTimestampGuard ? { futureTimestampGuard: {
|
|
260
|
+
...options.futureTimestampGuard,
|
|
261
|
+
onReject: (info) => this.recordFutureTimestampRejection(info)
|
|
262
|
+
} } : {});
|
|
257
263
|
const retentionMode = options.retentionMode ?? "archive";
|
|
258
264
|
if (retentionMode !== "archive" && retentionMode !== "tiered") throw new CustomError("INVALID_CONFIG", `Invalid retentionMode "${String(retentionMode)}": expected "archive" or "tiered"`);
|
|
259
265
|
if (retentionMode === "tiered" && !options.coldArchiveStore) throw new CustomError("INVALID_CONFIG", "FollowerSyncService with retentionMode=\"tiered\" requires coldArchiveStore");
|
|
@@ -530,6 +536,17 @@ var FollowerSyncService = class {
|
|
|
530
536
|
if (liveCommit && liveCommit !== "UNKNOWN" && liveCommit !== "GENESIS") return liveCommit;
|
|
531
537
|
return localCp?.stateRoot ?? null;
|
|
532
538
|
}
|
|
539
|
+
recordFutureTimestampRejection(info) {
|
|
540
|
+
this.futureTimestampRejections++;
|
|
541
|
+
this.lastFutureTimestampRejection = { ...info };
|
|
542
|
+
}
|
|
543
|
+
/** #1961: how many peer entries were refused for a future timestamp, and the last one (for alerting/tests). */
|
|
544
|
+
getFutureTimestampRejections() {
|
|
545
|
+
return {
|
|
546
|
+
count: this.futureTimestampRejections,
|
|
547
|
+
last: this.lastFutureTimestampRejection ? { ...this.lastFutureTimestampRejection } : null
|
|
548
|
+
};
|
|
549
|
+
}
|
|
533
550
|
async getFollowerStatus() {
|
|
534
551
|
const [localSequence, latestCp, localStateCommitHash, synced] = await Promise.all([
|
|
535
552
|
this.resolver.ledger.getLatestSequence(),
|
|
@@ -1891,7 +1908,7 @@ var FollowerSyncService = class {
|
|
|
1891
1908
|
}
|
|
1892
1909
|
async replayCrashWindowEntry(entry) {
|
|
1893
1910
|
try {
|
|
1894
|
-
this.replayer.validateWireEntry(entry);
|
|
1911
|
+
this.replayer.validateWireEntry(entry, { skipFutureTimestampCheck: true });
|
|
1895
1912
|
const expectedCommit = (entry.stateCommitHash ?? "").trim();
|
|
1896
1913
|
const v2Cutoff = typeof this.resolver.ledger.getEntryHashV2From === "function" ? this.resolver.ledger.getEntryHashV2From() : void 0;
|
|
1897
1914
|
if (typeof v2Cutoff === "number" && !Number.isNaN(v2Cutoff)) {
|
|
@@ -2024,7 +2041,8 @@ var FollowerSyncService = class {
|
|
|
2024
2041
|
if (!matchedBase && unappliedOrdered.length > 0 && unappliedOrdered[0].sequence === expectedDryRunPrevSeq + 1 && typeof this.resolver.statedb.runWithinDryRunSession === "function") {
|
|
2025
2042
|
const dryRun = await this.replayer.dryRunVerifyEntries(unappliedOrdered, {
|
|
2026
2043
|
expectedPrevSequence: expectedDryRunPrevSeq,
|
|
2027
|
-
prevStateRoot: currentCommit
|
|
2044
|
+
prevStateRoot: currentCommit,
|
|
2045
|
+
skipFutureTimestampCheck: true
|
|
2028
2046
|
}).catch((dryErr) => {
|
|
2029
2047
|
if (isTransientSqliteLockError(dryErr)) throw dryErr;
|
|
2030
2048
|
return null;
|
|
@@ -2380,7 +2398,13 @@ var FollowerSyncService = class {
|
|
|
2380
2398
|
this.haltFailClosed(haltReason, errCode);
|
|
2381
2399
|
throw err;
|
|
2382
2400
|
}
|
|
2383
|
-
this.resolver.logger.
|
|
2401
|
+
if (errCode === FUTURE_LEDGER_ENTRY_TIMESTAMP) this.resolver.logger.error(`FollowerSyncService refused a future-dated ledger entry (${errCode}); will retry`, {
|
|
2402
|
+
chainId: this.chainId,
|
|
2403
|
+
code: errCode,
|
|
2404
|
+
rejections: this.futureTimestampRejections,
|
|
2405
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2406
|
+
});
|
|
2407
|
+
else this.resolver.logger.warn("FollowerSyncService transient sync error", {
|
|
2384
2408
|
chainId: this.chainId,
|
|
2385
2409
|
error: err instanceof Error ? err.message : String(err)
|
|
2386
2410
|
});
|
package/esm/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { CreateNodeDashboardRouterOptions, CreateUnifiedConsoleMiddlewareOptions
|
|
|
3
3
|
import { IAddressArgs, IAssetState, IChainConfig, IChunkIterator, IDataObject, IDelegateState, IEvidenceState, IFilter as IFilter$1, IFollowerStatusResponse, IGetAccountStateArgs, IGetAccountTokensArgs, IGetStateParams, IIndexDB as IIndexDB$1, IListChunksParams, INodeRuntimeAdapter, IPaginatedResult, IPipelineLogger as IPipelineLogger$1, IResolver, IResolverAccountState, IResolverChainInfo, IResolverContext as IResolverContext$1, IResolverFactoryState, IResolverForgeStats, IResolverListAccountsResult, IResolverListAssetsResult, IResolverListDelegationsResult, IResolverListFactoriesResult, IResolverListRollupBlocksResult, IResolverListRollupValidatorsResult, IResolverListRollupsResult, IResolverListStakesResult, IResolverListTokenFactoriesResult, IResolverListTokensResult, IResolverListTransactionsResult, IResolverNetInfo, IResolverNodeInfo, IResolverPaging, IResolverParams, IResolverRollupState, IResolverStakeState, IResolverTransaction, IResolverValidatorsInfo, IRollupBlock, IStateDB as IStateDB$1, ITokenCache, ITokenFactoryState, ITokenFlowsResult, ITokenInfo, ITokenState, TIndexedTokenState as TIndexedTokenState$1, TRequestEstimateGas, TRequestGetEvidenceState, TRequestGetRollupBlock, TRequestGetTokenDistribution, TRequestGetTx, TRequestListAssetTransactions, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokenFlows, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions, TRequestSearch, TRequestVerifyAccountRisk, TSearchResult, TTokenDistribution, TVerifyAccountRiskResult } from "./types.mjs";
|
|
4
4
|
import { CreateAPIHandlerOptions, ICreateAPIHandlerParams } from "./api.mjs";
|
|
5
5
|
import { CreateExplorerMiddlewareOptions, createExplorerMiddleware, isExplorerEnabled } from "./explorer.mjs";
|
|
6
|
-
import { IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.mjs";
|
|
6
|
+
import { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer } from "./replayer.mjs";
|
|
7
7
|
import { DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FollowerSyncService, FollowerSyncServiceOptions, IColdSegmentReader, ILeaderRouterLike, TFollowerUpstreamFetchInterceptor, TFollowerUpstreamFetchKind, isTransientSqliteLockError } from "./follower.mjs";
|
|
8
8
|
import { ConsensusAbortError, HotStuffNodeRuntime, HotStuffNodeRuntimeOptions, IHotStuffNetworkInterceptorContext, IHotStuffRuntimeStateSnapshot, IHotStuffRuntimeStateStore, TConsensusAbortCode } from "./hotstuff-runtime.mjs";
|
|
9
9
|
import { MigrationChainManager } from "./migration-chain.mjs";
|
|
@@ -350,4 +350,4 @@ declare class OCAPResolver implements IResolver {
|
|
|
350
350
|
}): Promise<IChunkIterator<IResolverStakeState>>;
|
|
351
351
|
}
|
|
352
352
|
//#endregion
|
|
353
|
-
export { type AdminAuthGuardOptions, ConsensusAbortError, type CreateAPIHandlerOptions, type CreateExplorerMiddlewareOptions, type CreateNodeDashboardRouterOptions, type CreateUnifiedConsoleMiddlewareOptions, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, type DnsLookupAllFn, FollowerSyncService, type FollowerSyncServiceOptions, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, type HotStuffNodeRuntimeOptions, type IAdminAuthGuard, type IAttributedBlockedAccount, type IAttributedReservedSymbol, type IAttributedTrustedAccount, type IBlockedAccountEntry, type IChainConfig, type IChunkIterator, type IColdSegmentReader, type ICreateAPIHandlerParams, type IDashboardResolverTarget, type IDataObject, type IDatabaseFileMetrics, type IDryRunVerifyEntriesOptions, type IDryRunVerifyEntriesResult, type IFollowerStatusResponse, type IHotStuffNetworkInterceptorContext, type IHotStuffRuntimeStateSnapshot, type IHotStuffRuntimeStateStore, type ILeaderRouterLike, type ILedgerHealthSummary, type ILedgerHealthThresholds, type ILegacyPreferencesResult, type INodeMaintenanceController, type INodeMaintenanceStatusSummary, type INodePreferencesFileSchema, type INodePreferencesSnapshot, type INodeRuntimeAdapter, type INodeRuntimePreferences, type IPaginatedResult, type IReplayEntryOptions, type IReplayEntryResult, type IReplayerResolverTarget, type IReservedSymbolEntry, type IResolverPaging, type IResolverParams, type IResolverTransaction, type ISlowStorageTelemetry, type ITokenInfo, type ITrustedAccountEntry, type IUpdateNodePreferencesInput, type IUpdateNodePreferencesResult, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, type NodeMaintenanceControllerOptions, NodePreferencesError, NodePreferencesManager, type NodePreferencesManagerOptions, type TConsensusAbortCode, type TFollowerUpstreamFetchInterceptor, type TFollowerUpstreamFetchKind, type TPreferenceSource, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
|
353
|
+
export { type AdminAuthGuardOptions, ConsensusAbortError, type CreateAPIHandlerOptions, type CreateExplorerMiddlewareOptions, type CreateNodeDashboardRouterOptions, type CreateUnifiedConsoleMiddlewareOptions, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, type DnsLookupAllFn, FUTURE_LEDGER_ENTRY_TIMESTAMP, FollowerSyncService, type FollowerSyncServiceOptions, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, type HotStuffNodeRuntimeOptions, type IAdminAuthGuard, type IAttributedBlockedAccount, type IAttributedReservedSymbol, type IAttributedTrustedAccount, type IBlockedAccountEntry, type IChainConfig, type IChunkIterator, type IColdSegmentReader, type ICreateAPIHandlerParams, type IDashboardResolverTarget, type IDataObject, type IDatabaseFileMetrics, type IDryRunVerifyEntriesOptions, type IDryRunVerifyEntriesResult, type IFollowerStatusResponse, type IFutureTimestampGuardOptions, type IFutureTimestampRejection, type IHotStuffNetworkInterceptorContext, type IHotStuffRuntimeStateSnapshot, type IHotStuffRuntimeStateStore, type ILeaderRouterLike, type ILedgerEntryReplayerOptions, type ILedgerHealthSummary, type ILedgerHealthThresholds, type ILegacyPreferencesResult, type INodeMaintenanceController, type INodeMaintenanceStatusSummary, type INodePreferencesFileSchema, type INodePreferencesSnapshot, type INodeRuntimeAdapter, type INodeRuntimePreferences, type IPaginatedResult, type IReplayEntryOptions, type IReplayEntryResult, type IReplayerResolverTarget, type IReservedSymbolEntry, type IResolverPaging, type IResolverParams, type IResolverTransaction, type ISlowStorageTelemetry, type ITokenInfo, type ITrustedAccountEntry, type IUpdateNodePreferencesInput, type IUpdateNodePreferencesResult, type IValidateWireEntryOptions, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, type NodeMaintenanceControllerOptions, NodePreferencesError, NodePreferencesManager, type NodePreferencesManagerOptions, type TConsensusAbortCode, type TFollowerUpstreamFetchInterceptor, type TFollowerUpstreamFetchKind, type TPreferenceSource, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
package/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, NodePreferencesError, NodePreferencesManager, applyBootRuntimePreferences, createAdminAuthGuard, createFollowerPeerFetchGuard, isPrivateOrReservedIpAddress, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls } from "./node-preferences.mjs";
|
|
2
2
|
import { UNIFIED_CONSOLE_APP_JS, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, isDashboardEnabled } from "./dashboard.mjs";
|
|
3
3
|
import { createExplorerMiddleware, isExplorerEnabled } from "./explorer.mjs";
|
|
4
|
-
import { LedgerEntryReplayer } from "./replayer.mjs";
|
|
4
|
+
import { FUTURE_LEDGER_ENTRY_TIMESTAMP, LedgerEntryReplayer } from "./replayer.mjs";
|
|
5
5
|
import { DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FollowerSyncService, isTransientSqliteLockError } from "./follower.mjs";
|
|
6
6
|
import { name } from "./package.mjs";
|
|
7
7
|
import { onCreateRollup, onCreateRollupBlock, onCreateTx, onUpdateToken } from "./hooks.mjs";
|
|
@@ -2653,4 +2653,4 @@ var OCAPResolver = class {
|
|
|
2653
2653
|
};
|
|
2654
2654
|
|
|
2655
2655
|
//#endregion
|
|
2656
|
-
export { ConsensusAbortError, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FollowerSyncService, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, NodePreferencesError, NodePreferencesManager, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
|
2656
|
+
export { ConsensusAbortError, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FUTURE_LEDGER_ENTRY_TIMESTAMP, FollowerSyncService, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, NodePreferencesError, NodePreferencesManager, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
package/esm/replayer.d.mts
CHANGED
|
@@ -28,6 +28,38 @@ interface IDryRunVerifyEntriesOptions {
|
|
|
28
28
|
expectedPrevSequence?: number;
|
|
29
29
|
prevStateRoot?: string | null;
|
|
30
30
|
entryHashV2From?: number | 'infinity';
|
|
31
|
+
/** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
|
|
32
|
+
skipFutureTimestampCheck?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface IValidateWireEntryOptions {
|
|
35
|
+
/** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
|
|
36
|
+
skipFutureTimestampCheck?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Error code of a replayed entry refused for a timestamp ahead of the local clock (retryable, never halting). */
|
|
39
|
+
declare const FUTURE_LEDGER_ENTRY_TIMESTAMP = "FUTURE_LEDGER_ENTRY_TIMESTAMP";
|
|
40
|
+
interface IFutureTimestampRejection {
|
|
41
|
+
sequence: number;
|
|
42
|
+
hash: string;
|
|
43
|
+
timestamp: number;
|
|
44
|
+
nowMs: number;
|
|
45
|
+
maxSkewMs: number;
|
|
46
|
+
activationSequence: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* #1961: `entry.timestamp` is not covered by `entryHash`, so a leader can stamp a real entry with a future time
|
|
50
|
+
* (and with it every time lock the tx sets). A follower refuses peer entries at or after `activationSequence` whose
|
|
51
|
+
* timestamp is more than `maxSkewMs` ahead of its own clock. Past timestamps are always accepted (no monotonic
|
|
52
|
+
* rule, #1972). The refusal is retryable: the entry is accepted once the local clock catches up.
|
|
53
|
+
*/
|
|
54
|
+
interface IFutureTimestampGuardOptions {
|
|
55
|
+
activationSequence: number;
|
|
56
|
+
maxSkewMs: number;
|
|
57
|
+
now?: () => number;
|
|
58
|
+
onReject?: (info: IFutureTimestampRejection) => void;
|
|
59
|
+
}
|
|
60
|
+
interface ILedgerEntryReplayerOptions {
|
|
61
|
+
/** Unset (default): no timestamp guard, today's behavior. */
|
|
62
|
+
futureTimestampGuard?: IFutureTimestampGuardOptions;
|
|
31
63
|
}
|
|
32
64
|
interface IDryRunVerifyEntriesResult {
|
|
33
65
|
derivedStateRoot: string;
|
|
@@ -43,15 +75,23 @@ declare class LedgerEntryReplayer {
|
|
|
43
75
|
private lastCommitMismatchError;
|
|
44
76
|
private lastStorageError;
|
|
45
77
|
private mutex;
|
|
46
|
-
|
|
78
|
+
private readonly futureTimestampGuard;
|
|
79
|
+
constructor(resolver: IReplayerResolverTarget, options?: ILedgerEntryReplayerOptions);
|
|
47
80
|
private runExclusive;
|
|
48
81
|
private appendVerifiedEntryToLedger;
|
|
49
82
|
private verifyRawTxHashMatchesEntry;
|
|
83
|
+
/**
|
|
84
|
+
* #1961 future-timestamp guard (no-op unless `futureTimestampGuard` is configured). Throws a retryable
|
|
85
|
+
* `FUTURE_LEDGER_ENTRY_TIMESTAMP` that is neither a local divergence nor a peer authentication failure, so the
|
|
86
|
+
* follower logs it, keeps its state and retries on the next sync cycle.
|
|
87
|
+
*/
|
|
88
|
+
assertEntryTimestampNotInFuture(entry: ILedgerEntry): void;
|
|
50
89
|
/**
|
|
51
90
|
* Pre-replay wire & primitive validation for untrusted network hot-tail / cold-segment payloads (#1710).
|
|
52
|
-
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion
|
|
91
|
+
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion,
|
|
92
|
+
* and the retryable `FUTURE_LEDGER_ENTRY_TIMESTAMP` when the #1961 guard is on (unless the entry is local).
|
|
53
93
|
*/
|
|
54
|
-
validateWireEntry(entry: ILedgerEntry): void;
|
|
94
|
+
validateWireEntry(entry: ILedgerEntry, options?: IValidateWireEntryOptions): void;
|
|
55
95
|
private authenticateAndDecodeEntry;
|
|
56
96
|
private indexOrphanEntry;
|
|
57
97
|
/**
|
|
@@ -71,4 +111,4 @@ declare class LedgerEntryReplayer {
|
|
|
71
111
|
indexExistingOrphanEntries(fromSeq?: number, toSeq?: number): Promise<number>;
|
|
72
112
|
}
|
|
73
113
|
//#endregion
|
|
74
|
-
export { IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, LedgerEntryReplayer };
|
|
114
|
+
export { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer };
|
package/esm/replayer.mjs
CHANGED
|
@@ -21,6 +21,8 @@ import { Blacklist } from "@ocap/state";
|
|
|
21
21
|
* - Enforces pre-commit `expectedCommitHash` on `statedb.runAsLambda` so any state divergence rolls back
|
|
22
22
|
* SQLite atomically BEFORE `COMMIT` and before appending to `ledger.sqlite`.
|
|
23
23
|
*/
|
|
24
|
+
/** Error code of a replayed entry refused for a timestamp ahead of the local clock (retryable, never halting). */
|
|
25
|
+
const FUTURE_LEDGER_ENTRY_TIMESTAMP = "FUTURE_LEDGER_ENTRY_TIMESTAMP";
|
|
24
26
|
function normalizeHexLower(raw) {
|
|
25
27
|
return String(raw ?? "").trim().replace(/^0x/i, "").toLowerCase();
|
|
26
28
|
}
|
|
@@ -43,7 +45,7 @@ function isLocalStorageEngineError(err, depth = 0) {
|
|
|
43
45
|
return cause !== void 0 && cause !== err ? isLocalStorageEngineError(cause, depth + 1) : false;
|
|
44
46
|
}
|
|
45
47
|
var LedgerEntryReplayer = class {
|
|
46
|
-
constructor(resolver) {
|
|
48
|
+
constructor(resolver, options = {}) {
|
|
47
49
|
this.activeSubLambdaOverride = null;
|
|
48
50
|
this.lastCommittedHash = null;
|
|
49
51
|
this.lastCommitMismatchError = null;
|
|
@@ -51,6 +53,12 @@ var LedgerEntryReplayer = class {
|
|
|
51
53
|
this.mutex = Promise.resolve();
|
|
52
54
|
this.resolver = resolver;
|
|
53
55
|
this.emptyFilter = new Blacklist();
|
|
56
|
+
const guard = options.futureTimestampGuard;
|
|
57
|
+
if (guard) {
|
|
58
|
+
if (!Number.isSafeInteger(guard.activationSequence) || guard.activationSequence < 1) throw new CustomError("INVALID_CONFIG", `futureTimestampGuard.activationSequence must be a positive integer, got ${String(guard.activationSequence)}`);
|
|
59
|
+
if (!Number.isSafeInteger(guard.maxSkewMs) || guard.maxSkewMs < 0) throw new CustomError("INVALID_CONFIG", `futureTimestampGuard.maxSkewMs must be a non-negative integer, got ${String(guard.maxSkewMs)}`);
|
|
60
|
+
}
|
|
61
|
+
this.futureTimestampGuard = guard ? { ...guard } : null;
|
|
54
62
|
const statedb = resolver.statedb;
|
|
55
63
|
const runAsLambda = typeof statedb.runAsLambda === "function" ? async (fn, opts = {}) => {
|
|
56
64
|
const expectedCommitHash = this.activeExpectedCommitHash;
|
|
@@ -140,13 +148,40 @@ var LedgerEntryReplayer = class {
|
|
|
140
148
|
if (computedTxHash.toUpperCase() !== entry.hash.toUpperCase()) throw new CustomError(throwCodeOnMismatch, `Ledger entry txRaw hash mismatch at seq=${entry.sequence}: computed ${computedTxHash}, entry has ${entry.hash}`);
|
|
141
149
|
}
|
|
142
150
|
/**
|
|
151
|
+
* #1961 future-timestamp guard (no-op unless `futureTimestampGuard` is configured). Throws a retryable
|
|
152
|
+
* `FUTURE_LEDGER_ENTRY_TIMESTAMP` that is neither a local divergence nor a peer authentication failure, so the
|
|
153
|
+
* follower logs it, keeps its state and retries on the next sync cycle.
|
|
154
|
+
*/
|
|
155
|
+
assertEntryTimestampNotInFuture(entry) {
|
|
156
|
+
const guard = this.futureTimestampGuard;
|
|
157
|
+
if (!guard || !Number.isSafeInteger(entry?.sequence) || entry.sequence < guard.activationSequence) return;
|
|
158
|
+
const nowMs = guard.now ? guard.now() : Date.now();
|
|
159
|
+
if (!Number.isFinite(nowMs) || entry.timestamp <= nowMs + guard.maxSkewMs) return;
|
|
160
|
+
const info = {
|
|
161
|
+
sequence: entry.sequence,
|
|
162
|
+
hash: String(entry.hash ?? ""),
|
|
163
|
+
timestamp: entry.timestamp,
|
|
164
|
+
nowMs,
|
|
165
|
+
maxSkewMs: guard.maxSkewMs,
|
|
166
|
+
activationSequence: guard.activationSequence
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
guard.onReject?.(info);
|
|
170
|
+
} catch {}
|
|
171
|
+
const err = new CustomError(FUTURE_LEDGER_ENTRY_TIMESTAMP, `Ledger entry seq=${entry.sequence} timestamp ${entry.timestamp} is ${entry.timestamp - nowMs} ms ahead of the local clock (max skew ${guard.maxSkewMs} ms, guard active from seq=${guard.activationSequence}); will retry`);
|
|
172
|
+
err.retryable = true;
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
143
176
|
* Pre-replay wire & primitive validation for untrusted network hot-tail / cold-segment payloads (#1710).
|
|
144
|
-
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion
|
|
177
|
+
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion,
|
|
178
|
+
* and the retryable `FUTURE_LEDGER_ENTRY_TIMESTAMP` when the #1961 guard is on (unless the entry is local).
|
|
145
179
|
*/
|
|
146
|
-
validateWireEntry(entry) {
|
|
180
|
+
validateWireEntry(entry, options = {}) {
|
|
147
181
|
if (!entry || typeof entry !== "object" || !Number.isSafeInteger(entry.sequence) || entry.sequence < 1 || !Number.isSafeInteger(entry.nonce) || entry.nonce < 0 || !Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > 864e13 || typeof entry.hash !== "string" || typeof entry.from !== "string" || typeof entry.pk !== "string" || typeof entry.signature !== "string" || typeof entry.txRaw !== "string" || typeof entry.txType !== "string" || typeof entry.chainId !== "string" || typeof entry.entryHash !== "string" || typeof entry.finalized !== "boolean" || entry.stateCommitHash !== void 0 && typeof entry.stateCommitHash !== "string" || entry.tx === null || typeof entry.tx !== "object" || Array.isArray(entry.tx)) throw new CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${String(entry?.sequence)} has invalid wire primitive types`);
|
|
148
182
|
this.verifyRawTxHashMatchesEntry(entry, "INVALID_LEDGER_ENTRY");
|
|
149
183
|
this.authenticateAndDecodeEntry(entry);
|
|
184
|
+
if (!options.skipFutureTimestampCheck) this.assertEntryTimestampNotInFuture(entry);
|
|
150
185
|
}
|
|
151
186
|
authenticateAndDecodeEntry(entry) {
|
|
152
187
|
const authRes = authenticateEntryDecodedFields(entry, true, { requireFullWireEntry: true });
|
|
@@ -203,6 +238,7 @@ var LedgerEntryReplayer = class {
|
|
|
203
238
|
}
|
|
204
239
|
if (entry.sequence !== localLatestSeq + 1) throw new CustomError("SEQUENCE_GAP", `Non-contiguous replay sequence: localLatest=${localLatestSeq}, got seq=${entry.sequence}`);
|
|
205
240
|
}
|
|
241
|
+
if (appendToLedger) this.assertEntryTimestampNotInFuture(entry);
|
|
206
242
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
207
243
|
const decodedTx = this.authenticateAndDecodeEntry(entry);
|
|
208
244
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
@@ -294,7 +330,7 @@ var LedgerEntryReplayer = class {
|
|
|
294
330
|
if (entry.finalized !== true) throw new CustomError("UNFINALIZED_LEDGER_ENTRY", `Proposal entry seq=${String(entry.sequence)} must be finalized`);
|
|
295
331
|
if (entry.chainId !== expectedChainId) throw new CustomError("CHAIN_ID_MISMATCH", `Proposal entry chainId mismatch at seq=${String(entry.sequence)}: expected ${expectedChainId}, got ${entry.chainId}`);
|
|
296
332
|
if (entry.sequence !== baseSeq + i + 1) throw new CustomError("SEQUENCE_GAP", `Proposal entry sequence mismatch at index ${i}: expected ${baseSeq + i + 1}, got ${entry.sequence}`);
|
|
297
|
-
this.validateWireEntry(entry);
|
|
333
|
+
this.validateWireEntry(entry, { skipFutureTimestampCheck: options.skipFutureTimestampCheck });
|
|
298
334
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
299
335
|
const expectedEntryHash = computeEntryHash(entry.sequence, entry.txRaw, expectedStateCommit, entry.sequence >= v2Cutoff ? 2 : 1);
|
|
300
336
|
if (entry.entryHash !== expectedEntryHash) throw new CustomError("INVALID_LEDGER_ENTRY", `Proposal entryHash mismatch at seq=${entry.sequence}: expected ${expectedEntryHash}, got ${entry.entryHash}`);
|
|
@@ -391,4 +427,4 @@ var LedgerEntryReplayer = class {
|
|
|
391
427
|
};
|
|
392
428
|
|
|
393
429
|
//#endregion
|
|
394
|
-
export { LedgerEntryReplayer };
|
|
430
|
+
export { FUTURE_LEDGER_ENTRY_TIMESTAMP, LedgerEntryReplayer };
|
package/lib/follower.cjs
CHANGED
|
@@ -145,7 +145,8 @@ const UPSTREAM_OR_TRANSPORT_ERROR_CODES = new Set([
|
|
|
145
145
|
"COLD_SEGMENT_CHAIN_MISMATCH",
|
|
146
146
|
"INVALID_LEDGER_ENTRY",
|
|
147
147
|
"UNFINALIZED_LEDGER_ENTRY",
|
|
148
|
-
"HTTP_ARCHIVE_ERROR"
|
|
148
|
+
"HTTP_ARCHIVE_ERROR",
|
|
149
|
+
require_replayer.FUTURE_LEDGER_ENTRY_TIMESTAMP
|
|
149
150
|
]);
|
|
150
151
|
function sanitizeUntrustedWireToken(value, maxLen = 128) {
|
|
151
152
|
return String(value ?? "").replace(/[\r\n\t\x00-\x1f\x7f]+/g, " ").trim().slice(0, maxLen);
|
|
@@ -238,6 +239,8 @@ var FollowerSyncService = class {
|
|
|
238
239
|
this.stopped = false;
|
|
239
240
|
this.halted = false;
|
|
240
241
|
this.haltReason = null;
|
|
242
|
+
this.futureTimestampRejections = 0;
|
|
243
|
+
this.lastFutureTimestampRejection = null;
|
|
241
244
|
this.pendingCrashWindowReconcile = false;
|
|
242
245
|
this.initialCrashReconcileCompleted = false;
|
|
243
246
|
this.upstreamSequence = null;
|
|
@@ -254,7 +257,10 @@ var FollowerSyncService = class {
|
|
|
254
257
|
this.writePolicy = options.writePolicy;
|
|
255
258
|
this.syncMode = options.syncMode;
|
|
256
259
|
this.chainId = options.resolver.config.chainId || options.resolver.ledger.chainId;
|
|
257
|
-
this.replayer = new require_replayer.LedgerEntryReplayer(options.resolver
|
|
260
|
+
this.replayer = new require_replayer.LedgerEntryReplayer(options.resolver, options.futureTimestampGuard ? { futureTimestampGuard: {
|
|
261
|
+
...options.futureTimestampGuard,
|
|
262
|
+
onReject: (info) => this.recordFutureTimestampRejection(info)
|
|
263
|
+
} } : {});
|
|
258
264
|
const retentionMode = options.retentionMode ?? "archive";
|
|
259
265
|
if (retentionMode !== "archive" && retentionMode !== "tiered") throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `Invalid retentionMode "${String(retentionMode)}": expected "archive" or "tiered"`);
|
|
260
266
|
if (retentionMode === "tiered" && !options.coldArchiveStore) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", "FollowerSyncService with retentionMode=\"tiered\" requires coldArchiveStore");
|
|
@@ -531,6 +537,17 @@ var FollowerSyncService = class {
|
|
|
531
537
|
if (liveCommit && liveCommit !== "UNKNOWN" && liveCommit !== "GENESIS") return liveCommit;
|
|
532
538
|
return localCp?.stateRoot ?? null;
|
|
533
539
|
}
|
|
540
|
+
recordFutureTimestampRejection(info) {
|
|
541
|
+
this.futureTimestampRejections++;
|
|
542
|
+
this.lastFutureTimestampRejection = { ...info };
|
|
543
|
+
}
|
|
544
|
+
/** #1961: how many peer entries were refused for a future timestamp, and the last one (for alerting/tests). */
|
|
545
|
+
getFutureTimestampRejections() {
|
|
546
|
+
return {
|
|
547
|
+
count: this.futureTimestampRejections,
|
|
548
|
+
last: this.lastFutureTimestampRejection ? { ...this.lastFutureTimestampRejection } : null
|
|
549
|
+
};
|
|
550
|
+
}
|
|
534
551
|
async getFollowerStatus() {
|
|
535
552
|
const [localSequence, latestCp, localStateCommitHash, synced] = await Promise.all([
|
|
536
553
|
this.resolver.ledger.getLatestSequence(),
|
|
@@ -1892,7 +1909,7 @@ var FollowerSyncService = class {
|
|
|
1892
1909
|
}
|
|
1893
1910
|
async replayCrashWindowEntry(entry) {
|
|
1894
1911
|
try {
|
|
1895
|
-
this.replayer.validateWireEntry(entry);
|
|
1912
|
+
this.replayer.validateWireEntry(entry, { skipFutureTimestampCheck: true });
|
|
1896
1913
|
const expectedCommit = (entry.stateCommitHash ?? "").trim();
|
|
1897
1914
|
const v2Cutoff = typeof this.resolver.ledger.getEntryHashV2From === "function" ? this.resolver.ledger.getEntryHashV2From() : void 0;
|
|
1898
1915
|
if (typeof v2Cutoff === "number" && !Number.isNaN(v2Cutoff)) {
|
|
@@ -2025,7 +2042,8 @@ var FollowerSyncService = class {
|
|
|
2025
2042
|
if (!matchedBase && unappliedOrdered.length > 0 && unappliedOrdered[0].sequence === expectedDryRunPrevSeq + 1 && typeof this.resolver.statedb.runWithinDryRunSession === "function") {
|
|
2026
2043
|
const dryRun = await this.replayer.dryRunVerifyEntries(unappliedOrdered, {
|
|
2027
2044
|
expectedPrevSequence: expectedDryRunPrevSeq,
|
|
2028
|
-
prevStateRoot: currentCommit
|
|
2045
|
+
prevStateRoot: currentCommit,
|
|
2046
|
+
skipFutureTimestampCheck: true
|
|
2029
2047
|
}).catch((dryErr) => {
|
|
2030
2048
|
if (isTransientSqliteLockError(dryErr)) throw dryErr;
|
|
2031
2049
|
return null;
|
|
@@ -2381,7 +2399,13 @@ var FollowerSyncService = class {
|
|
|
2381
2399
|
this.haltFailClosed(haltReason, errCode);
|
|
2382
2400
|
throw err;
|
|
2383
2401
|
}
|
|
2384
|
-
this.resolver.logger.
|
|
2402
|
+
if (errCode === require_replayer.FUTURE_LEDGER_ENTRY_TIMESTAMP) this.resolver.logger.error(`FollowerSyncService refused a future-dated ledger entry (${errCode}); will retry`, {
|
|
2403
|
+
chainId: this.chainId,
|
|
2404
|
+
code: errCode,
|
|
2405
|
+
rejections: this.futureTimestampRejections,
|
|
2406
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2407
|
+
});
|
|
2408
|
+
else this.resolver.logger.warn("FollowerSyncService transient sync error", {
|
|
2385
2409
|
chainId: this.chainId,
|
|
2386
2410
|
error: err instanceof Error ? err.message : String(err)
|
|
2387
2411
|
});
|
package/lib/follower.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DnsLookupAllFn } from "./node-preferences.cjs";
|
|
2
|
-
import { IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.cjs";
|
|
2
|
+
import { IFutureTimestampRejection, IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.cjs";
|
|
3
3
|
import { IFollowerStatusResponse, IHotStuffClusterConfig, ILedgerArchiveHead, ILedgerSegment, INodeRuntimeAdapter, IResolverContext, TFollowerSyncMode, TNodeRetentionMode, TNodeRole, TNodeWritePolicy } from "@ocap/types";
|
|
4
4
|
import { ICheckpointSignerWallet } from "@arcblock/ledger-core";
|
|
5
5
|
|
|
@@ -90,6 +90,15 @@ interface FollowerSyncServiceOptions {
|
|
|
90
90
|
fetchImpl?: typeof fetch;
|
|
91
91
|
dnsLookup?: DnsLookupAllFn;
|
|
92
92
|
env?: Record<string, string | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* #1961: refuse (retryably) peer entries with `sequence >= activationSequence` whose timestamp is more than
|
|
95
|
+
* `maxSkewMs` ahead of `now()`. Unset (default): no guard, today's behavior.
|
|
96
|
+
*/
|
|
97
|
+
futureTimestampGuard?: {
|
|
98
|
+
activationSequence: number;
|
|
99
|
+
maxSkewMs: number;
|
|
100
|
+
now?: () => number;
|
|
101
|
+
};
|
|
93
102
|
}
|
|
94
103
|
declare function isTransientSqliteLockError(err: unknown): boolean;
|
|
95
104
|
declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
@@ -129,6 +138,8 @@ declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
|
129
138
|
private stopped;
|
|
130
139
|
private halted;
|
|
131
140
|
private haltReason;
|
|
141
|
+
private futureTimestampRejections;
|
|
142
|
+
private lastFutureTimestampRejection;
|
|
132
143
|
private pendingCrashWindowReconcile;
|
|
133
144
|
private initialCrashReconcileCompleted;
|
|
134
145
|
private upstreamSequence;
|
|
@@ -185,6 +196,12 @@ declare class FollowerSyncService implements INodeRuntimeAdapter {
|
|
|
185
196
|
* reading untrusted upstream `segmentEntries` (#1711).
|
|
186
197
|
*/
|
|
187
198
|
private resolveLocalFraudAlertStateRoot;
|
|
199
|
+
private recordFutureTimestampRejection;
|
|
200
|
+
/** #1961: how many peer entries were refused for a future timestamp, and the last one (for alerting/tests). */
|
|
201
|
+
getFutureTimestampRejections(): {
|
|
202
|
+
count: number;
|
|
203
|
+
last: IFutureTimestampRejection | null;
|
|
204
|
+
};
|
|
188
205
|
getFollowerStatus(): Promise<IFollowerStatusResponse>;
|
|
189
206
|
private isAllowedHotStuffValidator;
|
|
190
207
|
private hasCommittedTrustAnchor;
|
package/lib/index.cjs
CHANGED
|
@@ -2672,6 +2672,7 @@ exports.ConsensusAbortError = require_hotstuff_runtime.ConsensusAbortError;
|
|
|
2672
2672
|
exports.DEFAULT_FOLLOWER_MAX_SYNC_LAG = require_follower.DEFAULT_FOLLOWER_MAX_SYNC_LAG;
|
|
2673
2673
|
exports.DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS = require_follower.DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS;
|
|
2674
2674
|
exports.DEFAULT_FOLLOWER_POLL_INTERVAL_MS = require_follower.DEFAULT_FOLLOWER_POLL_INTERVAL_MS;
|
|
2675
|
+
exports.FUTURE_LEDGER_ENTRY_TIMESTAMP = require_replayer.FUTURE_LEDGER_ENTRY_TIMESTAMP;
|
|
2675
2676
|
exports.FollowerSyncService = require_follower.FollowerSyncService;
|
|
2676
2677
|
exports.GRAPHQL_INDEXED_TX_COLUMNS = GRAPHQL_INDEXED_TX_COLUMNS;
|
|
2677
2678
|
exports.HotStuffNodeRuntime = require_hotstuff_runtime.HotStuffNodeRuntime;
|
package/lib/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { CreateNodeDashboardRouterOptions, CreateUnifiedConsoleMiddlewareOptions
|
|
|
3
3
|
import { IAddressArgs, IAssetState, IChainConfig, IChunkIterator, IDataObject, IDelegateState, IEvidenceState, IFilter as IFilter$1, IFollowerStatusResponse, IGetAccountStateArgs, IGetAccountTokensArgs, IGetStateParams, IIndexDB as IIndexDB$1, IListChunksParams, INodeRuntimeAdapter, IPaginatedResult, IPipelineLogger as IPipelineLogger$1, IResolver, IResolverAccountState, IResolverChainInfo, IResolverContext as IResolverContext$1, IResolverFactoryState, IResolverForgeStats, IResolverListAccountsResult, IResolverListAssetsResult, IResolverListDelegationsResult, IResolverListFactoriesResult, IResolverListRollupBlocksResult, IResolverListRollupValidatorsResult, IResolverListRollupsResult, IResolverListStakesResult, IResolverListTokenFactoriesResult, IResolverListTokensResult, IResolverListTransactionsResult, IResolverNetInfo, IResolverNodeInfo, IResolverPaging, IResolverParams, IResolverRollupState, IResolverStakeState, IResolverTransaction, IResolverValidatorsInfo, IRollupBlock, IStateDB as IStateDB$1, ITokenCache, ITokenFactoryState, ITokenFlowsResult, ITokenInfo, ITokenState, TIndexedTokenState as TIndexedTokenState$1, TRequestEstimateGas, TRequestGetEvidenceState, TRequestGetRollupBlock, TRequestGetTokenDistribution, TRequestGetTx, TRequestListAssetTransactions, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokenFlows, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions, TRequestSearch, TRequestVerifyAccountRisk, TSearchResult, TTokenDistribution, TVerifyAccountRiskResult } from "./types.cjs";
|
|
4
4
|
import { CreateAPIHandlerOptions, ICreateAPIHandlerParams } from "./api.cjs";
|
|
5
5
|
import { CreateExplorerMiddlewareOptions, createExplorerMiddleware, isExplorerEnabled } from "./explorer.cjs";
|
|
6
|
-
import { IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, LedgerEntryReplayer } from "./replayer.cjs";
|
|
6
|
+
import { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer } from "./replayer.cjs";
|
|
7
7
|
import { DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, FollowerSyncService, FollowerSyncServiceOptions, IColdSegmentReader, ILeaderRouterLike, TFollowerUpstreamFetchInterceptor, TFollowerUpstreamFetchKind, isTransientSqliteLockError } from "./follower.cjs";
|
|
8
8
|
import { ConsensusAbortError, HotStuffNodeRuntime, HotStuffNodeRuntimeOptions, IHotStuffNetworkInterceptorContext, IHotStuffRuntimeStateSnapshot, IHotStuffRuntimeStateStore, TConsensusAbortCode } from "./hotstuff-runtime.cjs";
|
|
9
9
|
import { MigrationChainManager } from "./migration-chain.cjs";
|
|
@@ -350,4 +350,4 @@ declare class OCAPResolver implements IResolver {
|
|
|
350
350
|
}): Promise<IChunkIterator<IResolverStakeState>>;
|
|
351
351
|
}
|
|
352
352
|
//#endregion
|
|
353
|
-
export { type AdminAuthGuardOptions, ConsensusAbortError, type CreateAPIHandlerOptions, type CreateExplorerMiddlewareOptions, type CreateNodeDashboardRouterOptions, type CreateUnifiedConsoleMiddlewareOptions, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, type DnsLookupAllFn, FollowerSyncService, type FollowerSyncServiceOptions, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, type HotStuffNodeRuntimeOptions, type IAdminAuthGuard, type IAttributedBlockedAccount, type IAttributedReservedSymbol, type IAttributedTrustedAccount, type IBlockedAccountEntry, type IChainConfig, type IChunkIterator, type IColdSegmentReader, type ICreateAPIHandlerParams, type IDashboardResolverTarget, type IDataObject, type IDatabaseFileMetrics, type IDryRunVerifyEntriesOptions, type IDryRunVerifyEntriesResult, type IFollowerStatusResponse, type IHotStuffNetworkInterceptorContext, type IHotStuffRuntimeStateSnapshot, type IHotStuffRuntimeStateStore, type ILeaderRouterLike, type ILedgerHealthSummary, type ILedgerHealthThresholds, type ILegacyPreferencesResult, type INodeMaintenanceController, type INodeMaintenanceStatusSummary, type INodePreferencesFileSchema, type INodePreferencesSnapshot, type INodeRuntimeAdapter, type INodeRuntimePreferences, type IPaginatedResult, type IReplayEntryOptions, type IReplayEntryResult, type IReplayerResolverTarget, type IReservedSymbolEntry, type IResolverPaging, type IResolverParams, type IResolverTransaction, type ISlowStorageTelemetry, type ITokenInfo, type ITrustedAccountEntry, type IUpdateNodePreferencesInput, type IUpdateNodePreferencesResult, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, type NodeMaintenanceControllerOptions, NodePreferencesError, NodePreferencesManager, type NodePreferencesManagerOptions, type TConsensusAbortCode, type TFollowerUpstreamFetchInterceptor, type TFollowerUpstreamFetchKind, type TPreferenceSource, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
|
353
|
+
export { type AdminAuthGuardOptions, ConsensusAbortError, type CreateAPIHandlerOptions, type CreateExplorerMiddlewareOptions, type CreateNodeDashboardRouterOptions, type CreateUnifiedConsoleMiddlewareOptions, DEFAULT_FOLLOWER_MAX_SYNC_LAG, DEFAULT_FOLLOWER_MAX_UPSTREAM_STALE_MS, DEFAULT_FOLLOWER_POLL_INTERVAL_MS, type DnsLookupAllFn, FUTURE_LEDGER_ENTRY_TIMESTAMP, FollowerSyncService, type FollowerSyncServiceOptions, GRAPHQL_INDEXED_TX_COLUMNS, HotStuffNodeRuntime, type HotStuffNodeRuntimeOptions, type IAdminAuthGuard, type IAttributedBlockedAccount, type IAttributedReservedSymbol, type IAttributedTrustedAccount, type IBlockedAccountEntry, type IChainConfig, type IChunkIterator, type IColdSegmentReader, type ICreateAPIHandlerParams, type IDashboardResolverTarget, type IDataObject, type IDatabaseFileMetrics, type IDryRunVerifyEntriesOptions, type IDryRunVerifyEntriesResult, type IFollowerStatusResponse, type IFutureTimestampGuardOptions, type IFutureTimestampRejection, type IHotStuffNetworkInterceptorContext, type IHotStuffRuntimeStateSnapshot, type IHotStuffRuntimeStateStore, type ILeaderRouterLike, type ILedgerEntryReplayerOptions, type ILedgerHealthSummary, type ILedgerHealthThresholds, type ILegacyPreferencesResult, type INodeMaintenanceController, type INodeMaintenanceStatusSummary, type INodePreferencesFileSchema, type INodePreferencesSnapshot, type INodeRuntimeAdapter, type INodeRuntimePreferences, type IPaginatedResult, type IReplayEntryOptions, type IReplayEntryResult, type IReplayerResolverTarget, type IReservedSymbolEntry, type IResolverPaging, type IResolverParams, type IResolverTransaction, type ISlowStorageTelemetry, type ITokenInfo, type ITrustedAccountEntry, type IUpdateNodePreferencesInput, type IUpdateNodePreferencesResult, type IValidateWireEntryOptions, LedgerEntryReplayer, MAX_BLOCKED_ACCOUNTS, MAX_CONFIG_BODY_BYTES, MAX_MEMO_LENGTH, MAX_PEER_URLS, MAX_RESERVED_SYMBOLS, MAX_TRUSTED_ACCOUNTS, type NodeMaintenanceControllerOptions, NodePreferencesError, NodePreferencesManager, type NodePreferencesManagerOptions, type TConsensusAbortCode, type TFollowerUpstreamFetchInterceptor, type TFollowerUpstreamFetchKind, type TPreferenceSource, UNIFIED_CONSOLE_APP_JS, applyBootRuntimePreferences, buildUnifiedConsoleHtml, collectLedgerHealthSummary, createAdminAuthGuard, createExplorerMiddleware, createFollowerPeerFetchGuard, createNodeDashboardRouter, createNodeMaintenanceController, createUnifiedConsoleMiddleware, OCAPResolver as default, formatData, formatDelegationOps, isDashboardEnabled, isExplorerEnabled, isPrivateOrReservedIpAddress, isTransientSqliteLockError, isValidAccountAddressCandidate, loadNodePreferences, normalizeBlockedAccountKey, timingSafeTokenEqual, validateFollowerPeerUrls };
|
package/lib/replayer.cjs
CHANGED
|
@@ -22,6 +22,8 @@ let _ocap_state = require("@ocap/state");
|
|
|
22
22
|
* - Enforces pre-commit `expectedCommitHash` on `statedb.runAsLambda` so any state divergence rolls back
|
|
23
23
|
* SQLite atomically BEFORE `COMMIT` and before appending to `ledger.sqlite`.
|
|
24
24
|
*/
|
|
25
|
+
/** Error code of a replayed entry refused for a timestamp ahead of the local clock (retryable, never halting). */
|
|
26
|
+
const FUTURE_LEDGER_ENTRY_TIMESTAMP = "FUTURE_LEDGER_ENTRY_TIMESTAMP";
|
|
25
27
|
function normalizeHexLower(raw) {
|
|
26
28
|
return String(raw ?? "").trim().replace(/^0x/i, "").toLowerCase();
|
|
27
29
|
}
|
|
@@ -44,7 +46,7 @@ function isLocalStorageEngineError(err, depth = 0) {
|
|
|
44
46
|
return cause !== void 0 && cause !== err ? isLocalStorageEngineError(cause, depth + 1) : false;
|
|
45
47
|
}
|
|
46
48
|
var LedgerEntryReplayer = class {
|
|
47
|
-
constructor(resolver) {
|
|
49
|
+
constructor(resolver, options = {}) {
|
|
48
50
|
this.activeSubLambdaOverride = null;
|
|
49
51
|
this.lastCommittedHash = null;
|
|
50
52
|
this.lastCommitMismatchError = null;
|
|
@@ -52,6 +54,12 @@ var LedgerEntryReplayer = class {
|
|
|
52
54
|
this.mutex = Promise.resolve();
|
|
53
55
|
this.resolver = resolver;
|
|
54
56
|
this.emptyFilter = new _ocap_state.Blacklist();
|
|
57
|
+
const guard = options.futureTimestampGuard;
|
|
58
|
+
if (guard) {
|
|
59
|
+
if (!Number.isSafeInteger(guard.activationSequence) || guard.activationSequence < 1) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `futureTimestampGuard.activationSequence must be a positive integer, got ${String(guard.activationSequence)}`);
|
|
60
|
+
if (!Number.isSafeInteger(guard.maxSkewMs) || guard.maxSkewMs < 0) throw new _ocap_util_lib_error.CustomError("INVALID_CONFIG", `futureTimestampGuard.maxSkewMs must be a non-negative integer, got ${String(guard.maxSkewMs)}`);
|
|
61
|
+
}
|
|
62
|
+
this.futureTimestampGuard = guard ? { ...guard } : null;
|
|
55
63
|
const statedb = resolver.statedb;
|
|
56
64
|
const runAsLambda = typeof statedb.runAsLambda === "function" ? async (fn, opts = {}) => {
|
|
57
65
|
const expectedCommitHash = this.activeExpectedCommitHash;
|
|
@@ -141,13 +149,40 @@ var LedgerEntryReplayer = class {
|
|
|
141
149
|
if (computedTxHash.toUpperCase() !== entry.hash.toUpperCase()) throw new _ocap_util_lib_error.CustomError(throwCodeOnMismatch, `Ledger entry txRaw hash mismatch at seq=${entry.sequence}: computed ${computedTxHash}, entry has ${entry.hash}`);
|
|
142
150
|
}
|
|
143
151
|
/**
|
|
152
|
+
* #1961 future-timestamp guard (no-op unless `futureTimestampGuard` is configured). Throws a retryable
|
|
153
|
+
* `FUTURE_LEDGER_ENTRY_TIMESTAMP` that is neither a local divergence nor a peer authentication failure, so the
|
|
154
|
+
* follower logs it, keeps its state and retries on the next sync cycle.
|
|
155
|
+
*/
|
|
156
|
+
assertEntryTimestampNotInFuture(entry) {
|
|
157
|
+
const guard = this.futureTimestampGuard;
|
|
158
|
+
if (!guard || !Number.isSafeInteger(entry?.sequence) || entry.sequence < guard.activationSequence) return;
|
|
159
|
+
const nowMs = guard.now ? guard.now() : Date.now();
|
|
160
|
+
if (!Number.isFinite(nowMs) || entry.timestamp <= nowMs + guard.maxSkewMs) return;
|
|
161
|
+
const info = {
|
|
162
|
+
sequence: entry.sequence,
|
|
163
|
+
hash: String(entry.hash ?? ""),
|
|
164
|
+
timestamp: entry.timestamp,
|
|
165
|
+
nowMs,
|
|
166
|
+
maxSkewMs: guard.maxSkewMs,
|
|
167
|
+
activationSequence: guard.activationSequence
|
|
168
|
+
};
|
|
169
|
+
try {
|
|
170
|
+
guard.onReject?.(info);
|
|
171
|
+
} catch {}
|
|
172
|
+
const err = new _ocap_util_lib_error.CustomError(FUTURE_LEDGER_ENTRY_TIMESTAMP, `Ledger entry seq=${entry.sequence} timestamp ${entry.timestamp} is ${entry.timestamp - nowMs} ms ahead of the local clock (max skew ${guard.maxSkewMs} ms, guard active from seq=${guard.activationSequence}); will retry`);
|
|
173
|
+
err.retryable = true;
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
144
177
|
* Pre-replay wire & primitive validation for untrusted network hot-tail / cold-segment payloads (#1710).
|
|
145
|
-
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion
|
|
178
|
+
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion,
|
|
179
|
+
* and the retryable `FUTURE_LEDGER_ENTRY_TIMESTAMP` when the #1961 guard is on (unless the entry is local).
|
|
146
180
|
*/
|
|
147
|
-
validateWireEntry(entry) {
|
|
181
|
+
validateWireEntry(entry, options = {}) {
|
|
148
182
|
if (!entry || typeof entry !== "object" || !Number.isSafeInteger(entry.sequence) || entry.sequence < 1 || !Number.isSafeInteger(entry.nonce) || entry.nonce < 0 || !Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > 864e13 || typeof entry.hash !== "string" || typeof entry.from !== "string" || typeof entry.pk !== "string" || typeof entry.signature !== "string" || typeof entry.txRaw !== "string" || typeof entry.txType !== "string" || typeof entry.chainId !== "string" || typeof entry.entryHash !== "string" || typeof entry.finalized !== "boolean" || entry.stateCommitHash !== void 0 && typeof entry.stateCommitHash !== "string" || entry.tx === null || typeof entry.tx !== "object" || Array.isArray(entry.tx)) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${String(entry?.sequence)} has invalid wire primitive types`);
|
|
149
183
|
this.verifyRawTxHashMatchesEntry(entry, "INVALID_LEDGER_ENTRY");
|
|
150
184
|
this.authenticateAndDecodeEntry(entry);
|
|
185
|
+
if (!options.skipFutureTimestampCheck) this.assertEntryTimestampNotInFuture(entry);
|
|
151
186
|
}
|
|
152
187
|
authenticateAndDecodeEntry(entry) {
|
|
153
188
|
const authRes = (0, _arcblock_ledger_core.authenticateEntryDecodedFields)(entry, true, { requireFullWireEntry: true });
|
|
@@ -204,6 +239,7 @@ var LedgerEntryReplayer = class {
|
|
|
204
239
|
}
|
|
205
240
|
if (entry.sequence !== localLatestSeq + 1) throw new _ocap_util_lib_error.CustomError("SEQUENCE_GAP", `Non-contiguous replay sequence: localLatest=${localLatestSeq}, got seq=${entry.sequence}`);
|
|
206
241
|
}
|
|
242
|
+
if (appendToLedger) this.assertEntryTimestampNotInFuture(entry);
|
|
207
243
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
208
244
|
const decodedTx = this.authenticateAndDecodeEntry(entry);
|
|
209
245
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
@@ -295,7 +331,7 @@ var LedgerEntryReplayer = class {
|
|
|
295
331
|
if (entry.finalized !== true) throw new _ocap_util_lib_error.CustomError("UNFINALIZED_LEDGER_ENTRY", `Proposal entry seq=${String(entry.sequence)} must be finalized`);
|
|
296
332
|
if (entry.chainId !== expectedChainId) throw new _ocap_util_lib_error.CustomError("CHAIN_ID_MISMATCH", `Proposal entry chainId mismatch at seq=${String(entry.sequence)}: expected ${expectedChainId}, got ${entry.chainId}`);
|
|
297
333
|
if (entry.sequence !== baseSeq + i + 1) throw new _ocap_util_lib_error.CustomError("SEQUENCE_GAP", `Proposal entry sequence mismatch at index ${i}: expected ${baseSeq + i + 1}, got ${entry.sequence}`);
|
|
298
|
-
this.validateWireEntry(entry);
|
|
334
|
+
this.validateWireEntry(entry, { skipFutureTimestampCheck: options.skipFutureTimestampCheck });
|
|
299
335
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
300
336
|
const expectedEntryHash = (0, _arcblock_ledger_core.computeEntryHash)(entry.sequence, entry.txRaw, expectedStateCommit, entry.sequence >= v2Cutoff ? 2 : 1);
|
|
301
337
|
if (entry.entryHash !== expectedEntryHash) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Proposal entryHash mismatch at seq=${entry.sequence}: expected ${expectedEntryHash}, got ${entry.entryHash}`);
|
|
@@ -392,4 +428,5 @@ var LedgerEntryReplayer = class {
|
|
|
392
428
|
};
|
|
393
429
|
|
|
394
430
|
//#endregion
|
|
431
|
+
exports.FUTURE_LEDGER_ENTRY_TIMESTAMP = FUTURE_LEDGER_ENTRY_TIMESTAMP;
|
|
395
432
|
exports.LedgerEntryReplayer = LedgerEntryReplayer;
|
package/lib/replayer.d.cts
CHANGED
|
@@ -28,6 +28,38 @@ interface IDryRunVerifyEntriesOptions {
|
|
|
28
28
|
expectedPrevSequence?: number;
|
|
29
29
|
prevStateRoot?: string | null;
|
|
30
30
|
entryHashV2From?: number | 'infinity';
|
|
31
|
+
/** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
|
|
32
|
+
skipFutureTimestampCheck?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface IValidateWireEntryOptions {
|
|
35
|
+
/** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
|
|
36
|
+
skipFutureTimestampCheck?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Error code of a replayed entry refused for a timestamp ahead of the local clock (retryable, never halting). */
|
|
39
|
+
declare const FUTURE_LEDGER_ENTRY_TIMESTAMP = "FUTURE_LEDGER_ENTRY_TIMESTAMP";
|
|
40
|
+
interface IFutureTimestampRejection {
|
|
41
|
+
sequence: number;
|
|
42
|
+
hash: string;
|
|
43
|
+
timestamp: number;
|
|
44
|
+
nowMs: number;
|
|
45
|
+
maxSkewMs: number;
|
|
46
|
+
activationSequence: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* #1961: `entry.timestamp` is not covered by `entryHash`, so a leader can stamp a real entry with a future time
|
|
50
|
+
* (and with it every time lock the tx sets). A follower refuses peer entries at or after `activationSequence` whose
|
|
51
|
+
* timestamp is more than `maxSkewMs` ahead of its own clock. Past timestamps are always accepted (no monotonic
|
|
52
|
+
* rule, #1972). The refusal is retryable: the entry is accepted once the local clock catches up.
|
|
53
|
+
*/
|
|
54
|
+
interface IFutureTimestampGuardOptions {
|
|
55
|
+
activationSequence: number;
|
|
56
|
+
maxSkewMs: number;
|
|
57
|
+
now?: () => number;
|
|
58
|
+
onReject?: (info: IFutureTimestampRejection) => void;
|
|
59
|
+
}
|
|
60
|
+
interface ILedgerEntryReplayerOptions {
|
|
61
|
+
/** Unset (default): no timestamp guard, today's behavior. */
|
|
62
|
+
futureTimestampGuard?: IFutureTimestampGuardOptions;
|
|
31
63
|
}
|
|
32
64
|
interface IDryRunVerifyEntriesResult {
|
|
33
65
|
derivedStateRoot: string;
|
|
@@ -43,15 +75,23 @@ declare class LedgerEntryReplayer {
|
|
|
43
75
|
private lastCommitMismatchError;
|
|
44
76
|
private lastStorageError;
|
|
45
77
|
private mutex;
|
|
46
|
-
|
|
78
|
+
private readonly futureTimestampGuard;
|
|
79
|
+
constructor(resolver: IReplayerResolverTarget, options?: ILedgerEntryReplayerOptions);
|
|
47
80
|
private runExclusive;
|
|
48
81
|
private appendVerifiedEntryToLedger;
|
|
49
82
|
private verifyRawTxHashMatchesEntry;
|
|
83
|
+
/**
|
|
84
|
+
* #1961 future-timestamp guard (no-op unless `futureTimestampGuard` is configured). Throws a retryable
|
|
85
|
+
* `FUTURE_LEDGER_ENTRY_TIMESTAMP` that is neither a local divergence nor a peer authentication failure, so the
|
|
86
|
+
* follower logs it, keeps its state and retries on the next sync cycle.
|
|
87
|
+
*/
|
|
88
|
+
assertEntryTimestampNotInFuture(entry: ILedgerEntry): void;
|
|
50
89
|
/**
|
|
51
90
|
* Pre-replay wire & primitive validation for untrusted network hot-tail / cold-segment payloads (#1710).
|
|
52
|
-
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion
|
|
91
|
+
* Throws `INVALID_LEDGER_ENTRY` (peer-disqualifying, non-halting) on any malformed wire field or lossy JSON coercion,
|
|
92
|
+
* and the retryable `FUTURE_LEDGER_ENTRY_TIMESTAMP` when the #1961 guard is on (unless the entry is local).
|
|
53
93
|
*/
|
|
54
|
-
validateWireEntry(entry: ILedgerEntry): void;
|
|
94
|
+
validateWireEntry(entry: ILedgerEntry, options?: IValidateWireEntryOptions): void;
|
|
55
95
|
private authenticateAndDecodeEntry;
|
|
56
96
|
private indexOrphanEntry;
|
|
57
97
|
/**
|
|
@@ -71,4 +111,4 @@ declare class LedgerEntryReplayer {
|
|
|
71
111
|
indexExistingOrphanEntries(fromSeq?: number, toSeq?: number): Promise<number>;
|
|
72
112
|
}
|
|
73
113
|
//#endregion
|
|
74
|
-
export { IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, LedgerEntryReplayer };
|
|
114
|
+
export { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer };
|
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": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -54,21 +54,21 @@
|
|
|
54
54
|
"tsdown": "^0.18.4"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/did": "1.32.
|
|
58
|
-
"@arcblock/did-ext": "1.32.
|
|
59
|
-
"@arcblock/did-util": "1.32.
|
|
60
|
-
"@arcblock/ledger-core": "1.32.
|
|
57
|
+
"@arcblock/did": "1.32.1",
|
|
58
|
+
"@arcblock/did-ext": "1.32.1",
|
|
59
|
+
"@arcblock/did-util": "1.32.1",
|
|
60
|
+
"@arcblock/ledger-core": "1.32.1",
|
|
61
61
|
"@arcblock/nft-display": "^3.2.3",
|
|
62
|
-
"@arcblock/validator": "1.32.
|
|
63
|
-
"@ocap/config": "1.32.
|
|
64
|
-
"@ocap/indexdb": "1.32.
|
|
65
|
-
"@ocap/mcrypto": "1.32.
|
|
66
|
-
"@ocap/message": "1.32.
|
|
67
|
-
"@ocap/state": "1.32.
|
|
68
|
-
"@ocap/tx-protocols": "1.32.
|
|
69
|
-
"@ocap/types": "1.32.
|
|
70
|
-
"@ocap/util": "1.32.
|
|
71
|
-
"@ocap/wallet": "1.32.
|
|
62
|
+
"@arcblock/validator": "1.32.1",
|
|
63
|
+
"@ocap/config": "1.32.1",
|
|
64
|
+
"@ocap/indexdb": "1.32.1",
|
|
65
|
+
"@ocap/mcrypto": "1.32.1",
|
|
66
|
+
"@ocap/message": "1.32.1",
|
|
67
|
+
"@ocap/state": "1.32.1",
|
|
68
|
+
"@ocap/tx-protocols": "1.32.1",
|
|
69
|
+
"@ocap/types": "1.32.1",
|
|
70
|
+
"@ocap/util": "1.32.1",
|
|
71
|
+
"@ocap/wallet": "1.32.1",
|
|
72
72
|
"debug": "^4.4.3",
|
|
73
73
|
"express": "^4.22.1",
|
|
74
74
|
"lodash": "^4.17.23",
|