@aztec/archiver 0.16.3 → 0.16.5
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/package.json +6 -6
- package/src/archiver/archiver.ts +0 -428
- package/src/archiver/archiver_store.ts +0 -158
- package/src/archiver/archiver_store_test_suite.ts +0 -638
- package/src/archiver/config.ts +0 -86
- package/src/archiver/data_retrieval.ts +0 -186
- package/src/archiver/eth_log_handlers.ts +0 -268
- package/src/archiver/index.ts +0 -5
- package/src/archiver/lmdb_archiver_store.ts +0 -728
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -110
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -399
- package/src/index.ts +0 -53
package/src/archiver/config.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { L1ContractAddresses } from '@aztec/ethereum';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS.
|
|
6
|
-
* This is the interval between successive calls to eth_blockNumber via viem.
|
|
7
|
-
* Results of calls to eth_blockNumber are cached by viem with this cache being updated periodically at the interval specified by viemPollingIntervalMS.
|
|
8
|
-
* As a result the maximum observed polling time for new blocks will be viemPollingIntervalMS + archiverPollingIntervalMS.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The archiver configuration.
|
|
13
|
-
*/
|
|
14
|
-
export interface ArchiverConfig {
|
|
15
|
-
/**
|
|
16
|
-
* The url of the Ethereum RPC node.
|
|
17
|
-
*/
|
|
18
|
-
rpcUrl: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The key for the ethereum node.
|
|
22
|
-
*/
|
|
23
|
-
apiKey?: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The polling interval in ms for retrieving new L2 blocks and encrypted logs.
|
|
27
|
-
*/
|
|
28
|
-
archiverPollingIntervalMS?: number;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The polling interval viem uses in ms
|
|
32
|
-
*/
|
|
33
|
-
viemPollingIntervalMS?: number;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The deployed L1 contract addresses
|
|
37
|
-
*/
|
|
38
|
-
l1Contracts: L1ContractAddresses;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Optional dir to store data. If omitted will store in memory.
|
|
42
|
-
*/
|
|
43
|
-
dataDirectory?: string;
|
|
44
|
-
|
|
45
|
-
/** The max number of logs that can be obtained in 1 "getUnencryptedLogs" call. */
|
|
46
|
-
maxLogs?: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns the archiver configuration from the environment variables.
|
|
51
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
52
|
-
* @returns The archiver configuration.
|
|
53
|
-
*/
|
|
54
|
-
export function getConfigEnvVars(): ArchiverConfig {
|
|
55
|
-
const {
|
|
56
|
-
ETHEREUM_HOST,
|
|
57
|
-
ARCHIVER_POLLING_INTERVAL_MS,
|
|
58
|
-
ARCHIVER_VIEM_POLLING_INTERVAL_MS,
|
|
59
|
-
ROLLUP_CONTRACT_ADDRESS,
|
|
60
|
-
CONTRACT_DEPLOYMENT_EMITTER_ADDRESS,
|
|
61
|
-
API_KEY,
|
|
62
|
-
INBOX_CONTRACT_ADDRESS,
|
|
63
|
-
OUTBOX_CONTRACT_ADDRESS,
|
|
64
|
-
REGISTRY_CONTRACT_ADDRESS,
|
|
65
|
-
DATA_DIRECTORY,
|
|
66
|
-
} = process.env;
|
|
67
|
-
// Populate the relevant addresses for use by the archiver.
|
|
68
|
-
const addresses: L1ContractAddresses = {
|
|
69
|
-
rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
70
|
-
registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
71
|
-
inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
72
|
-
outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
73
|
-
contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
|
|
74
|
-
? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS)
|
|
75
|
-
: EthAddress.ZERO,
|
|
76
|
-
decoderHelperAddress: EthAddress.ZERO,
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/',
|
|
80
|
-
archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000,
|
|
81
|
-
viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000,
|
|
82
|
-
apiKey: API_KEY,
|
|
83
|
-
l1Contracts: addresses,
|
|
84
|
-
dataDirectory: DATA_DIRECTORY,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { CancelledL1ToL2Message, ExtendedContractData, L2Block, PendingL1ToL2Message } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
import { PublicClient } from 'viem';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
getContractDeploymentLogs,
|
|
8
|
-
getL1ToL2MessageCancelledLogs,
|
|
9
|
-
getL2BlockProcessedLogs,
|
|
10
|
-
getPendingL1ToL2MessageLogs,
|
|
11
|
-
processBlockLogs,
|
|
12
|
-
processCancelledL1ToL2MessagesLogs,
|
|
13
|
-
processContractDeploymentLogs,
|
|
14
|
-
processPendingL1ToL2MessageAddedLogs,
|
|
15
|
-
} from './eth_log_handlers.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Data retrieved from logs
|
|
19
|
-
*/
|
|
20
|
-
type DataRetrieval<T> = {
|
|
21
|
-
/**
|
|
22
|
-
* The next block number.
|
|
23
|
-
*/
|
|
24
|
-
nextEthBlockNumber: bigint;
|
|
25
|
-
/**
|
|
26
|
-
* The data returned.
|
|
27
|
-
*/
|
|
28
|
-
retrievedData: T[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Fetches new L2 Blocks.
|
|
33
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
34
|
-
* @param rollupAddress - The address of the rollup contract.
|
|
35
|
-
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
36
|
-
* @param searchStartBlock - The block number to use for starting the search.
|
|
37
|
-
* @param searchEndBlock - The highest block number that we should search up to.
|
|
38
|
-
* @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
|
|
39
|
-
* @returns An array of L2 Blocks and the next eth block to search from
|
|
40
|
-
*/
|
|
41
|
-
export async function retrieveBlocks(
|
|
42
|
-
publicClient: PublicClient,
|
|
43
|
-
rollupAddress: EthAddress,
|
|
44
|
-
blockUntilSynced: boolean,
|
|
45
|
-
searchStartBlock: bigint,
|
|
46
|
-
searchEndBlock: bigint,
|
|
47
|
-
expectedNextL2BlockNum: bigint,
|
|
48
|
-
): Promise<DataRetrieval<L2Block>> {
|
|
49
|
-
const retrievedBlocks: L2Block[] = [];
|
|
50
|
-
do {
|
|
51
|
-
if (searchStartBlock > searchEndBlock) {
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
const l2BlockProcessedLogs = await getL2BlockProcessedLogs(
|
|
55
|
-
publicClient,
|
|
56
|
-
rollupAddress,
|
|
57
|
-
searchStartBlock,
|
|
58
|
-
searchEndBlock,
|
|
59
|
-
);
|
|
60
|
-
if (l2BlockProcessedLogs.length === 0) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const newBlocks = await processBlockLogs(publicClient, expectedNextL2BlockNum, l2BlockProcessedLogs);
|
|
65
|
-
retrievedBlocks.push(...newBlocks);
|
|
66
|
-
searchStartBlock = l2BlockProcessedLogs[l2BlockProcessedLogs.length - 1].blockNumber! + 1n;
|
|
67
|
-
expectedNextL2BlockNum += BigInt(newBlocks.length);
|
|
68
|
-
} while (blockUntilSynced && searchStartBlock <= searchEndBlock);
|
|
69
|
-
return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedBlocks };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Fetches new contract data.
|
|
74
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
75
|
-
* @param contractDeploymentEmitterAddress - The address of the contract deployment emitter contract.
|
|
76
|
-
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
77
|
-
* @param searchStartBlock - The block number to use for starting the search.
|
|
78
|
-
* @param searchEndBlock - The highest block number that we should search up to.
|
|
79
|
-
* @param blockHashMapping - A mapping from block number to relevant block hash.
|
|
80
|
-
* @returns An array of ExtendedContractData and their equivalent L2 Block number along with the next eth block to search from..
|
|
81
|
-
*/
|
|
82
|
-
export async function retrieveNewContractData(
|
|
83
|
-
publicClient: PublicClient,
|
|
84
|
-
contractDeploymentEmitterAddress: EthAddress,
|
|
85
|
-
blockUntilSynced: boolean,
|
|
86
|
-
searchStartBlock: bigint,
|
|
87
|
-
searchEndBlock: bigint,
|
|
88
|
-
blockHashMapping: { [key: number]: Buffer | undefined },
|
|
89
|
-
): Promise<DataRetrieval<[ExtendedContractData[], number]>> {
|
|
90
|
-
let retrievedNewContracts: [ExtendedContractData[], number][] = [];
|
|
91
|
-
do {
|
|
92
|
-
if (searchStartBlock > searchEndBlock) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
const contractDataLogs = await getContractDeploymentLogs(
|
|
96
|
-
publicClient,
|
|
97
|
-
contractDeploymentEmitterAddress,
|
|
98
|
-
searchStartBlock,
|
|
99
|
-
searchEndBlock,
|
|
100
|
-
);
|
|
101
|
-
if (contractDataLogs.length === 0) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
const newContracts = processContractDeploymentLogs(blockHashMapping, contractDataLogs);
|
|
105
|
-
retrievedNewContracts = retrievedNewContracts.concat(newContracts);
|
|
106
|
-
searchStartBlock = (contractDataLogs.findLast(cd => !!cd)?.blockNumber || searchStartBlock) + 1n;
|
|
107
|
-
} while (blockUntilSynced && searchStartBlock <= searchEndBlock);
|
|
108
|
-
return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewContracts };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Fetch new pending L1 to L2 messages.
|
|
113
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
114
|
-
* @param inboxAddress - The address of the inbox contract to fetch messages from.
|
|
115
|
-
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
116
|
-
* @param searchStartBlock - The block number to use for starting the search.
|
|
117
|
-
* @param searchEndBlock - The highest block number that we should search up to.
|
|
118
|
-
* @returns An array of L1ToL2Message and next eth block to search from.
|
|
119
|
-
*/
|
|
120
|
-
export async function retrieveNewPendingL1ToL2Messages(
|
|
121
|
-
publicClient: PublicClient,
|
|
122
|
-
inboxAddress: EthAddress,
|
|
123
|
-
blockUntilSynced: boolean,
|
|
124
|
-
searchStartBlock: bigint,
|
|
125
|
-
searchEndBlock: bigint,
|
|
126
|
-
): Promise<DataRetrieval<PendingL1ToL2Message>> {
|
|
127
|
-
const retrievedNewL1ToL2Messages: PendingL1ToL2Message[] = [];
|
|
128
|
-
do {
|
|
129
|
-
if (searchStartBlock > searchEndBlock) {
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
const newL1ToL2MessageLogs = await getPendingL1ToL2MessageLogs(
|
|
133
|
-
publicClient,
|
|
134
|
-
inboxAddress,
|
|
135
|
-
searchStartBlock,
|
|
136
|
-
searchEndBlock,
|
|
137
|
-
);
|
|
138
|
-
if (newL1ToL2MessageLogs.length === 0) {
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
const newL1ToL2Messages = processPendingL1ToL2MessageAddedLogs(newL1ToL2MessageLogs);
|
|
142
|
-
retrievedNewL1ToL2Messages.push(...newL1ToL2Messages);
|
|
143
|
-
// handles the case when there are no new messages:
|
|
144
|
-
searchStartBlock = (newL1ToL2MessageLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
|
|
145
|
-
} while (blockUntilSynced && searchStartBlock <= searchEndBlock);
|
|
146
|
-
return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewL1ToL2Messages };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Fetch newly cancelled L1 to L2 messages.
|
|
151
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
152
|
-
* @param inboxAddress - The address of the inbox contract to fetch messages from.
|
|
153
|
-
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
154
|
-
* @param searchStartBlock - The block number to use for starting the search.
|
|
155
|
-
* @param searchEndBlock - The highest block number that we should search up to.
|
|
156
|
-
* @returns An array of message keys that were cancelled and next eth block to search from.
|
|
157
|
-
*/
|
|
158
|
-
export async function retrieveNewCancelledL1ToL2Messages(
|
|
159
|
-
publicClient: PublicClient,
|
|
160
|
-
inboxAddress: EthAddress,
|
|
161
|
-
blockUntilSynced: boolean,
|
|
162
|
-
searchStartBlock: bigint,
|
|
163
|
-
searchEndBlock: bigint,
|
|
164
|
-
): Promise<DataRetrieval<CancelledL1ToL2Message>> {
|
|
165
|
-
const retrievedNewCancelledL1ToL2Messages: CancelledL1ToL2Message[] = [];
|
|
166
|
-
do {
|
|
167
|
-
if (searchStartBlock > searchEndBlock) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
const newL1ToL2MessageCancelledLogs = await getL1ToL2MessageCancelledLogs(
|
|
171
|
-
publicClient,
|
|
172
|
-
inboxAddress,
|
|
173
|
-
searchStartBlock,
|
|
174
|
-
searchEndBlock,
|
|
175
|
-
);
|
|
176
|
-
if (newL1ToL2MessageCancelledLogs.length === 0) {
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
const newCancelledL1ToL2Messages = processCancelledL1ToL2MessagesLogs(newL1ToL2MessageCancelledLogs);
|
|
180
|
-
retrievedNewCancelledL1ToL2Messages.push(...newCancelledL1ToL2Messages);
|
|
181
|
-
// handles the case when there are no new messages:
|
|
182
|
-
searchStartBlock =
|
|
183
|
-
(newL1ToL2MessageCancelledLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n;
|
|
184
|
-
} while (blockUntilSynced && searchStartBlock <= searchEndBlock);
|
|
185
|
-
return { nextEthBlockNumber: searchStartBlock, retrievedData: retrievedNewCancelledL1ToL2Messages };
|
|
186
|
-
}
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { Fr, Point } from '@aztec/foundation/fields';
|
|
4
|
-
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
5
|
-
import {
|
|
6
|
-
BufferReader,
|
|
7
|
-
CancelledL1ToL2Message,
|
|
8
|
-
ContractData,
|
|
9
|
-
EncodedContractFunction,
|
|
10
|
-
ExtendedContractData,
|
|
11
|
-
L1Actor,
|
|
12
|
-
L1ToL2Message,
|
|
13
|
-
L2Actor,
|
|
14
|
-
L2Block,
|
|
15
|
-
PendingL1ToL2Message,
|
|
16
|
-
} from '@aztec/types';
|
|
17
|
-
|
|
18
|
-
import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hexToBytes } from 'viem';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Processes newly received MessageAdded (L1 to L2) logs.
|
|
22
|
-
* @param logs - MessageAdded logs.
|
|
23
|
-
* @returns Array of all Pending L1 to L2 messages that were processed
|
|
24
|
-
*/
|
|
25
|
-
export function processPendingL1ToL2MessageAddedLogs(
|
|
26
|
-
logs: Log<bigint, number, undefined, true, typeof InboxAbi, 'MessageAdded'>[],
|
|
27
|
-
): PendingL1ToL2Message[] {
|
|
28
|
-
const l1ToL2Messages: PendingL1ToL2Message[] = [];
|
|
29
|
-
for (const [index, log] of logs.entries()) {
|
|
30
|
-
const { sender, senderChainId, recipient, recipientVersion, content, secretHash, deadline, fee, entryKey } =
|
|
31
|
-
log.args;
|
|
32
|
-
l1ToL2Messages.push(
|
|
33
|
-
new PendingL1ToL2Message(
|
|
34
|
-
new L1ToL2Message(
|
|
35
|
-
new L1Actor(EthAddress.fromString(sender), Number(senderChainId)),
|
|
36
|
-
new L2Actor(AztecAddress.fromString(recipient), Number(recipientVersion)),
|
|
37
|
-
Fr.fromString(content),
|
|
38
|
-
Fr.fromString(secretHash),
|
|
39
|
-
deadline,
|
|
40
|
-
Number(fee),
|
|
41
|
-
Fr.fromString(entryKey),
|
|
42
|
-
),
|
|
43
|
-
log.blockNumber!,
|
|
44
|
-
index,
|
|
45
|
-
),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return l1ToL2Messages;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Process newly received L1ToL2MessageCancelled logs.
|
|
53
|
-
* @param logs - L1ToL2MessageCancelled logs.
|
|
54
|
-
* @returns Array of message keys of the L1 to L2 messages that were cancelled
|
|
55
|
-
*/
|
|
56
|
-
export function processCancelledL1ToL2MessagesLogs(
|
|
57
|
-
logs: Log<bigint, number, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[],
|
|
58
|
-
): CancelledL1ToL2Message[] {
|
|
59
|
-
const cancelledL1ToL2Messages: CancelledL1ToL2Message[] = [];
|
|
60
|
-
for (const [index, log] of logs.entries()) {
|
|
61
|
-
cancelledL1ToL2Messages.push(new CancelledL1ToL2Message(Fr.fromString(log.args.entryKey), log.blockNumber!, index));
|
|
62
|
-
}
|
|
63
|
-
return cancelledL1ToL2Messages;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Processes newly received L2BlockProcessed logs.
|
|
68
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
69
|
-
* @param expectedL2BlockNumber - The next expected L2 block number.
|
|
70
|
-
* @param logs - L2BlockProcessed logs.
|
|
71
|
-
*/
|
|
72
|
-
export async function processBlockLogs(
|
|
73
|
-
publicClient: PublicClient,
|
|
74
|
-
expectedL2BlockNumber: bigint,
|
|
75
|
-
logs: Log<bigint, number, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
|
|
76
|
-
): Promise<L2Block[]> {
|
|
77
|
-
const retrievedBlocks: L2Block[] = [];
|
|
78
|
-
for (const log of logs) {
|
|
79
|
-
const blockNum = log.args.blockNum;
|
|
80
|
-
if (blockNum !== expectedL2BlockNumber) {
|
|
81
|
-
throw new Error('Block number mismatch. Expected: ' + expectedL2BlockNumber + ' but got: ' + blockNum + '.');
|
|
82
|
-
}
|
|
83
|
-
// TODO: Fetch blocks from calldata in parallel
|
|
84
|
-
const newBlock = await getBlockFromCallData(publicClient, log.transactionHash!, log.args.blockNum);
|
|
85
|
-
newBlock.setL1BlockNumber(log.blockNumber!);
|
|
86
|
-
retrievedBlocks.push(newBlock);
|
|
87
|
-
expectedL2BlockNumber++;
|
|
88
|
-
}
|
|
89
|
-
return retrievedBlocks;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Builds an L2 block out of calldata from the tx that published it.
|
|
94
|
-
* Assumes that the block was published from an EOA.
|
|
95
|
-
* TODO: Add retries and error management.
|
|
96
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
97
|
-
* @param txHash - Hash of the tx that published it.
|
|
98
|
-
* @param l2BlockNum - L2 block number.
|
|
99
|
-
* @returns An L2 block deserialized from the calldata.
|
|
100
|
-
*/
|
|
101
|
-
async function getBlockFromCallData(
|
|
102
|
-
publicClient: PublicClient,
|
|
103
|
-
txHash: `0x${string}`,
|
|
104
|
-
l2BlockNum: bigint,
|
|
105
|
-
): Promise<L2Block> {
|
|
106
|
-
const { input: data } = await publicClient.getTransaction({ hash: txHash });
|
|
107
|
-
// TODO: File a bug in viem who complains if we dont remove the ctor from the abi here
|
|
108
|
-
const { functionName, args } = decodeFunctionData({
|
|
109
|
-
abi: RollupAbi.filter(item => item.type.toString() !== 'constructor'),
|
|
110
|
-
data,
|
|
111
|
-
});
|
|
112
|
-
if (functionName !== 'process') {
|
|
113
|
-
throw new Error(`Unexpected method called ${functionName}`);
|
|
114
|
-
}
|
|
115
|
-
const [, l2BlockHex] = args! as [Hex, Hex];
|
|
116
|
-
const block = L2Block.fromBufferWithLogs(Buffer.from(hexToBytes(l2BlockHex)));
|
|
117
|
-
if (BigInt(block.number) !== l2BlockNum) {
|
|
118
|
-
throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${block.number}`);
|
|
119
|
-
}
|
|
120
|
-
return block;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Gets relevant `L2BlockProcessed` logs from chain.
|
|
125
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
126
|
-
* @param rollupAddress - The address of the rollup contract.
|
|
127
|
-
* @param fromBlock - First block to get logs from (inclusive).
|
|
128
|
-
* @param toBlock - Last block to get logs from (inclusive).
|
|
129
|
-
* @returns An array of `L2BlockProcessed` logs.
|
|
130
|
-
*/
|
|
131
|
-
export async function getL2BlockProcessedLogs(
|
|
132
|
-
publicClient: PublicClient,
|
|
133
|
-
rollupAddress: EthAddress,
|
|
134
|
-
fromBlock: bigint,
|
|
135
|
-
toBlock: bigint,
|
|
136
|
-
) {
|
|
137
|
-
// Note: For some reason the return type of `getLogs` would not get correctly derived if I didn't set the abiItem
|
|
138
|
-
// as a standalone constant.
|
|
139
|
-
const abiItem = getAbiItem({
|
|
140
|
-
abi: RollupAbi,
|
|
141
|
-
name: 'L2BlockProcessed',
|
|
142
|
-
});
|
|
143
|
-
return await publicClient.getLogs<typeof abiItem, true>({
|
|
144
|
-
address: getAddress(rollupAddress.toString()),
|
|
145
|
-
event: abiItem,
|
|
146
|
-
fromBlock,
|
|
147
|
-
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Gets relevant `ContractDeployment` logs from chain.
|
|
153
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
154
|
-
* @param contractDeploymentEmitterAddress - The address of the L2 contract deployment emitter contract.
|
|
155
|
-
* @param fromBlock - First block to get logs from (inclusive).
|
|
156
|
-
* @param toBlock - Last block to get logs from (inclusive).
|
|
157
|
-
* @returns An array of `ContractDeployment` logs.
|
|
158
|
-
*/
|
|
159
|
-
export async function getContractDeploymentLogs(
|
|
160
|
-
publicClient: PublicClient,
|
|
161
|
-
contractDeploymentEmitterAddress: EthAddress,
|
|
162
|
-
fromBlock: bigint,
|
|
163
|
-
toBlock: bigint,
|
|
164
|
-
): Promise<Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[]> {
|
|
165
|
-
const abiItem = getAbiItem({
|
|
166
|
-
abi: ContractDeploymentEmitterAbi,
|
|
167
|
-
name: 'ContractDeployment',
|
|
168
|
-
});
|
|
169
|
-
return await publicClient.getLogs({
|
|
170
|
-
address: getAddress(contractDeploymentEmitterAddress.toString()),
|
|
171
|
-
event: abiItem,
|
|
172
|
-
fromBlock,
|
|
173
|
-
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Processes newly received ContractDeployment logs.
|
|
179
|
-
* @param blockHashMapping - A mapping from block number to relevant block hash.
|
|
180
|
-
* @param logs - ContractDeployment logs.
|
|
181
|
-
* @returns The set of retrieved extended contract data items.
|
|
182
|
-
*/
|
|
183
|
-
export function processContractDeploymentLogs(
|
|
184
|
-
blockHashMapping: { [key: number]: Buffer | undefined },
|
|
185
|
-
logs: Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[],
|
|
186
|
-
): [ExtendedContractData[], number][] {
|
|
187
|
-
const extendedContractData: [ExtendedContractData[], number][] = [];
|
|
188
|
-
for (let i = 0; i < logs.length; i++) {
|
|
189
|
-
const log = logs[i];
|
|
190
|
-
const l2BlockNum = Number(log.args.l2BlockNum);
|
|
191
|
-
const blockHash = Buffer.from(hexToBytes(log.args.l2BlockHash));
|
|
192
|
-
const expectedBlockHash = blockHashMapping[l2BlockNum];
|
|
193
|
-
if (expectedBlockHash === undefined || !blockHash.equals(expectedBlockHash)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const publicFnsReader = BufferReader.asReader(Buffer.from(log.args.acir.slice(2), 'hex'));
|
|
197
|
-
const partialAddress = Fr.fromBuffer(Buffer.from(hexToBytes(log.args.partialAddress)));
|
|
198
|
-
const publicKey = new Point(
|
|
199
|
-
Fr.fromBuffer(Buffer.from(hexToBytes(log.args.pubKeyX))),
|
|
200
|
-
Fr.fromBuffer(Buffer.from(hexToBytes(log.args.pubKeyY))),
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
const contractData = new ExtendedContractData(
|
|
204
|
-
new ContractData(AztecAddress.fromString(log.args.aztecAddress), EthAddress.fromString(log.args.portalAddress)),
|
|
205
|
-
publicFnsReader.readVector(EncodedContractFunction),
|
|
206
|
-
partialAddress,
|
|
207
|
-
publicKey,
|
|
208
|
-
);
|
|
209
|
-
if (extendedContractData[i]) {
|
|
210
|
-
extendedContractData[i][0].push(contractData);
|
|
211
|
-
} else {
|
|
212
|
-
extendedContractData[i] = [[contractData], l2BlockNum];
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return extendedContractData;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Get relevant `MessageAdded` logs emitted by Inbox on chain.
|
|
220
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
221
|
-
* @param inboxAddress - The address of the inbox contract.
|
|
222
|
-
* @param fromBlock - First block to get logs from (inclusive).
|
|
223
|
-
* @param toBlock - Last block to get logs from (inclusive).
|
|
224
|
-
* @returns An array of `MessageAdded` logs.
|
|
225
|
-
*/
|
|
226
|
-
export async function getPendingL1ToL2MessageLogs(
|
|
227
|
-
publicClient: PublicClient,
|
|
228
|
-
inboxAddress: EthAddress,
|
|
229
|
-
fromBlock: bigint,
|
|
230
|
-
toBlock: bigint,
|
|
231
|
-
): Promise<Log<bigint, number, undefined, true, typeof InboxAbi, 'MessageAdded'>[]> {
|
|
232
|
-
const abiItem = getAbiItem({
|
|
233
|
-
abi: InboxAbi,
|
|
234
|
-
name: 'MessageAdded',
|
|
235
|
-
});
|
|
236
|
-
return await publicClient.getLogs({
|
|
237
|
-
address: getAddress(inboxAddress.toString()),
|
|
238
|
-
event: abiItem,
|
|
239
|
-
fromBlock,
|
|
240
|
-
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Get relevant `L1ToL2MessageCancelled` logs emitted by Inbox on chain when pending messages are cancelled
|
|
246
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
247
|
-
* @param inboxAddress - The address of the inbox contract.
|
|
248
|
-
* @param fromBlock - First block to get logs from (inclusive).
|
|
249
|
-
* @param toBlock - Last block to get logs from (inclusive).
|
|
250
|
-
* @returns An array of `L1ToL2MessageCancelled` logs.
|
|
251
|
-
*/
|
|
252
|
-
export async function getL1ToL2MessageCancelledLogs(
|
|
253
|
-
publicClient: PublicClient,
|
|
254
|
-
inboxAddress: EthAddress,
|
|
255
|
-
fromBlock: bigint,
|
|
256
|
-
toBlock: bigint,
|
|
257
|
-
): Promise<Log<bigint, number, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[]> {
|
|
258
|
-
const abiItem = getAbiItem({
|
|
259
|
-
abi: InboxAbi,
|
|
260
|
-
name: 'L1ToL2MessageCancelled',
|
|
261
|
-
});
|
|
262
|
-
return await publicClient.getLogs({
|
|
263
|
-
address: getAddress(inboxAddress.toString()),
|
|
264
|
-
event: abiItem,
|
|
265
|
-
fromBlock,
|
|
266
|
-
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
|
|
267
|
-
});
|
|
268
|
-
}
|
package/src/archiver/index.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * from './archiver.js';
|
|
2
|
-
export * from './config.js';
|
|
3
|
-
export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
|
|
4
|
-
export { LMDBArchiverStore } from './lmdb_archiver_store.js';
|
|
5
|
-
export { ArchiverDataStore } from './archiver_store.js';
|