Skip to content
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

chore: Delete ExtendedContractData struct #5248

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
ContractData,
ContractDataSource,
EncodedContractFunction,
ExtendedContractData,
GetUnencryptedLogsResponse,
L1ToL2Message,
L1ToL2MessageSource,
Expand All @@ -27,7 +25,7 @@ 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 { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
import { ContractClassPublic, ContractInstanceWithAddress, PublicFunction } from '@aztec/types/contracts';

import { Chain, HttpTransport, PublicClient, createPublicClient, getAddress, getContract, http } from 'viem';

Expand Down Expand Up @@ -425,37 +423,6 @@ export class Archiver implements ArchiveSource {
return this.store.getSettledTxReceipt(txHash);
}

/**
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The extended contract data or undefined if not found.
*/
public async getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
return (
(await this.store.getExtendedContractData(contractAddress)) ?? this.makeExtendedContractDataFor(contractAddress)
);
}

/**
* Temporary method for creating a fake extended contract data out of classes and instances registered in the node.
* Used as a fallback if the extended contract data is not found.
* TODO(palla/purge-old-contract-deploy): Use proper classes
*/
private async makeExtendedContractDataFor(address: AztecAddress): Promise<ExtendedContractData | undefined> {
const instance = await this.store.getContractInstance(address);
if (!instance) {
return undefined;
}

const contractClass = await this.store.getContractClass(instance.contractClassId);
if (!contractClass) {
this.log.warn(`Class ${instance.contractClassId.toString()} for address ${address.toString()} not found`);
return undefined;
}

return ExtendedContractData.fromClassAndInstance(contractClass, instance);
}

/**
* Lookup the contract data for this contract.
* Contains contract address & the ethereum portal address.
Expand All @@ -481,16 +448,23 @@ export class Archiver implements ArchiveSource {

/**
* Gets the public function data for a contract.
* @param contractAddress - The contract address containing the function to fetch.
* @param address - The contract address containing the function to fetch.
* @param selector - The function selector of the function to fetch.
* @returns The public function data (if found).
*/
public async getPublicFunction(
contractAddress: AztecAddress,
address: AztecAddress,
selector: FunctionSelector,
): Promise<EncodedContractFunction | undefined> {
const contractData = await this.getExtendedContractData(contractAddress);
return contractData?.getPublicFunction(selector);
): Promise<PublicFunction | undefined> {
const instance = await this.getContract(address);
if (!instance) {
throw new Error(`Contract ${address.toString()} not found`);
}
const contractClass = await this.getContractClass(instance.contractClassId);
if (!contractClass) {
throw new Error(`Contract class ${instance.contractClassId.toString()} for ${address.toString()} not found`);
}
return contractClass.publicFunctions.find(f => f.selector.equals(selector));
}

/**
Expand Down
16 changes: 0 additions & 16 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Body,
ExtendedContractData,
GetUnencryptedLogsResponse,
L1ToL2Message,
L2Block,
Expand Down Expand Up @@ -164,21 +163,6 @@ export interface ArchiverDataStore {
*/
getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse>;

/**
* Add new extended contract data 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.
*/
addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean>;

/**
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The extended contract data or undefined if not found.
*/
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined>;

/**
* Gets the number of the latest L2 block processed.
* @returns The number of the latest L2 block processed.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Body,
ExtendedContractData,
GetUnencryptedLogsResponse,
L1ToL2Message,
L2Block,
Expand All @@ -23,7 +22,6 @@ import { BlockBodyStore } from './block_body_store.js';
import { BlockStore } from './block_store.js';
import { ContractClassStore } from './contract_class_store.js';
import { ContractInstanceStore } from './contract_instance_store.js';
import { ContractStore } from './contract_store.js';
import { LogStore } from './log_store.js';
import { MessageStore } from './message_store.js';

Expand All @@ -34,7 +32,6 @@ export class KVArchiverDataStore implements ArchiverDataStore {
#blockStore: BlockStore;
#blockBodyStore: BlockBodyStore;
#logStore: LogStore;
#contractStore: ContractStore;
#messageStore: MessageStore;
#contractClassStore: ContractClassStore;
#contractInstanceStore: ContractInstanceStore;
Expand All @@ -45,7 +42,6 @@ export class KVArchiverDataStore implements ArchiverDataStore {
this.#blockBodyStore = new BlockBodyStore(db);
this.#blockStore = new BlockStore(db, this.#blockBodyStore);
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
this.#contractStore = new ContractStore(db, this.#blockStore);
this.#messageStore = new MessageStore(db);
this.#contractClassStore = new ContractClassStore(db);
this.#contractInstanceStore = new ContractInstanceStore(db);
Expand Down Expand Up @@ -252,25 +248,6 @@ export class KVArchiverDataStore implements ArchiverDataStore {
}
}

/**
* Add new extended contract data 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.
*/
addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
return this.#contractStore.addExtendedContractData(data, blockNum);
}

