Skip to content

Commit

Permalink
chore: updating viem (#4783)
Browse files Browse the repository at this point in the history
`e2e-public-cross-chain-messaging` is flaky and it's caused by a failure
to retrieve logs from anvil. The low hanging fruit here was to try to
update viem and see whether by any chance this gets resolved. I don't
think viem is the culprit but given that the version we used now was
ancient, they fixed a lot of bugs and we'll need to do the update anyway
to get blobs support it made sense to just do it.
  • Loading branch information
benesjan committed Feb 27, 2024
1 parent 8307dad commit 23bc26a
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 228 deletions.
2 changes: 1 addition & 1 deletion yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"lodash.omit": "^4.5.0",
"tsc-watch": "^6.0.0",
"tslib": "^2.5.0",
"viem": "1.4.2",
"viem": "^2.7.15",
"ws": "^8.13.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function makeL2BlockProcessedEvent(l1BlockNum: bigint, l2BlockNum: bigint) {
blockNumber: l1BlockNum,
args: { blockNumber: l2BlockNum },
transactionHash: `0x${l2BlockNum}`,
} as Log<bigint, number, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>;
} as Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>;
}

/**
Expand All @@ -296,7 +296,7 @@ function makeContractDeploymentEvent(l1BlockNum: bigint, l2Block: L2Block) {
acir: '0x' + acir,
},
transactionHash: `0x${l2Block.number}`,
} as Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>;
} as Log<bigint, number, false, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>;
}

/**
Expand All @@ -321,7 +321,7 @@ function makeL1ToL2MessageAddedEvents(l1BlockNum: bigint, entryKeys: string[]) {
entryKey: entryKey,
},
transactionHash: `0x${l1BlockNum}`,
} as Log<bigint, number, undefined, true, typeof InboxAbi, 'MessageAdded'>;
} as Log<bigint, number, false, undefined, true, typeof InboxAbi, 'MessageAdded'>;
});
}

Expand All @@ -339,7 +339,7 @@ function makeL1ToL2MessageCancelledEvents(l1BlockNum: bigint, entryKeys: string[
entryKey,
},
transactionHash: `0x${l1BlockNum}`,
} as Log<bigint, number, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>;
} as Log<bigint, number, false, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>;
});
}

Expand Down
73 changes: 33 additions & 40 deletions yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hex
* @returns Array of all Pending L1 to L2 messages that were processed
*/
export function processPendingL1ToL2MessageAddedLogs(
logs: Log<bigint, number, undefined, true, typeof InboxAbi, 'MessageAdded'>[],
logs: Log<bigint, number, false, undefined, true, typeof InboxAbi, 'MessageAdded'>[],
): [L1ToL2Message, bigint][] {
const l1ToL2Messages: [L1ToL2Message, bigint][] = [];
for (const log of logs) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export function processPendingL1ToL2MessageAddedLogs(
* @returns Array of message keys of the L1 to L2 messages that were cancelled
*/
export function processCancelledL1ToL2MessagesLogs(
logs: Log<bigint, number, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[],
logs: Log<bigint, number, false, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[],
): [Fr, bigint][] {
const cancelledL1ToL2Messages: [Fr, bigint][] = [];
for (const log of logs) {
Expand All @@ -67,7 +67,7 @@ export function processCancelledL1ToL2MessagesLogs(
export async function processBlockLogs(
publicClient: PublicClient,
expectedL2BlockNumber: bigint,
logs: Log<bigint, number, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
logs: Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
): Promise<L2Block[]> {
const retrievedBlocks: L2Block[] = [];
for (const log of logs) {
Expand Down Expand Up @@ -99,9 +99,8 @@ async function getBlockFromCallData(
l2BlockNum: bigint,
): Promise<L2Block> {
const { input: data } = await publicClient.getTransaction({ hash: txHash });
// TODO: File a bug in viem who complains if we dont remove the ctor from the abi here
const { functionName, args } = decodeFunctionData({
abi: RollupAbi.filter(item => item.type.toString() !== 'constructor'),
abi: RollupAbi,
data,
});
if (functionName !== 'process') {
Expand Down Expand Up @@ -129,21 +128,18 @@ async function getBlockFromCallData(
* @param toBlock - Last block to get logs from (inclusive).
* @returns An array of `L2BlockProcessed` logs.
*/
export async function getL2BlockProcessedLogs(
export function getL2BlockProcessedLogs(
publicClient: PublicClient,
rollupAddress: EthAddress,
fromBlock: bigint,
toBlock: bigint,
) {
// Note: For some reason the return type of `getLogs` would not get correctly derived if I didn't set the abiItem
// as a standalone constant.
const abiItem = getAbiItem({
abi: RollupAbi,
name: 'L2BlockProcessed',
});
return await publicClient.getLogs<typeof abiItem, true>({
): Promise<Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[]> {
return publicClient.getLogs({
address: getAddress(rollupAddress.toString()),
event: abiItem,
event: getAbiItem({
abi: RollupAbi,
name: 'L2BlockProcessed',
}),
fromBlock,
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
});
Expand All @@ -157,19 +153,18 @@ export async function getL2BlockProcessedLogs(
* @param toBlock - Last block to get logs from (inclusive).
* @returns An array of `ContractDeployment` logs.
*/
export async function getContractDeploymentLogs(
export function getContractDeploymentLogs(
publicClient: PublicClient,
contractDeploymentEmitterAddress: EthAddress,
fromBlock: bigint,
toBlock: bigint,
): Promise<Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[]> {
const abiItem = getAbiItem({
abi: ContractDeploymentEmitterAbi,
name: 'ContractDeployment',
});
return await publicClient.getLogs({
): Promise<Log<bigint, number, false, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[]> {
return publicClient.getLogs({
address: getAddress(contractDeploymentEmitterAddress.toString()),
event: abiItem,
event: getAbiItem({
abi: ContractDeploymentEmitterAbi,
name: 'ContractDeployment',
}),
fromBlock,
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
});
Expand All @@ -183,7 +178,7 @@ export async function getContractDeploymentLogs(
*/
export function processContractDeploymentLogs(
blockNumberToBodyHash: { [key: number]: Buffer | undefined },
logs: Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[],
logs: Log<bigint, number, false, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[],
): [ExtendedContractData[], number][] {
const extendedContractData: [ExtendedContractData[], number][] = [];
for (let i = 0; i < logs.length; i++) {
Expand Down Expand Up @@ -223,19 +218,18 @@ export function processContractDeploymentLogs(
* @param toBlock - Last block to get logs from (inclusive).
* @returns An array of `MessageAdded` logs.
*/
export async function getPendingL1ToL2MessageLogs(
export function getPendingL1ToL2MessageLogs(
publicClient: PublicClient,
inboxAddress: EthAddress,
fromBlock: bigint,
toBlock: bigint,
): Promise<Log<bigint, number, undefined, true, typeof InboxAbi, 'MessageAdded'>[]> {
const abiItem = getAbiItem({
abi: InboxAbi,
name: 'MessageAdded',
});
return await publicClient.getLogs({
): Promise<Log<bigint, number, false, undefined, true, typeof InboxAbi, 'MessageAdded'>[]> {
return publicClient.getLogs({
address: getAddress(inboxAddress.toString()),
event: abiItem,
event: getAbiItem({
abi: InboxAbi,
name: 'MessageAdded',
}),
fromBlock,
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
});
Expand All @@ -249,19 +243,18 @@ export async function getPendingL1ToL2MessageLogs(
* @param toBlock - Last block to get logs from (inclusive).
* @returns An array of `L1ToL2MessageCancelled` logs.
*/
export async function getL1ToL2MessageCancelledLogs(
export function getL1ToL2MessageCancelledLogs(
publicClient: PublicClient,
inboxAddress: EthAddress,
fromBlock: bigint,
toBlock: bigint,
): Promise<Log<bigint, number, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[]> {
const abiItem = getAbiItem({
abi: InboxAbi,
name: 'L1ToL2MessageCancelled',
});
return await publicClient.getLogs({
): Promise<Log<bigint, number, false, undefined, true, typeof InboxAbi, 'L1ToL2MessageCancelled'>[]> {
return publicClient.getLogs({
address: getAddress(inboxAddress.toString()),
event: abiItem,
event: getAbiItem({
abi: InboxAbi,
name: 'L1ToL2MessageCancelled',
}),
fromBlock,
toBlock: toBlock + 1n, // the toBlock argument in getLogs is exclusive
});
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"koa": "^2.14.2",
"koa-cors": "^0.0.16",
"koa-router": "^12.0.0",
"viem": "^1.2.5"
"viem": "^2.7.15"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"commander": "^11.1.0",
"koa": "^2.14.2",
"koa-router": "^12.0.0",
"viem": "^1.2.5",
"viem": "^2.7.15",
"winston": "^3.10.0",
"winston-daily-rotate-file": "^4.7.1"
},
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"semver": "^7.5.4",
"source-map-support": "^0.5.21",
"tslib": "^2.4.0",
"viem": "^1.2.5"
"viem": "^2.7.15"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"viem": "^1.2.5",
"viem": "^2.7.15",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"winston": "^3.10.0"
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ describe('e2e_cheat_codes', () => {
await cc.aztec.warp(newTimestamp);

// ensure rollup contract is correctly updated
const rollup = getContract({ address: getAddress(rollupAddress.toString()), abi: RollupAbi, publicClient });
const rollup = getContract({
address: getAddress(rollupAddress.toString()),
abi: RollupAbi,
client: publicClient,
});
expect(Number(await rollup.read.lastBlockTs())).toEqual(newTimestamp);
expect(Number(await rollup.read.lastWarpedBlockTs())).toEqual(newTimestamp);

Expand Down
13 changes: 4 additions & 9 deletions yarn-project/end-to-end/src/integration_l1_publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ describe('L1Publisher integration', () => {
let outboxAddress: Address;

let rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, Chain>>;
let inbox: GetContractReturnType<
typeof InboxAbi,
PublicClient<HttpTransport, Chain>,
WalletClient<HttpTransport, Chain>
>;
let inbox: GetContractReturnType<typeof InboxAbi, WalletClient<HttpTransport, Chain>>;
let outbox: GetContractReturnType<typeof OutboxAbi, PublicClient<HttpTransport, Chain>>;

let publisher: L1Publisher;
Expand Down Expand Up @@ -123,18 +119,17 @@ describe('L1Publisher integration', () => {
rollup = getContract({
address: rollupAddress,
abi: RollupAbi,
publicClient,
client: publicClient,
});
inbox = getContract({
address: inboxAddress,
abi: InboxAbi,
publicClient,
walletClient,
client: walletClient,
});
outbox = getContract({
address: outboxAddress,
abi: OutboxAbi,
publicClient,
client: publicClient,
});

builderDb = await MerkleTrees.new(openTmpStore()).then(t => t.asLatest());
Expand Down
12 changes: 4 additions & 8 deletions yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ export async function deployAndInitializeTokenAndBridgeContracts(
const underlyingERC20 = getContract({
address: underlyingERC20Address.toString(),
abi: PortalERC20Abi,
walletClient,
publicClient,
client: walletClient,
});

// deploy the token portal
const tokenPortalAddress = await deployL1Contract(walletClient, publicClient, TokenPortalAbi, TokenPortalBytecode);
const tokenPortal = getContract({
address: tokenPortalAddress.toString(),
abi: TokenPortalAbi,
walletClient,
publicClient,
client: walletClient,
});

// deploy l2 token
Expand Down Expand Up @@ -138,15 +136,13 @@ export class CrossChainTestHarness {
const inbox = getContract({
address: l1ContractAddresses.inboxAddress.toString(),
abi: InboxAbi,
walletClient,
publicClient,
client: walletClient,
});

const outbox = getContract({
address: l1ContractAddresses.outboxAddress.toString(),
abi: OutboxAbi,
walletClient,
publicClient,
client: walletClient,
});

// Deploy and initialize all required contracts
Expand Down
9 changes: 3 additions & 6 deletions yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,15 @@ export async function deployAndInitializeTokenAndBridgeContracts(
const gasL1 = getContract({
address: underlyingERC20Address.toString(),
abi: PortalERC20Abi,
walletClient,
publicClient,
client: walletClient,
});

// deploy the gas portal
const gasPortalAddress = await deployL1Contract(walletClient, publicClient, GasPortalAbi, GasPortalBytecode);
const gasPortal = getContract({
address: gasPortalAddress.toString(),
abi: GasPortalAbi,
walletClient,
publicClient,
client: walletClient,
});

// deploy l2 token
Expand Down Expand Up @@ -107,8 +105,7 @@ export class GasBridgingTestHarness {
const outbox = getContract({
address: l1ContractAddresses.outboxAddress.toString(),
abi: OutboxAbi,
walletClient,
publicClient,
client: walletClient,
});

// Deploy and initialize all required contracts
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ export const uniswapL1L2TestSuite = (
uniswapPortal = getContract({
address: uniswapPortalAddress.toString(),
abi: UniswapPortalAbi,
walletClient,
publicClient,
client: walletClient,
});
// deploy l2 uniswap contract and attach to portal
uniswapL2Contract = await UniswapContract.deploy(ownerWallet)
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@aztec/foundation": "workspace:^",
"dotenv": "^16.0.3",
"tslib": "^2.4.0",
"viem": "^1.2.5"
"viem": "^2.7.15"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/ethereum/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ export const deployL1Contracts = async (
const registryContract = getContract({
address: getAddress(registryAddress.toString()),
abi: contractsToDeploy.registry.contractAbi,
publicClient,
walletClient,
client: walletClient,
});
await registryContract.write.upgrade(
[getAddress(rollupAddress.toString()), getAddress(inboxAddress.toString()), getAddress(outboxAddress.toString())],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/ethereum/src/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const createTestnetChain = (apiKey: string) => {
const chain: Chain = {
id: +CHAIN_ID,
name: 'testnet',
network: 'aztec',
testnet: true,
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
Expand Down
Loading

0 comments on commit 23bc26a

Please sign in to comment.