Skip to content

Commit eeacc9d

Browse files
Nico Chamonchamo
authored andcommitted
refactor(pxe): skip redundant getBlock RPC when querying at anchor block
1 parent 4b5178a commit eeacc9d

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
@@ -995,6 +995,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
995995

996996
/** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
997997
async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
998+
const anchorHash = await this.anchorBlockHeader.hash();
999+
if (blockHash.equals(anchorHash)) {
1000+
return query();
1001+
}
1002+
9981003
const [response] = await Promise.all([
9991004
query(),
10001005
(async () => {
@@ -1006,7 +1011,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
10061011

10071012
if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
10081013
throw new Error(
1009-
`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()}).`,
1014+
`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}).`,
10101015
);
10111016
}
10121017
})(),

0 commit comments

Comments
 (0)