Skip to content

Commit 54d5437

Browse files
spalladinoclaude
andcommitted
fix: resolve backport conflicts for #22154
v4 has no setInboxTreeInProgress/treeInProgress persistence concept, so: - simplify setMessageSyncState to take only l1Block (drop treeInProgress param) - drop the tree-in-progress guard tests that don't apply to v4 - keep the improved fake_l1_state getState that computes treeInProgress from checkpoint/message visibility (InboxContractState.treeInProgress is still returned by the real inbox contract in v4) - drop getInboxTreeInProgress from message_store Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7be3ed7 commit 54d5437

6 files changed

Lines changed: 17 additions & 109 deletions

File tree

yarn-project/archiver/src/archiver.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
487487
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
488488
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
489489
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
490-
await this.store.setMessageSyncState(
491-
{ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash },
492-
undefined,
493-
);
490+
await this.store.setMessageSyncState({ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash });
494491
if (targetL2BlockNumber < currentProvenBlock) {
495492
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
496493
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);

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

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { L1BlockId } from '@aztec/ethereum/l1-types';
55
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
66
import { maxBigint } from '@aztec/foundation/bigint';
77
import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
8-
import { Buffer32 } from '@aztec/foundation/buffer';
8+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
99
import { pick } from '@aztec/foundation/collection';
1010
import { Fr } from '@aztec/foundation/curves/bn254';
1111
import { type Logger, createLogger } from '@aztec/foundation/log';
@@ -384,30 +384,11 @@ export class ArchiverL1Synchronizer implements Traceable {
384384

385385
// Compare local message store state with the remote. If they match, we just advance the match pointer.
386386
const remoteMessagesState = await this.inbox.getState({ blockNumber: currentL1BlockNumber });
387-
<<<<<<< HEAD
388-
389-
this.log.trace(`Retrieved remote inbox state at L1 block ${currentL1BlockNumber}.`, {
390-
localMessagesInserted,
391-
localLastMessage,
392-
remoteMessagesState,
393-
});
394-
395-
// Compare message count and rolling hash. If they match, no need to retrieve anything.
396-
if (
397-
remoteMessagesState.totalMessagesInserted === localMessagesInserted &&
398-
remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer32.ZERO)
399-
) {
400-
this.log.trace(
401-
`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`,
402-
);
403-
return;
404-
=======
405387
const localLastMessage = await this.store.getLastL1ToL2Message();
406388
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
407389
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
408-
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
390+
await this.store.setMessageSyncState(currentL1Block);
409391
return true;
410-
>>>>>>> 77c78761552 (fix(archiver): always advance L1-to-L2 messages syncpoint to current L1 block)
411392
}
412393

413394
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
@@ -422,7 +403,7 @@ export class ArchiverL1Synchronizer implements Traceable {
422403
`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`,
423404
{ inboxMessage: error.inboxMessage },
424405
);
425-
await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
406+
await this.rollbackL1ToL2Messages();
426407
return false;
427408
}
428409
throw error;
@@ -437,12 +418,12 @@ export class ArchiverL1Synchronizer implements Traceable {
437418
`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`,
438419
{ localLastMessageAfterSync, remoteMessagesState },
439420
);
440-
await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
421+
await this.rollbackL1ToL2Messages();
441422
return false;
442423
}
443424

444425
// Advance the syncpoint after a successful sync
445-
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
426+
await this.store.setMessageSyncState(currentL1Block);
446427
return true;
447428
}
448429

