Skip to content

Commit 0628844

Browse files
nchamoaztec-bot
authored andcommitted
refactor(pxe): skip redundant getBlock RPC when querying at anchor block (#23100)
1 parent 6696135 commit 0628844

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 () => {
@@ -1005,7 +1010,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
10051010

10061011
if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
10071012
throw new Error(
1008-
`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()}).`,
1013+
`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}).`,
10091014
);
10101015
}
10111016
})(),

0 commit comments

Comments
 (0)