Skip to content

Commit

Permalink
fix: publicly register contract classes (#10385)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr authored Dec 3, 2024
1 parent e6060ec commit 94e6e1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
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([
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

0 comments on commit 94e6e1a

Please sign in to comment.