/**
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The extended contract data or undefined if not found.
*/
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
return Promise.resolve(this.#contractStore.getExtendedContractData(contractAddress));
}

/**
* Gets the number of the latest L2 block processed.
* @returns The number of the latest L2 block processed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Body,
ExtendedContractData,
ExtendedUnencryptedL2Log,
GetUnencryptedLogsResponse,
L1ToL2Message,
Expand Down Expand Up @@ -55,16 +54,6 @@ export class MemoryArchiverStore implements ArchiverDataStore {
*/
private unencryptedLogsPerBlock: L2BlockL2Logs[] = [];

/**
* A sparse array containing all the extended contract data that have been fetched so far.
*/
private extendedContractDataByBlock: (ExtendedContractData[] | undefined)[] = [];

/**
* A mapping of contract address to extended contract data.
*/
private extendedContractData: Map<string, ExtendedContractData> = new Map();

// TODO(#4492): Nuke the other message stores
private newL1ToL2Messages = new NewL1ToL2MessageStore();

Expand Down Expand Up @@ -249,28 +238,6 @@ export class MemoryArchiverStore implements ArchiverDataStore {
return Promise.resolve(true);
}

/**
* Store new extended contract data 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 addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
// Add to the contracts mapping
for (const contractData of data) {
const key = contractData.contractData.contractAddress.toString();
this.extendedContractData.set(key, contractData);
}

// Add the index per block
if (this.extendedContractDataByBlock[blockNum]?.length) {
this.extendedContractDataByBlock[blockNum]?.push(...data);
} else {
this.extendedContractDataByBlock[blockNum] = [...data];
}
return Promise.resolve(true);
}

/**
* Gets up to `limit` amount of L2 blocks starting from `from`.
* @param from - Number of the first block to return (inclusive).
Expand Down Expand Up @@ -456,17 +423,6 @@ export class MemoryArchiverStore implements ArchiverDataStore {
});
}

/**
* Get the extended contract data for this contract.
* TODO(palla/purge-old-contract-deploy): Delete me?
* @param contractAddress - The contract data address.
* @returns The extended contract data or undefined if not found.
*/
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
const result = this.extendedContractData.get(contractAddress.toString());
return Promise.resolve(result);
}

/**
* Gets the number of the latest L2 block processed.
* @returns The number of the latest L2 block processed.
Expand Down
4 changes: 0 additions & 4 deletions yarn-project/archiver/src/rpc/archiver_client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ContractData,
EncodedContractFunction,
ExtendedContractData,
ExtendedUnencryptedL2Log,
L1ToL2Message,
L2Block,
Expand All @@ -19,9 +17,7 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t
url,
{
ContractData,
EncodedContractFunction,
EthAddress,
ExtendedContractData,
ExtendedUnencryptedL2Log,
Fr,
L1ToL2Message,
Expand Down
4 changes: 0 additions & 4 deletions yarn-project/archiver/src/rpc/archiver_server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ContractData,
EncodedContractFunction,
ExtendedContractData,
ExtendedUnencryptedL2Log,
L1ToL2Message,
L2Block,
Expand All @@ -25,9 +23,7 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe
archiverService,
{
ContractData,
EncodedContractFunction,
EthAddress,
ExtendedContractData,
ExtendedUnencryptedL2Log,
Fr,
L1ToL2Message,
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AztecNode,
ContractData,
ExtendedContractData,
ExtendedUnencryptedL2Log,
L1ToL2MessageAndIndex,
L2Block,
Expand Down Expand Up @@ -31,7 +30,6 @@ export function createAztecNodeRpcServer(node: AztecNode) {
{
AztecAddress,
EthAddress,
ExtendedContractData,
ExtendedUnencryptedL2Log,
ContractData,
Fr,
Expand Down
10 changes: 0 additions & 10 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
AztecNode,
ContractData,
ContractDataSource,
ExtendedContractData,
GetUnencryptedLogsResponse,
L1ToL2MessageAndIndex,
L1ToL2MessageSource,
Expand Down Expand Up @@ -232,15 +231,6 @@ export class AztecNodeService implements AztecNode {
return Promise.resolve(this.chainId);
}

/**
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The extended contract data or undefined if not found.
*/
async getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
return await this.contractDataSource.getExtendedContractData(contractAddress);
}

/**
* Lookup the contract data for this contract.
* Contains the ethereum portal address .
Expand Down
Loading
Loading