Skip to content

Commit 1c4833b

Browse files
committed
wip
1 parent 5acc032 commit 1c4833b

5 files changed

Lines changed: 32 additions & 29 deletions

File tree

yarn-project/pxe/src/entrypoints/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export { ORACLE_VERSION } from '../../oracle_version.js';
88
export { type PXECreationOptions } from '../pxe_creation_options.js';
99
export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
1010
export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
11-
export { syncState } from '../../contract_sync/helpers.js';

yarn-project/txe/src/oracle/txe_oracle_top_level_context.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import type { KeyStore } from '@aztec/key-store';
1515
import {
1616
AddressStore,
1717
CapsuleStore,
18+
ContractSyncService,
1819
NoteStore,
1920
ORACLE_VERSION,
2021
PrivateEventStore,
2122
RecipientTaggingStore,
2223
SenderAddressBookStore,
2324
SenderTaggingStore,
2425
enrichPublicSimulationError,
25-
syncState,
2626
} from '@aztec/pxe/server';
2727
import {
2828
ExecutionNoteCache,
@@ -83,7 +83,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
8383

8484
import { DEFAULT_ADDRESS } from '../constants.js';
8585
import type { TXEStateMachine } from '../state_machine/index.js';
86-
import { NoopContractSyncService } from '../util/noop_contract_sync_service.js';
8786
import type { TXEAccountStore } from '../util/txe_account_store.js';
8887
import type { TXEContractStore } from '../util/txe_contract_store.js';
8988
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
@@ -108,6 +107,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
108107
private senderAddressBookStore: SenderAddressBookStore,
109108
private capsuleStore: CapsuleStore,
110109
private privateEventStore: PrivateEventStore,
110+
private contractSyncService: ContractSyncService,
111111
private jobId: string,
112112
private nextBlockTimestamp: bigint,
113113
private version: Fr,
@@ -303,7 +303,13 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
303303
await this.executeUtilityCall(call);
304304
};
305305

306-
await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
306+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
307+
await this.contractSyncService.ensureContractSynced(
308+
targetContractAddress,
309+
functionSelector,
310+
utilityExecutor,
311+
blockHeader,
312+
);
307313

308314
const blockNumber = await this.txeGetNextBlockNumber();
309315

@@ -315,8 +321,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
315321

316322
const txContext = new TxContext(this.chainId, this.version, gasSettings);
317323

318-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
319-
320324
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
321325
const noteCache = new ExecutionNoteCache(protocolNullifier);
322326
// In production, the account contract sets the min revertible counter before calling the app function.
@@ -352,7 +356,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
352356
this.senderAddressBookStore,
353357
this.capsuleStore,
354358
this.privateEventStore,
355-
new NoopContractSyncService(),
359+
this.contractSyncService,
356360
this.jobId,
357361
0, // totalPublicArgsCount
358362
minRevertibleSideEffectCounter, // (start) sideEffectCounter
@@ -665,9 +669,15 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
665669
}
666670

667671
// Sync notes before executing utility function to discover notes from previous transactions
668-
await syncState(targetContractAddress, this.contractStore, functionSelector, async call => {
669-
await this.executeUtilityCall(call);
670-
});
672+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
673+
await this.contractSyncService.ensureContractSynced(
674+
targetContractAddress,
675+
functionSelector,
676+
async call => {
677+
await this.executeUtilityCall(call);
678+
},
679+
blockHeader,
680+
);
671681

672682
const call = new FunctionCall(
673683
artifact.name,

yarn-project/txe/src/txe_session.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('TXESession.processFunction', () => {
2121
{} as any, // senderAddressBook
2222
{} as any, // capsuleStore
2323
{} as any, // privateEventStore
24+
{} as any, // contractSyncService
2425
{} as any, // jobCoordinator
2526
{} as any, // initialJobId
2627
new Fr(1), // chainId

yarn-project/txe/src/txe_session.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { ProtocolContract } from '@aztec/protocol-contracts';
77
import {
88
AddressStore,
99
CapsuleStore,
10+
ContractSyncService,
1011
JobCoordinator,
1112
NoteService,
1213
NoteStore,
@@ -51,7 +52,6 @@ import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.
5152
import { RPCTranslator } from './rpc_translator.js';
5253
import { TXEStateMachine } from './state_machine/index.js';
5354
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
54-
import { NoopContractSyncService } from './util/noop_contract_sync_service.js';
5555
import { TXEAccountStore } from './util/txe_account_store.js';
5656
import { TXEContractStore } from './util/txe_contract_store.js';
5757
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
@@ -140,6 +140,7 @@ export class TXESession implements TXESessionStateHandler {
140140
private senderAddressBookStore: SenderAddressBookStore,
141141
private capsuleStore: CapsuleStore,
142142
private privateEventStore: PrivateEventStore,
143+
private contractSyncService: ContractSyncService,
143144
private jobCoordinator: JobCoordinator,
144145
private currentJobId: string,
145146
private chainId: Fr,
@@ -183,6 +184,12 @@ export class TXESession implements TXESessionStateHandler {
183184
const version = new Fr(await stateMachine.node.getVersion());
184185
const chainId = new Fr(await stateMachine.node.getChainId());
185186

187+
const contractSyncService = new ContractSyncService(
188+
stateMachine.node,
189+
contractStore,
190+
createLogger('txe:contract_sync'),
191+
);
192+
186193
const initialJobId = jobCoordinator.beginJob();
187194

188195
const topLevelOracleHandler = new TXEOracleTopLevelContext(
@@ -197,6 +204,7 @@ export class TXESession implements TXESessionStateHandler {
197204
senderAddressBookStore,
198205
capsuleStore,
199206
privateEventStore,
207+
contractSyncService,
200208
initialJobId,
201209
nextBlockTimestamp,
202210
version,
@@ -219,6 +227,7 @@ export class TXESession implements TXESessionStateHandler {
219227
senderAddressBookStore,
220228
capsuleStore,
221229
privateEventStore,
230+
contractSyncService,
222231
jobCoordinator,
223232
initialJobId,
224233
version,
@@ -296,6 +305,7 @@ export class TXESession implements TXESessionStateHandler {
296305
this.senderAddressBookStore,
297306
this.capsuleStore,
298307
this.privateEventStore,
308+
this.contractSyncService,
299309
this.currentJobId,
300310
this.nextBlockTimestamp,
301311
this.version,
@@ -357,7 +367,7 @@ export class TXESession implements TXESessionStateHandler {
357367
this.senderAddressBookStore,
358368
this.capsuleStore,
359369
this.privateEventStore,
360-
new NoopContractSyncService(),
370+
this.contractSyncService,
361371
this.currentJobId,
362372
);
363373

yarn-project/txe/src/util/noop_contract_sync_service.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)