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

fix: publicly register contract classes #10385

Merged
merged 4 commits into from
Dec 3, 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
44 changes: 23 additions & 21 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,28 +922,28 @@ class ArchiverStoreHelper
}

async addBlocks(blocks: L1Published<L2Block>[]): Promise<boolean> {
return [
const opResults = await Promise.all([
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same change as in #10380 but for adding blocks

this.store.addLogs(blocks.map(block => block.data)),
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
...(await Promise.all(
blocks.map(async block => {
const contractClassLogs = block.data.body.txEffects
.flatMap(txEffect => (txEffect ? [txEffect.contractClassLogs] : []))
.flatMap(txLog => txLog.unrollLogs());
// ContractInstanceDeployed event logs are broadcast in privateLogs.
const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
return (
await Promise.all([
this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Store),
this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Store),
this.#storeBroadcastedIndividualFunctions(contractClassLogs, block.data.number),
])
).every(Boolean);
}),
)),
...blocks.map(async block => {
const contractClassLogs = block.data.body.txEffects
.flatMap(txEffect => (txEffect ? [txEffect.contractClassLogs] : []))
.flatMap(txLog => txLog.unrollLogs());
// ContractInstanceDeployed event logs are broadcast in privateLogs.
const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);
return (
await Promise.all([
this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Store),
this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Store),
this.#storeBroadcastedIndividualFunctions(contractClassLogs, block.data.number),
])
).every(Boolean);
}),
this.store.addNullifiers(blocks.map(block => block.data)),
this.store.addBlocks(blocks),
].every(Boolean);
]);

return opResults.every(Boolean);
}

async unwindBlocks(from: number, blocksToUnwind: number): Promise<boolean> {
Expand All @@ -966,9 +966,11 @@ class ArchiverStoreHelper
const privateLogs = block.data.body.txEffects.flatMap(txEffect => txEffect.privateLogs);

return (
(await this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Delete)) &&
(await this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Delete))
);
await Promise.all([
this.#updateRegisteredContractClasses(contractClassLogs, block.data.number, Operation.Delete),
this.#updateDeployedContractInstances(privateLogs, block.data.number, Operation.Delete),
])
).every(Boolean);
}),

this.store.deleteLogs(blocks.map(b => b.data)),
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/aztec.js/src/contract/deploy_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
* it returns a promise for an array instead of a function call directly.
*/
public async request(options: DeployOptions = {}): Promise<ExecutionRequestInit> {
const deployment = await this.getDeploymentFunctionCalls(options);

// NOTE: MEGA HACK. Remove with #10007
// register the contract after generating deployment function calls in order to publicly register the class and (optioanlly) emit its bytecode
//
// TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
// Note that we need to run this registerContract here so it's available when computeFeeOptionsFromEstimatedGas
// runs, since it needs the contract to have been registered in order to estimate gas for its initialization,
Expand All @@ -97,7 +102,6 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
// once this tx has gone through.
await this.wallet.registerContract({ artifact: this.artifact, instance: this.getInstance(options) });

const deployment = await this.getDeploymentFunctionCalls(options);
const bootstrap = await this.getInitializeFunctionCalls(options);

if (deployment.calls.length + bootstrap.calls.length === 0) {
Expand Down
Loading