Skip to content

Commit

Permalink
refactor: renamed contract public data and contract info
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 9, 2023
1 parent 9347b17 commit d7ffc33
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 173 deletions.
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sleep } from '@aztec/foundation/sleep';
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import {
ContractData,
ContractPublicData,
ContractDataAndBytecode,
EncodedContractFunction,
L2Block,
L2BlockL2Logs,
Expand Down Expand Up @@ -158,7 +158,7 @@ function makeContractDeploymentEvent(l1BlockNum: bigint, l2Block: L2Block) {
// const contractData = ContractData.random();
const aztecAddress = AztecAddress.random();
const portalAddress = EthAddress.random();
const contractData = new ContractPublicData(new ContractData(aztecAddress, portalAddress), [
const contractData = new ContractDataAndBytecode(new ContractData(aztecAddress, portalAddress), [
EncodedContractFunction.random(),
EncodedContractFunction.random(),
]);
Expand Down
28 changes: 14 additions & 14 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import {
ContractData,
ContractDataAndBytecode,
ContractDataSource,
ContractPublicData,
EncodedContractFunction,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
Expand Down Expand Up @@ -221,9 +221,9 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
// store contracts for which we have retrieved L2 blocks
const lastKnownL2BlockNum = retrievedBlocks.retrievedData[retrievedBlocks.retrievedData.length - 1].number;
retrievedContracts.retrievedData.forEach(async ([contracts, l2BlockNum], index) => {
this.log(`Retrieved contract public data for l2 block number: ${index}`);
this.log(`Retrieved contract data and bytecode for l2 block number: ${index}`);
if (l2BlockNum <= lastKnownL2BlockNum) {
await this.store.addL2ContractPublicData(contracts, l2BlockNum);
await this.store.addContractDataAndBytecode(contracts, l2BlockNum);
}
});

Expand Down Expand Up @@ -287,37 +287,37 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
* @param contractAddress - The contract data address.
* @returns The contract data.
*/
public getL2ContractPublicData(contractAddress: AztecAddress): Promise<ContractPublicData | undefined> {
return this.store.getL2ContractPublicData(contractAddress);
public getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
return this.store.getContractDataAndBytecode(contractAddress);
}

/**
* Lookup all contract data in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All new contract data in the block (if found).
*/
public getL2ContractPublicDataInBlock(blockNum: number): Promise<ContractPublicData[]> {
return this.store.getL2ContractPublicDataInBlock(blockNum);
public getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]> {
return this.store.getContractDataAndBytecodeInBlock(blockNum);
}

/**
* Lookup the L2 contract info for this contract.
* Lookup the contract data for this contract.
* Contains contract address & the ethereum portal address.
* @param contractAddress - The contract data address.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
public getL2ContractInfo(contractAddress: AztecAddress): Promise<ContractData | undefined> {
return this.store.getL2ContractInfo(contractAddress);
public getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
return this.store.getContractData(contractAddress);
}

/**
* Lookup the L2 contract info inside a block.
* Lookup the L2 contract data inside a block.
* Contains contract address & the ethereum portal address.
* @param l2BlockNum - The L2 block number to get the contract data from.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
public getL2ContractInfoInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
return this.store.getL2ContractInfoInBlock(l2BlockNum);
public getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
return this.store.getContractDataInBlock(l2BlockNum);
}

/**
Expand All @@ -330,7 +330,7 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
contractAddress: AztecAddress,
functionSelector: Buffer,
): Promise<EncodedContractFunction | undefined> {
const contractData = await this.getL2ContractPublicData(contractAddress);
const contractData = await this.getContractDataAndBytecode(contractAddress);
const result = contractData?.publicFunctions?.find(fn => fn.functionSelector.equals(functionSelector));
return result;
}
Expand Down
48 changes: 24 additions & 24 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import {
ContractData,
ContractPublicData,
ContractDataAndBytecode,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L2Block,
Expand All @@ -14,7 +14,7 @@ import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_messag

/**
* Interface describing a data store to be used by the archiver to store all its relevant data
* (blocks, encrypted logs, aztec contract public data).
* (blocks, encrypted logs, aztec contract data and bytecode).
*/
export interface ArchiverDataStore {
/**
Expand Down Expand Up @@ -86,42 +86,42 @@ export interface ArchiverDataStore {
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]>;

/**
* Store new Contract Public Data from an L2 block to the store's list.
* Store new Contract data and bytecode from an L2 block to the store's list.
* @param data - List of contracts' data to be added.
* @param blockNum - Number of the L2 block the contract data was deployed in.
* @returns True if the operation is successful.
*/
addL2ContractPublicData(data: ContractPublicData[], blockNum: number): Promise<boolean>;
addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean>;

/**
* Lookup the L2 contract data for a contract address.
* @param contractAddress - The contract data address.
* @returns The contract's public data.
*/
getL2ContractPublicData(contractAddress: AztecAddress): Promise<ContractPublicData | undefined>;
getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined>;

/**
* Lookup all contract data in an L2 block.
* Lookup all contract data and bytecode in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All contract public data in the block (if found).
* @returns All contract data and bytecode in the block (if found).
*/
getL2ContractPublicDataInBlock(blockNum: number): Promise<ContractPublicData[]>;
getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]>;

/**
* Get basic info for an L2 contract.
* Contains contract address & the ethereum portal address.
* @param contractAddress - The contract data address.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
getL2ContractInfo(contractAddress: AztecAddress): Promise<ContractData | undefined>;
getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined>;

/**
* Get basic info for an all L2 contracts deployed in a block.
* Contains contract address & the ethereum portal address.
* @param l2BlockNum - Number of the L2 block where contracts were deployed.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
getL2ContractInfoInBlock(l2BlockNum: number): Promise<ContractData[] | undefined>;
getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined>;

/**
* Gets the number of the latest L2 block processed.
Expand Down Expand Up @@ -160,7 +160,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
/**
* A sparse array containing all the contract data that have been fetched so far.
*/
private contractPublicData: (ContractPublicData[] | undefined)[] = [];
private contractDataAndBytecode: (ContractDataAndBytecode[] | undefined)[] = [];

/**
* Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
Expand Down Expand Up @@ -235,16 +235,16 @@ export class MemoryArchiverStore implements ArchiverDataStore {
}

/**
* Store new Contract Public Data from an L2 block to the store's list.
* Store new Contract data and bytecode from an L2 block to the store's list.
* @param data - List of contracts' data to be added.
* @param blockNum - Number of the L2 block the contract data was deployed in.
* @returns True if the operation is successful (always in this implementation).
*/
public addL2ContractPublicData(data: ContractPublicData[], blockNum: number): Promise<boolean> {
if (this.contractPublicData[blockNum]?.length) {
this.contractPublicData[blockNum]?.push(...data);
public addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean> {
if (this.contractDataAndBytecode[blockNum]?.length) {
this.contractDataAndBytecode[blockNum]?.push(...data);
} else {
this.contractPublicData[blockNum] = [...data];
this.contractDataAndBytecode[blockNum] = [...data];
}
return Promise.resolve(true);
}
Expand Down Expand Up @@ -315,10 +315,10 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @param contractAddress - The contract data address.
* @returns The contract's public data.
*/
public getL2ContractPublicData(contractAddress: AztecAddress): Promise<ContractPublicData | undefined> {
public getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
let result;
for (let i = INITIAL_L2_BLOCK_NUM; i < this.contractPublicData.length; i++) {
const contracts = this.contractPublicData[i];
for (let i = INITIAL_L2_BLOCK_NUM; i < this.contractDataAndBytecode.length; i++) {
const contracts = this.contractDataAndBytecode[i];
const contract = contracts?.find(c => c.contractData.contractAddress.equals(contractAddress));
if (contract) {
result = contract;
Expand All @@ -331,13 +331,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
/**
* Lookup all contract data in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All contract public data in the block (if found).
* @returns All contract data and bytecode in the block (if found).
*/
public getL2ContractPublicDataInBlock(blockNum: number): Promise<ContractPublicData[]> {
public getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]> {
if (blockNum > this.l2Blocks.length) {
return Promise.resolve([]);
}
return Promise.resolve(this.contractPublicData[blockNum] || []);
return Promise.resolve(this.contractDataAndBytecode[blockNum] || []);
}

/**
Expand All @@ -346,7 +346,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @param contractAddress - The contract data address.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
public getL2ContractInfo(contractAddress: AztecAddress): Promise<ContractData | undefined> {
public getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
if (contractAddress.isZero()) {
return Promise.resolve(undefined);
}
Expand All @@ -366,7 +366,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @param l2BlockNum - Number of the L2 block where contracts were deployed.
* @returns ContractData with the portal address (if we didn't throw an error).
*/
public getL2ContractInfoInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
public getContractDataInBlock(l2BlockNum: number): Promise<ContractData[] | undefined> {
if (l2BlockNum > this.l2Blocks.length) {
return Promise.resolve([]);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/data_retrieval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { ContractPublicData, L1ToL2Message, L2Block } from '@aztec/types';
import { ContractDataAndBytecode, L1ToL2Message, L2Block } from '@aztec/types';

import { PublicClient } from 'viem';

Expand Down Expand Up @@ -73,7 +73,7 @@ export async function retrieveBlocks(
* @param currentBlockNumber - Latest available block number in the ETH node.
* @param searchStartBlock - The block number to use for starting the search.
* @param blockHashMapping - A mapping from block number to relevant block hash.
* @returns An array of ContractPublicData and their equivalent L2 Block number along with the next eth block to search from..
* @returns An array of ContractDataAndBytecode and their equivalent L2 Block number along with the next eth block to search from..
*/
export async function retrieveNewContractData(
publicClient: PublicClient,
Expand All @@ -82,8 +82,8 @@ export async function retrieveNewContractData(
currentBlockNumber: bigint,
searchStartBlock: bigint,
blockHashMapping: { [key: number]: Buffer | undefined },
): Promise<DataRetrieval<[ContractPublicData[], number]>> {
let retrievedNewContracts: [ContractPublicData[], number][] = [];
): Promise<DataRetrieval<[ContractDataAndBytecode[], number]>> {
let retrievedNewContracts: [ContractDataAndBytecode[], number][] = [];
do {
if (searchStartBlock > currentBlockNumber) {
break;
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-art
import {
BufferReader,
ContractData,
ContractPublicData,
ContractDataAndBytecode,
EncodedContractFunction,
L1Actor,
L1ToL2Message,
Expand Down Expand Up @@ -163,13 +163,13 @@ export async function getContractDeploymentLogs(
* Processes newly received ContractDeployment logs.
* @param blockHashMapping - A mapping from block number to relevant block hash.
* @param logs - ContractDeployment logs.
* @returns The set of retrieved contract public data items.
* @returns The set of retrieved contract data and bytecode items.
*/
export function processContractDeploymentLogs(
blockHashMapping: { [key: number]: Buffer | undefined },
logs: Log<bigint, number, undefined, true, typeof ContractDeploymentEmitterAbi, 'ContractDeployment'>[],
): [ContractPublicData[], number][] {
const contractPublicData: [ContractPublicData[], number][] = [];
): [ContractDataAndBytecode[], number][] {
const contractDataAndBytecode: [ContractDataAndBytecode[], number][] = [];
for (let i = 0; i < logs.length; i++) {
const log = logs[i];
const l2BlockNum = Number(log.args.l2BlockNum);
Expand All @@ -179,17 +179,17 @@ export function processContractDeploymentLogs(
continue;
}
const publicFnsReader = BufferReader.asReader(Buffer.from(log.args.acir.slice(2), 'hex'));
const contractData = new ContractPublicData(
const contractData = new ContractDataAndBytecode(
new ContractData(AztecAddress.fromString(log.args.aztecAddress), EthAddress.fromString(log.args.portalAddress)),
publicFnsReader.readVector(EncodedContractFunction),
);
if (contractPublicData[i]) {
contractPublicData[i][0].push(contractData);
if (contractDataAndBytecode[i]) {
contractDataAndBytecode[i][0].push(contractData);
} else {
contractPublicData[i] = [[contractData], l2BlockNum];
contractDataAndBytecode[i] = [[contractData], l2BlockNum];
}
}
return contractPublicData;
return contractDataAndBytecode;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,25 @@ async function main() {
.action(async (contractAddress, options) => {
const client = createAztecRpcClient(options.rpcUrl);
const address = AztecAddress.fromString(contractAddress);
const contractDataOrInfo = options.includeBytecode
? await client.getContractData(address)
: await client.getContractInfo(address);
const contractDataWithOrWithoutBytecode = options.includeBytecode
? await client.getContractDataAndBytecode(address)
: await client.getContractData(address);

if (!contractDataOrInfo) {
if (!contractDataWithOrWithoutBytecode) {
log(`No contract data found at ${contractAddress}`);
return;
}
let contractData: ContractData;

if ('contractData' in contractDataOrInfo) {
contractData = contractDataOrInfo.contractData;
if ('contractData' in contractDataWithOrWithoutBytecode) {
contractData = contractDataWithOrWithoutBytecode.contractData;
} else {
contractData = contractDataOrInfo;
contractData = contractDataWithOrWithoutBytecode;
}
log(`\nContract Data: \nAddress: ${contractData.contractAddress.toString()}`);
log(`Portal: ${contractData.portalContractAddress.toString()}`);
if ('bytecode' in contractDataOrInfo) {
log(`Bytecode: ${contractDataOrInfo.bytecode}`);
if ('bytecode' in contractDataWithOrWithoutBytecode) {
log(`Bytecode: ${contractDataWithOrWithoutBytecode.bytecode}`);
}
log('\n');
});
Expand Down
Loading

0 comments on commit d7ffc33

Please sign in to comment.