refactor(txe): migrate rpc_translator to typed oracle registry#23530
refactor(txe): migrate rpc_translator to typed oracle registry#23530nchamo wants to merge 3 commits into
Conversation
| import { packAsHintedNote } from './note_packing_utils.js'; | ||
|
|
||
| const FIELD: TypeMapping<Fr> = { | ||
| export const FIELD: TypeMapping<Fr> = { |
There was a problem hiding this comment.
We export the ones we need over at TXE's registry
| nullifierExists(siloedNullifier: Fr): Promise<boolean>; | ||
| storageWrite(slot: Fr, value: Fr): Promise<void>; | ||
| storageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr>; | ||
| getContractInstanceDeployer(address: AztecAddress): Promise<{ member: Fr; exists: boolean }>; |
There was a problem hiding this comment.
Previously, oracles like aztec_avm_getContractInstanceDeployer did something like this:
{
const address = addressFromSingle(foreignAddress);
const instance = await this.handlerAsUtility().getContractInstance(address);
return toForeignCallResult([
toSingle(instance.deployer),
// AVM requires an extra boolean indicating the instance was found
toSingle(new Fr(1)),
]);
}The thing is that we needed to get this logic out of rpc_translator.ts. I considered a few different options, but I decided that it would be best to add this logic to the avm handler
If you think about it, we want to get to an auto-generated world where the oracle call aztec_avm_getContractInstanceDeployer auto-generates the function getContractInstanceDeployer on the interface. So I decided to do exactly that, but manually for now
| }) | ||
| ).map(e => e.packedEvent); | ||
|
|
||
| if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) { |
There was a problem hiding this comment.
Moved here this logic that was previously on rpc_translator.ts
| return callTxeHandler({ | ||
| oracle: 'aztec_txe_getPrivateEvents', | ||
| inputs, | ||
| handler: async ([selector, contractAddress, scope]) => { |
There was a problem hiding this comment.
This one needs more work. It would require a bigger refactor to have this be only a thin transport layer, so I decided to do that in future PR
| * - TXE_ORACLE_VERSION_MINOR for additive changes (new oracle method added). | ||
| */ | ||
| export const TXE_ORACLE_INTERFACE_HASH = '833b77ccdba925b1ed129028432c7d4b116867fb426cee40f9d6104c5aa31e42'; | ||
| export const TXE_ORACLE_INTERFACE_HASH = 'e191c3083fae4aed4802d9fe8f2fbf3366dcbd058b2096c24be1110250f40db2'; |
There was a problem hiding this comment.
The hash changed because we added new functions to the ts interface, but we didn't actually change the oracles. So no version bump
| deserialization: { fn: ([reader]) => reader.readField().toNumber() }, | ||
| }; | ||
|
|
||
| export const BIGINT: TypeMapping<bigint> = { |
There was a problem hiding this comment.
I decided to add here some of the mappings we need for TXE, but that we would probably need for PXE in the future
Summary
TXE_TX_EFFECTS,TXE_OFFCHAIN_EFFECTS,TXE_CALL_CONTEXT,CONTRACT_INSTANCE_MEMBER,TXE_PRIVATE_EVENTS, etc.).callTxeHandlerwith typed serialization/deserialization, so handlers become pure domain-type passthroughs.privateCallNewFlow,executeUtilityFunction,publicCallNewFlow) still contain orchestration logic (tracked by TODO(F-674)) that will be tackled in a follow-up.