Skip to content

Commit 3bc986d

Browse files
authored
refactor: optimizing utilityStorageRead (#19921)
We fetched individually slots sequentially instead of doing so in parallel in the oracle handler. In this PR I address that.
2 parents 7eabcd2 + 6a7be6f commit 3bc986d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
323323
startStorageSlot: Fr,
324324
numberOfElements: number,
325325
) {
326-
const values = [];
326+
const slots = Array(numberOfElements)
327+
.fill(0)
328+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
327329

328-
// TODO: why do we serialize these requests? This should probably a single call
329-
// Privacy considerations?
330-
for (let i = 0n; i < numberOfElements; i++) {
331-
const storageSlot = new Fr(startStorageSlot.value + i);
332-
const value = await this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot);
330+
const values = await Promise.all(
331+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
332+
);
333+
334+
this.log.debug(
335+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
336+
);
333337

334-
this.log.debug(
335-
`Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
336-
);
337-
values.push(value);
338-
}
339338
return values;
340339
}
341340

0 commit comments

Comments
 (0)