Skip to content

Commit e00089f

Browse files
dbanks12dbanks12
andauthored
fix: dependency cycles in public simulator - part 0 (sim -> context) (#13678)
Brings cycles down from 66 to 19. ![image](https://github.com/user-attachments/assets/85cc7057-d66d-4396-9750-021ce3d2fc80) Co-authored-by: dbanks12 <[email protected]>
1 parent 062c6a9 commit e00089f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

yarn-project/simulator/src/public/avm/avm_context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag
55
import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
66
import { type Gas, gasToGasLeft } from './avm_gas.js';
77
import { AvmMachineState } from './avm_machine_state.js';
8-
import type { AvmSimulator } from './avm_simulator.js';
8+
import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
99

1010
/**
1111
* An execution context includes the information necessary to initiate AVM
@@ -27,7 +27,7 @@ export class AvmContext {
2727

2828
// This is needed to break a dependency cycle created by the CALL opcode,
2929
// which needs to create a new simulator but cannot depend directly on AvmSimulator.
30-
public provideSimulator?: (ctx: this) => Promise<AvmSimulator>;
30+
public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;
3131

3232
/**
3333
* Prepare a new AVM context that will be ready for an external/nested call

yarn-project/simulator/src/public/avm/avm_simulator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AvmContractCallResult } from './avm_contract_call_result.js';
1313
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
1414
import type { Gas } from './avm_gas.js';
1515
import { AvmMachineState } from './avm_machine_state.js';
16+
import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
1617
import {
1718
AvmExecutionError,
1819
AvmRevertReason,
@@ -32,7 +33,7 @@ type OpcodeTally = {
3233
gas: Gas;
3334
};
3435

35-
export class AvmSimulator {
36+
export class AvmSimulator implements AvmSimulatorInterface {
3637
private log: Logger;
3738
private bytecode: Buffer | undefined;
3839
private opcodeTallies: Map<string, OpcodeTally> = new Map();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Interface for AvmSimulator to break the circular dependency between avm_context.ts and avm_simulator.ts
3+
*/
4+
export interface AvmSimulatorInterface {
5+
execute(): Promise<any>; // Using any here to avoid importing AvmContractCallResult
6+
executeBytecode(bytecode: Buffer): Promise<any>;
7+
getBytecode(): Buffer | undefined;
8+
}

0 commit comments

Comments
 (0)