Skip to content

Commit 4ffdee5

Browse files
authored
refactor: passing anchor block header instead of block store (#20043)
Discussed in DMs with @mverzilli that it doesn't make sense to pass around anchor block store to the execution oracles given that the anchor block needs to be fixed during the duration of the execution. Hence in this PR I am dropping it from the relevant constructors and instead just an anchor block header is passed around. Related to this also makes sense to make the `AnchorBlockStore` work solely in memory and not with persistent db as we always first sync the block header from node before simulation. This will be tackled in a followup PR.
2 parents 795cd3a + 0e79d93 commit 4ffdee5

15 files changed

+52
-119
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import {
7373
} from '@aztec/stdlib/tx';
7474

7575
import type { AddressStore } from '../storage/address_store/address_store.js';
76-
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
7776
import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
7877
import type { ContractStore } from '../storage/contract_store/contract_store.js';
7978
import type { NoteStore } from '../storage/note_store/note_store.js';
@@ -102,7 +101,6 @@ export class ContractFunctionSimulator {
102101
private keyStore: KeyStore,
103102
private addressStore: AddressStore,
104103
private aztecNode: AztecNode,
105-
private anchorBlockStore: AnchorBlockStore,
106104
private senderTaggingStore: SenderTaggingStore,
107105
private recipientTaggingStore: RecipientTaggingStore,
108106
private senderAddressBookStore: SenderAddressBookStore,
@@ -183,7 +181,6 @@ export class ContractFunctionSimulator {
183181
this.keyStore,
184182
this.addressStore,
185183
this.aztecNode,
186-
this.anchorBlockStore,
187184
this.senderTaggingStore,
188185
this.recipientTaggingStore,
189186
this.senderAddressBookStore,
@@ -279,7 +276,6 @@ export class ContractFunctionSimulator {
279276
this.keyStore,
280277
this.addressStore,
281278
this.aztecNode,
282-
this.anchorBlockStore,
283279
this.recipientTaggingStore,
284280
this.senderAddressBookStore,
285281
this.capsuleStore,

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { jest } from '@jest/globals';
1313
import { mock } from 'jest-mock-extended';
1414

1515
import type { AddressStore } from '../../storage/address_store/address_store.js';
16-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
1716
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
1817
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
1918
import type { NoteStore } from '../../storage/note_store/note_store.js';
@@ -32,7 +31,6 @@ describe('Oracle Version Check test suite', () => {
3231
let keyStore: ReturnType<typeof mock<KeyStore>>;
3332
let addressStore: ReturnType<typeof mock<AddressStore>>;
3433
let aztecNode: ReturnType<typeof mock<AztecNode>>;
35-
let anchorBlockStore: ReturnType<typeof mock<AnchorBlockStore>>;
3634
let senderTaggingStore: ReturnType<typeof mock<SenderTaggingStore>>;
3735
let recipientTaggingStore: ReturnType<typeof mock<RecipientTaggingStore>>;
3836
let senderAddressBookStore: ReturnType<typeof mock<SenderAddressBookStore>>;
@@ -51,7 +49,6 @@ describe('Oracle Version Check test suite', () => {
5149
keyStore = mock<KeyStore>();
5250
addressStore = mock<AddressStore>();
5351
aztecNode = mock<AztecNode>();
54-
anchorBlockStore = mock<AnchorBlockStore>();
5552
senderTaggingStore = mock<SenderTaggingStore>();
5653
recipientTaggingStore = mock<RecipientTaggingStore>();
5754
senderAddressBookStore = mock<SenderAddressBookStore>();
@@ -65,7 +62,6 @@ describe('Oracle Version Check test suite', () => {
6562

6663
aztecNode.getPublicStorageAt.mockResolvedValue(Fr.ZERO);
6764
anchorBlockHeader = BlockHeader.random();
68-
anchorBlockStore.getBlockHeader.mockResolvedValue(anchorBlockHeader);
6965
capsuleStore.loadCapsule.mockImplementation((_, __) => Promise.resolve(null));
7066
capsuleStore.readCapsuleArray.mockResolvedValue([]);
7167
senderTaggingStore.getLastFinalizedIndex.mockResolvedValue(undefined);
@@ -97,7 +93,6 @@ describe('Oracle Version Check test suite', () => {
9793
keyStore,
9894
addressStore,
9995
aztecNode,
100-
anchorBlockStore,
10196
senderTaggingStore,
10297
recipientTaggingStore,
10398
senderAddressBookStore,

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import { Matcher, type MatcherCreator, type MockProxy, mock } from 'jest-mock-ex
6565
import { toFunctionSelector } from 'viem';
6666

6767
import type { AddressStore } from '../../storage/address_store/address_store.js';
68-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
6968
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
7069
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
7170
import type { NoteStore } from '../../storage/note_store/note_store.js';
@@ -119,7 +118,6 @@ describe('Private Execution test suite', () => {
119118
let recipientTaggingStore: MockProxy<RecipientTaggingStore>;
120119
let senderAddressBookStore: MockProxy<SenderAddressBookStore>;
121120
let aztecNode: MockProxy<AztecNode>;
122-
let anchorBlockStore: MockProxy<AnchorBlockStore>;
123121
let capsuleStore: MockProxy<CapsuleStore>;
124122
let privateEventStore: MockProxy<PrivateEventStore>;
125123
let acirSimulator: ContractFunctionSimulator;
@@ -319,13 +317,11 @@ describe('Private Execution test suite', () => {
319317
recipientTaggingStore = mock<RecipientTaggingStore>();
320318
aztecNode = mock<AztecNode>();
321319
keyStore = mock<KeyStore>();
322-
anchorBlockStore = mock<AnchorBlockStore>();
323320
capsuleStore = mock<CapsuleStore>();
324321
privateEventStore = mock<PrivateEventStore>();
325322
senderAddressBookStore = mock<SenderAddressBookStore>();
326323
contracts = {};
327324
anchorBlockHeader = makeBlockHeader();
328-
anchorBlockStore.getBlockHeader.mockImplementation(() => Promise.resolve(anchorBlockHeader));
329325
capsuleStore.readCapsuleArray.mockResolvedValue([]);
330326

331327
// Mock sender tagging data provider methods
@@ -468,7 +464,6 @@ describe('Private Execution test suite', () => {
468464
keyStore,
469465
addressStore,
470466
aztecNode,
471-
anchorBlockStore,
472467
senderTaggingStore,
473468
recipientTaggingStore,
474469
senderAddressBookStore,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
import { ensureContractSynced } from '../../contract_sync/index.js';
3434
import { NoteService } from '../../notes/note_service.js';
3535
import type { AddressStore } from '../../storage/address_store/address_store.js';
36-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
3736
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
3837
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
3938
import type { NoteStore } from '../../storage/note_store/note_store.js';
@@ -89,7 +88,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
8988
keyStore: KeyStore,
9089
addressStore: AddressStore,
9190
aztecNode: AztecNode,
92-
anchorBlockStore: AnchorBlockStore,
9391
private readonly senderTaggingStore: SenderTaggingStore,
9492
recipientTaggingStore: RecipientTaggingStore,
9593
senderAddressBookStore: SenderAddressBookStore,
@@ -113,7 +111,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
113111
keyStore,
114112
addressStore,
115113
aztecNode,
116-
anchorBlockStore,
117114
recipientTaggingStore,
118115
senderAddressBookStore,
119116
capsuleStore,
@@ -364,7 +361,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
364361

365362
const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.contractAddress);
366363

367-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
364+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
368365
const dbNotes = await noteService.getNotes(
369366
this.callContext.contractAddress,
370367
owner,
@@ -574,7 +571,6 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
574571
this.keyStore,
575572
this.addressStore,
576573
this.aztecNode,
577-
this.anchorBlockStore,
578574
this.senderTaggingStore,
579575
this.recipientTaggingStore,
580576
this.senderAddressBookStore,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { mock } from 'jest-mock-extended';
1818
import type { _MockProxy } from 'jest-mock-extended/lib/Mock.js';
1919

2020
import type { AddressStore } from '../../storage/address_store/address_store.js';
21-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
2221
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
2322
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
2423
import type { NoteStore } from '../../storage/note_store/note_store.js';
@@ -37,7 +36,6 @@ describe('Utility Execution test suite', () => {
3736
let keyStore: ReturnType<typeof mock<KeyStore>>;
3837
let addressStore: ReturnType<typeof mock<AddressStore>>;
3938
let aztecNode: ReturnType<typeof mock<AztecNode>>;
40-
let anchorBlockStore: ReturnType<typeof mock<AnchorBlockStore>>;
4139
let senderTaggingStore: ReturnType<typeof mock<SenderTaggingStore>>;
4240
let recipientTaggingStore: ReturnType<typeof mock<RecipientTaggingStore>>;
4341
let senderAddressBookStore: ReturnType<typeof mock<SenderAddressBookStore>>;
@@ -59,15 +57,13 @@ describe('Utility Execution test suite', () => {
5957
keyStore = mock<KeyStore>();
6058
addressStore = mock<AddressStore>();
6159
aztecNode = mock<AztecNode>();
62-
anchorBlockStore = mock<AnchorBlockStore>();
6360
senderTaggingStore = mock<SenderTaggingStore>();
6461
recipientTaggingStore = mock<RecipientTaggingStore>();
6562
senderAddressBookStore = mock<SenderAddressBookStore>();
6663
capsuleStore = mock<CapsuleStore>();
6764
privateEventStore = mock<PrivateEventStore>();
6865
const capsuleArrays = new Map<string, Fr[][]>();
6966
anchorBlockHeader = BlockHeader.random();
70-
anchorBlockStore.getBlockHeader.mockImplementation(() => Promise.resolve(anchorBlockHeader));
7167
senderTaggingStore.getLastFinalizedIndex.mockResolvedValue(undefined);
7268
senderTaggingStore.getLastUsedIndex.mockResolvedValue(undefined);
7369
senderTaggingStore.getTxHashesOfPendingIndexes.mockResolvedValue([]);
@@ -97,7 +93,6 @@ describe('Utility Execution test suite', () => {
9793
keyStore,
9894
addressStore,
9995
aztecNode,
100-
anchorBlockStore,
10196
senderTaggingStore,
10297
recipientTaggingStore,
10398
senderAddressBookStore,
@@ -205,7 +200,6 @@ describe('Utility Execution test suite', () => {
205200
anchorBlockHeader = BlockHeader.empty({
206201
globalVariables: GlobalVariables.empty({ blockNumber: BlockNumber(syncedBlockNumber) }),
207202
});
208-
anchorBlockStore.getBlockHeader.mockResolvedValue(anchorBlockHeader);
209203

210204
utilityExecutionOracle = new UtilityExecutionOracle(
211205
contractAddress,
@@ -217,7 +211,6 @@ describe('Utility Execution test suite', () => {
217211
keyStore,
218212
addressStore,
219213
aztecNode,
220-
anchorBlockStore,
221214
recipientTaggingStore,
222215
senderAddressBookStore,
223216
capsuleStore,

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { LogService } from '../../logs/log_service.js';
2525
import { NoteService } from '../../notes/note_service.js';
2626
import { ORACLE_VERSION } from '../../oracle_version.js';
2727
import type { AddressStore } from '../../storage/address_store/address_store.js';
28-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
2928
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
3029
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
3130
import type { NoteStore } from '../../storage/note_store/note_store.js';
@@ -61,7 +60,6 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
6160
protected readonly keyStore: KeyStore,
6261
protected readonly addressStore: AddressStore,
6362
protected readonly aztecNode: AztecNode,
64-
protected readonly anchorBlockStore: AnchorBlockStore,
6563
protected readonly recipientTaggingStore: RecipientTaggingStore,
6664
protected readonly senderAddressBookStore: SenderAddressBookStore,
6765
protected readonly capsuleStore: CapsuleStore,
@@ -166,7 +164,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
166164
* @returns Block extracted from a block with block number `blockNumber`.
167165
*/
168166
public async utilityGetBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
169-
const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
167+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
170168
if (blockNumber > anchorBlockNumber) {
171169
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
172170
}
@@ -262,7 +260,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
262260
offset: number,
263261
status: NoteStatus,
264262
): Promise<NoteData[]> {
265-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
263+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
266264

267265
const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
268266
return pickNotes<NoteData>(dbNotes, {
@@ -349,7 +347,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
349347
public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
350348
const logService = new LogService(
351349
this.aztecNode,
352-
this.anchorBlockStore,
350+
this.anchorBlockHeader,
353351
this.keyStore,
354352
this.capsuleStore,
355353
this.recipientTaggingStore,
@@ -359,7 +357,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
359357
this.log.getBindings(),
360358
);
361359

362-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
360+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
363361

364362
// It is acceptable to run the following operations in parallel for several reasons:
365363
// 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
@@ -401,7 +399,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
401399
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
402400
).map(EventValidationRequest.fromFields);
403401

404-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
402+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
405403
const noteStorePromises = noteValidationRequests.map(request =>
406404
noteService.validateAndStoreNote(
407405
request.contractAddress,
@@ -417,7 +415,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
417415
),
418416
);
419417

420-
const eventService = new EventService(this.anchorBlockStore, this.aztecNode, this.privateEventStore, this.jobId);
418+
const eventService = new EventService(this.anchorBlockHeader, this.aztecNode, this.privateEventStore, this.jobId);
421419
const eventStorePromises = eventValidationRequests.map(request =>
422420
eventService.validateAndStoreEvent(
423421
request.contractAddress,
@@ -455,7 +453,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
455453

456454
const logService = new LogService(
457455
this.aztecNode,
458-
this.anchorBlockStore,
456+
this.anchorBlockHeader,
459457
this.keyStore,
460458
this.capsuleStore,
461459
this.recipientTaggingStore,

yarn-project/pxe/src/events/event_service.test.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
66
import { BlockHash } from '@aztec/stdlib/block';
77
import { siloNullifier } from '@aztec/stdlib/hash';
88
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
9-
import { BlockHeader, GlobalVariables, type IndexedTxEffect, TxEffect } from '@aztec/stdlib/tx';
9+
import { makeBlockHeader } from '@aztec/stdlib/testing';
10+
import { type IndexedTxEffect, TxEffect } from '@aztec/stdlib/tx';
1011

1112
import { mock } from 'jest-mock-extended';
1213

13-
import { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
1414
import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
1515
import { EventService } from './event_service.js';
1616

@@ -26,25 +26,15 @@ describe('validateAndStoreEvent', () => {
2626
let contractAddress: AztecAddress;
2727
let recipient: AztecAddress;
2828

29-
let anchorBlockStore: AnchorBlockStore;
3029
let privateEventStore: PrivateEventStore;
3130
let aztecNode: ReturnType<typeof mock<AztecNode>>;
3231

3332
let eventService: EventService;
3433

35-
const setSyncedBlockNumber = (blockNumber: BlockNumber) => {
36-
return anchorBlockStore.setHeader(
37-
BlockHeader.empty({
38-
globalVariables: GlobalVariables.empty({ blockNumber }),
39-
}),
40-
);
41-
};
42-
4334
// beforeEach sets up the happy path case, so error modes are tested
4435
// by minimally failing happy path conditions
4536
beforeEach(async () => {
4637
const store = await openTmpStore('test');
47-
anchorBlockStore = new AnchorBlockStore(store);
4838
privateEventStore = new PrivateEventStore(store);
4939

5040
aztecNode = mock<AztecNode>();
@@ -76,11 +66,11 @@ describe('validateAndStoreEvent', () => {
7666
** - PXE is sync'd to _at least_ block including tx
7767
** - Node returns the corresponding tx effect and the tx effect includes the event commitment
7868
*/
79-
await setSyncedBlockNumber(blockNumber);
69+
const anchorBlockHeader = makeBlockHeader(0, { blockNumber });
8070

8171
aztecNode.getTxEffect.mockImplementation(() => Promise.resolve(indexedTxEffect));
8272

83-
eventService = new EventService(anchorBlockStore, aztecNode, privateEventStore, 'test');
73+
eventService = new EventService(anchorBlockHeader, aztecNode, privateEventStore, 'test');
8474
});
8575

8676
async function runStoreEvent(

yarn-project/pxe/src/events/event_service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import type { EventSelector } from '@aztec/stdlib/abi';
33
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
44
import { siloNullifier } from '@aztec/stdlib/hash';
55
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
6-
import type { TxHash } from '@aztec/stdlib/tx';
6+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
77

8-
import { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
98
import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
109

1110
export class EventService {
1211
constructor(
13-
private readonly anchorBlockStore: AnchorBlockStore,
12+
private readonly anchorBlockHeader: BlockHeader,
1413
private readonly aztecNode: AztecNode,
1514
private readonly privateEventStore: PrivateEventStore,
1615
private readonly jobId: string,
@@ -29,13 +28,12 @@ export class EventService {
2928
// (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
3029
// maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
3130
// since `fetchTaggedLogs` only processes logs up to the synced block.
32-
const [anchorBlockHeader, siloedEventCommitment, txEffect] = await Promise.all([
33-
this.anchorBlockStore.getBlockHeader(),
31+
const [siloedEventCommitment, txEffect] = await Promise.all([
3432
siloNullifier(contractAddress, eventCommitment),
3533
this.aztecNode.getTxEffect(txHash),
3634
]);
3735

38-
const anchorBlockNumber = anchorBlockHeader.getBlockNumber();
36+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
3937

4038
if (!txEffect) {
4139
throw new Error(`Could not find tx effect for tx hash ${txHash}`);

0 commit comments

Comments
 (0)