From 5a024803648e8a645cbafdeb4e2ab9f6bfa26117 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Dec 2024 16:45:20 +0000 Subject: [PATCH] fix: await block unwind when a reorg happens (#10380) 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) --- .../archiver/src/archiver/archiver.ts | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index ff6b9624902..550e98ce172 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -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[]> {