-
Notifications
You must be signed in to change notification settings - Fork 598
feat: updating archiver with new inbox #5025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
023dced
700d186
d84de5e
7eddb74
ea861ad
7e4608d
0225cb4
2bd8f87
4391571
8ea370d
8d21119
eddd3ae
fd23e3b
2f28e89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; | |
| import { Fr } from '@aztec/foundation/fields'; | ||
| import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; | ||
| import { RunningPromise } from '@aztec/foundation/running-promise'; | ||
| import { RollupAbi } from '@aztec/l1-artifacts'; | ||
| import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; | ||
| import { InstanceDeployerAddress } from '@aztec/protocol-contracts/instance-deployer'; | ||
| import { | ||
|
|
@@ -34,7 +35,7 @@ import { | |
| ContractInstanceWithAddress, | ||
| } from '@aztec/types/contracts'; | ||
|
|
||
| import { Chain, HttpTransport, PublicClient, createPublicClient, http } from 'viem'; | ||
| import { Chain, HttpTransport, PublicClient, createPublicClient, getAddress, getContract, http } from 'viem'; | ||
|
|
||
| import { ArchiverDataStore } from './archiver_store.js'; | ||
| import { ArchiverConfig } from './config.js'; | ||
|
|
@@ -43,6 +44,7 @@ import { | |
| retrieveBlockMetadataFromRollup, | ||
| retrieveNewCancelledL1ToL2Messages, | ||
| retrieveNewContractData, | ||
| retrieveNewL1ToL2Messages, | ||
| retrieveNewPendingL1ToL2Messages, | ||
| } from './data_retrieval.js'; | ||
|
|
||
|
|
@@ -72,6 +74,7 @@ export class Archiver implements ArchiveSource { | |
| * @param publicClient - A client for interacting with the Ethereum node. | ||
| * @param rollupAddress - Ethereum address of the rollup contract. | ||
| * @param inboxAddress - Ethereum address of the inbox contract. | ||
| * @param newInboxAddress - Ethereum address of the new inbox contract. | ||
| * @param registryAddress - Ethereum address of the registry contract. | ||
| * @param contractDeploymentEmitterAddress - Ethereum address of the contractDeploymentEmitter contract. | ||
| * @param pollingIntervalMs - The interval for polling for L1 logs (in milliseconds). | ||
|
|
@@ -83,6 +86,7 @@ export class Archiver implements ArchiveSource { | |
| private readonly rollupAddress: EthAddress, | ||
| private readonly availabilityOracleAddress: EthAddress, | ||
| private readonly inboxAddress: EthAddress, | ||
| private readonly newInboxAddress: EthAddress, | ||
| private readonly registryAddress: EthAddress, | ||
| private readonly contractDeploymentEmitterAddress: EthAddress, | ||
| private readonly store: ArchiverDataStore, | ||
|
|
@@ -109,11 +113,23 @@ export class Archiver implements ArchiveSource { | |
| pollingInterval: config.viemPollingIntervalMS, | ||
| }); | ||
|
|
||
| // TODO(#4492): Nuke this once the old inbox is purged | ||
| let newInboxAddress!: EthAddress; | ||
| { | ||
| const rollup = getContract({ | ||
| address: getAddress(config.l1Contracts.rollupAddress.toString()), | ||
| abi: RollupAbi, | ||
| client: publicClient, | ||
| }); | ||
| newInboxAddress = EthAddress.fromString(await rollup.read.NEW_INBOX()); | ||
| } | ||
|
|
||
| const archiver = new Archiver( | ||
| publicClient, | ||
| config.l1Contracts.rollupAddress, | ||
| config.l1Contracts.availabilityOracleAddress, | ||
| config.l1Contracts.inboxAddress, | ||
| newInboxAddress, | ||
| config.l1Contracts.registryAddress, | ||
| config.l1Contracts.contractDeploymentEmitterAddress, | ||
| archiverStore, | ||
|
|
@@ -163,6 +179,7 @@ export class Archiver implements ArchiveSource { | |
|
|
||
| if ( | ||
| currentL1BlockNumber <= lastL1Blocks.addedBlock && | ||
| currentL1BlockNumber <= lastL1Blocks.newMessages && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is newMessages the best name we can use here ? Would newL1toL2Messages be an improvement ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Will tackle that during purge. |
||
| currentL1BlockNumber <= lastL1Blocks.addedMessages && | ||
| currentL1BlockNumber <= lastL1Blocks.cancelledMessages | ||
| ) { | ||
|
|
@@ -192,6 +209,7 @@ export class Archiver implements ArchiveSource { | |
|
|
||
| // ********** Events that are processed per L1 block ********** | ||
|
|
||
| // TODO(#4492): Nuke the following when purging the old inbox | ||
| // Process l1ToL2Messages, these are consumed as time passes, not each block | ||
| const retrievedPendingL1ToL2Messages = await retrieveNewPendingL1ToL2Messages( | ||
| this.publicClient, | ||
|
|
@@ -235,6 +253,20 @@ export class Archiver implements ArchiveSource { | |
|
|
||
| // ********** Events that are processed per L2 block ********** | ||
|
|
||
| const retrievedNewL1ToL2Messages = await retrieveNewL1ToL2Messages( | ||
| this.publicClient, | ||
| this.newInboxAddress, | ||
| blockUntilSynced, | ||
| lastL1Blocks.newMessages + 1n, | ||
| currentL1BlockNumber, | ||
| ); | ||
| await this.store.addNewL1ToL2Messages( | ||
| retrievedNewL1ToL2Messages.retrievedData, | ||
| // -1n because the function expects the last block in which the message was emitted and not the one after next | ||
| // TODO(#4492): Check whether this could be cleaned up - `nextEthBlockNumber` value doesn't seem to be used much | ||
| retrievedNewL1ToL2Messages.nextEthBlockNumber - 1n, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sheesh 😅 |
||
| ); | ||
|
|
||
| // Read all data from chain and then write to our stores at the end | ||
| const nextExpectedL2BlockNum = BigInt((await this.store.getBlockNumber()) + 1); | ||
|
|
||
|
|
@@ -583,6 +615,15 @@ export class Archiver implements ArchiveSource { | |
| return this.store.getConfirmedL1ToL2Message(entryKey); | ||
| } | ||
|
|
||
| /** | ||
| * Gets new L1 to L2 message (to be) included in a given block. | ||
| * @param blockNumber - L2 block number to get messages for. | ||
| * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found). | ||
| */ | ||
| getNewL1ToL2Messages(blockNumber: bigint): Promise<Buffer[]> { | ||
| return this.store.getNewL1ToL2Messages(blockNumber); | ||
| } | ||
|
|
||
| getContractClassIds(): Promise<Fr[]> { | ||
| return this.store.getContractClassIds(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |
| L2BlockL2Logs, | ||
| LogFilter, | ||
| LogType, | ||
| NewInboxLeaf, | ||
| TxEffect, | ||
| TxHash, | ||
| TxReceipt, | ||
|
|
@@ -22,6 +23,9 @@ import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/c | |
| export type ArchiverL1SynchPoint = { | ||
| /** The last L1 block that added a new L2 block. */ | ||
| addedBlock: bigint; | ||
| /** The last L1 block that added messages from the new inbox. */ | ||
| // TODO(#4492): Clean this up and fix the naming | ||
| newMessages: bigint; | ||
| /** The last L1 block that added pending messages */ | ||
| addedMessages: bigint; | ||
| /** The last L1 block that cancelled messages */ | ||
|
|
@@ -90,11 +94,20 @@ export interface ArchiverDataStore { | |
| blockNumber: number, | ||
| ): Promise<boolean>; | ||
|
|
||
| /** | ||
| * Append new L1 to L2 messages to the store. | ||
| * @param messages - The L1 to L2 messages to be added to the store. | ||
| * @param lastMessageL1BlockNumber - The L1 block number in which the last message was emitted. | ||
| * @returns True if the operation is successful. | ||
| */ | ||
| addNewL1ToL2Messages(messages: NewInboxLeaf[], lastMessageL1BlockNumber: bigint): Promise<boolean>; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming here is stupid but I will clean that up when doing the purge. |
||
|
|
||
| /** | ||
| * Append new pending L1 to L2 messages to the store. | ||
| * @param messages - The L1 to L2 messages to be added to the store. | ||
| * @param l1BlockNumber - The block number of the L1 block that added the messages. | ||
| * @returns True if the operation is successful. | ||
| * TODO(#4492): Nuke the following when purging the old inbox | ||
| */ | ||
| addPendingL1ToL2Messages(messages: L1ToL2Message[], l1BlockNumber: bigint): Promise<boolean>; | ||
|
|
||
|
|
@@ -103,6 +116,7 @@ export interface ArchiverDataStore { | |
| * @param entryKeys - The entry keys to be removed from the store. | ||
| * @param l1BlockNumber - The block number of the L1 block that cancelled the messages. | ||
| * @returns True if the operation is successful. | ||
| * TODO(#4492): Nuke the following when purging the old inbox | ||
| */ | ||
| cancelPendingL1ToL2EntryKeys(entryKeys: Fr[], l1BlockNumber: bigint): Promise<boolean>; | ||
|
|
||
|
|
@@ -128,6 +142,13 @@ export interface ArchiverDataStore { | |
| */ | ||
| getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message>; | ||
|
|
||
| /** | ||
| * Gets new L1 to L2 message (to be) included in a given block. | ||
| * @param blockNumber - L2 block number to get messages for. | ||
| * @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found). | ||
| */ | ||
| getNewL1ToL2Messages(blockNumber: bigint): Promise<Buffer[]>; | ||
|
|
||
| /** | ||
| * Gets up to `limit` amount of logs starting from `from`. | ||
| * @param from - Number of the L2 block to which corresponds the first logs to be returned. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ^ is the least annoying way of getting the new inbox address. Once the old inbox is purged the new inbox address will be passed config.l1Contracts.inboxAddress as well.
BTW I feel like having all these addresses passed via config is quite shit and it would be better to just pass registry address and fetch the rest from chain.