Skip to content

Commit d0cbb19

Browse files
author
Nico Chamo
committed
refactor(pxe): skip redundant getBlock RPC when querying at anchor block
1 parent 420fd55 commit d0cbb19

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution_oracle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
978978

979979
/** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
980980
async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
981+
const anchorHash = await this.anchorBlockHeader.hash();
982+
if (blockHash.equals(anchorHash)) {
983+
return query();
984+
}
985+
981986
const [response] = await Promise.all([
982987
query(),
983988
(async () => {
@@ -989,7 +994,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
989994

990995
if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
991996
throw new Error(
992-
`Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${await this.anchorBlockHeader.hash()}).`,
997+
`Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${anchorHash}).`,
993998
);
994999
}
9951000
})(),

0 commit comments

Comments
 (0)