Skip to content

Commit 301ca61

Browse files
nchamoNico Chamo
authored andcommitted
refactor(pxe): short-circuit block header lookup at anchor block (#23128)
## Summary - Skip the `aztecNode.getBlock` RPC in `getBlockHeader` when the requested block number matches the anchor — the anchor's header is already in memory. - Most utility executions query state at the anchor block, so this avoids a redundant round-trip on the hot path. Co-authored-by: Nico Chamo <nico.chamo@gmail.com>
1 parent e0366c9 commit 301ca61

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
307307
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
308308
}
309309

310+
// Most contracts query state at the "current" block, which is the anchor. Skip the RPC when we can.
311+
if (blockNumber === anchorBlockNumber) {
312+
return this.anchorBlockHeader;
313+
}
314+
310315
const block = await this.aztecNode.getBlock(blockNumber);
311316
return block?.header;
312317
}
@@ -995,6 +1000,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
9951000

9961001
/** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
9971002
async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
1003+
// Most contracts query state at the "current" block, which is the anchor. Skip the validation when we can.
9981004
const anchorHash = await this.anchorBlockHeader.hash();
9991005
if (blockHash.equals(anchorHash)) {
10001006
return query();

0 commit comments

Comments
 (0)