Skip to content

Commit bd9f3ce

Browse files
authored
chore: use rollup.ts more consistenty (#12863)
To ease the work in #12753, we have done a bunch of refactoring in this one to use the `rollup.ts` more throughout the code base. This will make it simpler to alter the code for simualtion as viem is not happy about doing a `read` for a function that is not `view` and we need to fiddle a bit there.
1 parent 87bb6da commit bd9f3ce

File tree

19 files changed

+245
-232
lines changed

19 files changed

+245
-232
lines changed

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

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
2-
import { type ViemPublicClient, createEthereumChain } from '@aztec/ethereum';
2+
import { RollupContract, type ViemPublicClient, createEthereumChain } from '@aztec/ethereum';
33
import type { EthAddress } from '@aztec/foundation/eth-address';
44
import { Fr } from '@aztec/foundation/fields';
55
import { type Logger, createLogger } from '@aztec/foundation/log';
66
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
77
import { count } from '@aztec/foundation/string';
88
import { elapsed } from '@aztec/foundation/timer';
9-
import { InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
9+
import { InboxAbi } from '@aztec/l1-artifacts';
1010
import {
1111
ContractClassRegisteredEvent,
1212
PrivateFunctionBroadcastedEvent,
@@ -84,7 +84,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
8484
*/
8585
private runningPromise?: RunningPromise;
8686

87-
private rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
87+
private rollup: RollupContract;
8888
private inbox: GetContractReturnType<typeof InboxAbi, ViemPublicClient>;
8989

9090
private store: ArchiverStoreHelper;
@@ -119,11 +119,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
119119
this.tracer = instrumentation.tracer;
120120
this.store = new ArchiverStoreHelper(dataStore);
121121

122-
this.rollup = getContract({
123-
address: l1Addresses.rollupAddress.toString(),
124-
abi: RollupAbi,
125-
client: publicClient,
126-
});
122+
this.rollup = new RollupContract(publicClient, l1Addresses.rollupAddress);
127123

128124
this.inbox = getContract({
129125
address: l1Addresses.inboxAddress.toString(),
@@ -152,15 +148,11 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
152148
pollingInterval: config.viemPollingIntervalMS,
153149
});
154150

155-
const rollup = getContract({
156-
address: config.l1Contracts.rollupAddress.toString(),
157-
abi: RollupAbi,
158-
client: publicClient,
159-
});
151+
const rollup = new RollupContract(publicClient, config.l1Contracts.rollupAddress);
160152

161153
const [l1StartBlock, l1GenesisTime] = await Promise.all([
162-
rollup.read.L1_BLOCK_AT_GENESIS(),
163-
rollup.read.getGenesisTime(),
154+
rollup.getL1StartBlock(),
155+
rollup.getL1GenesisTime(),
164156
] as const);
165157

166158
const { aztecEpochDuration: epochDuration, aztecSlotDuration: slotDuration, ethereumSlotDuration } = config;
@@ -306,7 +298,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
306298
/** Queries the rollup contract on whether a prune can be executed on the immediatenext L1 block. */
307299
private async canPrune(currentL1BlockNumber: bigint, currentL1Timestamp: bigint) {
308300
const time = (currentL1Timestamp ?? 0n) + BigInt(this.l1constants.ethereumSlotDuration);
309-
return await this.rollup.read.canPruneAtTime([time], { blockNumber: currentL1BlockNumber });
301+
return await this.rollup.canPruneAtTime(time, { blockNumber: currentL1BlockNumber });
310302
}
311303

312304
/** Checks if there'd be a reorg for the next block submission and start pruning now. */
@@ -394,7 +386,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
394386
): Promise<{ provenBlockNumber: bigint }> {
395387
const localPendingBlockNumber = BigInt(await this.getBlockNumber());
396388
const [provenBlockNumber, provenArchive, pendingBlockNumber, pendingArchive, archiveForLocalPendingBlockNumber] =
397-
await this.rollup.read.status([localPendingBlockNumber], { blockNumber: currentL1BlockNumber });
389+
await this.rollup.status(localPendingBlockNumber, { blockNumber: currentL1BlockNumber });
398390

399391
const updateProvenBlock = async () => {
400392
const localBlockForDestinationProvenBlockNumber = await this.getBlock(Number(provenBlockNumber));
@@ -473,7 +465,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
473465
break;
474466
}
475467

476-
const archiveAtContract = await this.rollup.read.archiveAt([BigInt(candidateBlock.number)]);
468+
const archiveAtContract = await this.rollup.archiveAt(BigInt(candidateBlock.number));
477469

478470
if (archiveAtContract === candidateBlock.archive.root.toString()) {
479471
break;
@@ -504,7 +496,7 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
504496

505497
// TODO(md): Retrieve from blob sink then from consensus client, then from peers
506498
const retrievedBlocks = await retrieveBlocksFromRollup(
507-
this.rollup,
499+
this.rollup.getContract(),
508500
this.publicClient,
509501
this.blobSinkClient,
510502
searchStartBlock, // TODO(palla/reorg): If the L2 reorg was due to an L1 reorg, we need to start search earlier

yarn-project/cli/src/cmds/infrastructure/sequencers.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCompatibleClient } from '@aztec/aztec.js';
2-
import { createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
2+
import { RollupContract, createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
33
import type { LogFn, Logger } from '@aztec/foundation/log';
44
import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';
55

@@ -35,11 +35,7 @@ export async function sequencers(opts: {
3535
})
3636
: undefined;
3737

38-
const rollup = getContract({
39-
address: l1ContractAddresses.rollupAddress.toString(),
40-
abi: RollupAbi,
41-
client: publicClient,
42-
});
38+
const rollup = new RollupContract(publicClient, l1ContractAddresses.rollupAddress);
4339

4440
const writeableRollup = walletClient
4541
? getContract({
@@ -52,7 +48,7 @@ export async function sequencers(opts: {
5248
const who = (maybeWho as `0x{string}`) ?? walletClient?.account.address.toString();
5349

5450
if (command === 'list') {
55-
const sequencers = await rollup.read.getAttesters();
51+
const sequencers = await rollup.getAttesters();
5652
if (sequencers.length === 0) {
5753
log(`No sequencers registered on rollup`);
5854
} else {
@@ -69,7 +65,7 @@ export async function sequencers(opts: {
6965
log(`Adding ${who} as sequencer`);
7066

7167
const stakingAsset = getContract({
72-
address: await rollup.read.getStakingAsset(),
68+
address: await rollup.getStakingAsset(),
7369
abi: TestERC20Abi,
7470
client: walletClient,
7571
});
@@ -95,7 +91,7 @@ export async function sequencers(opts: {
9591
await publicClient.waitForTransactionReceipt({ hash });
9692
log(`Removed in tx ${hash}`);
9793
} else if (command === 'who-next') {
98-
const next = await rollup.read.getCurrentProposer();
94+
const next = await rollup.getCurrentProposer();
9995
log(`Sequencer expected to build is ${next}`);
10096
} else {
10197
throw new Error(`Unknown command ${command}`);

yarn-project/cli/src/cmds/l1/update_l1_validators.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
EthCheatCodes,
3+
RollupContract,
34
createEthereumChain,
45
getExpectedAddress,
56
getL1ContractsConfigEnvVars,
@@ -181,30 +182,26 @@ export async function fastForwardEpochs({
181182
export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: RollupCommandArgs & LoggerArgs) {
182183
const config = getL1ContractsConfigEnvVars();
183184
const publicClient = getPublicClient(rpcUrls, chainId);
184-
const rollup = getContract({
185-
address: rollupAddress.toString(),
186-
abi: RollupAbi,
187-
client: publicClient,
188-
});
185+
const rollup = new RollupContract(publicClient, rollupAddress);
189186

190-
const pendingNum = await rollup.read.getPendingBlockNumber();
187+
const pendingNum = await rollup.getBlockNumber();
191188
log(`Pending block num: ${pendingNum}`);
192-
const provenNum = await rollup.read.getProvenBlockNumber();
189+
const provenNum = await rollup.getProvenBlockNumber();
193190
log(`Proven block num: ${provenNum}`);
194-
const validators = await rollup.read.getAttesters();
191+
const validators = await rollup.getAttesters();
195192
log(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
196-
const committee = await rollup.read.getCurrentEpochCommittee();
193+
const committee = await rollup.getCurrentEpochCommittee();
197194
log(`Committee: ${committee.map(v => v.toString()).join(', ')}`);
198-
const archive = await rollup.read.archive();
195+
const archive = await rollup.archive();
199196
log(`Archive: ${archive}`);
200-
const epochNum = await rollup.read.getCurrentEpoch();
197+
const epochNum = await rollup.getEpochNumber();
201198
log(`Current epoch: ${epochNum}`);
202-
const slot = await rollup.read.getCurrentSlot();
199+
const slot = await rollup.getSlotNumber();
203200
log(`Current slot: ${slot}`);
204-
const proposerDuringPrevL1Block = await rollup.read.getCurrentProposer();
201+
const proposerDuringPrevL1Block = await rollup.getCurrentProposer();
205202
log(`Proposer during previous L1 block: ${proposerDuringPrevL1Block}`);
206203
const nextBlockTS = BigInt((await publicClient.getBlock()).timestamp + BigInt(config.ethereumSlotDuration));
207-
const proposer = await rollup.read.getProposerAt([nextBlockTS]);
204+
const proposer = await rollup.getProposerAt(nextBlockTS);
208205
log(`Proposer NOW: ${proposer.toString()}`);
209206
}
210207

yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('L1Publisher integration', () => {
8181
let rollupAddress: Address;
8282
let outboxAddress: Address;
8383

84-
let rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
84+
let rollup: RollupContract;
8585
let outbox: GetContractReturnType<typeof OutboxAbi, ViemPublicClient>;
8686

8787
let publisher: SequencerPublisher;
@@ -111,8 +111,8 @@ describe('L1Publisher integration', () => {
111111

112112
const progressTimeBySlot = async (slotsToJump = 1n) => {
113113
const currentTime = (await publicClient.getBlock()).timestamp;
114-
const currentSlot = await rollup.read.getCurrentSlot();
115-
const timestamp = await rollup.read.getTimestampForSlot([currentSlot + slotsToJump]);
114+
const currentSlot = await rollup.getSlotNumber();
115+
const timestamp = await rollup.getTimestampForSlot(currentSlot + slotsToJump);
116116
if (timestamp > currentTime) {
117117
await ethCheatCodes.warp(Number(timestamp));
118118
}
@@ -133,11 +133,7 @@ describe('L1Publisher integration', () => {
133133
outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString());
134134

135135
// Set up contract instances
136-
rollup = getContract({
137-
address: rollupAddress,
138-
abi: RollupAbi,
139-
client: publicClient,
140-
});
136+
rollup = new RollupContract(publicClient, l1ContractAddresses.rollupAddress);
141137
outbox = getContract({
142138
address: outboxAddress,
143139
abi: OutboxAbi,
@@ -242,10 +238,10 @@ describe('L1Publisher integration', () => {
242238
await fork.close();
243239

244240
const ts = (await publicClient.getBlock()).timestamp;
245-
baseFee = new GasFees(0, await rollup.read.getManaBaseFeeAt([ts, true]));
241+
baseFee = new GasFees(0, await rollup.getManaBaseFeeAt(ts, true));
246242

247243
// We jump to the next epoch such that the committee can be setup.
248-
const timeToJump = await rollup.read.getEpochDuration();
244+
const timeToJump = await rollup.getEpochDuration();
249245
await progressTimeBySlot(timeToJump);
250246
});
251247

@@ -394,7 +390,7 @@ describe('L1Publisher integration', () => {
394390
};
395391

396392
const buildAndPublishBlock = async (numTxs: number, jsonFileNamePrefix: string) => {
397-
const archiveInRollup_ = await rollup.read.archive();
393+
const archiveInRollup_ = await rollup.archive();
398394
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());
399395

400396
const blockNumber = await publicClient.getBlockNumber();
@@ -421,8 +417,8 @@ describe('L1Publisher integration', () => {
421417
);
422418

423419
const ts = (await publicClient.getBlock()).timestamp;
424-
const slot = await rollup.read.getSlotAt([ts + BigInt(config.ethereumSlotDuration)]);
425-
const timestamp = await rollup.read.getTimestampForSlot([slot]);
420+
const slot = await rollup.getSlotAt(ts + BigInt(config.ethereumSlotDuration));
421+
const timestamp = await rollup.getTimestampForSlot(slot);
426422

427423
const globalVariables = new GlobalVariables(
428424
new Fr(chainId),
@@ -432,7 +428,7 @@ describe('L1Publisher integration', () => {
432428
new Fr(timestamp),
433429
coinbase,
434430
feeRecipient,
435-
new GasFees(Fr.ZERO, new Fr(await rollup.read.getManaBaseFeeAt([timestamp, true]))),
431+
new GasFees(Fr.ZERO, new Fr(await rollup.getManaBaseFeeAt(timestamp, true))),
436432
);
437433

438434
const block = await buildBlock(globalVariables, txs, currentL1ToL2Messages);
@@ -482,7 +478,7 @@ describe('L1Publisher integration', () => {
482478
hash: logs[i].transactionHash!,
483479
});
484480

485-
const blobPublicInputsHash = await rollup.read.getBlobPublicInputsHash([BigInt(i + 1)]);
481+
const blobPublicInputsHash = await rollup.getBlobPublicInputsHash(BigInt(i + 1));
486482
const expectedHash = sha256(Buffer.from(BlockBlobPublicInputs.fromBlobs(blobs).toString().substring(2), 'hex'));
487483
expect(blobPublicInputsHash).toEqual(`0x${expectedHash.toString('hex')}`);
488484

@@ -549,7 +545,7 @@ describe('L1Publisher integration', () => {
549545

550546
it(`shows propose custom errors if tx reverts`, async () => {
551547
// REFACTOR: code below is duplicated from "builds blocks of 2 empty txs building on each other"
552-
const archiveInRollup_ = await rollup.read.archive();
548+
const archiveInRollup_ = await rollup.archive();
553549
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());
554550

555551
// Set up different l1-to-l2 messages than the ones on the inbox, so this submission reverts
@@ -559,8 +555,8 @@ describe('L1Publisher integration', () => {
559555

560556
const txs = await Promise.all([makeProcessedTx(0x1000), makeProcessedTx(0x2000)]);
561557
const ts = (await publicClient.getBlock()).timestamp;
562-
const slot = await rollup.read.getSlotAt([ts + BigInt(config.ethereumSlotDuration)]);
563-
const timestamp = await rollup.read.getTimestampForSlot([slot]);
558+
const slot = await rollup.getSlotAt(ts + BigInt(config.ethereumSlotDuration));
559+
const timestamp = await rollup.getTimestampForSlot(slot);
564560
const globalVariables = new GlobalVariables(
565561
new Fr(chainId),
566562
new Fr(config.version),
@@ -569,7 +565,7 @@ describe('L1Publisher integration', () => {
569565
new Fr(timestamp),
570566
coinbase,
571567
feeRecipient,
572-
new GasFees(Fr.ZERO, new Fr(await rollup.read.getManaBaseFeeAt([timestamp, true]))),
568+
new GasFees(Fr.ZERO, new Fr(await rollup.getManaBaseFeeAt(timestamp, true))),
573569
);
574570
const block = await buildBlock(globalVariables, txs, l1ToL2Messages);
575571
prevHeader = block.header;

yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@aztec/aztec.js';
1313
import { CheatCodes } from '@aztec/aztec.js/testing';
1414
import { type ViemPublicClient, createL1Clients, deployL1Contract } from '@aztec/ethereum';
15-
import { InboxAbi, OutboxAbi, RollupAbi, TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
15+
import { InboxAbi, OutboxAbi, TestERC20Abi, TestERC20Bytecode } from '@aztec/l1-artifacts';
1616
import { TokenContract } from '@aztec/noir-contracts.js/Token';
1717
import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
1818

@@ -49,7 +49,6 @@ export class CrossChainMessagingTest {
4949
l2Token!: TokenContract;
5050
l2Bridge!: TokenBridgeContract;
5151

52-
rollup!: any; // GetContractReturnType<typeof RollupAbi> | undefined;
5352
inbox!: any; // GetContractReturnType<typeof InboxAbi> | undefined;
5453
outbox!: any; // GetContractReturnType<typeof OutboxAbi> | undefined;
5554
cheatcodes!: CheatCodes;
@@ -60,7 +59,7 @@ export class CrossChainMessagingTest {
6059
}
6160

6261
async assumeProven() {
63-
await this.cheatcodes.rollup.markAsProven(await this.rollup.read.getPendingBlockNumber());
62+
await this.cheatcodes.rollup.markAsProven();
6463
}
6564

6665
async setup() {
@@ -88,17 +87,11 @@ export class CrossChainMessagingTest {
8887
await this.snapshotManager.snapshot(
8988
'3_accounts',
9089
deployAccounts(3, this.logger),
91-
async ({ deployedAccounts }, { pxe, aztecNodeConfig, aztecNode, deployL1ContractsValues }) => {
90+
async ({ deployedAccounts }, { pxe, aztecNodeConfig, aztecNode }) => {
9291
this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)));
9392
this.accounts = this.wallets.map(w => w.getCompleteAddress());
9493
this.wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`));
9594

96-
this.rollup = getContract({
97-
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
98-
abi: RollupAbi,
99-
client: deployL1ContractsValues.walletClient,
100-
});
101-
10295
this.user1Wallet = this.wallets[0];
10396
this.user2Wallet = this.wallets[1];
10497

yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Fr } from '@aztec/aztec.js';
22
import { CheatCodes } from '@aztec/aztec.js/testing';
3-
import { RollupAbi } from '@aztec/l1-artifacts';
4-
5-
import { getContract } from 'viem';
3+
import { RollupContract } from '@aztec/ethereum';
64

75
import { CrossChainMessagingTest } from './cross_chain_messaging_test.js';
86

@@ -19,8 +17,8 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
1917
l2Token,
2018
user1Wallet,
2119
user2Wallet,
22-
rollup,
2320
} = t;
21+
let rollup: RollupContract;
2422
let cheatCodes: CheatCodes;
2523

2624
beforeEach(async () => {
@@ -35,11 +33,10 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
3533
ownerAddress = crossChainTestHarness.ownerAddress;
3634
l2Bridge = crossChainTestHarness.l2Bridge;
3735
l2Token = crossChainTestHarness.l2Token;
38-
rollup = getContract({
39-
address: crossChainTestHarness.l1ContractAddresses.rollupAddress.toString(),
40-
abi: RollupAbi,
41-
client: crossChainTestHarness.walletClient,
42-
});
36+
rollup = new RollupContract(
37+
crossChainTestHarness!.publicClient,
38+
crossChainTestHarness!.l1ContractAddresses.rollupAddress,
39+
);
4340

4441
cheatCodes = await CheatCodes.create(t.aztecNodeConfig.l1RpcUrls, t.pxe);
4542
}, 300_000);
@@ -91,7 +88,7 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => {
9188
);
9289

9390
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
94-
await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
91+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
9592

9693
// Check balance before and after exit.
9794
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount);

0 commit comments

Comments
 (0)