From 1e4b1f9a1826130a0e8063f73327cc8310b14e80 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Tue, 17 Sep 2024 15:47:55 +0000 Subject: [PATCH] refactor: delete eth-log-handler --- .../archiver/src/archiver/archiver.test.ts | 7 +- .../archiver/src/archiver/archiver.ts | 20 +- .../archiver/src/archiver/data_retrieval.ts | 198 +++++++++++++-- .../archiver/src/archiver/eth_log_handlers.ts | 233 ------------------ yarn-project/archiver/src/index.ts | 2 - yarn-project/circuit-types/src/l2_block.ts | 2 +- yarn-project/cli/src/cmds/l1/prover_stats.ts | 19 +- 7 files changed, 208 insertions(+), 273 deletions(-) delete mode 100644 yarn-project/archiver/src/archiver/eth_log_handlers.ts diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index fb18418ca0a..80773cb89d0 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -31,10 +31,6 @@ interface MockRollupContractRead { archiveAt: (args: readonly [bigint]) => Promise<`0x${string}`>; } -class MockRollupContract { - constructor(public read: MockRollupContractRead, public address: `0x${string}`) {} -} - describe('Archiver', () => { const rollupAddress = EthAddress.ZERO; const inboxAddress = EthAddress.ZERO; @@ -74,10 +70,9 @@ describe('Archiver', () => { blocks = blockNumbers.map(x => L2Block.random(x, 4, x, x + 1, 2, 2)); - const mockRollupRead = mock({ + ((archiver as any).rollup as any).read = mock({ archiveAt: (args: readonly [bigint]) => Promise.resolve(blocks[Number(args[0] - 1n)].archive.root.toString()), }); - (archiver as any).rollup = new MockRollupContract(mockRollupRead, rollupAddress.toString()); }); afterEach(async () => { diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 7744d02d3f1..d5a2962c448 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -30,7 +30,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { Timer } from '@aztec/foundation/timer'; -import { RollupAbi } from '@aztec/l1-artifacts'; +import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts'; import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; import { type TelemetryClient } from '@aztec/telemetry-client'; import { @@ -55,8 +55,12 @@ import { import { type ArchiverDataStore } from './archiver_store.js'; import { type ArchiverConfig } from './config.js'; -import { retrieveBlockFromRollup, retrieveL1ToL2Messages, retrieveL2ProofVerifiedEvents } from './data_retrieval.js'; -import { getL1BlockTime } from './eth_log_handlers.js'; +import { + getL1BlockTime, + retrieveBlockFromRollup, + retrieveL1ToL2Messages, + retrieveL2ProofVerifiedEvents, +} from './data_retrieval.js'; import { ArchiverInstrumentation } from './instrumentation.js'; import { type SingletonDataRetrieval } from './structs/data_retrieval.js'; @@ -77,6 +81,7 @@ export class Archiver implements ArchiveSource { private runningPromise?: RunningPromise; private rollup: GetContractReturnType>; + private inbox: GetContractReturnType>; /** * Creates a new instance of the Archiver. @@ -104,6 +109,12 @@ export class Archiver implements ArchiveSource { abi: RollupAbi, client: publicClient, }); + + this.inbox = getContract({ + address: inboxAddress.toString(), + abi: InboxAbi, + client: publicClient, + }); } /** @@ -244,8 +255,7 @@ export class Archiver implements ArchiveSource { // ********** Events that are processed per L2 block ********** const retrievedL1ToL2Messages = await retrieveL1ToL2Messages( - this.publicClient, - this.inboxAddress, + this.inbox, blockUntilSynced, messagesSynchedTo + 1n, currentL1BlockNumber, diff --git a/yarn-project/archiver/src/archiver/data_retrieval.ts b/yarn-project/archiver/src/archiver/data_retrieval.ts index f9c7fa3f865..89400c6a3f2 100644 --- a/yarn-project/archiver/src/archiver/data_retrieval.ts +++ b/yarn-project/archiver/src/archiver/data_retrieval.ts @@ -1,27 +1,25 @@ -import { type InboxLeaf, type L2Block } from '@aztec/circuit-types'; -import { Fr, type Proof } from '@aztec/circuits.js'; -import { EthAddress } from '@aztec/foundation/eth-address'; +import { Body, InboxLeaf, L2Block } from '@aztec/circuit-types'; +import { AppendOnlyTreeSnapshot, Fr, Header, Proof } from '@aztec/circuits.js'; +import { type EthAddress } from '@aztec/foundation/eth-address'; +import { type ViemSignature } from '@aztec/foundation/eth-signature'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; -import { RollupAbi } from '@aztec/l1-artifacts'; +import { numToUInt32BE } from '@aztec/foundation/serialize'; +import { type InboxAbi, RollupAbi } from '@aztec/l1-artifacts'; import { type Chain, + type GetContractEventsReturnType, type GetContractReturnType, type Hex, type HttpTransport, type PublicClient, + decodeFunctionData, getAbiItem, + hexToBytes, } from 'viem'; -import { - getBlockProofFromSubmitProofTx, - getL2BlockProposedLogs, - getMessageSentLogs, - processL2BlockProposedLogs, - processMessageSentLogs, -} from './eth_log_handlers.js'; import { type DataRetrieval } from './structs/data_retrieval.js'; -import { type L1Published } from './structs/published.js'; +import { type L1Published, type L1PublishedData } from './structs/published.js'; /** * Fetches new L2 blocks. @@ -46,11 +44,12 @@ export async function retrieveBlockFromRollup( if (searchStartBlock > searchEndBlock) { break; } - const l2BlockProposedLogs = await getL2BlockProposedLogs( - publicClient, - EthAddress.fromString(rollup.address), - searchStartBlock, - searchEndBlock, + const l2BlockProposedLogs = await rollup.getEvents.L2BlockProposed( + {}, + { + fromBlock: searchStartBlock, + toBlock: searchEndBlock + 1n, + }, ); if (l2BlockProposedLogs.length === 0) { @@ -69,6 +68,96 @@ export async function retrieveBlockFromRollup( return retrievedBlocks; } +/** + * Processes newly received L2BlockProposed logs. + * @param rollup - The rollup contract + * @param publicClient - The viem public client to use for transaction retrieval. + * @param logs - L2BlockProposed logs. + * @returns - An array blocks. + */ +export async function processL2BlockProposedLogs( + rollup: GetContractReturnType>, + publicClient: PublicClient, + logs: GetContractEventsReturnType, + logger: DebugLogger, +): Promise[]> { + const retrievedBlocks: L1Published[] = []; + for (const log of logs) { + const blockNum = log.args.blockNumber!; + const archive = log.args.archive!; + const archiveFromChain = await rollup.read.archiveAt([blockNum]); + + // The value from the event and contract will match only if the block is in the chain. + if (archive === archiveFromChain) { + // TODO: Fetch blocks from calldata in parallel + const block = await getBlockFromRollupTx(publicClient, log.transactionHash!, blockNum); + + const l1: L1PublishedData = { + blockNumber: log.blockNumber, + blockHash: log.blockHash, + timestamp: await getL1BlockTime(publicClient, log.blockNumber), + }; + + retrievedBlocks.push({ data: block, l1 }); + } else { + logger.warn( + `Archive mismatch matching, ignoring block ${blockNum} with archive: ${archive}, expected ${archiveFromChain}`, + ); + } + } + + return retrievedBlocks; +} + +export async function getL1BlockTime(publicClient: PublicClient, blockNumber: bigint): Promise { + const block = await publicClient.getBlock({ blockNumber, includeTransactions: false }); + return block.timestamp; +} + +/** + * Gets block from the calldata of an L1 transaction. + * Assumes that the block was published from an EOA. + * TODO: Add retries and error management. + * @param publicClient - The viem public client to use for transaction retrieval. + * @param txHash - Hash of the tx that published it. + * @param l2BlockNum - L2 block number. + * @returns L2 block from the calldata, deserialized + */ +async function getBlockFromRollupTx( + publicClient: PublicClient, + txHash: `0x${string}`, + l2BlockNum: bigint, +): Promise { + const { input: data } = await publicClient.getTransaction({ hash: txHash }); + const { functionName, args } = decodeFunctionData({ + abi: RollupAbi, + data, + }); + + if (!(functionName === 'propose')) { + throw new Error(`Unexpected method called ${functionName}`); + } + const [headerHex, archiveRootHex, , , , bodyHex] = args! as readonly [Hex, Hex, Hex, Hex[], ViemSignature[], Hex]; + + const header = Header.fromBuffer(Buffer.from(hexToBytes(headerHex))); + const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex))); + + const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt(); + + if (blockNumberFromHeader !== l2BlockNum) { + throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`); + } + + const archive = AppendOnlyTreeSnapshot.fromBuffer( + Buffer.concat([ + Buffer.from(hexToBytes(archiveRootHex)), // L2Block.archive.root + numToUInt32BE(Number(l2BlockNum + 1n)), // L2Block.archive.nextAvailableLeafIndex + ]), + ); + + return new L2Block(archive, header, blockBody); +} + /** * Fetch L1 to L2 messages. * @param publicClient - The viem public client to use for transaction retrieval. @@ -79,8 +168,7 @@ export async function retrieveBlockFromRollup( * @returns An array of InboxLeaf and next eth block to search from. */ export async function retrieveL1ToL2Messages( - publicClient: PublicClient, - inboxAddress: EthAddress, + inbox: GetContractReturnType>, blockUntilSynced: boolean, searchStartBlock: bigint, searchEndBlock: bigint, @@ -90,12 +178,24 @@ export async function retrieveL1ToL2Messages( if (searchStartBlock > searchEndBlock) { break; } - const messageSentLogs = await getMessageSentLogs(publicClient, inboxAddress, searchStartBlock, searchEndBlock); + + const messageSentLogs = await inbox.getEvents.MessageSent( + {}, + { + fromBlock: searchStartBlock, + toBlock: searchEndBlock + 1n, + }, + ); + if (messageSentLogs.length === 0) { break; } - const l1ToL2Messages = processMessageSentLogs(messageSentLogs); - retrievedL1ToL2Messages.push(...l1ToL2Messages); + + for (const log of messageSentLogs) { + const { l2BlockNumber, index, hash } = log.args; + retrievedL1ToL2Messages.push(new InboxLeaf(l2BlockNumber!, index!, Fr.fromString(hash!))); + } + // handles the case when there are no new messages: searchStartBlock = (messageSentLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock) + 1n; } while (blockUntilSynced && searchStartBlock <= searchEndBlock); @@ -145,3 +245,57 @@ export async function retrieveL2ProofsFromRollup( lastProcessedL1BlockNumber, }; } + +export type SubmitBlockProof = { + header: Header; + archiveRoot: Fr; + proverId: Fr; + aggregationObject: Buffer; + proof: Proof; +}; + +/** + * Gets block metadata (header and archive snapshot) from the calldata of an L1 transaction. + * Assumes that the block was published from an EOA. + * TODO: Add retries and error management. + * @param publicClient - The viem public client to use for transaction retrieval. + * @param txHash - Hash of the tx that published it. + * @param l2BlockNum - L2 block number. + * @returns L2 block metadata (header and archive) from the calldata, deserialized + */ +export async function getBlockProofFromSubmitProofTx( + publicClient: PublicClient, + txHash: `0x${string}`, + l2BlockNum: bigint, + expectedProverId: Fr, +): Promise { + const { input: data } = await publicClient.getTransaction({ hash: txHash }); + const { functionName, args } = decodeFunctionData({ + abi: RollupAbi, + data, + }); + + if (!(functionName === 'submitBlockRootProof')) { + throw new Error(`Unexpected method called ${functionName}`); + } + const [headerHex, archiveHex, proverIdHex, aggregationObjectHex, proofHex] = args!; + + const header = Header.fromBuffer(Buffer.from(hexToBytes(headerHex))); + const proverId = Fr.fromString(proverIdHex); + + const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt(); + if (blockNumberFromHeader !== l2BlockNum) { + throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`); + } + if (!proverId.equals(expectedProverId)) { + throw new Error(`Prover ID mismatch: expected ${expectedProverId} but got ${proverId}`); + } + + return { + header, + proverId, + aggregationObject: Buffer.from(hexToBytes(aggregationObjectHex)), + archiveRoot: Fr.fromString(archiveHex), + proof: Proof.fromBuffer(Buffer.from(hexToBytes(proofHex))), + }; +} diff --git a/yarn-project/archiver/src/archiver/eth_log_handlers.ts b/yarn-project/archiver/src/archiver/eth_log_handlers.ts deleted file mode 100644 index b9cc3e710c7..00000000000 --- a/yarn-project/archiver/src/archiver/eth_log_handlers.ts +++ /dev/null @@ -1,233 +0,0 @@ -import { Body, InboxLeaf, L2Block } from '@aztec/circuit-types'; -import { AppendOnlyTreeSnapshot, Header, Proof } from '@aztec/circuits.js'; -import { type EthAddress } from '@aztec/foundation/eth-address'; -import { type ViemSignature } from '@aztec/foundation/eth-signature'; -import { Fr } from '@aztec/foundation/fields'; -import { type DebugLogger } from '@aztec/foundation/log'; -import { numToUInt32BE } from '@aztec/foundation/serialize'; -import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts'; - -import { - type Chain, - type GetContractReturnType, - type Hex, - type HttpTransport, - type Log, - type PublicClient, - decodeFunctionData, - getAbiItem, - getAddress, - hexToBytes, -} from 'viem'; - -import { type L1Published, type L1PublishedData } from './structs/published.js'; - -/** - * Processes newly received MessageSent (L1 to L2) logs. - * @param logs - MessageSent logs. - * @returns Array of all processed MessageSent logs - */ -export function processMessageSentLogs( - logs: Log[], -): InboxLeaf[] { - const leaves: InboxLeaf[] = []; - for (const log of logs) { - const { l2BlockNumber, index, hash } = log.args; - leaves.push(new InboxLeaf(l2BlockNumber, index, Fr.fromString(hash))); - } - return leaves; -} - -/** - * Processes newly received L2BlockProposed logs. - * @param rollup - The rollup contract - * @param publicClient - The viem public client to use for transaction retrieval. - * @param logs - L2BlockProposed logs. - * @returns - An array blocks. - */ -export async function processL2BlockProposedLogs( - rollup: GetContractReturnType>, - publicClient: PublicClient, - logs: Log[], - logger: DebugLogger, -): Promise[]> { - const retrievedBlocks: L1Published[] = []; - for (const log of logs) { - const blockNum = log.args.blockNumber!; - const archive = log.args.archive!; - const archiveFromChain = await rollup.read.archiveAt([blockNum]); - - // The value from the event and contract will match only if the block is in the chain. - if (archive === archiveFromChain) { - // TODO: Fetch blocks from calldata in parallel - const block = await getBlockFromRollupTx(publicClient, log.transactionHash!, blockNum); - - const l1: L1PublishedData = { - blockNumber: log.blockNumber, - blockHash: log.blockHash, - timestamp: await getL1BlockTime(publicClient, log.blockNumber), - }; - - retrievedBlocks.push({ data: block, l1 }); - } else { - logger.warn( - `Archive mismatch matching, ignoring block ${blockNum} with archive: ${archive}, expected ${archiveFromChain}`, - ); - } - } - - return retrievedBlocks; -} - -export async function getL1BlockTime(publicClient: PublicClient, blockNumber: bigint): Promise { - const block = await publicClient.getBlock({ blockNumber, includeTransactions: false }); - return block.timestamp; -} - -/** - * Gets block from the calldata of an L1 transaction. - * Assumes that the block was published from an EOA. - * TODO: Add retries and error management. - * @param publicClient - The viem public client to use for transaction retrieval. - * @param txHash - Hash of the tx that published it. - * @param l2BlockNum - L2 block number. - * @returns L2 block from the calldata, deserialized - */ -async function getBlockFromRollupTx( - publicClient: PublicClient, - txHash: `0x${string}`, - l2BlockNum: bigint, -): Promise { - const { input: data } = await publicClient.getTransaction({ hash: txHash }); - const { functionName, args } = decodeFunctionData({ - abi: RollupAbi, - data, - }); - - if (!(functionName === 'propose')) { - throw new Error(`Unexpected method called ${functionName}`); - } - const [headerHex, archiveRootHex, , , , bodyHex] = args! as readonly [Hex, Hex, Hex, Hex[], ViemSignature[], Hex]; - - const header = Header.fromBuffer(Buffer.from(hexToBytes(headerHex))); - const blockBody = Body.fromBuffer(Buffer.from(hexToBytes(bodyHex))); - - const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt(); - - if (blockNumberFromHeader !== l2BlockNum) { - throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`); - } - - const archive = AppendOnlyTreeSnapshot.fromBuffer( - Buffer.concat([ - Buffer.from(hexToBytes(archiveRootHex)), // L2Block.archive.root - numToUInt32BE(Number(l2BlockNum + 1n)), // L2Block.archive.nextAvailableLeafIndex - ]), - ); - - return new L2Block(archive, header, blockBody); -} - -/** - * Gets relevant `L2BlockProposed` logs from chain. - * @param publicClient - The viem public client to use for transaction retrieval. - * @param rollupAddress - The address of the rollup contract. - * @param fromBlock - First block to get logs from (inclusive). - * @param toBlock - Last block to get logs from (inclusive). - * @returns An array of `L2BlockProposed` logs. - */ -export function getL2BlockProposedLogs( - publicClient: PublicClient, - rollupAddress: EthAddress, - fromBlock: bigint, - toBlock: bigint, -): Promise[]> { - return publicClient.getLogs({ - address: getAddress(rollupAddress.toString()), - event: getAbiItem({ - abi: RollupAbi, - name: 'L2BlockProposed', - }), - fromBlock, - toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive - }); -} - -/** - * Get relevant `MessageSent` logs emitted by Inbox on chain. - * @param publicClient - The viem public client to use for transaction retrieval. - * @param inboxAddress - The address of the inbox contract. - * @param fromBlock - First block to get logs from (inclusive). - * @param toBlock - Last block to get logs from (inclusive). - * @returns An array of `MessageSent` logs. - */ -export function getMessageSentLogs( - publicClient: PublicClient, - inboxAddress: EthAddress, - fromBlock: bigint, - toBlock: bigint, -): Promise[]> { - return publicClient.getLogs({ - address: getAddress(inboxAddress.toString()), - event: getAbiItem({ - abi: InboxAbi, - name: 'MessageSent', - }), - fromBlock, - toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive - }); -} - -export type SubmitBlockProof = { - header: Header; - archiveRoot: Fr; - proverId: Fr; - aggregationObject: Buffer; - proof: Proof; -}; - -/** - * Gets block metadata (header and archive snapshot) from the calldata of an L1 transaction. - * Assumes that the block was published from an EOA. - * TODO: Add retries and error management. - * @param publicClient - The viem public client to use for transaction retrieval. - * @param txHash - Hash of the tx that published it. - * @param l2BlockNum - L2 block number. - * @returns L2 block metadata (header and archive) from the calldata, deserialized - */ -export async function getBlockProofFromSubmitProofTx( - publicClient: PublicClient, - txHash: `0x${string}`, - l2BlockNum: bigint, - expectedProverId: Fr, -): Promise { - const { input: data } = await publicClient.getTransaction({ hash: txHash }); - const { functionName, args } = decodeFunctionData({ - abi: RollupAbi, - data, - }); - - if (!(functionName === 'submitBlockRootProof')) { - throw new Error(`Unexpected method called ${functionName}`); - } - const [headerHex, archiveHex, proverIdHex, aggregationObjectHex, proofHex] = args!; - - const header = Header.fromBuffer(Buffer.from(hexToBytes(headerHex))); - const proverId = Fr.fromString(proverIdHex); - - const blockNumberFromHeader = header.globalVariables.blockNumber.toBigInt(); - if (blockNumberFromHeader !== l2BlockNum) { - throw new Error(`Block number mismatch: expected ${l2BlockNum} but got ${blockNumberFromHeader}`); - } - if (!proverId.equals(expectedProverId)) { - throw new Error(`Prover ID mismatch: expected ${expectedProverId} but got ${proverId}`); - } - - return { - header, - proverId, - aggregationObject: Buffer.from(hexToBytes(aggregationObjectHex)), - archiveRoot: Fr.fromString(archiveHex), - proof: Proof.fromBuffer(Buffer.from(hexToBytes(proofHex))), - }; -} diff --git a/yarn-project/archiver/src/index.ts b/yarn-project/archiver/src/index.ts index f23f973101c..6cd0fe60b15 100644 --- a/yarn-project/archiver/src/index.ts +++ b/yarn-project/archiver/src/index.ts @@ -15,8 +15,6 @@ export * from './factory.js'; export { retrieveL2ProofVerifiedEvents, retrieveBlockFromRollup } from './archiver/data_retrieval.js'; -export { getL2BlockProposedLogs } from './archiver/eth_log_handlers.js'; - const log = createDebugLogger('aztec:archiver'); /** diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index 5f2fb4052b6..0fa89491bae 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -108,7 +108,7 @@ export class L2Block { const txsEffectsHash = body.getTxsEffectsHash(); return L2Block.fromFields({ - archive: makeAppendOnlyTreeSnapshot(1), + archive: makeAppendOnlyTreeSnapshot(l2BlockNum + 1), header: makeHeader(0, l2BlockNum, slotNumber ?? l2BlockNum, txsEffectsHash, inHash), body, }); diff --git a/yarn-project/cli/src/cmds/l1/prover_stats.ts b/yarn-project/cli/src/cmds/l1/prover_stats.ts index 2184144fd1c..8a9acbb0da0 100644 --- a/yarn-project/cli/src/cmds/l1/prover_stats.ts +++ b/yarn-project/cli/src/cmds/l1/prover_stats.ts @@ -1,13 +1,14 @@ -import { getL2BlockProposedLogs, retrieveL2ProofVerifiedEvents } from '@aztec/archiver'; +import { retrieveL2ProofVerifiedEvents } from '@aztec/archiver'; import { createAztecNodeClient } from '@aztec/circuit-types'; import { EthAddress } from '@aztec/circuits.js'; import { createEthereumChain } from '@aztec/ethereum'; import { compactArray, mapValues, unique } from '@aztec/foundation/collection'; import { type LogFn, type Logger, createDebugLogger } from '@aztec/foundation/log'; +import { RollupAbi } from '@aztec/l1-artifacts'; import chunk from 'lodash.chunk'; import groupBy from 'lodash.groupby'; -import { type PublicClient, createPublicClient, http } from 'viem'; +import { type PublicClient, createPublicClient, getAbiItem, getAddress, http } from 'viem'; export async function proverStats(opts: { l1RpcUrl: string; @@ -85,7 +86,7 @@ export async function proverStats(opts: { // Map from l2 block number to the l1 block in which it was submitted const l2BlockSubmissions: Record = {}; for (const blockEvent of blockEvents) { - l2BlockSubmissions[blockEvent.args.blockNumber.toString()] = blockEvent.blockNumber; + l2BlockSubmissions[blockEvent.args.blockNumber!.toString()] = blockEvent.blockNumber; } // If we want raw logs, output them @@ -172,7 +173,17 @@ async function getL2BlockEvents( const events = []; while (blockNum <= lastBlockNum) { const end = blockNum + batchSize > lastBlockNum + 1n ? lastBlockNum + 1n : blockNum + batchSize; - const newEvents = await getL2BlockProposedLogs(publicClient, rollup, blockNum, end); + + const newEvents = await publicClient.getLogs({ + address: getAddress(rollup.toString()), + event: getAbiItem({ + abi: RollupAbi, + name: 'L2BlockProposed', + }), + fromBlock: blockNum, + toBlock: end + 1n, // the toBlock argument in getLogs is exclusive + }); + events.push(...newEvents); debugLog.verbose(`Got ${newEvents.length} events querying l2 block submitted from block ${blockNum} to ${end}`); blockNum += batchSize;