-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Quick TXE after public executor changes (#8661)
This PR https://github.com/AztecProtocol/aztec-packages/pull/8585/files made it so the TXE uses a world state db. But a fresh one is created for every call so all the changes uncommited to the tree were lost. --------- Co-authored-by: ludamad <[email protected]>
- Loading branch information
1 parent
22f6084
commit 48a715b
Showing
4 changed files
with
58 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { MerkleTreeId, type MerkleTreeOperations } from '@aztec/circuit-types'; | ||
import { | ||
type AztecAddress, | ||
Fr, | ||
PUBLIC_DATA_SUBTREE_HEIGHT, | ||
PublicDataTreeLeaf, | ||
type PublicDataTreeLeafPreimage, | ||
} from '@aztec/circuits.js'; | ||
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; | ||
import { WorldStateDB } from '@aztec/simulator'; | ||
import { type ContractDataSource } from '@aztec/types/contracts'; | ||
|
||
export class TXEWorldStateDB extends WorldStateDB { | ||
constructor(private merkleDb: MerkleTreeOperations, dataSource: ContractDataSource) { | ||
super(merkleDb, dataSource); | ||
} | ||
|
||
override async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> { | ||
const leafSlot = computePublicDataTreeLeafSlot(contract, slot).toBigInt(); | ||
|
||
const lowLeafResult = await this.merkleDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot); | ||
|
||
let value = Fr.ZERO; | ||
if (lowLeafResult && lowLeafResult.alreadyPresent) { | ||
const preimage = (await this.merkleDb.getLeafPreimage( | ||
MerkleTreeId.PUBLIC_DATA_TREE, | ||
lowLeafResult.index, | ||
)) as PublicDataTreeLeafPreimage; | ||
value = preimage.value; | ||
} | ||
return value; | ||
} | ||
|
||
override async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<bigint> { | ||
await this.merkleDb.batchInsert( | ||
MerkleTreeId.PUBLIC_DATA_TREE, | ||
[new PublicDataTreeLeaf(computePublicDataTreeLeafSlot(contract, slot), newValue).toBuffer()], | ||
PUBLIC_DATA_SUBTREE_HEIGHT, | ||
); | ||
return newValue.toBigInt(); | ||
} | ||
|
||
override checkpoint(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
override rollbackToCheckpoint(): Promise<void> { | ||
throw new Error('Cannot rollback'); | ||
} | ||
override commit(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
override rollbackToCommit(): Promise<void> { | ||
throw new Error('Cannot rollback'); | ||
} | ||
} |