Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: await block unwind when a reorg happens #10380

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks bigger than it actually is: I moved the Promise.all to the outside of the array rather than the inside.

}

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