Skip to content

Commit 970ad77

Browse files
authored
fix: toBlock argument in L1 getLogs is inclusive (#10828)
As @alexghr identified, we got a spurious reorg on a node in the exp1 network. This was caused by the node getting a current `l1BlockNumber=245`, but then fetching an L2 block mined at 246. This caused the `canPrune` check to fail: ``` const canPrune = localPendingBlockNumber > provenBlockNumber && (await this.rollup.read.canPruneAtTime([time], { blockNumber: currentL1BlockNumber })); ``` The `canPruneAtTime` was evaluated at L1 block number 245, and it correctly returned true, since there had been a reorg shortly before (at 240), and no new L2 block had been mined so the rollup hadn't reset its state by then. However, the `localPendingBlockNumber` was incorrectly increased due to the block mined at 246, which caused the archiver to incorrectly reorg it. This PR fixes the L1 event queries so the `toBlock` is inclusive. A quick test with cast shows that this is the case: ``` $ cast logs -r https://mainnet.infura.io/v3/$INFURA_API_KEY --from-block 0x146eade --to-block 0x146eadf --address 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --json | jq .[].blockNumber | uniq "0x146eade" "0x146eadf" ``` And just for good measure, we also filter the logs returned by the block range searched.
1 parent b13bc93 commit 970ad77

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

yarn-project/archiver/src/archiver/data_retrieval.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ export async function retrieveBlocksFromRollup(
4444
if (searchStartBlock > searchEndBlock) {
4545
break;
4646
}
47-
const l2BlockProposedLogs = await rollup.getEvents.L2BlockProposed(
48-
{},
49-
{
50-
fromBlock: searchStartBlock,
51-
toBlock: searchEndBlock + 1n,
52-
},
53-
);
47+
const l2BlockProposedLogs = (
48+
await rollup.getEvents.L2BlockProposed(
49+
{},
50+
{
51+
fromBlock: searchStartBlock,
52+
toBlock: searchEndBlock,
53+
},
54+
)
55+
).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
5456

5557
if (l2BlockProposedLogs.length === 0) {
5658
break;
@@ -218,13 +220,15 @@ export async function retrieveL1ToL2Messages(
218220
break;
219221
}
220222

221-
const messageSentLogs = await inbox.getEvents.MessageSent(
222-
{},
223-
{
224-
fromBlock: searchStartBlock,
225-
toBlock: searchEndBlock + 1n,
226-
},
227-
);
223+
const messageSentLogs = (
224+
await inbox.getEvents.MessageSent(
225+
{},
226+
{
227+
fromBlock: searchStartBlock,
228+
toBlock: searchEndBlock,
229+
},
230+
)
231+
).filter(log => log.blockNumber! >= searchStartBlock && log.blockNumber! <= searchEndBlock);
228232

229233
if (messageSentLogs.length === 0) {
230234
break;
@@ -251,7 +255,7 @@ export async function retrieveL2ProofVerifiedEvents(
251255
const logs = await publicClient.getLogs({
252256
address: rollupAddress.toString(),
253257
fromBlock: searchStartBlock,
254-
toBlock: searchEndBlock ? searchEndBlock + 1n : undefined,
258+
toBlock: searchEndBlock ? searchEndBlock : undefined,
255259
strict: true,
256260
event: getAbiItem({ abi: RollupAbi, name: 'L2ProofVerified' }),
257261
});

yarn-project/cli/src/cmds/l1/prover_stats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async function getL2BlockEvents(
181181
name: 'L2BlockProposed',
182182
}),
183183
fromBlock: blockNum,
184-
toBlock: end + 1n, // the toBlock argument in getLogs is exclusive
184+
toBlock: end,
185185
});
186186

187187
events.push(...newEvents);

0 commit comments

Comments
 (0)