Skip to content

Commit

Permalink
fix: await block unwind when a reorg happens (#10380)
Browse files Browse the repository at this point in the history
Noticed the unwind operation did not block on the delete operation (I
saw this in the prover node logs where logs were printed out of order)
  • Loading branch information
alexghr authored Dec 3, 2024
1 parent da809c5 commit 5a02480
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,22 +955,27 @@ class ArchiverStoreHelper
// from - blocksToUnwind = the new head, so + 1 for what we need to remove
const blocks = await this.getBlocks(from - blocksToUnwind + 1, blocksToUnwind);

return [
const opResults = await Promise.all([
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
...(await Promise.all(
blocks.map(async block => {
const contractClassLogs = block.data.body.txEffects
.flatMap(txEffect => (txEffect ? [txEffect.contractClassLogs] : []))
.flatMap(txLog => txLog.unrollLogs());
// ContractInstanceDeployed event logs are broadcast in privateLogs.
const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
await this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Delete);
await this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Delete);
}),
)),
...blocks.map(async block => {
const contractClassLogs = block.data.body.txEffects
.flatMap(txEffect => (txEffect ? [txEffect.contractClassLogs] : []))
.flatMap(txLog => txLog.unrollLogs());

// ContractInstanceDeployed event logs are broadcast in privateLogs.
const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);

return (
(await this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Delete)) &&
(await this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Delete))
);
}),

this.store.deleteLogs(blocks.map(b => b.data)),
this.store.unwindBlocks(from, blocksToUnwind),
].every(Boolean);
]);

return opResults.every(Boolean);
}

getBlocks(from: number, limit: number): Promise<L1Published<L2Block>[]> {
Expand Down

0 comments on commit 5a02480

Please sign in to comment.