Skip to content

Commit

Permalink
feat(archiver): use registry to fetch searchStartBlock (#2830)
Browse files Browse the repository at this point in the history
Fix #2829 - remove searchStartBlock env var by using registry to fetch
current block number
  • Loading branch information
rahul-kothari authored Oct 13, 2023
1 parent 5585075 commit e5bc067
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 34 deletions.
15 changes: 13 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 { RegistryAbi } from '@aztec/l1-artifacts';
import {
ContractData,
ContractDataSource,
Expand All @@ -24,7 +25,7 @@ import {
} from '@aztec/types';

import omit from 'lodash.omit';
import { Chain, HttpTransport, PublicClient, createPublicClient, http } from 'viem';
import { Chain, HttpTransport, PublicClient, createPublicClient, getContract, http } from 'viem';

import { ArchiverDataStore, MemoryArchiverStore } from './archiver_store.js';
import { ArchiverConfig } from './config.js';
Expand Down Expand Up @@ -101,14 +102,24 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
transport: http(chain.rpcUrl),
pollingInterval: config.viemPollingIntervalMS,
});

// ask the registry for the block number when the rollup was deployed
// this is the block from which archiver has to search from
const registryContract = getContract({
address: config.l1Contracts.registryAddress.toString(),
abi: RegistryAbi,
publicClient,
});
const searchStartBlock = Number((await registryContract.read.getCurrentSnapshot()).blockNumber);

const archiverStore = new MemoryArchiverStore(config.maxLogs ?? 1000);
const archiver = new Archiver(
publicClient,
config.l1Contracts.rollupAddress,
config.l1Contracts.inboxAddress,
config.l1Contracts.registryAddress,
config.l1Contracts.contractDeploymentEmitterAddress,
config.searchStartBlock,
searchStartBlock,
archiverStore,
config.archiverPollingIntervalMS,
);
Expand Down
7 changes: 0 additions & 7 deletions yarn-project/archiver/src/archiver/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ export interface ArchiverConfig {
*/
viemPollingIntervalMS?: number;

/**
* Eth block from which we start scanning for L2Blocks.
*/
searchStartBlock: number;

/**
* The deployed L1 contract addresses
*/
Expand All @@ -63,7 +58,6 @@ export function getConfigEnvVars(): ArchiverConfig {
ARCHIVER_VIEM_POLLING_INTERVAL_MS,
ROLLUP_CONTRACT_ADDRESS,
CONTRACT_DEPLOYMENT_EMITTER_ADDRESS,
SEARCH_START_BLOCK,
API_KEY,
INBOX_CONTRACT_ADDRESS,
OUTBOX_CONTRACT_ADDRESS,
Expand All @@ -85,7 +79,6 @@ export function getConfigEnvVars(): ArchiverConfig {
rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/',
archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000,
viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000,
searchStartBlock: SEARCH_START_BLOCK ? +SEARCH_START_BLOCK : 0,
apiKey: API_KEY,
l1Contracts: addresses,
dataDirectory: DATA_DIRECTORY,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const log = createDebugLogger('aztec:archiver');
// eslint-disable-next-line require-await
async function main() {
const config = getConfigEnvVars();
const { rpcUrl, l1Contracts, searchStartBlock } = config;
const { rpcUrl, l1Contracts } = config;

const publicClient = createPublicClient({
chain: localhost,
Expand All @@ -32,7 +32,7 @@ async function main() {
l1Contracts.inboxAddress,
l1Contracts.registryAddress,
l1Contracts.contractDeploymentEmitterAddress,
searchStartBlock,
0, // searchStartBlock
archiverStore,
);

Expand Down
8 changes: 0 additions & 8 deletions yarn-project/aztec-node/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ resource "aws_ecs_task_definition" "aztec-node-1" {
"name": "API_PREFIX",
"value": "/${var.DEPLOY_TAG}/aztec-node-1"
},
{
"name": "SEARCH_START_BLOCK",
"value": "15920300"
},
{
"name": "P2P_TCP_LISTEN_PORT",
"value": "${var.NODE_1_TCP_PORT}"
Expand Down Expand Up @@ -460,10 +456,6 @@ resource "aws_ecs_task_definition" "aztec-node-2" {
"name": "API_PREFIX",
"value": "/${var.DEPLOY_TAG}/aztec-node-2"
},
{
"name": "SEARCH_START_BLOCK",
"value": "15920300"
},
{
"name": "P2P_TCP_LISTEN_PORT",
"value": "${var.NODE_2_TCP_PORT}"
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec-sandbox/docker-compose-fork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ services:
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: 17514288
1 change: 0 additions & 1 deletion yarn-project/canary/scripts/docker-compose-browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
ports:
- '8080:8080'

Expand Down
2 changes: 0 additions & 2 deletions yarn-project/canary/scripts/docker-compose-e2e-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
ports:
- '8080:8080'

Expand All @@ -34,5 +33,4 @@ services:
ETHEREUM_HOST: http://fork:8545
CHAIN_ID: 31337
PXE_URL: http://sandbox:8080
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
command: ${TEST:-./src/e2e_deploy_contract.test.ts}
2 changes: 0 additions & 2 deletions yarn-project/canary/scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
ports:
- '8080:8080'

Expand All @@ -34,5 +33,4 @@ services:
ETHEREUM_HOST: http://fork:8545
CHAIN_ID: 31337
PXE_URL: http://sandbox:8080
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
command: ${TEST:-./src/uniswap_trade_on_l1_from_l2.test.ts}
2 changes: 0 additions & 2 deletions yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const MNEMONIC = 'test test test test test test test test test test test
const hdAccount = mnemonicToAccount(MNEMONIC);
// This tests works on forked mainnet, configured on the CI.
const EXPECTED_FORKED_BLOCK = 17514288;
// We tell the archiver to only sync from this block.
process.env.SEARCH_START_BLOCK = EXPECTED_FORKED_BLOCK.toString();

const setupRPC = async (): Promise<UniswapSetupContext> => {
const logger = createDebugLogger('aztec:canary_uniswap');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
ports:
- '8080:8080'

Expand All @@ -36,7 +35,6 @@ services:
ETHEREUM_HOST: http://fork:8545
CHAIN_ID: 31337
PXE_URL: http://sandbox:8080
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
entrypoint: ['./scripts/start_e2e_ci_browser.sh', './src/e2e_aztec_js_browser.test.ts']
volumes:
- ../log:/usr/src/yarn-project/end-to-end/log:rw
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
ports:
- '8080:8080'

Expand All @@ -36,7 +35,6 @@ services:
ETHEREUM_HOST: http://fork:8545
CHAIN_ID: 31337
PXE_URL: http://sandbox:8080
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
command: ${TEST:-./src/e2e_deploy_contract.test.ts}
volumes:
- ../log:/usr/src/yarn-project/end-to-end/log:rw
1 change: 0 additions & 1 deletion yarn-project/end-to-end/scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0}
command: ${TEST:-./src/e2e_deploy_contract.test.ts}
volumes:
- ../log:/usr/src/yarn-project/end-to-end/log:rw
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { setup as e2eSetup } from './fixtures/utils.js';
const dumpedState = 'src/fixtures/dumps/uniswap_state';
// When taking a dump use the block number of the fork to improve speed.
const EXPECTED_FORKED_BLOCK = 0; //17514288;
// We tell the archiver to only sync from this block.
process.env.SEARCH_START_BLOCK = EXPECTED_FORKED_BLOCK.toString();

let teardown: () => Promise<void>;

Expand Down

0 comments on commit e5bc067

Please sign in to comment.