Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export class BlockStore {
*/
async *getBlocks(start: number, limit: number): AsyncIterableIterator<PublishedL2Block> {
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;
}
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
Loading