@aztec/archiver 0.54.0 → 0.55.0
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/dest/archiver/archiver.d.ts +2 -3
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +28 -61
- package/dest/archiver/data_retrieval.d.ts +6 -16
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +10 -35
- package/dest/archiver/eth_log_handlers.d.ts +6 -16
- package/dest/archiver/eth_log_handlers.d.ts.map +1 -1
- package/dest/archiver/eth_log_handlers.js +15 -84
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -3
- package/package.json +10 -10
- package/src/archiver/archiver.ts +39 -89
- package/src/archiver/data_retrieval.ts +12 -58
- package/src/archiver/eth_log_handlers.ts +17 -117
- package/src/index.ts +1 -2
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
import { Body, InboxLeaf } from '@aztec/circuit-types';
|
|
1
|
+
import { Body, InboxLeaf, L2Block, type ViemSignature } from '@aztec/circuit-types';
|
|
2
2
|
import { AppendOnlyTreeSnapshot, Header, Proof } from '@aztec/circuits.js';
|
|
3
3
|
import { type EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { numToUInt32BE } from '@aztec/foundation/serialize';
|
|
6
|
-
import {
|
|
6
|
+
import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
type Hex,
|
|
10
|
-
type Log,
|
|
11
|
-
type PublicClient,
|
|
12
|
-
decodeFunctionData,
|
|
13
|
-
getAbiItem,
|
|
14
|
-
getAddress,
|
|
15
|
-
hexToBytes,
|
|
16
|
-
slice,
|
|
17
|
-
} from 'viem';
|
|
8
|
+
import { type Hex, type Log, type PublicClient, decodeFunctionData, getAbiItem, getAddress, hexToBytes } from 'viem';
|
|
18
9
|
|
|
19
|
-
import { type L1PublishedData } from './structs/published.js';
|
|
10
|
+
import { type L1Published, type L1PublishedData } from './structs/published.js';
|
|
20
11
|
|
|
21
12
|
/**
|
|
22
13
|
* Processes newly received MessageSent (L1 to L2) logs.
|
|
@@ -39,25 +30,21 @@ export function processMessageSentLogs(
|
|
|
39
30
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
40
31
|
* @param expectedL2BlockNumber - The next expected L2 block number.
|
|
41
32
|
* @param logs - L2BlockProposed logs.
|
|
42
|
-
* @returns - An array
|
|
33
|
+
* @returns - An array blocks.
|
|
43
34
|
*/
|
|
44
35
|
export async function processL2BlockProposedLogs(
|
|
45
36
|
publicClient: PublicClient,
|
|
46
37
|
expectedL2BlockNumber: bigint,
|
|
47
38
|
logs: Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProposed'>[],
|
|
48
|
-
): Promise<[
|
|
49
|
-
const
|
|
39
|
+
): Promise<L1Published<L2Block>[]> {
|
|
40
|
+
const retrievedBlocks: L1Published<L2Block>[] = [];
|
|
50
41
|
for (const log of logs) {
|
|
51
42
|
const blockNum = log.args.blockNumber;
|
|
52
43
|
if (blockNum !== expectedL2BlockNumber) {
|
|
53
44
|
throw new Error('Block number mismatch. Expected: ' + expectedL2BlockNumber + ' but got: ' + blockNum + '.');
|
|
54
45
|
}
|
|
55
46
|
// TODO: Fetch blocks from calldata in parallel
|
|
56
|
-
const
|
|
57
|
-
publicClient,
|
|
58
|
-
log.transactionHash!,
|
|
59
|
-
log.args.blockNumber,
|
|
60
|
-
);
|
|
47
|
+
const block = await getBlockFromRollupTx(publicClient, log.transactionHash!, log.args.blockNumber);
|
|
61
48
|
|
|
62
49
|
const l1: L1PublishedData = {
|
|
63
50
|
blockNumber: log.blockNumber,
|
|
@@ -65,11 +52,11 @@ export async function processL2BlockProposedLogs(
|
|
|
65
52
|
timestamp: await getL1BlockTime(publicClient, log.blockNumber),
|
|
66
53
|
};
|
|
67
54
|
|
|
68
|
-
|
|
55
|
+
retrievedBlocks.push({ data: block, l1 });
|
|
69
56
|
expectedL2BlockNumber++;
|
|
70
57
|
}
|
|
71
58
|
|
|
72
|
-
return
|
|
59
|
+
return retrievedBlocks;
|
|
73
60
|
}
|
|
74
61
|
|
|
75
62
|
export async function getL1BlockTime(publicClient: PublicClient, blockNumber: bigint): Promise<bigint> {
|
|
@@ -77,33 +64,20 @@ export async function getL1BlockTime(publicClient: PublicClient, blockNumber: bi
|
|
|
77
64
|
return block.timestamp;
|
|
78
65
|
}
|
|
79
66
|
|
|
80
|
-
export async function processTxsPublishedLogs(
|
|
81
|
-
publicClient: PublicClient,
|
|
82
|
-
logs: Log<bigint, number, false, undefined, true, typeof AvailabilityOracleAbi, 'TxsPublished'>[],
|
|
83
|
-
): Promise<[Body, Buffer][]> {
|
|
84
|
-
const retrievedBlockBodies: [Body, Buffer][] = [];
|
|
85
|
-
for (const log of logs) {
|
|
86
|
-
const newBlockBody = await getBlockBodiesFromAvailabilityOracleTx(publicClient, log.transactionHash!);
|
|
87
|
-
retrievedBlockBodies.push([newBlockBody, Buffer.from(hexToBytes(log.args.txsEffectsHash))]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return retrievedBlockBodies;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
67
|
/**
|
|
94
|
-
* Gets block
|
|
68
|
+
* Gets block from the calldata of an L1 transaction.
|
|
95
69
|
* Assumes that the block was published from an EOA.
|
|
96
70
|
* TODO: Add retries and error management.
|
|
97
71
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
98
72
|
* @param txHash - Hash of the tx that published it.
|
|
99
73
|
* @param l2BlockNum - L2 block number.
|
|
100
|
-
* @returns L2 block
|
|
74
|
+
* @returns L2 block from the calldata, deserialized
|
|
101
75
|
*/
|
|
102
|
-
async function
|
|
76
|
+
async function getBlockFromRollupTx(
|
|
103
77
|
publicClient: PublicClient,
|
|
104
78
|
txHash: `0x${string}`,
|
|
105
79
|
l2BlockNum: bigint,
|
|
106
|
-
): Promise<
|
|
80
|
+
): Promise<L2Block> {
|
|
107
81
|
const { input: data } = await publicClient.getTransaction({ hash: txHash });
|
|
108
82
|
const { functionName, args } = decodeFunctionData({
|
|
109
83
|
abi: RollupAbi,
|
|
@@ -113,9 +87,10 @@ async function getBlockMetadataFromRollupTx(
|
|
|
113
87
|
if (!(functionName === 'propose')) {
|
|
114
88
|
throw new Error(`Unexpected method called ${functionName}`);
|
|
115
89
|
}
|
|
116
|
-
const [headerHex, archiveRootHex,
|
|
90
|
+
const [headerHex, archiveRootHex, , , , bodyHex] = args! as readonly [Hex, Hex, Hex, Hex[], ViemSignature[], Hex];
|
|
117
91
|
|
|
118
92
|
const header = Header.fromBuffer(Buffer.from(hexToBytes(headerHex)));
|
|
93
|
+
const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex)));
|
|
119
94
|
|
|
120
95
|
const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt();
|
|
121
96
|
|
|
@@ -130,57 +105,7 @@ async function getBlockMetadataFromRollupTx(
|
|
|
130
105
|
]),
|
|
131
106
|
);
|
|
132
107
|
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Gets block bodies from calldata of an L1 transaction, and deserializes them into Body objects.
|
|
138
|
-
* @note Assumes that the block was published using `propose` or `publish`.
|
|
139
|
-
* TODO: Add retries and error management.
|
|
140
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
141
|
-
* @param txHash - Hash of the tx that published it.
|
|
142
|
-
* @returns An L2 block body from the calldata, deserialized
|
|
143
|
-
*/
|
|
144
|
-
async function getBlockBodiesFromAvailabilityOracleTx(
|
|
145
|
-
publicClient: PublicClient,
|
|
146
|
-
txHash: `0x${string}`,
|
|
147
|
-
): Promise<Body> {
|
|
148
|
-
const { input: data } = await publicClient.getTransaction({ hash: txHash });
|
|
149
|
-
|
|
150
|
-
// @note Use `forge inspect Rollup methodIdentifiers to get this,
|
|
151
|
-
// If using `forge sig` you will get an INVALID value for the case with a struct.
|
|
152
|
-
// [
|
|
153
|
-
// "propose(bytes,bytes32,bytes32,(bool,uint8,bytes32,bytes32)[],bytes)": "08978fe9",
|
|
154
|
-
// "propose(bytes,bytes32,bytes32,bytes)": "81e6f472",
|
|
155
|
-
// "publish(bytes calldata _body)"
|
|
156
|
-
// ]
|
|
157
|
-
const DATA_INDEX = [4, 3, 0];
|
|
158
|
-
const SUPPORTED_SIGS = ['0x08978fe9', '0x81e6f472', '0x7fd28346'];
|
|
159
|
-
|
|
160
|
-
const signature = slice(data, 0, 4);
|
|
161
|
-
|
|
162
|
-
if (!SUPPORTED_SIGS.includes(signature)) {
|
|
163
|
-
throw new Error(`Unexpected method called ${signature}`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (signature === SUPPORTED_SIGS[SUPPORTED_SIGS.length - 1]) {
|
|
167
|
-
const { args } = decodeFunctionData({
|
|
168
|
-
abi: AvailabilityOracleAbi,
|
|
169
|
-
data,
|
|
170
|
-
});
|
|
171
|
-
const [bodyHex] = args! as [Hex];
|
|
172
|
-
const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex)));
|
|
173
|
-
return blockBody;
|
|
174
|
-
} else {
|
|
175
|
-
const { args } = decodeFunctionData({
|
|
176
|
-
abi: RollupAbi,
|
|
177
|
-
data,
|
|
178
|
-
});
|
|
179
|
-
const index = SUPPORTED_SIGS.indexOf(signature);
|
|
180
|
-
const bodyHex = args![DATA_INDEX[index]] as Hex;
|
|
181
|
-
const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex)));
|
|
182
|
-
return blockBody;
|
|
183
|
-
}
|
|
108
|
+
return new L2Block(archive, header, blockBody);
|
|
184
109
|
}
|
|
185
110
|
|
|
186
111
|
/**
|
|
@@ -208,31 +133,6 @@ export function getL2BlockProposedLogs(
|
|
|
208
133
|
});
|
|
209
134
|
}
|
|
210
135
|
|
|
211
|
-
/**
|
|
212
|
-
* Gets relevant `TxsPublished` logs from chain.
|
|
213
|
-
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
214
|
-
* @param dataAvailabilityOracleAddress - The address of the availability oracle contract.
|
|
215
|
-
* @param fromBlock - First block to get logs from (inclusive).
|
|
216
|
-
* @param toBlock - Last block to get logs from (inclusive).
|
|
217
|
-
* @returns An array of `TxsPublished` logs.
|
|
218
|
-
*/
|
|
219
|
-
export function getTxsPublishedLogs(
|
|
220
|
-
publicClient: PublicClient,
|
|
221
|
-
dataAvailabilityOracleAddress: EthAddress,
|
|
222
|
-
fromBlock: bigint,
|
|
223
|
-
toBlock: bigint,
|
|
224
|
-
): Promise<Log<bigint, number, false, undefined, true, typeof AvailabilityOracleAbi, 'TxsPublished'>[]> {
|
|
225
|
-
return publicClient.getLogs({
|
|
226
|
-
address: getAddress(dataAvailabilityOracleAddress.toString()),
|
|
227
|
-
event: getAbiItem({
|
|
228
|
-
abi: AvailabilityOracleAbi,
|
|
229
|
-
name: 'TxsPublished',
|
|
230
|
-
}),
|
|
231
|
-
fromBlock,
|
|
232
|
-
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
136
|
/**
|
|
237
137
|
* Get relevant `MessageSent` logs emitted by Inbox on chain.
|
|
238
138
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export * from './archiver/index.js';
|
|
|
13
13
|
export * from './rpc/index.js';
|
|
14
14
|
export * from './factory.js';
|
|
15
15
|
|
|
16
|
-
export { retrieveL2ProofVerifiedEvents,
|
|
16
|
+
export { retrieveL2ProofVerifiedEvents, retrieveBlockFromRollup } from './archiver/data_retrieval.js';
|
|
17
17
|
|
|
18
18
|
export { getL2BlockProposedLogs } from './archiver/eth_log_handlers.js';
|
|
19
19
|
|
|
@@ -37,7 +37,6 @@ async function main() {
|
|
|
37
37
|
const archiver = new Archiver(
|
|
38
38
|
publicClient,
|
|
39
39
|
l1Contracts.rollupAddress,
|
|
40
|
-
l1Contracts.availabilityOracleAddress,
|
|
41
40
|
l1Contracts.inboxAddress,
|
|
42
41
|
l1Contracts.registryAddress,
|
|
43
42
|
archiverStore,
|