@@ -492,7 +473,7 @@ export class ArchiverL1Synchronizer implements Traceable {
492473
* Rolls back local L1 to L2 messages to the last common message with L1, and updates the syncpoint to the L1 block of that message.
493474
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
494475
*/
495-
private async rollbackL1ToL2Messages(remoteTreeInProgress: bigint): Promise<L1BlockId> {
476+
private async rollbackL1ToL2Messages(): Promise<L1BlockId> {
496477
// Slowly go back through our messages until we find the last common message.
497478
// We could query the logs in batch as an optimization, but the depth of the reorg should not be deep, and this
498479
// is a very rare case, so it's fine to query one log at a time.
@@ -532,11 +513,8 @@ export class ArchiverL1Synchronizer implements Traceable {
532513
const syncPointL1BlockNumber = commonMsg ? commonMsg.l1BlockNumber - 1n : this.l1Constants.l1StartBlock;
533514
const syncPointL1BlockHash = await this.getL1BlockHash(syncPointL1BlockNumber);
534515
const messagesSyncPoint = { l1BlockNumber: syncPointL1BlockNumber, l1BlockHash: syncPointL1BlockHash };
535-
await this.store.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
536-
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
537-
...messagesSyncPoint,
538-
remoteTreeInProgress,
539-
});
516+
await this.store.setMessageSyncState(messagesSyncPoint);
517+
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, messagesSyncPoint);
540518
return messagesSyncPoint;
541519
}
542520

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

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ describe('KVArchiverDataStore', () => {
18111811
it('returns the L1 block set via setMessageSyncState', async () => {
18121812
const l1BlockHash = Buffer32.random();
18131813
const l1BlockNumber = 10n;
1814-
await store.setMessageSyncState({ l1BlockNumber, l1BlockHash }, 1n);
1814+
await store.setMessageSyncState({ l1BlockNumber, l1BlockHash });
18151815
await store.addL1ToL2Messages([
18161816
makeInboxMessage(Buffer16.ZERO, { l1BlockNumber: 5n, l1BlockHash: Buffer32.random() }),
18171817
]);
@@ -2225,46 +2225,6 @@ describe('KVArchiverDataStore', () => {
22252225
await store.removeL1ToL2Messages(msgs[13].index);
22262226
await checkMessages(msgs.slice(0, 13));
22272227
});
2228-
<<<<<<< HEAD
2229-
=======
2230-
2231-
describe('inbox tree in progress guard', () => {
2232-
it('throws when checkpointNumber >= treeInProgress', async () => {
2233-
const msgs = makeInboxMessages(3, { initialCheckpointNumber: CheckpointNumber(5) });
2234-
await store.addL1ToL2Messages(msgs);
2235-
2236-
// Set treeInProgress to 7, meaning checkpoints 5 and 6 are sealed, 7+ are not
2237-
await store.setMessageSyncState({ l1BlockNumber: 1n, l1BlockHash: Buffer32.random() }, 7n);
2238-
2239-
// Sealed checkpoint should succeed
2240-
await expect(store.getL1ToL2Messages(CheckpointNumber(5))).resolves.toEqual([msgs[0].leaf]);
2241-
2242-
// Unsealed checkpoint (== treeInProgress) should throw
2243-
await expect(store.getL1ToL2Messages(CheckpointNumber(7))).rejects.toThrow(L1ToL2MessagesNotReadyError);
2244-
2245-
// Future checkpoint should also throw
2246-
await expect(store.getL1ToL2Messages(CheckpointNumber(8))).rejects.toThrow(L1ToL2MessagesNotReadyError);
2247-
});
2248-
2249-
it('returns messages when checkpointNumber < treeInProgress', async () => {
2250-
const msgs = makeInboxMessages(3, { initialCheckpointNumber: CheckpointNumber(10) });
2251-
await store.addL1ToL2Messages(msgs);
2252-
2253-
await store.setMessageSyncState({ l1BlockNumber: 1n, l1BlockHash: Buffer32.random() }, 13n);
2254-
2255-
await expect(store.getL1ToL2Messages(CheckpointNumber(10))).resolves.toEqual([msgs[0].leaf]);
2256-
await expect(store.getL1ToL2Messages(CheckpointNumber(11))).resolves.toEqual([msgs[1].leaf]);
2257-
});
2258-
2259-
it('skips guard when treeInProgress is not set', async () => {
2260-
const msgs = makeInboxMessages(2, { initialCheckpointNumber: CheckpointNumber(1) });
2261-
await store.addL1ToL2Messages(msgs);
2262-
2263-
// No setMessageSyncState call — guard should be permissive
2264-
await expect(store.getL1ToL2Messages(CheckpointNumber(1))).resolves.toEqual([msgs[0].leaf]);
2265-
});
2266-
});
2267-
>>>>>>> 77c78761552 (fix(archiver): always advance L1-to-L2 messages syncpoint to current L1 block)
22682228
});
22692229

22702230
describe('contractInstances', () => {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,11 @@ export class KVArchiverDataStore implements ContractDataSource {
592592
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
593593
}
594594

595-
<<<<<<< HEAD
596-
=======
597-
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */
598-
public setMessageSyncState(l1Block: L1BlockId, treeInProgress: bigint | undefined): Promise<void> {
599-
return this.#messageStore.setMessageSyncState(l1Block, treeInProgress);
595+
/** Updates the message sync state: the L1 sync point. */
596+
public setMessageSyncState(l1Block: L1BlockId): Promise<void> {
597+
return this.#messageStore.setMessageSyncState(l1Block);
600598
}
601599

602-
>>>>>>> 77c78761552 (fix(archiver): always advance L1-to-L2 messages syncpoint to current L1 block)
603600
/** Returns an async iterator to all L1 to L2 messages on the range. */
604601
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
605602
return this.#messageStore.iterateL1ToL2Messages(range);

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,26 +176,11 @@ export class MessageStore {
176176
return msg ? deserializeInboxMessage(msg) : undefined;
177177
}
178178

179-
<<<<<<< HEAD
180-
=======
181-
/** Returns the inbox tree-in-progress checkpoint number from L1, or undefined if not yet set. */
182-
public getInboxTreeInProgress(): Promise<bigint | undefined> {
183-
return this.#inboxTreeInProgress.getAsync();
179+
/** Updates the message sync state: the L1 sync point. */
180+
public setMessageSyncState(l1Block: L1BlockId): Promise<void> {
181+
return this.setSynchedL1Block(l1Block);
184182
}
185183

186-
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */
187-
public setMessageSyncState(l1Block: L1BlockId, treeInProgress: bigint | undefined): Promise<void> {
188-
return this.db.transactionAsync(async () => {
189-
await this.setSynchedL1Block(l1Block);
190-
if (treeInProgress !== undefined) {
191-
await this.#inboxTreeInProgress.set(treeInProgress);
192-
} else {
193-
await this.#inboxTreeInProgress.delete();
194-
}
195-
});
196-
}
197-
198-
>>>>>>> 77c78761552 (fix(archiver): always advance L1-to-L2 messages syncpoint to current L1 block)
199184
public async getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
200185
const messages: Fr[] = [];
201186

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { BlobClientInterface } from '@aztec/blob-client/client';
22
import { type Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
3+
import { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
34
import type { CheckpointProposedLog, InboxContract, MessageSentLog, RollupContract } from '@aztec/ethereum/contracts';
45
import { MULTI_CALL_3_ADDRESS } from '@aztec/ethereum/contracts';
56
import type { ViemPublicClient } from '@aztec/ethereum/types';
@@ -465,15 +466,6 @@ export class FakeL1State {
465466
createMockInboxContract(_publicClient: MockProxy<ViemPublicClient>): MockProxy<InboxContract> {
466467
const mockInbox = mock<InboxContract>();
467468

468-
<<<<<<< HEAD
469-
mockInbox.getState.mockImplementation(() =>
470-
Promise.resolve({
471-
messagesRollingHash: this.messagesRollingHash,
472-
totalMessagesInserted: BigInt(this.messages.length),
473-
treeInProgress: 0n,
474-
}),
475-
);
476-
=======
477469
mockInbox.getState.mockImplementation((opts: { blockTag?: string; blockNumber?: bigint } = {}) => {
478470
// Filter messages visible at the given block number (or all if not specified)
479471
const blockNumber = opts.blockNumber ?? this.l1BlockNumber;
@@ -504,7 +496,6 @@ export class FakeL1State {
504496
treeInProgress: BigInt(treeInProgress),
505497
});
506498
});
507-
>>>>>>> 77c78761552 (fix(archiver): always advance L1-to-L2 messages syncpoint to current L1 block)
508499

509500
// Mock the wrapper methods for fetching message events
510501
mockInbox.getMessageSentEvents.mockImplementation((fromBlock: bigint, toBlock: bigint) =>

0 commit comments

Comments
 (0)