Skip to content

Commit 97e4074

Browse files
committed
Extra logging and test fix
1 parent e7264c3 commit 97e4074

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

yarn-project/archiver/src/archiver/archiver.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,20 @@ describe('Archiver', () => {
397397

398398
// And define a bad block 2 with attestations from random signers
399399
const badBlock2 = await makeBlock(2);
400+
badBlock2.archive.root = new Fr(0x1002);
400401
const badBlock2RollupTx = await makeRollupTx(badBlock2, times(3, Secp256k1Signer.random));
401402
const badBlock2BlobHashes = await makeVersionedBlobHashes(badBlock2);
402403
const badBlock2Blobs = await makeBlobsFromBlock(badBlock2);
403404

405+
// Return the archive root for the bad block 2 when queried
406+
mockRollupRead.archiveAt.mockImplementation((args: readonly [bigint]) =>
407+
Promise.resolve((args[0] === 2n ? badBlock2 : blocks[Number(args[0] - 1n)]).archive.root.toString()),
408+
);
409+
410+
logger.warn(`Created 3 valid blocks`);
411+
blocks.forEach(block => logger.warn(`Block ${block.number} with root ${block.archive.root.toString()}`));
412+
logger.warn(`Created invalid block 2 with root ${badBlock2.archive.root.toString()}`);
413+
404414
// During the first archiver loop, we fetch block 1 and the block 2 with bad attestations
405415
publicClient.getBlockNumber.mockResolvedValue(85n);
406416
makeL2BlockProposedEvent(70n, 1n, blocks[0].archive.root.toString(), blobHashes[0]);
@@ -429,6 +439,9 @@ describe('Archiver', () => {
429439
]);
430440
publicClient.getTransaction.mockResolvedValueOnce(rollupTxs[1]).mockResolvedValueOnce(rollupTxs[2]);
431441
blobSinkClient.getBlobSidecar.mockResolvedValueOnce(blobsFromBlocks[1]).mockResolvedValueOnce(blobsFromBlocks[2]);
442+
mockRollupRead.archiveAt.mockImplementation((args: readonly [bigint]) =>
443+
Promise.resolve(blocks[Number(args[0] - 1n)].archive.root.toString()),
444+
);
432445

433446
// Now we should move to block 3
434447
await waitUntilArchiverBlock(3);
@@ -534,7 +547,7 @@ describe('Archiver', () => {
534547
// Lets take a look to see if we can find re-org stuff!
535548
await sleep(2000);
536549

537-
expect(loggerSpy).toHaveBeenCalledWith(`L2 prune has been detected.`);
550+
expect(loggerSpy).toHaveBeenCalledWith(expect.stringContaining(`L2 prune has been detected`), expect.anything());
538551

539552
// Should also see the block number be reduced
540553
latestBlockNum = await archiver.getBlockNumber();

yarn-project/archiver/src/archiver/archiver.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
703703
throw new Error(`Missing block ${localPendingBlockNumber}`);
704704
}
705705

706-
const noBlockSinceLast = localPendingBlock && pendingArchive === localPendingBlock.archive.root.toString();
706+
const localPendingArchiveRoot = localPendingBlock.archive.root.toString();
707+
const noBlockSinceLast = localPendingBlock && pendingArchive === localPendingArchiveRoot;
707708
if (noBlockSinceLast) {
708709
// We believe the following line causes a problem when we encounter L1 re-orgs.
709710
// Basically, by setting the synched L1 block number here, we are saying that we have
@@ -717,13 +718,16 @@ export class Archiver extends (EventEmitter as new () => ArchiverEmitter) implem
717718
return rollupStatus;
718719
}
719720

720-
const localPendingBlockInChain = archiveForLocalPendingBlockNumber === localPendingBlock.archive.root.toString();
721+
const localPendingBlockInChain = archiveForLocalPendingBlockNumber === localPendingArchiveRoot;
721722
if (!localPendingBlockInChain) {
722723
// If our local pending block tip is not in the chain on L1 a "prune" must have happened
723724
// or the L1 have reorged.
724725
// In any case, we have to figure out how far into the past the action will take us.
725726
// For simplicity here, we will simply rewind until we end in a block that is also on the chain on L1.
726-
this.log.debug(`L2 prune has been detected.`);
727+
this.log.debug(
728+
`L2 prune has been detected due to local pending block ${localPendingBlockNumber} not in chain`,
729+
{ localPendingBlockNumber, localPendingArchiveRoot, archiveForLocalPendingBlockNumber },
730+
);
727731

728732
let tipAfterUnwind = localPendingBlockNumber;
729733
while (true) {

yarn-project/archiver/src/archiver/validation.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ export async function validateBlockAttestations(
1515
): Promise<boolean> {
1616
const attestations = getAttestationsFromPublishedL2Block(publishedBlock);
1717
const { block } = publishedBlock;
18+
const blockHash = await block.hash().then(hash => hash.toString());
19+
const archiveRoot = block.archive.root.toString();
1820
const slot = block.header.getSlot();
1921
const epoch = getEpochAtSlot(slot, constants);
2022
const { committee } = await epochCache.getCommitteeForEpoch(epoch);
21-
logger?.debug(`Validating attestations for block at slot ${slot} in epoch ${epoch}`, {
23+
const logData = { blockNumber: block.number, slot, epoch, blockHash, archiveRoot };
24+
logger?.debug(`Validating attestations for block ${block.number} at slot ${slot} in epoch ${epoch}`, {
2225
committee: (committee ?? []).map(member => member.toString()),
2326
recoveredAttestors: attestations.map(a => a.getSender().toString()),
2427
postedAttestations: publishedBlock.attestations.map(a =>
2528
a.address.isZero() ? a.signature.toString() : a.address.toString(),
2629
),
27-
blockNumber: block.number,
28-
slot,
29-
epoch,
30+
...logData,
3031
});
3132

3233
if (!committee || committee.length === 0) {
3334
// Q: Should we accept blocks with no committee?
34-
logger?.warn(`No committee found for epoch ${epoch} at slot ${slot}`);
35+
logger?.warn(`No committee found for epoch ${epoch} at slot ${slot}. Accepting block without validation.`, logData);
3536
return true;
3637
}
3738

@@ -50,14 +51,11 @@ export async function validateBlockAttestations(
5051
logger?.warn(`Insufficient attestations for block at slot ${slot}`, {
5152
requiredAttestations: requiredAttestationCount,
5253
actualAttestations: attestations.length,
54+
...logData,
5355
});
5456
return false;
5557
}
5658

57-
logger?.debug(`Block attestations validated successfully for block at slot ${slot}`, {
58-
blockNumber: block.number,
59-
slot,
60-
epoch,
61-
});
59+
logger?.debug(`Block attestations validated successfully for block ${block.number} at slot ${slot}`, logData);
6260
return true;
6361
}

0 commit comments

Comments
 (0)