diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index cd4ced6ea3ce..eeb7d3005e7d 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -8,6 +8,7 @@ import { times, timesParallel } from '@aztec/foundation/collection'; import { randomInt } from '@aztec/foundation/crypto'; import { Signature } from '@aztec/foundation/eth-signature'; import { Fr } from '@aztec/foundation/fields'; +import { sleep } from '@aztec/foundation/sleep'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { L2Block, wrapInBlock } from '@aztec/stdlib/block'; import { @@ -254,6 +255,20 @@ export function describeArchiverDataStore( it('returns undefined if tx is not found', async () => { await expect(store.getTxEffect(TxHash.random())).resolves.toBeUndefined(); }); + + it('does not fail if the block is unwound while requesting a tx', async () => { + const expectedTx = await wrapInBlock(blocks[1].block.body.txEffects[0], blocks[1].block); + let done = false; + void (async () => { + while (!done) { + void store.getTxEffect(expectedTx.data.txHash); + await sleep(1); + } + })(); + await store.unwindBlocks(blocks.length, blocks.length); + done = true; + expect(await store.getTxEffect(expectedTx.data.txHash)).toEqual(undefined); + }); }); describe('L1 to L2 Messages', () => { diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts index 74b85355b1ae..1be92110e45a 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts @@ -131,7 +131,10 @@ export class BlockStore { */ async *getBlocks(start: number, limit: number): AsyncIterableIterator { for await (const blockStorage of this.#blocks.valuesAsync(this.#computeBlockRange(start, limit))) { - yield await this.getBlockFromBlockStorage(blockStorage); + const block = await this.getBlockFromBlockStorage(blockStorage); + if (block) { + yield block; + } } } @@ -166,9 +169,8 @@ export class BlockStore { const blockHash = (await header.hash()).toString(); const blockBodyBuffer = await this.#blockBodies.getAsync(blockHash); if (blockBodyBuffer === undefined) { - throw new Error( - `Could not retrieve body for block ${header.globalVariables.blockNumber.toNumber()} ${blockHash}`, - ); + this.#log.warn(`Could not find body for block ${header.globalVariables.blockNumber.toNumber()} ${blockHash}`); + return undefined; } const body = Body.fromBuffer(blockBodyBuffer); const block = new L2Block(archive, header, body); @@ -210,7 +212,11 @@ export class BlockStore { return undefined; } - const block = (await this.getBlock(blockNumber))!; + const block = await this.getBlock(blockNumber); + if (!block) { + return undefined; + } + const tx = block.block.body.txEffects[txIndex]; return new TxReceipt(