Skip to content

Commit 4d28f3e

Browse files
ThunkarAztecBot
authored andcommitted
fix: avoid calling the node for L2 tips on every sync (#22558)
`fetchTaggedLogs` repeatedly called the node for current timestamp and finalization block number. `PXE` triggers a sync just before simulation, so this is extremely wasteful and causes extra round trips on every sync
1 parent b98da73 commit 4d28f3e

14 files changed

Lines changed: 72 additions & 65 deletions

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
4242
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4343
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4444
import { AztecAddress } from '@aztec/stdlib/aztec-address';
45-
import type { BlockParameter } from '@aztec/stdlib/block';
45+
import type { BlockParameter, L2TipsProvider } from '@aztec/stdlib/block';
4646
import { Gas } from '@aztec/stdlib/gas';
4747
import {
4848
computeNoteHashNonce,
@@ -134,6 +134,7 @@ export type ContractFunctionSimulatorArgs = {
134134
keyStore: KeyStore;
135135
addressStore: AddressStore;
136136
aztecNode: AztecNode;
137+
l2TipsStore: L2TipsProvider;
137138
senderTaggingStore: SenderTaggingStore;
138139
recipientTaggingStore: RecipientTaggingStore;
139140
senderAddressBookStore: SenderAddressBookStore;
@@ -154,6 +155,7 @@ export class ContractFunctionSimulator {
154155
private readonly keyStore: KeyStore;
155156
private readonly addressStore: AddressStore;
156157
private readonly aztecNode: AztecNode;
158+
private readonly l2TipsStore: L2TipsProvider;
157159
private readonly senderTaggingStore: SenderTaggingStore;
158160
private readonly recipientTaggingStore: RecipientTaggingStore;
159161
private readonly senderAddressBookStore: SenderAddressBookStore;
@@ -169,6 +171,7 @@ export class ContractFunctionSimulator {
169171
this.keyStore = args.keyStore;
170172
this.addressStore = args.addressStore;
171173
this.aztecNode = args.aztecNode;
174+
this.l2TipsStore = args.l2TipsStore;
172175
this.senderTaggingStore = args.senderTaggingStore;
173176
this.recipientTaggingStore = args.recipientTaggingStore;
174177
this.senderAddressBookStore = args.senderAddressBookStore;
@@ -255,6 +258,7 @@ export class ContractFunctionSimulator {
255258
scopes,
256259
senderForTags,
257260
simulator: this.simulator,
261+
l2TipsStore: this.l2TipsStore,
258262
});
259263

260264
const setupTime = simulatorSetupTimer.ms();
@@ -344,6 +348,7 @@ export class ContractFunctionSimulator {
344348
privateEventStore: this.privateEventStore,
345349
messageContextService: this.messageContextService,
346350
contractSyncService: this.contractSyncService,
351+
l2TipsStore: this.l2TipsStore,
347352
jobId,
348353
scopes,
349354
});

yarn-project/pxe/src/contract_function_simulator/oracle/oracle_version_is_checked.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { OracleVersionCheckContractArtifact } from '@aztec/noir-test-contracts.j
44
import { WASMSimulator } from '@aztec/simulator/client';
55
import { FunctionCall, FunctionSelector, FunctionType, encodeArguments } from '@aztec/stdlib/abi';
66
import { AztecAddress } from '@aztec/stdlib/aztec-address';
7+
import type { L2TipsProvider } from '@aztec/stdlib/block';
78
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
89
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
910
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
@@ -43,6 +44,7 @@ describe('Oracle Version Check test suite', () => {
4344
let privateEventStore: ReturnType<typeof mock<PrivateEventStore>>;
4445
let contractSyncService: ReturnType<typeof mock<ContractSyncService>>;
4546
let messageContextService: ReturnType<typeof mock<MessageContextService>>;
47+
let l2TipsStore: ReturnType<typeof mock<L2TipsProvider>>;
4648
let acirSimulator: ContractFunctionSimulator;
4749
let contractAddress: AztecAddress;
4850
let anchorBlockHeader: BlockHeader;
@@ -63,6 +65,7 @@ describe('Oracle Version Check test suite', () => {
6365
privateEventStore = mock<PrivateEventStore>();
6466
contractSyncService = mock<ContractSyncService>();
6567
messageContextService = mock<MessageContextService>();
68+
l2TipsStore = mock<L2TipsProvider>();
6669
assertCompatibleOracleVersionSpy = jest.spyOn(UtilityExecutionOracle.prototype, 'assertCompatibleOracleVersion');
6770
assertCompatibleOracleVersionSpy.mockClear();
6871

@@ -99,6 +102,7 @@ describe('Oracle Version Check test suite', () => {
99102
keyStore,
100103
addressStore,
101104
aztecNode,
105+
l2TipsStore: mock(),
102106
senderTaggingStore,
103107
recipientTaggingStore,
104108
senderAddressBookStore,
@@ -208,6 +212,7 @@ describe('Oracle Version Check test suite', () => {
208212
contractSyncService,
209213
jobId: 'test',
210214
scopes: [],
215+
l2TipsStore,
211216
});
212217
});
213218

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
getFunctionArtifactByName,
3535
} from '@aztec/stdlib/abi';
3636
import { AztecAddress } from '@aztec/stdlib/aztec-address';
37-
import { BlockHash, type BlockParameter } from '@aztec/stdlib/block';
37+
import { BlockHash, type BlockParameter, type L2TipsProvider } from '@aztec/stdlib/block';
3838
import {
3939
CompleteAddress,
4040
getContractClassFromArtifact,
@@ -125,6 +125,7 @@ describe('Private Execution test suite', () => {
125125
let privateEventStore: MockProxy<PrivateEventStore>;
126126
let contractSyncService: MockProxy<ContractSyncService>;
127127
let messageContextService: MockProxy<MessageContextService>;
128+
let l2TipsStore: MockProxy<L2TipsProvider>;
128129
let acirSimulator: ContractFunctionSimulator;
129130
let anchorBlockHeader = BlockHeader.empty();
130131
let logger: Logger;
@@ -316,6 +317,7 @@ describe('Private Execution test suite', () => {
316317
aztecNode = mock<AztecNode>();
317318
keyStore = mock<KeyStore>();
318319
capsuleStore = mock<CapsuleStore>();
320+
l2TipsStore = mock<L2TipsProvider>();
319321
privateEventStore = mock<PrivateEventStore>();
320322
senderAddressBookStore = mock<SenderAddressBookStore>();
321323
contractSyncService = mock<ContractSyncService>();
@@ -356,13 +358,7 @@ describe('Private Execution test suite', () => {
356358
aztecNode.getPrivateLogsByTags.mockImplementation((tags: SiloedTag[]) => Promise.resolve(tags.map(() => [])));
357359

358360
// Mock getL2Tips and getBlockHeader for loadPrivateLogsForSenderRecipientPair
359-
aztecNode.getL2Tips.mockResolvedValue(makeL2Tips(anchorBlockHeader.globalVariables.blockNumber));
360-
aztecNode.getBlockHeader.mockImplementation((blockNumber: BlockNumber | 'latest') => {
361-
if (blockNumber === 'latest') {
362-
return Promise.resolve(anchorBlockHeader);
363-
}
364-
return Promise.resolve(anchorBlockHeader);
365-
});
361+
l2TipsStore.getL2Tips.mockResolvedValue(makeL2Tips(anchorBlockHeader.globalVariables.blockNumber));
366362

367363
// TODO: refactor. Maybe it's worth stubbing a key store
368364
// and cleaning up the mess that is setting up keys.
@@ -496,6 +492,7 @@ describe('Private Execution test suite', () => {
496492
keyStore,
497493
addressStore,
498494
aztecNode,
495+
l2TipsStore,
499496
senderTaggingStore,
500497
recipientTaggingStore,
501498
senderAddressBookStore,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
575575
log: this.logger,
576576
senderForTags: this.senderForTags,
577577
simulator: this.simulator!,
578+
l2TipsStore: this.l2TipsStore,
578579
});
579580

580581
const setupTime = simulatorSetupTimer.ms();

yarn-project/pxe/src/contract_function_simulator/oracle/utility_execution.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { StatefulTestContractArtifact } from '@aztec/noir-test-contracts.js/Stat
77
import { WASMSimulator } from '@aztec/simulator/client';
88
import { FunctionCall, FunctionSelector, FunctionType, encodeArguments } from '@aztec/stdlib/abi';
99
import { AztecAddress } from '@aztec/stdlib/aztec-address';
10-
import { BlockHash } from '@aztec/stdlib/block';
10+
import { BlockHash, type L2TipsProvider } from '@aztec/stdlib/block';
1111
import {
1212
CompleteAddress,
1313
type ContractInstanceWithAddress,
@@ -51,6 +51,7 @@ describe('Utility Execution test suite', () => {
5151
let capsuleStore: ReturnType<typeof mock<CapsuleStore>>;
5252
let privateEventStore: ReturnType<typeof mock<PrivateEventStore>>;
5353
let contractSyncService: ReturnType<typeof mock<ContractSyncService>>;
54+
let l2TipsStore: ReturnType<typeof mock<L2TipsProvider>>;
5455
let messageContextService: MessageContextService;
5556
let acirSimulator: ContractFunctionSimulator;
5657
let owner: AztecAddress;
@@ -74,6 +75,7 @@ describe('Utility Execution test suite', () => {
7475
capsuleStore = mock<CapsuleStore>();
7576
privateEventStore = mock<PrivateEventStore>();
7677
contractSyncService = mock<ContractSyncService>();
78+
l2TipsStore = mock<L2TipsProvider>();
7779
messageContextService = new MessageContextService(aztecNode);
7880
const capsuleArrays = new Map<string, Fr[][]>();
7981
anchorBlockHeader = BlockHeader.random();
@@ -83,14 +85,7 @@ describe('Utility Execution test suite', () => {
8385
senderTaggingStore.storePendingIndexes.mockResolvedValue();
8486
senderAddressBookStore.getSenders.mockResolvedValue([]);
8587

86-
// Mock getL2Tips and getBlockHeader for loadPrivateLogsForSenderRecipientPair
87-
aztecNode.getL2Tips.mockResolvedValue(makeL2Tips(anchorBlockHeader.globalVariables.blockNumber));
88-
aztecNode.getBlockHeader.mockImplementation((blockNumber: BlockNumber | 'latest') => {
89-
if (blockNumber === 'latest') {
90-
return Promise.resolve(anchorBlockHeader);
91-
}
92-
return Promise.resolve(anchorBlockHeader);
93-
});
88+
l2TipsStore.getL2Tips.mockResolvedValue(makeL2Tips(anchorBlockHeader.globalVariables.blockNumber));
9489
aztecNode.getPrivateLogsByTags.mockImplementation((tags: any[]) => Promise.resolve(tags.map(() => [])));
9590

9691
capsuleStore.setCapsuleArray.mockImplementation((address, slot, content) => {
@@ -106,6 +101,7 @@ describe('Utility Execution test suite', () => {
106101
keyStore,
107102
addressStore,
108103
aztecNode,
104+
l2TipsStore,
109105
senderTaggingStore,
110106
recipientTaggingStore,
111107
senderAddressBookStore,
@@ -350,6 +346,7 @@ describe('Utility Execution test suite', () => {
350346
contractSyncService,
351347
jobId: 'test-job-id',
352348
scopes: [scope],
349+
l2TipsStore,
353350
});
354351
});
355352

@@ -416,6 +413,7 @@ describe('Utility Execution test suite', () => {
416413
contractSyncService,
417414
jobId: 'test-job-id',
418415
scopes: [scope],
416+
l2TipsStore,
419417
});
420418

421419
capsuleStore.getCapsule.mockResolvedValueOnce(persisted);
@@ -596,6 +594,7 @@ describe('Utility Execution test suite', () => {
596594
contractSyncService,
597595
jobId: 'test-job-id',
598596
scopes: [],
597+
l2TipsStore,
599598
});
600599

601600
const oracleA = makeOracle(contractAddressA);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { KeyStore } from '@aztec/key-store';
99
import { isProtocolContract } from '@aztec/protocol-contracts';
1010
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
1111
import { AztecAddress } from '@aztec/stdlib/aztec-address';
12-
import { BlockHash } from '@aztec/stdlib/block';
12+
import { BlockHash, type L2TipsProvider } from '@aztec/stdlib/block';
1313
import type { CompleteAddress, ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
1414
import { siloNullifier } from '@aztec/stdlib/hash';
1515
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
@@ -63,6 +63,7 @@ export type UtilityExecutionOracleArgs = {
6363
privateEventStore: PrivateEventStore;
6464
messageContextService: MessageContextService;
6565
contractSyncService: ContractSyncService;
66+
l2TipsStore: L2TipsProvider;
6667
jobId: string;
6768
log?: ReturnType<typeof createLogger>;
6869
scopes: AztecAddress[];
@@ -98,6 +99,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
9899
protected readonly privateEventStore: PrivateEventStore;
99100
protected readonly messageContextService: MessageContextService;
100101
protected readonly contractSyncService: ContractSyncService;
102+
protected readonly l2TipsStore: L2TipsProvider;
101103
protected readonly jobId: string;
102104
protected logger: ReturnType<typeof createLogger>;
103105
protected readonly scopes: AztecAddress[];
@@ -118,6 +120,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
118120
this.privateEventStore = args.privateEventStore;
119121
this.messageContextService = args.messageContextService;
120122
this.contractSyncService = args.contractSyncService;
123+
this.l2TipsStore = args.l2TipsStore;
121124
this.jobId = args.jobId;
122125
this.logger = args.log ?? createLogger('simulator:client_view_context');
123126
this.scopes = args.scopes;
@@ -531,6 +534,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
531534
return new LogService(
532535
this.aztecNode,
533536
this.anchorBlockHeader,
537+
this.l2TipsStore,
534538
this.keyStore,
535539
this.recipientTaggingStore,
536540
this.senderAddressBookStore,

yarn-project/pxe/src/logs/log_service.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
55
import { KeyStore } from '@aztec/key-store';
66
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
77
import { AztecAddress } from '@aztec/stdlib/aztec-address';
8+
import type { L2TipsProvider } from '@aztec/stdlib/block';
89
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
910
import { Tag } from '@aztec/stdlib/logs';
1011
import { makeBlockHeader, randomTxScopedPrivateL2Log } from '@aztec/stdlib/testing';
@@ -49,6 +50,7 @@ describe('LogService', () => {
4950
logService = new LogService(
5051
aztecNode,
5152
anchorBlockHeader,
53+
mock<L2TipsProvider>(),
5254
keyStore,
5355
recipientTaggingStore,
5456
senderAddressBookStore,

yarn-project/pxe/src/logs/log_service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
22
import type { KeyStore } from '@aztec/key-store';
33
import { AztecAddress } from '@aztec/stdlib/aztec-address';
4+
import type { L2TipsProvider } from '@aztec/stdlib/block';
45
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
56
import { ExtendedDirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag } from '@aztec/stdlib/logs';
67
import type { BlockHeader } from '@aztec/stdlib/tx';
@@ -22,6 +23,7 @@ export class LogService {
2223
constructor(
2324
private readonly aztecNode: AztecNode,
2425
private readonly anchorBlockHeader: BlockHeader,
26+
private readonly l2TipsStore: L2TipsProvider,
2527
private readonly keyStore: KeyStore,
2628
private readonly recipientTaggingStore: RecipientTaggingStore,
2729
private readonly senderAddressBookStore: SenderAddressBookStore,
@@ -118,6 +120,8 @@ export class LogService {
118120
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
119121
const anchorBlockHash = await this.anchorBlockHeader.hash();
120122

123+
const l2Tips = await this.l2TipsStore.getL2Tips();
124+
const currentTimestamp = this.anchorBlockHeader.globalVariables.timestamp;
121125
// Get all secrets for this recipient (one per sender)
122126
const secrets = await this.#getSecretsForSenders(contractAddress, recipient);
123127

@@ -130,6 +134,8 @@ export class LogService {
130134
this.recipientTaggingStore,
131135
anchorBlockNumber,
132136
anchorBlockHash,
137+
currentTimestamp,
138+
l2Tips.finalized.block.number,
133139
this.jobId,
134140
),
135141
),

yarn-project/pxe/src/pxe.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@aztec/stdlib/abi';
1919
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
2020
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21+
import type { L2TipsProvider } from '@aztec/stdlib/block';
2122
import {
2223
CompleteAddress,
2324
type ContractInstanceWithAddress,
@@ -160,6 +161,7 @@ export class PXE {
160161
private privateEventStore: PrivateEventStore,
161162
private contractSyncService: ContractSyncService,
162163
private messageContextService: MessageContextService,
164+
private l2TipsStore: L2TipsProvider,
163165
private simulator: CircuitSimulator,
164166
private proverEnabled: boolean,
165167
private proofCreator: PrivateKernelProver,
@@ -258,6 +260,7 @@ export class PXE {
258260
privateEventStore,
259261
contractSyncService,
260262
messageContextService,
263+
tipsStore,
261264
simulator,
262265
proverEnabled,
263266
proofCreator,
@@ -292,6 +295,7 @@ export class PXE {
292295
keyStore: this.keyStore,
293296
addressStore: this.addressStore,
294297
aztecNode: BenchmarkedNodeFactory.create(this.node),
298+
l2TipsStore: this.l2TipsStore,
295299
senderTaggingStore: this.senderTaggingStore,
296300
recipientTaggingStore: this.recipientTaggingStore,
297301
senderAddressBookStore: this.senderAddressBookStore,

0 commit comments

Comments
 (0)