@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +699 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -5
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +97 -13
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +148 -0
- package/dest/l1/calldata_retriever.d.ts +118 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +484 -0
- package/dest/l1/data_retrieval.d.ts +89 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +80 -153
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +157 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +80 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +323 -0
- package/dest/modules/instrumentation.d.ts +39 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +39 -62
- package/dest/modules/l1_synchronizer.d.ts +76 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +773 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +13 -9
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +354 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +456 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/inbox_message.js +6 -5
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +193 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +389 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +19 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +7 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +21 -11
- package/dest/test/mock_l2_block_source.d.ts +51 -18
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +245 -82
- package/dest/test/mock_structs.d.ts +80 -4
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +145 -11
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +20 -20
- package/src/archiver.ts +443 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +143 -13
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +181 -0
- package/src/l1/calldata_retriever.ts +663 -0
- package/src/{archiver → l1}/data_retrieval.ts +146 -224
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +448 -0
- package/src/{archiver → modules}/instrumentation.ts +43 -66
- package/src/modules/l1_synchronizer.ts +932 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +1015 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +13 -9
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +671 -0
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +637 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
- package/src/{archiver/structs → structs}/inbox_message.ts +8 -8
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +607 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +23 -16
- package/src/test/mock_l1_to_l2_message_source.ts +18 -11
- package/src/test/mock_l2_block_source.ts +296 -90
- package/src/test/mock_structs.ts +275 -13
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -287
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1408
- package/dest/archiver/archiver_store.d.ts +0 -255
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.d.ts +0 -79
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -124
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -370
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -168
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -296
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -336
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1858
- package/src/archiver/archiver_store.ts +0 -305
- package/src/archiver/archiver_store_test_suite.ts +0 -1264
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -481
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -422
- package/src/archiver/kv_archiver_store/log_store.ts +0 -406
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
package/src/factory.ts
CHANGED
|
@@ -1,35 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
6
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
|
+
import { merge } from '@aztec/foundation/collection';
|
|
8
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
2
10
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
3
11
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
4
12
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
5
13
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
6
14
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
15
|
+
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
7
16
|
import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
18
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
8
19
|
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
21
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
22
|
+
|
|
23
|
+
import { Archiver, type ArchiverDeps } from './archiver.js';
|
|
24
|
+
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
25
|
+
import { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
26
|
+
import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
27
|
+
import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
28
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
12
29
|
|
|
13
30
|
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
14
31
|
|
|
15
32
|
/** Creates an archiver store. */
|
|
16
33
|
export async function createArchiverStore(
|
|
17
34
|
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
|
|
35
|
+
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
18
36
|
) {
|
|
19
37
|
const config = {
|
|
20
38
|
...userConfig,
|
|
21
39
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
22
40
|
};
|
|
23
|
-
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config
|
|
24
|
-
return new KVArchiverDataStore(store, config.maxLogs);
|
|
41
|
+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
42
|
+
return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
/**
|
|
28
46
|
* Creates a local archiver.
|
|
29
47
|
* @param config - The archiver configuration.
|
|
30
|
-
* @param
|
|
48
|
+
* @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
|
|
31
49
|
* @param opts - The options.
|
|
32
|
-
* @param telemetry - The telemetry client.
|
|
33
50
|
* @returns The local archiver.
|
|
34
51
|
*/
|
|
35
52
|
export async function createArchiver(
|
|
@@ -37,12 +54,125 @@ export async function createArchiver(
|
|
|
37
54
|
deps: ArchiverDeps,
|
|
38
55
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
39
56
|
): Promise<Archiver> {
|
|
40
|
-
const archiverStore = await createArchiverStore(config);
|
|
57
|
+
const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
|
|
41
58
|
await registerProtocolContracts(archiverStore);
|
|
42
|
-
|
|
59
|
+
|
|
60
|
+
// Create Ethereum clients
|
|
61
|
+
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
62
|
+
const publicClient = createPublicClient({
|
|
63
|
+
chain: chain.chainInfo,
|
|
64
|
+
transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
|
|
65
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Create debug client using debug RPC URLs if available, otherwise fall back to regular RPC URLs
|
|
69
|
+
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
70
|
+
const debugClient = createPublicClient({
|
|
71
|
+
chain: chain.chainInfo,
|
|
72
|
+
transport: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
|
|
73
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
74
|
+
}) as ViemPublicDebugClient;
|
|
75
|
+
|
|
76
|
+
// Create L1 contract instances
|
|
77
|
+
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
|
|
78
|
+
const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
|
|
79
|
+
|
|
80
|
+
// Fetch L1 constants from rollup contract
|
|
81
|
+
const [
|
|
82
|
+
l1StartBlock,
|
|
83
|
+
l1GenesisTime,
|
|
84
|
+
proofSubmissionEpochs,
|
|
85
|
+
genesisArchiveRoot,
|
|
86
|
+
slashingProposerAddress,
|
|
87
|
+
targetCommitteeSize,
|
|
88
|
+
] = await Promise.all([
|
|
89
|
+
rollup.getL1StartBlock(),
|
|
90
|
+
rollup.getL1GenesisTime(),
|
|
91
|
+
rollup.getProofSubmissionEpochs(),
|
|
92
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
93
|
+
rollup.getSlashingProposerAddress(),
|
|
94
|
+
rollup.getTargetCommitteeSize(),
|
|
95
|
+
] as const);
|
|
96
|
+
|
|
97
|
+
const l1StartBlockHash = await publicClient
|
|
98
|
+
.getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
|
|
99
|
+
.then(block => Buffer32.fromString(block.hash));
|
|
100
|
+
|
|
101
|
+
const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
|
|
102
|
+
|
|
103
|
+
const l1Constants = {
|
|
104
|
+
l1StartBlockHash,
|
|
105
|
+
l1StartBlock,
|
|
106
|
+
l1GenesisTime,
|
|
107
|
+
epochDuration,
|
|
108
|
+
slotDuration,
|
|
109
|
+
ethereumSlotDuration,
|
|
110
|
+
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
111
|
+
targetCommitteeSize,
|
|
112
|
+
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const archiverConfig = merge(
|
|
116
|
+
{
|
|
117
|
+
pollingIntervalMs: 10_000,
|
|
118
|
+
batchSize: 100,
|
|
119
|
+
maxAllowedEthClientDriftSeconds: 300,
|
|
120
|
+
ethereumAllowNoDebugHosts: false,
|
|
121
|
+
},
|
|
122
|
+
mapArchiverConfig(config),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const epochCache = deps.epochCache ?? (await EpochCache.create(config.l1Contracts.rollupAddress, config, deps));
|
|
126
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
127
|
+
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
|
|
128
|
+
|
|
129
|
+
// Create the event emitter that will be shared by archiver and synchronizer
|
|
130
|
+
const events = new EventEmitter() as ArchiverEmitter;
|
|
131
|
+
|
|
132
|
+
// Create L2 tips cache shared by archiver and synchronizer
|
|
133
|
+
const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
|
|
134
|
+
|
|
135
|
+
// Create the L1 synchronizer
|
|
136
|
+
const synchronizer = new ArchiverL1Synchronizer(
|
|
137
|
+
publicClient,
|
|
138
|
+
debugClient,
|
|
139
|
+
rollup,
|
|
140
|
+
inbox,
|
|
141
|
+
{ ...config.l1Contracts, slashingProposerAddress },
|
|
142
|
+
archiverStore,
|
|
143
|
+
archiverConfig,
|
|
144
|
+
deps.blobClient,
|
|
145
|
+
epochCache,
|
|
146
|
+
deps.dateProvider ?? new DateProvider(),
|
|
147
|
+
instrumentation,
|
|
148
|
+
l1Constants,
|
|
149
|
+
events,
|
|
150
|
+
instrumentation.tracer,
|
|
151
|
+
l2TipsCache,
|
|
152
|
+
undefined, // log (use default)
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const archiver = new Archiver(
|
|
156
|
+
publicClient,
|
|
157
|
+
debugClient,
|
|
158
|
+
rollup,
|
|
159
|
+
{ ...config.l1Contracts, slashingProposerAddress },
|
|
160
|
+
archiverStore,
|
|
161
|
+
archiverConfig,
|
|
162
|
+
deps.blobClient,
|
|
163
|
+
instrumentation,
|
|
164
|
+
l1Constants,
|
|
165
|
+
synchronizer,
|
|
166
|
+
events,
|
|
167
|
+
l2TipsCache,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
await archiver.start(opts.blockUntilSync);
|
|
171
|
+
return archiver;
|
|
43
172
|
}
|
|
44
173
|
|
|
45
|
-
|
|
174
|
+
/** Registers protocol contracts in the archiver store. */
|
|
175
|
+
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
46
176
|
const blockNumber = 0;
|
|
47
177
|
for (const name of protocolContractNames) {
|
|
48
178
|
const provider = new BundledProtocolContractsProvider();
|
|
@@ -59,7 +189,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
59
189
|
|
|
60
190
|
await store.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
61
191
|
const bytecodeCommitment = await computePublicBytecodeCommitment(contractClassPublic.packedBytecode);
|
|
62
|
-
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], blockNumber);
|
|
63
|
-
await store.addContractInstances([contract.instance], blockNumber);
|
|
192
|
+
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
|
|
193
|
+
await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
64
194
|
}
|
|
65
195
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
export * from './archiver/index.js';
|
|
2
1
|
export * from './factory.js';
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './interfaces.js';
|
|
3
|
+
export * from './archiver.js';
|
|
4
|
+
export * from './modules/data_source_base.js';
|
|
5
|
+
export * from './modules/data_store_updater.js';
|
|
6
|
+
export * from './config.js';
|
|
4
7
|
|
|
5
|
-
export {
|
|
8
|
+
export { type L1PublishedData } from './structs/published.js';
|
|
9
|
+
export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_store.js';
|
|
10
|
+
export { ContractInstanceStore } from './store/contract_instance_store.js';
|
|
11
|
+
export { L2TipsCache } from './store/l2_tips_cache.js';
|
|
12
|
+
|
|
13
|
+
export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
2
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
3
|
+
import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper interface to combine all sources this archiver implementation provides.
|
|
8
|
+
*/
|
|
9
|
+
export type ArchiverDataSource = L2BlockSource & L2LogsSource & ContractDataSource & L1ToL2MessageSource;
|
package/src/l1/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Archiver L1 Data Retrieval
|
|
2
|
+
|
|
3
|
+
Modules and classes to handle data retrieval from L1 for the archiver.
|
|
4
|
+
|
|
5
|
+
## Calldata Retriever
|
|
6
|
+
|
|
7
|
+
The sequencer publisher bundles multiple operations into a single multicall3 transaction for gas
|
|
8
|
+
efficiency. A typical transaction includes:
|
|
9
|
+
|
|
10
|
+
1. Attestation invalidations (if needed): `invalidateBadAttestation`, `invalidateInsufficientAttestations`
|
|
11
|
+
2. Block proposal: `propose` (exactly one per transaction to the rollup contract)
|
|
12
|
+
3. Governance and slashing (if needed): votes, payload creation/execution
|
|
13
|
+
|
|
14
|
+
The archiver needs to extract the `propose` calldata from these bundled transactions to reconstruct
|
|
15
|
+
L2 blocks. This class needs to handle scenarios where the transaction was submitted via multicall3,
|
|
16
|
+
as well as alternative ways for submitting the `propose` call that other clients might use.
|
|
17
|
+
|
|
18
|
+
### Multicall3 Validation and Decoding
|
|
19
|
+
|
|
20
|
+
First attempt to decode the transaction as a multicall3 `aggregate3` call with validation:
|
|
21
|
+
|
|
22
|
+
- Check if transaction is to multicall3 address (`0xcA11bde05977b3631167028862bE2a173976CA11`)
|
|
23
|
+
- Decode as `aggregate3(Call3[] calldata calls)`
|
|
24
|
+
- Allow calls to known addresses and methods (rollup, governance, slashing contracts, etc.)
|
|
25
|
+
- Find the single `propose` call to the rollup contract
|
|
26
|
+
- Verify exactly one `propose` call exists
|
|
27
|
+
- Extract and return the propose calldata
|
|
28
|
+
|
|
29
|
+
This step handles the common case efficiently without requiring expensive trace or debug RPC calls.
|
|
30
|
+
Any validation failure triggers fallback to the next step.
|
|
31
|
+
|
|
32
|
+
### Direct Propose Call
|
|
33
|
+
|
|
34
|
+
Second attempt to decode the transaction as a direct `propose` call to the rollup contract:
|
|
35
|
+
|
|
36
|
+
- Check if transaction is to the rollup address
|
|
37
|
+
- Decode as `propose` function call
|
|
38
|
+
- Verify the function is indeed `propose`
|
|
39
|
+
- Return the transaction input as the propose calldata
|
|
40
|
+
|
|
41
|
+
This handles scenarios where clients submit transactions directly to the rollup contract without
|
|
42
|
+
using multicall3 for bundling. Any validation failure triggers fallback to the next step.
|
|
43
|
+
|
|
44
|
+
### Spire Proposer Call
|
|
45
|
+
|
|
46
|
+
Given existing attempts to route the call via the Spire proposer, we also check if the tx is `to` the
|
|
47
|
+
proposer known address, and if so, we try decoding it as either a multicall3 or a direct call to the
|
|
48
|
+
rollup contract.
|
|
49
|
+
|
|
50
|
+
Similar as with the multicall3 check, we check that there are no other calls in the Spire proposer, so
|
|
51
|
+
we are absolutely sure that the only call is the successful one to the rollup. Any extraneous call would
|
|
52
|
+
imply an unexpected path to calling `propose` in the rollup contract, and since we cannot verify if the
|
|
53
|
+
calldata arguments we extracted are the correct ones (see the section below), we cannot know for sure which
|
|
54
|
+
one is the call that succeeded, so we don't know which calldata to process.
|
|
55
|
+
|
|
56
|
+
Furthermore, since the Spire proposer is upgradeable, we check if the implementation has not changed in
|
|
57
|
+
order to decode. As usual, any validation failure triggers fallback to the next step.
|
|
58
|
+
|
|
59
|
+
### Verifying Multicall3 Arguments
|
|
60
|
+
|
|
61
|
+
**This is NOT implemented for simplicity's sake**
|
|
62
|
+
|
|
63
|
+
If the checks above don't hold, such as when there are multiple calls to `propose`, then we cannot
|
|
64
|
+
reliably extract the `propose` calldata from the multicall3 arguments alone. We can try a best-effort
|
|
65
|
+
where we try all `propose` calls we see and validate them against on-chain data. Note that we can use these
|
|
66
|
+
same strategies if we were to obtain the calldata from another source.
|
|
67
|
+
|
|
68
|
+
#### TempBlockLog Verification
|
|
69
|
+
|
|
70
|
+
Read the stored `TempBlockLog` for the L2 block number from L1 and verify it matches our decoded header hash,
|
|
71
|
+
since the `TempBlockLog` stores the hash of the proposed block header, the payload commitment, and the attestations.
|
|
72
|
+
|
|
73
|
+
However, `TempBlockLog` is only stored temporarily and deleted after proven, so this method only works for recent
|
|
74
|
+
blocks, not for historical data syncing.
|
|
75
|
+
|
|
76
|
+
#### Archive Verification
|
|
77
|
+
|
|
78
|
+
Verify that the archive root in the decoded propose is correct with regard to the block header. This requires
|
|
79
|
+
hashing the block header we have retrieved, inserting it into the archive tree, and checking the resulting root
|
|
80
|
+
against the one we got from L1.
|
|
81
|
+
|
|
82
|
+
However, this requires that the archive keeps a reference to world-state, which is not the case in the current
|
|
83
|
+
system.
|
|
84
|
+
|
|
85
|
+
#### Emit Commitments in Rollup Contract
|
|
86
|
+
|
|
87
|
+
Modify rollup contract to emit commitments to the block header in the `L2BlockProposed` event, allowing us to easily
|
|
88
|
+
verify the calldata we obtained vs the emitted event.
|
|
89
|
+
|
|
90
|
+
However, modifying the rollup contract is out of scope for this change. But we can implement this approach in `v2`.
|
|
91
|
+
|
|
92
|
+
### Debug and Trace Transaction Fallback
|
|
93
|
+
|
|
94
|
+
Last, we use L1 node's trace/debug RPC methods to definitively identify the one successful `propose` call within the tx.
|
|
95
|
+
We can then extract the exact calldata that hit the `propose` function in the rollup contract.
|
|
96
|
+
|
|
97
|
+
This approach requires access to a debug-enabled L1 node, which may be more resource-intensive, so we only
|
|
98
|
+
use it as a fallback when the first step fails, which should be rare in practice.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
7
|
+
|
|
8
|
+
import { type Hex, createPublicClient, getAbiItem, http, toEventSelector } from 'viem';
|
|
9
|
+
import { mainnet } from 'viem/chains';
|
|
10
|
+
|
|
11
|
+
import { CalldataRetriever } from '../calldata_retriever.js';
|
|
12
|
+
|
|
13
|
+
const logger = createLogger('archiver:calldata-test');
|
|
14
|
+
|
|
15
|
+
interface ScriptArgs {
|
|
16
|
+
rollupAddress: EthAddress;
|
|
17
|
+
txHash: Hex;
|
|
18
|
+
rpcUrl: string;
|
|
19
|
+
targetCommitteeSize: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function parseArgs(): ScriptArgs {
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
|
|
25
|
+
if (args.length < 2) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.error('Usage: node index.js <rollup-address> <tx-hash> [target-committee-size]');
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.error('');
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.error('Environment variables:');
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
console.error(' ETHEREUM_HOST or RPC_URL - Ethereum RPC endpoint');
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.error('');
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.error('Example:');
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.error(' RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY \\');
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.error(' node index.js 0x1234... 0xabcd... 32');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const rollupAddress = EthAddress.fromString(args[0]);
|
|
46
|
+
const txHash = args[1] as Hex;
|
|
47
|
+
const targetCommitteeSize = args[2] ? parseInt(args[2], 10) : 24;
|
|
48
|
+
|
|
49
|
+
const rpcUrl = process.env.ETHEREUM_HOST || process.env.RPC_URL;
|
|
50
|
+
if (!rpcUrl) {
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.error('Error: ETHEREUM_HOST or RPC_URL environment variable must be set');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (targetCommitteeSize <= 0 || targetCommitteeSize > 256) {
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
console.error('Error: target-committee-size must be between 1 and 256');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { rollupAddress, txHash, rpcUrl, targetCommitteeSize };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
const { rollupAddress, txHash, rpcUrl, targetCommitteeSize } = parseArgs();
|
|
67
|
+
|
|
68
|
+
logger.info('Calldata Retriever Test Script');
|
|
69
|
+
logger.info('===============================');
|
|
70
|
+
logger.info(`Rollup Address: ${rollupAddress.toString()}`);
|
|
71
|
+
logger.info(`Transaction Hash: ${txHash}`);
|
|
72
|
+
logger.info(`RPC URL: ${rpcUrl}`);
|
|
73
|
+
logger.info(`Target Committee Size: ${targetCommitteeSize}`);
|
|
74
|
+
logger.info('');
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
// Create viem public client
|
|
78
|
+
const publicClient = createPublicClient({
|
|
79
|
+
chain: mainnet,
|
|
80
|
+
transport: http(rpcUrl, { batch: false }),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
logger.info('Fetching transaction...');
|
|
84
|
+
const tx = await publicClient.getTransaction({ hash: txHash });
|
|
85
|
+
|
|
86
|
+
if (!tx) {
|
|
87
|
+
throw new Error(`Transaction ${txHash} not found`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
logger.info(`Transaction found in block ${tx.blockNumber}`);
|
|
91
|
+
|
|
92
|
+
// For simplicity, use zero addresses for optional contract addresses
|
|
93
|
+
// In production, these would be fetched from the rollup contract or configuration
|
|
94
|
+
const slashingProposerAddress = EthAddress.ZERO;
|
|
95
|
+
const governanceProposerAddress = EthAddress.ZERO;
|
|
96
|
+
const slashFactoryAddress = undefined;
|
|
97
|
+
|
|
98
|
+
logger.info('Using zero addresses for governance/slashing (can be configured if needed)');
|
|
99
|
+
|
|
100
|
+
// Create CalldataRetriever
|
|
101
|
+
const retriever = new CalldataRetriever(
|
|
102
|
+
publicClient as unknown as ViemPublicClient,
|
|
103
|
+
publicClient as unknown as ViemPublicDebugClient,
|
|
104
|
+
targetCommitteeSize,
|
|
105
|
+
undefined,
|
|
106
|
+
logger,
|
|
107
|
+
{
|
|
108
|
+
rollupAddress,
|
|
109
|
+
governanceProposerAddress,
|
|
110
|
+
slashingProposerAddress,
|
|
111
|
+
slashFactoryAddress,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Extract checkpoint number from transaction logs
|
|
116
|
+
logger.info('Decoding transaction to extract checkpoint number...');
|
|
117
|
+
const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
|
|
118
|
+
|
|
119
|
+
// Look for CheckpointProposed event (emitted when a checkpoint is proposed to the rollup)
|
|
120
|
+
// Event signature: CheckpointProposed(uint256 indexed checkpointNumber, bytes32 indexed archive, bytes32[], bytes32, bytes32)
|
|
121
|
+
// Hash: keccak256("CheckpointProposed(uint256,bytes32,bytes32[],bytes32,bytes32)")
|
|
122
|
+
const checkpointProposedEvent = receipt.logs.find(log => {
|
|
123
|
+
try {
|
|
124
|
+
return (
|
|
125
|
+
log.address.toLowerCase() === rollupAddress.toString().toLowerCase() &&
|
|
126
|
+
log.topics[0] === toEventSelector(getAbiItem({ abi: RollupAbi, name: 'CheckpointProposed' }))
|
|
127
|
+
);
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!checkpointProposedEvent || checkpointProposedEvent.topics[1] === undefined) {
|
|
134
|
+
throw new Error(`Checkpoint proposed event not found`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const checkpointNumber = CheckpointNumber.fromBigInt(BigInt(checkpointProposedEvent.topics[1]));
|
|
138
|
+
|
|
139
|
+
logger.info('');
|
|
140
|
+
logger.info('Retrieving checkpoint from rollup transaction...');
|
|
141
|
+
logger.info('');
|
|
142
|
+
|
|
143
|
+
// For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
|
|
144
|
+
const result = await retriever.getCheckpointFromRollupTx(txHash, [], checkpointNumber, {});
|
|
145
|
+
|
|
146
|
+
logger.info(' Successfully retrieved block header!');
|
|
147
|
+
logger.info('');
|
|
148
|
+
logger.info('Block Header Details:');
|
|
149
|
+
logger.info('====================');
|
|
150
|
+
logger.info(`Checkpoint Number: ${result.checkpointNumber}`);
|
|
151
|
+
logger.info(`Block Hash: ${result.blockHash}`);
|
|
152
|
+
logger.info(`Archive Root: ${result.archiveRoot.toString()}`);
|
|
153
|
+
logger.info('');
|
|
154
|
+
logger.info('Header:');
|
|
155
|
+
logger.info(` Slot Number: ${result.header.slotNumber.toString()}`);
|
|
156
|
+
logger.info(` Timestamp: ${result.header.timestamp.toString()}`);
|
|
157
|
+
logger.info(` Coinbase: ${result.header.coinbase.toString()}`);
|
|
158
|
+
logger.info(` Fee Recipient: ${result.header.feeRecipient.toString()}`);
|
|
159
|
+
logger.info(` Total Mana Used: ${result.header.totalManaUsed.toString()}`);
|
|
160
|
+
logger.info('');
|
|
161
|
+
logger.info('Attestations:');
|
|
162
|
+
logger.info(` Count: ${result.attestations.length}`);
|
|
163
|
+
logger.info(` Non-empty attestations: ${result.attestations.filter((a: any) => !a.signature.isEmpty()).length}`);
|
|
164
|
+
|
|
165
|
+
process.exit(0);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
logger.error('Error retrieving block header:');
|
|
168
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
169
|
+
|
|
170
|
+
if (error instanceof Error && error.stack) {
|
|
171
|
+
logger.debug(error.stack);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Only run if this is the main module
|
|
179
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
180
|
+
void main();
|
|
181
|
+
}
|