@aztec/archiver 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +164 -22
- package/dest/archiver.d.ts +158 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +881 -0
- package/dest/config.d.ts +33 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +31 -14
- package/dest/errors.d.ts +87 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +129 -0
- package/dest/factory.d.ts +16 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +112 -20
- package/dest/index.d.ts +19 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +17 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +136 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +412 -0
- package/dest/l1/data_retrieval.d.ts +97 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +65 -89
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +43 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- 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/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +113 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +351 -0
- package/dest/modules/data_store_updater.d.ts +105 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +392 -0
- package/dest/modules/instrumentation.d.ts +55 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +61 -19
- package/dest/modules/l1_synchronizer.d.ts +77 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1344 -0
- package/dest/modules/validation.d.ts +18 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +12 -6
- package/dest/store/block_store.d.ts +300 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +1219 -0
- package/dest/store/contract_class_store.d.ts +31 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.js +80 -0
- package/dest/store/contract_instance_store.d.ts +51 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +38 -3
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +59 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +310 -0
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +50 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +51 -9
- 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}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +214 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +517 -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 +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +65 -41
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +330 -151
- package/dest/test/mock_structs.d.ts +81 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +152 -7
- package/dest/test/noop_l1_archiver.d.ts +29 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +85 -0
- package/package.json +17 -18
- package/src/archiver.ts +681 -0
- package/src/{archiver/config.ts → config.ts} +43 -12
- package/src/errors.ts +203 -0
- package/src/factory.ts +175 -22
- package/src/index.ts +27 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +522 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +106 -134
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +493 -0
- package/src/modules/data_store_updater.ts +518 -0
- package/src/{archiver → modules}/instrumentation.ts +72 -20
- package/src/modules/l1_synchronizer.ts +1257 -0
- package/src/{archiver → modules}/validation.ts +15 -9
- package/src/store/block_store.ts +1590 -0
- package/src/store/contract_class_store.ts +108 -0
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +52 -6
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +379 -0
- package/src/store/log_store_codec.ts +132 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +60 -10
- package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +770 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +403 -171
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +139 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- 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 -2770
- package/dest/archiver/config.d.ts +0 -22
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -54
- 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 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -626
- 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_class_store.js +0 -120
- 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 -159
- 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 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -401
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts +0 -97
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.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.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 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/errors.ts +0 -90
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -850
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
- package/src/archiver/kv_archiver_store/log_store.ts +0 -516
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
6
|
-
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
7
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { L2BlockHash, L2BlockNew } from '@aztec/stdlib/block';
|
|
9
|
-
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
10
|
-
import {
|
|
11
|
-
ContractClassLog,
|
|
12
|
-
ExtendedContractClassLog,
|
|
13
|
-
ExtendedPublicLog,
|
|
14
|
-
type LogFilter,
|
|
15
|
-
LogId,
|
|
16
|
-
PublicLog,
|
|
17
|
-
type SiloedTag,
|
|
18
|
-
Tag,
|
|
19
|
-
TxScopedL2Log,
|
|
20
|
-
} from '@aztec/stdlib/logs';
|
|
21
|
-
|
|
22
|
-
import type { BlockStore } from './block_store.js';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A store for logs
|
|
26
|
-
*/
|
|
27
|
-
export class LogStore {
|
|
28
|
-
// `tag` --> private logs
|
|
29
|
-
#privateLogsByTag: AztecAsyncMap<string, Buffer[]>;
|
|
30
|
-
// `{contractAddress}_${tag}` --> public logs
|
|
31
|
-
#publicLogsByContractAndTag: AztecAsyncMap<string, Buffer[]>;
|
|
32
|
-
#privateLogKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
33
|
-
#publicLogKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
34
|
-
#publicLogsByBlock: AztecAsyncMap<number, Buffer>;
|
|
35
|
-
#contractClassLogsByBlock: AztecAsyncMap<number, Buffer>;
|
|
36
|
-
#logsMaxPageSize: number;
|
|
37
|
-
#log = createLogger('archiver:log_store');
|
|
38
|
-
|
|
39
|
-
constructor(
|
|
40
|
-
private db: AztecAsyncKVStore,
|
|
41
|
-
private blockStore: BlockStore,
|
|
42
|
-
logsMaxPageSize: number = 1000,
|
|
43
|
-
) {
|
|
44
|
-
this.#privateLogsByTag = db.openMap('archiver_private_tagged_logs_by_tag');
|
|
45
|
-
this.#publicLogsByContractAndTag = db.openMap('archiver_public_tagged_logs_by_tag');
|
|
46
|
-
this.#privateLogKeysByBlock = db.openMap('archiver_private_log_keys_by_block');
|
|
47
|
-
this.#publicLogKeysByBlock = db.openMap('archiver_public_log_keys_by_block');
|
|
48
|
-
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
49
|
-
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
50
|
-
|
|
51
|
-
this.#logsMaxPageSize = logsMaxPageSize;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Extracts tagged logs from a single block, grouping them into private and public maps.
|
|
56
|
-
*
|
|
57
|
-
* @param block - The L2 block to extract logs from.
|
|
58
|
-
* @returns An object containing the private and public tagged logs for the block.
|
|
59
|
-
*/
|
|
60
|
-
#extractTaggedLogsFromBlock(block: L2BlockNew) {
|
|
61
|
-
// SiloedTag (as string) -> array of log buffers.
|
|
62
|
-
const privateTaggedLogs = new Map<string, Buffer[]>();
|
|
63
|
-
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
64
|
-
const publicTaggedLogs = new Map<string, Buffer[]>();
|
|
65
|
-
|
|
66
|
-
block.body.txEffects.forEach(txEffect => {
|
|
67
|
-
const txHash = txEffect.txHash;
|
|
68
|
-
|
|
69
|
-
txEffect.privateLogs.forEach(log => {
|
|
70
|
-
// Private logs use SiloedTag (already siloed by kernel)
|
|
71
|
-
const tag = log.fields[0];
|
|
72
|
-
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
73
|
-
|
|
74
|
-
const currentLogs = privateTaggedLogs.get(tag.toString()) ?? [];
|
|
75
|
-
currentLogs.push(
|
|
76
|
-
new TxScopedL2Log(
|
|
77
|
-
txHash,
|
|
78
|
-
block.number,
|
|
79
|
-
block.timestamp,
|
|
80
|
-
log.getEmittedFields(),
|
|
81
|
-
txEffect.noteHashes,
|
|
82
|
-
txEffect.nullifiers[0],
|
|
83
|
-
).toBuffer(),
|
|
84
|
-
);
|
|
85
|
-
privateTaggedLogs.set(tag.toString(), currentLogs);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
txEffect.publicLogs.forEach(log => {
|
|
89
|
-
// Public logs use Tag directly (not siloed) and are stored with contract address
|
|
90
|
-
const tag = log.fields[0];
|
|
91
|
-
const contractAddress = log.contractAddress;
|
|
92
|
-
const key = `${contractAddress.toString()}_${tag.toString()}`;
|
|
93
|
-
this.#log.debug(
|
|
94
|
-
`Found public log with tag ${tag.toString()} from contract ${contractAddress.toString()} in block ${block.number}`,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
const currentLogs = publicTaggedLogs.get(key) ?? [];
|
|
98
|
-
currentLogs.push(
|
|
99
|
-
new TxScopedL2Log(
|
|
100
|
-
txHash,
|
|
101
|
-
block.number,
|
|
102
|
-
block.timestamp,
|
|
103
|
-
log.getEmittedFields(),
|
|
104
|
-
txEffect.noteHashes,
|
|
105
|
-
txEffect.nullifiers[0],
|
|
106
|
-
).toBuffer(),
|
|
107
|
-
);
|
|
108
|
-
publicTaggedLogs.set(key, currentLogs);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return { privateTaggedLogs, publicTaggedLogs };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Extracts and aggregates tagged logs from a list of blocks.
|
|
117
|
-
* @param blocks - The blocks to extract logs from.
|
|
118
|
-
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
119
|
-
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
120
|
-
*/
|
|
121
|
-
#extractTaggedLogs(blocks: L2BlockNew[]): {
|
|
122
|
-
privateTaggedLogs: Map<string, Buffer[]>;
|
|
123
|
-
publicTaggedLogs: Map<string, Buffer[]>;
|
|
124
|
-
} {
|
|
125
|
-
const taggedLogsInBlocks = blocks.map(block => this.#extractTaggedLogsFromBlock(block));
|
|
126
|
-
|
|
127
|
-
// Now we merge the maps from each block into a single map.
|
|
128
|
-
const privateTaggedLogs = taggedLogsInBlocks.reduce((acc, { privateTaggedLogs }) => {
|
|
129
|
-
for (const [tag, logs] of privateTaggedLogs.entries()) {
|
|
130
|
-
const currentLogs = acc.get(tag) ?? [];
|
|
131
|
-
acc.set(tag, currentLogs.concat(logs));
|
|
132
|
-
}
|
|
133
|
-
return acc;
|
|
134
|
-
}, new Map<string, Buffer[]>());
|
|
135
|
-
|
|
136
|
-
const publicTaggedLogs = taggedLogsInBlocks.reduce((acc, { publicTaggedLogs }) => {
|
|
137
|
-
for (const [key, logs] of publicTaggedLogs.entries()) {
|
|
138
|
-
const currentLogs = acc.get(key) ?? [];
|
|
139
|
-
acc.set(key, currentLogs.concat(logs));
|
|
140
|
-
}
|
|
141
|
-
return acc;
|
|
142
|
-
}, new Map<string, Buffer[]>());
|
|
143
|
-
|
|
144
|
-
return { privateTaggedLogs, publicTaggedLogs };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Append new logs to the store's list.
|
|
149
|
-
* @param blocks - The blocks for which to add the logs.
|
|
150
|
-
* @returns True if the operation is successful.
|
|
151
|
-
*/
|
|
152
|
-
addLogs(blocks: L2BlockNew[]): Promise<boolean> {
|
|
153
|
-
const { privateTaggedLogs, publicTaggedLogs } = this.#extractTaggedLogs(blocks);
|
|
154
|
-
|
|
155
|
-
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
156
|
-
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
157
|
-
|
|
158
|
-
return this.db.transactionAsync(async () => {
|
|
159
|
-
const currentPrivateTaggedLogs = await Promise.all(
|
|
160
|
-
keysOfPrivateLogsToUpdate.map(async key => ({
|
|
161
|
-
tag: key,
|
|
162
|
-
logBuffers: await this.#privateLogsByTag.getAsync(key),
|
|
163
|
-
})),
|
|
164
|
-
);
|
|
165
|
-
currentPrivateTaggedLogs.forEach(taggedLogBuffer => {
|
|
166
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
167
|
-
privateTaggedLogs.set(
|
|
168
|
-
taggedLogBuffer.tag,
|
|
169
|
-
taggedLogBuffer.logBuffers!.concat(privateTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const currentPublicTaggedLogs = await Promise.all(
|
|
175
|
-
keysOfPublicLogsToUpdate.map(async key => ({
|
|
176
|
-
key,
|
|
177
|
-
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key),
|
|
178
|
-
})),
|
|
179
|
-
);
|
|
180
|
-
currentPublicTaggedLogs.forEach(taggedLogBuffer => {
|
|
181
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
182
|
-
publicTaggedLogs.set(
|
|
183
|
-
taggedLogBuffer.key,
|
|
184
|
-
taggedLogBuffer.logBuffers!.concat(publicTaggedLogs.get(taggedLogBuffer.key)!),
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
for (const block of blocks) {
|
|
190
|
-
const blockHash = await block.hash();
|
|
191
|
-
|
|
192
|
-
const privateTagsInBlock: string[] = [];
|
|
193
|
-
for (const [tag, logs] of privateTaggedLogs.entries()) {
|
|
194
|
-
await this.#privateLogsByTag.set(tag, logs);
|
|
195
|
-
privateTagsInBlock.push(tag);
|
|
196
|
-
}
|
|
197
|
-
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
198
|
-
|
|
199
|
-
const publicKeysInBlock: string[] = [];
|
|
200
|
-
for (const [key, logs] of publicTaggedLogs.entries()) {
|
|
201
|
-
await this.#publicLogsByContractAndTag.set(key, logs);
|
|
202
|
-
publicKeysInBlock.push(key);
|
|
203
|
-
}
|
|
204
|
-
await this.#publicLogKeysByBlock.set(block.number, publicKeysInBlock);
|
|
205
|
-
|
|
206
|
-
const publicLogsInBlock = block.body.txEffects
|
|
207
|
-
.map((txEffect, txIndex) =>
|
|
208
|
-
[
|
|
209
|
-
numToUInt32BE(txIndex),
|
|
210
|
-
numToUInt32BE(txEffect.publicLogs.length),
|
|
211
|
-
txEffect.publicLogs.map(log => log.toBuffer()),
|
|
212
|
-
].flat(),
|
|
213
|
-
)
|
|
214
|
-
.flat();
|
|
215
|
-
|
|
216
|
-
const contractClassLogsInBlock = block.body.txEffects
|
|
217
|
-
.map((txEffect, txIndex) =>
|
|
218
|
-
[
|
|
219
|
-
numToUInt32BE(txIndex),
|
|
220
|
-
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
221
|
-
txEffect.contractClassLogs.map(log => log.toBuffer()),
|
|
222
|
-
].flat(),
|
|
223
|
-
)
|
|
224
|
-
.flat();
|
|
225
|
-
|
|
226
|
-
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
227
|
-
await this.#contractClassLogsByBlock.set(
|
|
228
|
-
block.number,
|
|
229
|
-
this.#packWithBlockHash(blockHash, contractClassLogsInBlock),
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return true;
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
#packWithBlockHash(blockHash: Fr, data: Buffer<ArrayBufferLike>[]): Buffer<ArrayBufferLike> {
|
|
238
|
-
return Buffer.concat([blockHash.toBuffer(), ...data]);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
#unpackBlockHash(reader: BufferReader): L2BlockHash {
|
|
242
|
-
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
243
|
-
|
|
244
|
-
if (!blockHash) {
|
|
245
|
-
throw new Error('Failed to read block hash from log entry buffer');
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return L2BlockHash.fromField(blockHash);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
deleteLogs(blocks: L2BlockNew[]): Promise<boolean> {
|
|
252
|
-
return this.db.transactionAsync(async () => {
|
|
253
|
-
await Promise.all(
|
|
254
|
-
blocks.map(async block => {
|
|
255
|
-
// Delete private logs
|
|
256
|
-
const privateKeys = (await this.#privateLogKeysByBlock.getAsync(block.number)) ?? [];
|
|
257
|
-
await Promise.all(privateKeys.map(tag => this.#privateLogsByTag.delete(tag)));
|
|
258
|
-
|
|
259
|
-
// Delete public logs
|
|
260
|
-
const publicKeys = (await this.#publicLogKeysByBlock.getAsync(block.number)) ?? [];
|
|
261
|
-
await Promise.all(publicKeys.map(key => this.#publicLogsByContractAndTag.delete(key)));
|
|
262
|
-
}),
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
await Promise.all(
|
|
266
|
-
blocks.map(block =>
|
|
267
|
-
Promise.all([
|
|
268
|
-
this.#publicLogsByBlock.delete(block.number),
|
|
269
|
-
this.#privateLogKeysByBlock.delete(block.number),
|
|
270
|
-
this.#publicLogKeysByBlock.delete(block.number),
|
|
271
|
-
this.#contractClassLogsByBlock.delete(block.number),
|
|
272
|
-
]),
|
|
273
|
-
),
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
return true;
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Gets all private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
282
|
-
* array implies no logs match that tag.
|
|
283
|
-
*/
|
|
284
|
-
async getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
|
|
285
|
-
const logs = await Promise.all(tags.map(tag => this.#privateLogsByTag.getAsync(tag.toString())));
|
|
286
|
-
|
|
287
|
-
return logs.map(logBuffers => logBuffers?.map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Gets all public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
292
|
-
* logs is returned. An empty array implies no logs match that tag.
|
|
293
|
-
*/
|
|
294
|
-
async getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
|
|
295
|
-
const logs = await Promise.all(
|
|
296
|
-
tags.map(tag => {
|
|
297
|
-
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
298
|
-
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
299
|
-
}),
|
|
300
|
-
);
|
|
301
|
-
return logs.map(logBuffers => logBuffers?.map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Gets public logs based on the provided filter.
|
|
306
|
-
* @param filter - The filter to apply to the logs.
|
|
307
|
-
* @returns The requested logs.
|
|
308
|
-
*/
|
|
309
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
310
|
-
if (filter.afterLog) {
|
|
311
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
312
|
-
} else if (filter.txHash) {
|
|
313
|
-
return this.#filterPublicLogsOfTx(filter);
|
|
314
|
-
} else {
|
|
315
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
async #filterPublicLogsOfTx(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
320
|
-
if (!filter.txHash) {
|
|
321
|
-
throw new Error('Missing txHash');
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const [blockNumber, txIndex] = (await this.blockStore.getTxLocation(filter.txHash)) ?? [];
|
|
325
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
326
|
-
return { logs: [], maxLogsHit: false };
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const buffer = (await this.#publicLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
330
|
-
const publicLogsInBlock: [PublicLog[]] = [[]];
|
|
331
|
-
const reader = new BufferReader(buffer);
|
|
332
|
-
|
|
333
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
334
|
-
|
|
335
|
-
while (reader.remainingBytes() > 0) {
|
|
336
|
-
const indexOfTx = reader.readNumber();
|
|
337
|
-
const numLogsInTx = reader.readNumber();
|
|
338
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
339
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
340
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
345
|
-
|
|
346
|
-
const logs: ExtendedPublicLog[] = [];
|
|
347
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
348
|
-
|
|
349
|
-
return { logs, maxLogsHit };
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
async #filterPublicLogsBetweenBlocks(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
353
|
-
const start =
|
|
354
|
-
filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
355
|
-
const end = filter.toBlock;
|
|
356
|
-
|
|
357
|
-
if (typeof end === 'number' && end < start) {
|
|
358
|
-
return {
|
|
359
|
-
logs: [],
|
|
360
|
-
maxLogsHit: true,
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const logs: ExtendedPublicLog[] = [];
|
|
365
|
-
|
|
366
|
-
let maxLogsHit = false;
|
|
367
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({ start, end })) {
|
|
368
|
-
const publicLogsInBlock: [PublicLog[]] = [[]];
|
|
369
|
-
const reader = new BufferReader(logBuffer);
|
|
370
|
-
|
|
371
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
372
|
-
|
|
373
|
-
while (reader.remainingBytes() > 0) {
|
|
374
|
-
const indexOfTx = reader.readNumber();
|
|
375
|
-
const numLogsInTx = reader.readNumber();
|
|
376
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
377
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
378
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++) {
|
|
382
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
383
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
384
|
-
if (maxLogsHit) {
|
|
385
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
386
|
-
break loopOverBlocks;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return { logs, maxLogsHit };
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Gets contract class logs based on the provided filter.
|
|
396
|
-
* @param filter - The filter to apply to the logs.
|
|
397
|
-
* @returns The requested logs.
|
|
398
|
-
*/
|
|
399
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
400
|
-
if (filter.afterLog) {
|
|
401
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
402
|
-
} else if (filter.txHash) {
|
|
403
|
-
return this.#filterContractClassLogsOfTx(filter);
|
|
404
|
-
} else {
|
|
405
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async #filterContractClassLogsOfTx(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
410
|
-
if (!filter.txHash) {
|
|
411
|
-
throw new Error('Missing txHash');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const [blockNumber, txIndex] = (await this.blockStore.getTxLocation(filter.txHash)) ?? [];
|
|
415
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
416
|
-
return { logs: [], maxLogsHit: false };
|
|
417
|
-
}
|
|
418
|
-
const contractClassLogsBuffer = (await this.#contractClassLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
419
|
-
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
420
|
-
|
|
421
|
-
const reader = new BufferReader(contractClassLogsBuffer);
|
|
422
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
423
|
-
|
|
424
|
-
while (reader.remainingBytes() > 0) {
|
|
425
|
-
const indexOfTx = reader.readNumber();
|
|
426
|
-
const numLogsInTx = reader.readNumber();
|
|
427
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
428
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
429
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
434
|
-
|
|
435
|
-
const logs: ExtendedContractClassLog[] = [];
|
|
436
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
437
|
-
|
|
438
|
-
return { logs, maxLogsHit };
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
async #filterContractClassLogsBetweenBlocks(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
442
|
-
const start =
|
|
443
|
-
filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
444
|
-
const end = filter.toBlock;
|
|
445
|
-
|
|
446
|
-
if (typeof end === 'number' && end < start) {
|
|
447
|
-
return {
|
|
448
|
-
logs: [],
|
|
449
|
-
maxLogsHit: true,
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const logs: ExtendedContractClassLog[] = [];
|
|
454
|
-
|
|
455
|
-
let maxLogsHit = false;
|
|
456
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#contractClassLogsByBlock.entriesAsync({
|
|
457
|
-
start,
|
|
458
|
-
end,
|
|
459
|
-
})) {
|
|
460
|
-
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
461
|
-
const reader = new BufferReader(logBuffer);
|
|
462
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
463
|
-
while (reader.remainingBytes() > 0) {
|
|
464
|
-
const indexOfTx = reader.readNumber();
|
|
465
|
-
const numLogsInTx = reader.readNumber();
|
|
466
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
467
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
468
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
|
|
472
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
473
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
474
|
-
if (maxLogsHit) {
|
|
475
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
476
|
-
break loopOverBlocks;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
return { logs, maxLogsHit };
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
#accumulateLogs(
|
|
485
|
-
results: (ExtendedContractClassLog | ExtendedPublicLog)[],
|
|
486
|
-
blockNumber: number,
|
|
487
|
-
blockHash: L2BlockHash,
|
|
488
|
-
txIndex: number,
|
|
489
|
-
txLogs: (ContractClassLog | PublicLog)[],
|
|
490
|
-
filter: LogFilter = {},
|
|
491
|
-
): boolean {
|
|
492
|
-
let maxLogsHit = false;
|
|
493
|
-
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
494
|
-
for (; logIndex < txLogs.length; logIndex++) {
|
|
495
|
-
const log = txLogs[logIndex];
|
|
496
|
-
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
497
|
-
if (log instanceof ContractClassLog) {
|
|
498
|
-
results.push(
|
|
499
|
-
new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log),
|
|
500
|
-
);
|
|
501
|
-
} else if (log instanceof PublicLog) {
|
|
502
|
-
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log));
|
|
503
|
-
} else {
|
|
504
|
-
throw new Error('Unknown log type');
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (results.length >= this.#logsMaxPageSize) {
|
|
508
|
-
maxLogsHit = true;
|
|
509
|
-
break;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return maxLogsHit;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
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.
|