@aztec/archiver 0.0.1-commit.f5d02921e → 0.0.1-commit.f7ea82942
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dest/archiver.d.ts +5 -3
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +15 -4
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -2
- package/dest/errors.d.ts +17 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +22 -0
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -1
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/l1/data_retrieval.d.ts +19 -10
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +25 -32
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/data_store_updater.d.ts +12 -5
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +13 -3
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +22 -6
- package/dest/modules/l1_synchronizer.d.ts +6 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +213 -124
- package/dest/store/block_store.d.ts +11 -3
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +88 -6
- package/dest/store/kv_archiver_store.d.ts +11 -9
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +9 -7
- package/dest/store/l2_tips_cache.d.ts +1 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +2 -2
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +2 -4
- package/dest/store/message_store.d.ts +3 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +9 -10
- package/dest/test/fake_l1_state.d.ts +14 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +55 -10
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +4 -2
- package/package.json +13 -13
- package/src/archiver.ts +28 -6
- package/src/config.ts +14 -1
- package/src/errors.ts +34 -0
- package/src/factory.ts +1 -0
- package/src/index.ts +2 -1
- package/src/l1/data_retrieval.ts +36 -45
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_store_updater.ts +27 -3
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +274 -148
- package/src/store/block_store.ts +112 -4
- package/src/store/kv_archiver_store.ts +18 -10
- package/src/store/l2_tips_cache.ts +8 -2
- package/src/store/log_store.ts +2 -5
- package/src/store/message_store.ts +10 -12
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +75 -13
- package/src/test/noop_l1_archiver.ts +3 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { getPublicClient, getRpcUrlsFromClient } from '@aztec/ethereum/client';
|
|
2
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
4
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
|
|
7
|
+
/** Subset of L1 contract addresses whose historical logs the Aztec node relies on. */
|
|
8
|
+
export type HistoricalLogsContractAddresses = Pick<
|
|
9
|
+
L1ContractAddresses,
|
|
10
|
+
'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress'
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
/** Result of probing a single RPC URL. */
|
|
14
|
+
type ProbeResult = { ok: true } | { ok: false; reason: string; clientVersion: string | undefined };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Validates that every configured L1 RPC URL returns historical logs for the Rollup contract.
|
|
18
|
+
*
|
|
19
|
+
* Some RPC providers prune old logs, which would cause L1 syncing to silently fail. To detect this,
|
|
20
|
+
* we query for the `OwnershipTransferred` event which every Rollup emits in its constructor (via
|
|
21
|
+
* Ownable) on the block it was deployed (`l1StartBlock`). The `client` is typically a viem fallback
|
|
22
|
+
* transport over several user-configured RPC URLs — checking only the first URL would miss a bad
|
|
23
|
+
* secondary, so we probe each URL independently. The first URL that fails aborts startup, unless
|
|
24
|
+
* the operator has explicitly opted out.
|
|
25
|
+
*
|
|
26
|
+
* @param client - The L1 public client built from the user-configured RPC URLs.
|
|
27
|
+
* @param addresses - The subset of L1 contract addresses we rely on for historical log retrieval.
|
|
28
|
+
* @param skipCheck - If true, log warnings instead of throwing.
|
|
29
|
+
* @param bindings - Optional logger bindings for context.
|
|
30
|
+
* @throws Error if any URL fails the probe and skipCheck is false.
|
|
31
|
+
*/
|
|
32
|
+
export async function validateAndLogHistoricalLogsAvailability(
|
|
33
|
+
client: ViemPublicClient,
|
|
34
|
+
addresses: HistoricalLogsContractAddresses,
|
|
35
|
+
skipCheck: boolean,
|
|
36
|
+
bindings?: LoggerBindings,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const logger = createLogger('archiver:validate_historical_logs', bindings);
|
|
39
|
+
logger.debug('Validating historical log availability on L1 RPCs');
|
|
40
|
+
|
|
41
|
+
const urls = getRpcUrlsFromClient(client);
|
|
42
|
+
if (urls.length === 0) {
|
|
43
|
+
logger.warn('Could not determine L1 RPC URLs from the public client; skipping historical logs check.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const chainId = client.chain?.id;
|
|
48
|
+
if (chainId === undefined) {
|
|
49
|
+
logger.warn('Could not determine L1 chain ID from the public client; skipping historical logs check.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const url of urls) {
|
|
54
|
+
const probeClient = getPublicClient({ l1RpcUrls: [url], l1ChainId: chainId });
|
|
55
|
+
const rollup = new RollupContract(probeClient, addresses.rollupAddress.toString());
|
|
56
|
+
const result = await probeRpcUrl(rollup, probeClient, logger);
|
|
57
|
+
|
|
58
|
+
if (result.ok) {
|
|
59
|
+
logger.debug(`L1 RPC ${url} returned historical OwnershipTransferred log for the Rollup contract.`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const errorMessage = buildErrorMessage(url, result, addresses);
|
|
64
|
+
if (skipCheck) {
|
|
65
|
+
logger.warn(`${errorMessage}\nContinuing because ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK is true.`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
logger.error(errorMessage);
|
|
70
|
+
throw new Error(errorMessage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Runs the OwnershipTransferred probe against a single RPC and queries its client version. */
|
|
75
|
+
async function probeRpcUrl(rollup: RollupContract, client: ViemPublicClient, logger: Logger): Promise<ProbeResult> {
|
|
76
|
+
let queryError: unknown;
|
|
77
|
+
try {
|
|
78
|
+
const logs = await rollup.getOwnershipTransferredEventsAtDeploy();
|
|
79
|
+
if (logs.length > 0) {
|
|
80
|
+
return { ok: true };
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
queryError = err;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const clientVersion = await getClientVersion(client, logger);
|
|
87
|
+
|
|
88
|
+
let reason: string;
|
|
89
|
+
if (queryError instanceof Error) {
|
|
90
|
+
reason = `Query for historical logs failed: ${queryError.message}`;
|
|
91
|
+
} else if (queryError !== undefined) {
|
|
92
|
+
reason = 'Query for historical logs failed with a non-Error value.';
|
|
93
|
+
} else {
|
|
94
|
+
reason = 'No OwnershipTransferred event was returned by the L1 RPC for the Rollup deploy block.';
|
|
95
|
+
}
|
|
96
|
+
return { ok: false, reason, clientVersion };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Builds the operator-facing error message for a failing RPC URL. */
|
|
100
|
+
function buildErrorMessage(
|
|
101
|
+
url: string,
|
|
102
|
+
result: Extract<ProbeResult, { ok: false }>,
|
|
103
|
+
addresses: HistoricalLogsContractAddresses,
|
|
104
|
+
): string {
|
|
105
|
+
return [
|
|
106
|
+
`L1 RPC at ${url} does not return historical logs for the Rollup contract. ${result.reason}`,
|
|
107
|
+
`This likely means this Ethereum RPC node prunes old logs, which would cause the archiver ` +
|
|
108
|
+
`to silently miss data during L1 sync.`,
|
|
109
|
+
result.clientVersion
|
|
110
|
+
? `Detected L1 client version for ${url}: ${result.clientVersion}.`
|
|
111
|
+
: `Could not determine L1 client version for ${url}.`,
|
|
112
|
+
`The following L1 contract addresses must have their historical logs retained by the RPC node:`,
|
|
113
|
+
` - Rollup: ${addresses.rollupAddress.toString()}`,
|
|
114
|
+
` - Inbox: ${addresses.inboxAddress.toString()}`,
|
|
115
|
+
` - Registry: ${addresses.registryAddress.toString()}`,
|
|
116
|
+
` - GovernanceProposer: ${addresses.governanceProposerAddress.toString()}`,
|
|
117
|
+
isReth(result.clientVersion)
|
|
118
|
+
? `To retain logs for these contracts, configure reth with a ` +
|
|
119
|
+
`prune.segments.receipts_log_filter entry for each address above ` +
|
|
120
|
+
`so reth does not prune their receipts/logs. See https://reth.rs/run/pruning.html for details.`
|
|
121
|
+
: `Point this RPC endpoint at a node that retains full log history for the addresses above.`,
|
|
122
|
+
`Set ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK=true to bypass this check at your own risk.`,
|
|
123
|
+
].join('\n');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Queries `web3_clientVersion` on the L1 RPC. Returns undefined if the call fails or returns a non-string. */
|
|
127
|
+
async function getClientVersion(client: ViemPublicClient, logger: Logger): Promise<string | undefined> {
|
|
128
|
+
try {
|
|
129
|
+
const result = await client.request({ method: 'web3_clientVersion' });
|
|
130
|
+
return typeof result === 'string' ? result : undefined;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
logger.debug(`Failed to query web3_clientVersion: ${err instanceof Error ? err.message : err}`);
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Heuristic check for reth based on the web3_clientVersion string (reth returns e.g. "reth/v1.0.0-..."). */
|
|
138
|
+
function isReth(clientVersion: string | undefined): boolean {
|
|
139
|
+
return !!clientVersion && /reth/i.test(clientVersion);
|
|
140
|
+
}
|
|
@@ -6,8 +6,13 @@ import {
|
|
|
6
6
|
ContractInstancePublishedEvent,
|
|
7
7
|
ContractInstanceUpdatedEvent,
|
|
8
8
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
9
|
-
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
-
import {
|
|
9
|
+
import type { CommitteeAttestation, L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
+
import {
|
|
11
|
+
type L1PublishedData,
|
|
12
|
+
type ProposedCheckpointInput,
|
|
13
|
+
type PublishedCheckpoint,
|
|
14
|
+
validateCheckpoint,
|
|
15
|
+
} from '@aztec/stdlib/checkpoint';
|
|
11
16
|
import {
|
|
12
17
|
type ContractClassPublicWithCommitment,
|
|
13
18
|
computeContractAddressFromInstance,
|
|
@@ -79,18 +84,29 @@ export class ArchiverDataStoreUpdater {
|
|
|
79
84
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
80
85
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
81
86
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
87
|
+
* If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
|
|
88
|
+
* as the added checkpoints so both updates are applied atomically.
|
|
82
89
|
*
|
|
83
|
-
* @param checkpoints - The published checkpoints to add.
|
|
90
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
84
91
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
92
|
+
* @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
|
|
85
93
|
* @returns Result with information about any pruned blocks.
|
|
86
94
|
*/
|
|
87
95
|
public async addCheckpoints(
|
|
88
96
|
checkpoints: PublishedCheckpoint[],
|
|
89
97
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
98
|
+
promoteProposed?: {
|
|
99
|
+
l1: L1PublishedData;
|
|
100
|
+
attestations: CommitteeAttestation[];
|
|
101
|
+
checkpoint: PublishedCheckpoint;
|
|
102
|
+
},
|
|
90
103
|
): Promise<ReconcileCheckpointsResult> {
|
|
91
104
|
for (const checkpoint of checkpoints) {
|
|
92
105
|
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
93
106
|
}
|
|
107
|
+
if (promoteProposed) {
|
|
108
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
109
|
+
}
|
|
94
110
|
|
|
95
111
|
const result = await this.store.transactionAsync(async () => {
|
|
96
112
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
@@ -110,6 +126,14 @@ export class ArchiverDataStoreUpdater {
|
|
|
110
126
|
this.store.addLogs(newBlocks),
|
|
111
127
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
112
128
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
129
|
+
// Promote the proposed checkpoint if requested
|
|
130
|
+
promoteProposed
|
|
131
|
+
? this.store.promoteProposedToCheckpointed(
|
|
132
|
+
promoteProposed.l1,
|
|
133
|
+
promoteProposed.attestations,
|
|
134
|
+
promoteProposed.checkpoint.checkpoint.archive.root,
|
|
135
|
+
)
|
|
136
|
+
: undefined,
|
|
113
137
|
]);
|
|
114
138
|
|
|
115
139
|
await this.l2TipsCache?.refresh();
|
|
@@ -32,6 +32,7 @@ export class ArchiverInstrumentation {
|
|
|
32
32
|
private pruneCount: UpDownCounter;
|
|
33
33
|
|
|
34
34
|
private syncDurationPerBlock: Histogram;
|
|
35
|
+
private syncDurationPerCheckpoint: Histogram;
|
|
35
36
|
private syncBlockCount: UpDownCounter;
|
|
36
37
|
private manaPerBlock: Histogram;
|
|
37
38
|
private txsPerBlock: Histogram;
|
|
@@ -42,6 +43,7 @@ export class ArchiverInstrumentation {
|
|
|
42
43
|
private blockProposalTxTargetCount: UpDownCounter;
|
|
43
44
|
|
|
44
45
|
private checkpointL1InclusionDelay: Histogram;
|
|
46
|
+
private checkpointPromotedCount: UpDownCounter;
|
|
45
47
|
|
|
46
48
|
private log = createLogger('archiver:instrumentation');
|
|
47
49
|
|
|
@@ -68,6 +70,8 @@ export class ArchiverInstrumentation {
|
|
|
68
70
|
|
|
69
71
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
70
72
|
|
|
73
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
74
|
+
|
|
71
75
|
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
72
76
|
|
|
73
77
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
@@ -92,6 +96,8 @@ export class ArchiverInstrumentation {
|
|
|
92
96
|
|
|
93
97
|
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
94
98
|
|
|
99
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
100
|
+
|
|
95
101
|
this.dbMetrics = new LmdbMetrics(
|
|
96
102
|
meter,
|
|
97
103
|
{
|
|
@@ -113,17 +119,26 @@ export class ArchiverInstrumentation {
|
|
|
113
119
|
return this.telemetry.isEnabled();
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
public
|
|
122
|
+
public processNewProposedBlock(syncTimePerBlock: number, block: L2Block) {
|
|
123
|
+
const attrs = { [Attributes.STATUS]: 'proposed' };
|
|
124
|
+
this.blockHeight.record(block.number, attrs);
|
|
117
125
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
126
|
+
|
|
127
|
+
// Per block metrics
|
|
128
|
+
this.txCount.add(block.body.txEffects.length);
|
|
129
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
130
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]) {
|
|
134
|
+
if (blocks.length === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
118
139
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
119
140
|
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
120
141
|
this.syncBlockCount.add(blocks.length);
|
|
121
|
-
|
|
122
|
-
for (const block of blocks) {
|
|
123
|
-
this.txCount.add(block.body.txEffects.length);
|
|
124
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
125
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
126
|
-
}
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
public processNewMessages(count: number, syncPerMessageMs: number) {
|
|
@@ -169,6 +184,11 @@ export class ArchiverInstrumentation {
|
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
186
|
|
|
187
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
188
|
+
public processCheckpointPromoted() {
|
|
189
|
+
this.checkpointPromotedCount.add(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
172
192
|
/**
|
|
173
193
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
174
194
|
*/
|