-
Notifications
You must be signed in to change notification settings - Fork 613
feat: contract class must be registered before deployment #10949
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
Changes from 19 commits
22752a0
c410d72
8c17959
a94436e
1a48caa
d00b64c
e61d500
359b483
8a35ea1
447e98d
161e18b
f569eb7
343d427
ee0a397
dcb4cb4
ac88083
9405f40
629796e
b0a937b
9f169f5
697e6e8
b29723b
21b6d79
8ff02f9
f27f6bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,8 +114,28 @@ export class FullProverTest { | |
| await this.snapshotManager.snapshot('2_accounts', addAccounts(2, this.logger), async ({ accountKeys }, { pxe }) => { | ||
| this.keys = accountKeys; | ||
| const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], SALT)); | ||
| this.wallets = await Promise.all(accountManagers.map(a => a.getWallet())); | ||
| this.accounts = await pxe.getRegisteredAccounts(); | ||
| this.wallets = (await Promise.all(accountManagers.map(a => a.getWallet()))).sort((aWallet, bWallet) => { | ||
| const a = aWallet.getAddress().toBigInt(); | ||
| const b = bWallet.getAddress().toBigInt(); | ||
| if (a < b) { | ||
| return -1; | ||
| } else if (a > b) { | ||
| return 1; | ||
| } else { | ||
| return 0; | ||
| } | ||
| }); | ||
| this.accounts = (await pxe.getRegisteredAccounts()).sort((aAccount, bAccount) => { | ||
| const a = aAccount.address.toBigInt(); | ||
| const b = bAccount.address.toBigInt(); | ||
| if (a < b) { | ||
| return -1; | ||
| } else if (a > b) { | ||
| return 1; | ||
| } else { | ||
| return 0; | ||
| } | ||
| }); | ||
| this.wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`)); | ||
|
Comment on lines
116
to
119
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to do something like this instead of what I had done here dcb4cb4 because it is later assumed that Even if all tests pass, I wouldn't be surprised if we run into issues/flakes down the line because of ordering mismatches in other tests. So, my questions are:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved it into a helper for now
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't think of a reason why this is happening now. But I think the easiest thing is to not get the registered accounts from the pxe but from the account managers themselves, so we ensure the order is the same. WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try that! |
||
| }); | ||
|
Comment on lines
113
to
120
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,12 @@ import { | |
| type CompleteAddress, | ||
| type DeployL1Contracts, | ||
| Fr, | ||
| type FunctionCall, | ||
| GrumpkinScalar, | ||
| type Logger, | ||
| type PXE, | ||
| type Wallet, | ||
| getContractClassFromArtifact, | ||
| } from '@aztec/aztec.js'; | ||
| import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; | ||
| import { type BlobSinkServer, createBlobSinkServer } from '@aztec/blob-sink/server'; | ||
|
|
@@ -550,13 +552,22 @@ export const addAccounts = | |
|
|
||
| logger.verbose('Simulating account deployment...'); | ||
| const provenTxs = await Promise.all( | ||
| accountKeys.map(async ([secretKey, signPk]) => { | ||
| accountKeys.map(async ([secretKey, signPk], index) => { | ||
| const account = getSchnorrAccount(pxe, secretKey, signPk, 1); | ||
| const deployMethod = await account.getDeployMethod(); | ||
|
|
||
| // only register the contract class once | ||
| let skipClassRegistration = true; | ||
| if (index === 0) { | ||
| // for the first account, check if the contract class is already registered, otherwise we should register now | ||
| if (!(await pxe.isContractClassPubliclyRegistered(account.getInstance().contractClassId))) { | ||
| skipClassRegistration = false; | ||
| } | ||
| } | ||
|
|
||
| const deployMethod = await account.getDeployMethod(); | ||
| const provenTx = await deployMethod.prove({ | ||
| contractAddressSalt: account.salt, | ||
| skipClassRegistration: true, | ||
| skipClassRegistration, | ||
| skipPublicDeployment: true, | ||
| universalDeploy: true, | ||
| }); | ||
|
|
@@ -589,9 +600,16 @@ export async function publicDeployAccounts( | |
| ) { | ||
| const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a)); | ||
| const instances = await Promise.all(accountAddressesToDeploy.map(account => sender.getContractInstance(account))); | ||
| const batch = new BatchCall(sender, [ | ||
| (await registerContractClass(sender, SchnorrAccountContractArtifact)).request(), | ||
| ...instances.map(instance => deployInstance(sender, instance!).request()), | ||
| ]); | ||
|
|
||
| const contractClass = getContractClassFromArtifact(SchnorrAccountContractArtifact); | ||
| const alreadyRegistered = await sender.isContractClassPubliclyRegistered(contractClass.id); | ||
|
|
||
| const calls: FunctionCall[] = []; | ||
| if (!alreadyRegistered) { | ||
| calls.push((await registerContractClass(sender, SchnorrAccountContractArtifact)).request()); | ||
| } | ||
| calls.push(...instances.map(instance => deployInstance(sender, instance!).request())); | ||
|
|
||
| const batch = new BatchCall(sender, calls); | ||
|
Comment on lines
-592
to
+613
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't batch a call to register the class if it is already registered |
||
| await batch.send().wait({ proven: waitUntilProven }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need better error messages :-P