From e930fcd6a2e4489089310d227d5f225ee23c3b76 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Dec 2024 18:19:57 +0000 Subject: [PATCH 1/4] fix: fully wait for block synch --- .../archiver/src/archiver/archiver.ts | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 550e98ce172..94c664d0f11 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -922,28 +922,28 @@ class ArchiverStoreHelper } async addBlocks(blocks: L1Published[]): Promise { - 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 { @@ -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)), From 8083d38ad01ed1dfd501b0dd43e48753f94c05eb Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Dec 2024 20:15:39 +0000 Subject: [PATCH 2/4] chore: logs --- yarn-project/archiver/src/archiver/archiver.ts | 5 ++++- yarn-project/aztec.js/src/contract/deploy_method.ts | 4 +++- yarn-project/aztec.js/src/deployment/register_class.ts | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 94c664d0f11..5e093a13588 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -827,8 +827,11 @@ class ArchiverStoreHelper .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data)) .map(log => ContractClassRegisteredEvent.fromLog(log.data)) .map(e => e.toContractClassPublic()); + this.#log.info( + `Block ${blockNum} has ${allLogs.length} logs, of which ${contractClasses} contract class registration events`, + ); if (contractClasses.length > 0) { - contractClasses.forEach(c => this.#log.verbose(`Registering contract class ${c.id.toString()}`)); + contractClasses.forEach(c => this.#log.info(`Registering contract class ${c.id.toString()}`)); if (operation == Operation.Store) { // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive return await this.store.addContractClasses( diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 9b45db9b49c..909c6b46bb5 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -234,8 +234,10 @@ export class DeployMethod extends Bas */ public override async prove(options: DeployOptions): Promise> { const txProvingResult = await this.proveInternal(options); + const tx = txProvingResult.toTx(); const instance = this.getInstance(options); - return new DeployProvenTx(this.wallet, txProvingResult.toTx(), this.postDeployCtor, instance); + this.log.info(`Tx ${tx.getTxHash()} contains ${tx.contractClassLogs.unrollLogs().length} contract class logs`); + return new DeployProvenTx(this.wallet, tx, this.postDeployCtor, instance); } /** diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index eaaba5e8b95..2875655360a 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -22,5 +22,6 @@ export async function registerContractClass( const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS); const registerer = getRegistererContract(wallet); await wallet.addCapsule(encodedBytecode); + console.log({ contract: artifact.name, emitPublicBytecode }); return registerer.methods.register(artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode); } From 9268fc1f2fb9e3e2596e3772443c7e03ac87978c Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Dec 2024 21:26:54 +0000 Subject: [PATCH 3/4] fix: publicly register class --- yarn-project/aztec.js/src/contract/deploy_method.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 909c6b46bb5..262406f004b 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -89,6 +89,11 @@ export class DeployMethod extends Bas * it returns a promise for an array instead of a function call directly. */ public async request(options: DeployOptions = {}): Promise { + 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, @@ -97,7 +102,6 @@ export class DeployMethod 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) { From 58360b822264dad6ed4b0bf18fc17c7b7566ff94 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 3 Dec 2024 22:28:31 +0000 Subject: [PATCH 4/4] Revert "chore: logs" This reverts commit 123309c89244762a2f7bbb446faea9c6518a2bb8. --- yarn-project/archiver/src/archiver/archiver.ts | 5 +---- yarn-project/aztec.js/src/contract/deploy_method.ts | 4 +--- yarn-project/aztec.js/src/deployment/register_class.ts | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 5e093a13588..94c664d0f11 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -827,11 +827,8 @@ class ArchiverStoreHelper .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data)) .map(log => ContractClassRegisteredEvent.fromLog(log.data)) .map(e => e.toContractClassPublic()); - this.#log.info( - `Block ${blockNum} has ${allLogs.length} logs, of which ${contractClasses} contract class registration events`, - ); if (contractClasses.length > 0) { - contractClasses.forEach(c => this.#log.info(`Registering contract class ${c.id.toString()}`)); + contractClasses.forEach(c => this.#log.verbose(`Registering contract class ${c.id.toString()}`)); if (operation == Operation.Store) { // TODO: Will probably want to create some worker threads to compute these bytecode commitments as they are expensive return await this.store.addContractClasses( diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 262406f004b..869981308a7 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -238,10 +238,8 @@ export class DeployMethod extends Bas */ public override async prove(options: DeployOptions): Promise> { const txProvingResult = await this.proveInternal(options); - const tx = txProvingResult.toTx(); const instance = this.getInstance(options); - this.log.info(`Tx ${tx.getTxHash()} contains ${tx.contractClassLogs.unrollLogs().length} contract class logs`); - return new DeployProvenTx(this.wallet, tx, this.postDeployCtor, instance); + return new DeployProvenTx(this.wallet, txProvingResult.toTx(), this.postDeployCtor, instance); } /** diff --git a/yarn-project/aztec.js/src/deployment/register_class.ts b/yarn-project/aztec.js/src/deployment/register_class.ts index 2875655360a..eaaba5e8b95 100644 --- a/yarn-project/aztec.js/src/deployment/register_class.ts +++ b/yarn-project/aztec.js/src/deployment/register_class.ts @@ -22,6 +22,5 @@ export async function registerContractClass( const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS); const registerer = getRegistererContract(wallet); await wallet.addCapsule(encodedBytecode); - console.log({ contract: artifact.name, emitPublicBytecode }); return registerer.methods.register(artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode); }