Repository navigation
feat: Speed up transaction execution #10172
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 all commits
bf362b8
759143b
c52e2fd
3c8e324
7d46400
2843505
0da28dc
b9dc6ac
92cdace
a0c21fc
f932cf3
05159b8
d01a9e3
95adcfc
3b73deb
8455cbf
57f5749
0cc95a4
3e5c8c5
332894f
41bca92
a5e9c16
cd6ba1c
98b957d
9439407
ae26b46
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 |
|---|---|---|
|
|
@@ -228,6 +228,7 @@ | |
| "rollups", | ||
| "rushstack", | ||
| "sanitise", | ||
| "sanitised", | ||
| "schnorr", | ||
| "secp", | ||
| "SEMRESATTRS", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import { | |
| type Header, | ||
| type UnconstrainedFunctionWithMembershipProof, | ||
| } from '@aztec/circuits.js'; | ||
| import { type ContractArtifact } from '@aztec/foundation/abi'; | ||
| import { type ContractArtifact, FunctionSelector } from '@aztec/foundation/abi'; | ||
| import { type AztecAddress } from '@aztec/foundation/aztec-address'; | ||
| import { createDebugLogger } from '@aztec/foundation/log'; | ||
| import { type AztecKVStore } from '@aztec/kv-store'; | ||
|
|
@@ -46,6 +46,7 @@ export class KVArchiverDataStore implements ArchiverDataStore { | |
| #contractClassStore: ContractClassStore; | ||
| #contractInstanceStore: ContractInstanceStore; | ||
| #contractArtifactStore: ContractArtifactsStore; | ||
| private functionNames = new Map<string, string>(); | ||
|
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. Shouldn't this be persisted, as opposed to an in-memory Map? If we do it memory-only as a cache, then the getter should recalculate it on a miss.
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. As discussed. These are currently in memory only as they are a debugging feature that is perhaps not a full feature of the node or it's api. I've commented that this needs to be reviewed along with other similar features. |
||
|
|
||
| #log = createDebugLogger('aztec:archiver:data-store'); | ||
|
|
||
|
|
@@ -63,8 +64,19 @@ export class KVArchiverDataStore implements ArchiverDataStore { | |
| return Promise.resolve(this.#contractArtifactStore.getContractArtifact(address)); | ||
| } | ||
|
|
||
| addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise<void> { | ||
| return this.#contractArtifactStore.addContractArtifact(address, contract); | ||
| // TODO: These function names are in memory only as they are for development/debugging. They require the full contract | ||
| // artifact supplied to the node out of band. This should be reviewed and potentially removed as part of | ||
| // the node api cleanup process. | ||
| getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> { | ||
| return Promise.resolve(this.functionNames.get(selector.toString())); | ||
| } | ||
|
|
||
| async addContractArtifact(address: AztecAddress, contract: ContractArtifact): Promise<void> { | ||
| await this.#contractArtifactStore.addContractArtifact(address, contract); | ||
| // Building tup this map of selectors to function names save expensive re-hydration of contract artifacts later | ||
| contract.functions.forEach(f => { | ||
| this.functionNames.set(FunctionSelector.fromNameAndParameters(f.name, f.parameters).toString(), f.name); | ||
| }); | ||
|
Comment on lines
+77
to
+79
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. This will cause issues down the road with selector clashes. A selector is just 4 bytes (we're borrowing this from Ethereum), so it's relatively easy to stumble upon a collision. Indexing the Unfortunately, I think the only recourse is to store both contract class id and selector as key.
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. Fun fact: proxies built using the DELEGATECALL pattern in Ethereum were subject to a vulnerability caused by selector clashing. https://forum.openzeppelin.com/t/beware-of-the-proxy-learn-how-to-exploit-function-clashing/1070 |
||
| } | ||
|
|
||
| getContractClass(id: Fr): Promise<ContractClassPublic | undefined> { | ||
|
|
@@ -76,11 +88,20 @@ export class KVArchiverDataStore implements ArchiverDataStore { | |
| } | ||
|
|
||
| getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> { | ||
| return Promise.resolve(this.#contractInstanceStore.getContractInstance(address)); | ||
| const contract = this.#contractInstanceStore.getContractInstance(address); | ||
| return Promise.resolve(contract); | ||
| } | ||
|
|
||
| async addContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean> { | ||
| return (await Promise.all(data.map(c => this.#contractClassStore.addContractClass(c, blockNumber)))).every(Boolean); | ||
| async addContractClasses( | ||
| data: ContractClassPublic[], | ||
| bytecodeCommitments: Fr[], | ||
| blockNumber: number, | ||
| ): Promise<boolean> { | ||
| return ( | ||
| await Promise.all( | ||
| data.map((c, i) => this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)), | ||
| ) | ||
| ).every(Boolean); | ||
| } | ||
|
|
||
| async deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean> { | ||
|
|
@@ -89,6 +110,10 @@ export class KVArchiverDataStore implements ArchiverDataStore { | |
| ); | ||
| } | ||
|
|
||
| getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> { | ||
| return Promise.resolve(this.#contractClassStore.getBytecodeCommitment(contractClassId)); | ||
| } | ||
|
|
||
| addFunctions( | ||
| contractClassId: Fr, | ||
| privateFunctions: ExecutablePrivateFunctionWithMembershipProof[], | ||
|
|
||
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.
I don't think there are any cases where we want the bytecode commitment but not the bytecode, right? If so, instead of having a separate getter for the bytecode commitment, I'd just store it along with the rest of the contract class in the same store, so we don't have to query for them separately. But this is just a cleanup, no need to do now.