Skip to content

Commit

Permalink
feat: interop logging & code cleanup (#140)
Browse files Browse the repository at this point in the history
* changes

* lint
  • Loading branch information
hamdiallam authored Sep 13, 2024
1 parent 6bd420b commit 5352b1d
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 407 deletions.
60 changes: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ supersim
Vanilla mode will start 3 chains, with the OP Stack contracts already deployed.

```
L1:
Name: L1 Chain ID: 900 RPC: http://127.0.0.1:8545 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-900
L2:
Name: OPChainA Chain ID: 901 RPC: http://127.0.0.1:9545 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-901
Name: OPChainB Chain ID: 902 RPC: http://127.0.0.1:9546 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-902
Chain Configuration
-----------------------
L1: Name: Local ChainID: 900 RPC: http://127.0.0.1:8545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-900-3719464405
L2s: Predeploy Contracts Spec ( https://specs.optimism.io/protocol/predeploys.html )
* Name: OPChainA ChainID: 901 RPC: http://127.0.0.1:9545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-901-1956365912
L1 Contracts:
- OptimismPortal: 0xF5fe61a258CeBb54CCe428F76cdeD04Cbc12F53d
- L1CrossDomainMessenger: 0xe5bda89cd85cE0DfB80E053281cA070D65B738e6
- L1StandardBridge: 0xa01ae68902e205B420FD164435F299E07b0C778b
* Name: OPChainB ChainID: 902 RPC: http://127.0.0.1:9546 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-902-1214175152
L1 Contracts:
- OptimismPortal: 0xdfC9DEAbEEbDaa7620C71e2E76AEda32919DE5f2
- L1CrossDomainMessenger: 0xCB9768921831677Ae15cE4B64A10B94F49cD88E2
- L1StandardBridge: 0x2D8543c236a4d626f54B51Fa8bc229a257C5143E
```

### 4. Start testing multichain features 🚀
Expand Down Expand Up @@ -137,23 +149,29 @@ supersim fork --chains=op,base,zora
The fork height is determined by L1 block height (default `latest`), which determines the maximum timestamp for the forked L2 state of each chain.

```
Available Accounts
-----------------------
(0): 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
--- truncated for brevity ---
Private Keys
Chain Configuration
-----------------------
(0): 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
--- truncated for brevity ---
Orchestrator Config:
L1:
Name: mainnet Chain ID: 1 RPC: http://127.0.0.1:8545 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-1-1521250718
L2:
Name: op Chain ID: 10 RPC: http://127.0.0.1:9545 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-10
Name: base Chain ID: 8453 RPC: http://127.0.0.1:9546 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-8453
Name: zora Chain ID: 7777777 RPC: http://127.0.0.1:9547 LogPath: /var/folders/0w/ethers-phoenix/T/anvil-chain-7777777
L1: Name: mainnet ChainID: 1 RPC: http://127.0.0.1:8545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-1-832151416
L2s: Predeploy Contracts Spec ( https://specs.optimism.io/protocol/predeploys.html )
* Name: op ChainID: 10 RPC: http://127.0.0.1:9545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-10-2710239022
L1 Contracts:
- OptimismPortal: 0xbEb5Fc579115071764c7423A4f12eDde41f106Ed
- L1CrossDomainMessenger: 0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1
- L1StandardBridge: 0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1
* Name: base ChainID: 8453 RPC: http://127.0.0.1:9546 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-8453-1054019892
L1 Contracts:
- OptimismPortal: 0x49048044D57e1C92A77f79988d21Fa8fAF74E97e
- L1CrossDomainMessenger: 0x866E82a600A1414e583f7F13623F1aC5d58b0Afa
- L1StandardBridge: 0x3154Cf16ccdb4C6d922629664174b904d80F2C35
* Name: zora ChainID: 7777777 RPC: http://127.0.0.1:9547 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-7777777-1949580962
L1 Contracts:
- OptimismPortal: 0x1a0ad011913A150f69f6A19DF447A0CfD9551054
- L1CrossDomainMessenger: 0xdC40a14d9abd6F410226f1E6de71aE03441ca506
- L1StandardBridge: 0x3e2Ea9B92B7E48A52296fD261dc26fd995284631
```

### Note
Expand Down
8 changes: 4 additions & 4 deletions anvil/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ func (a *Anvil) EthClient() *ethclient.Client {
return a.ethClient
}

func (a *Anvil) SetCode(ctx context.Context, result interface{}, address string, code string) error {
return a.rpcClient.CallContext(ctx, result, "anvil_setCode", address, code)
func (a *Anvil) SetCode(ctx context.Context, result interface{}, address common.Address, code string) error {
return a.rpcClient.CallContext(ctx, result, "anvil_setCode", address.Hex(), code)
}

func (a *Anvil) SetStorageAt(ctx context.Context, result interface{}, address string, storageSlot string, storageValue string) error {
return a.rpcClient.CallContext(ctx, result, "anvil_setStorageAt", address, storageSlot, storageValue)
func (a *Anvil) SetStorageAt(ctx context.Context, result interface{}, address common.Address, storageSlot string, storageValue string) error {
return a.rpcClient.CallContext(ctx, result, "anvil_setStorageAt", address.Hex(), storageSlot, storageValue)
}

func (a *Anvil) SetIntervalMining(ctx context.Context, result interface{}, interval int64) error {
Expand Down
14 changes: 11 additions & 3 deletions config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/supersim/hdaccount"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
Expand All @@ -25,7 +26,6 @@ var (
type ForkConfig struct {
RPCUrl string
BlockNumber uint64
UseInterop bool
}

type SecretsConfig struct {
Expand Down Expand Up @@ -63,6 +63,11 @@ type NetworkConfig struct {

L2StartingPort uint64
L2Configs []ChainConfig

// Signaled higher up as a way to generally
// check if Interop is enabled
InteropEnabled bool
InteropAutoRelay bool
}

type Chain interface {
Expand All @@ -74,8 +79,8 @@ type Chain interface {

// Additional methods
SimulatedLogs(ctx context.Context, tx *types.Transaction) ([]types.Log, error)
SetCode(ctx context.Context, result interface{}, address string, code string) error
SetStorageAt(ctx context.Context, result interface{}, address string, storageSlot string, storageValue string) error
SetCode(ctx context.Context, result interface{}, address common.Address, code string) error
SetStorageAt(ctx context.Context, result interface{}, address common.Address, storageSlot string, storageValue string) error
SetIntervalMining(ctx context.Context, result interface{}, interval int64) error

// Lifecycle
Expand All @@ -85,6 +90,9 @@ type Chain interface {

func GetDefaultNetworkConfig(startingTimestamp uint64) NetworkConfig {
return NetworkConfig{
// Enabled by default as it is included in genesis
InteropEnabled: true,

L1Config: ChainConfig{
Name: "Local",
ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID,
Expand Down
33 changes: 21 additions & 12 deletions config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const (
NetworkFlagName = "network"
L2StartingPortFlagName = "l2.starting.port"

InteropEnabledInForkModeFlagName = "interop.enabled"
InteropAutoRelayFlagName = "interop.autorelay"
InteropEnabledFlagName = "interop.enabled"
InteropAutoRelayFlagName = "interop.autorelay"
)

func BaseCLIFlags(envPrefix string) []cli.Flag {
Expand Down Expand Up @@ -71,10 +71,10 @@ func ForkCLIFlags(envPrefix string) []cli.Flag {
EnvVars: opservice.PrefixEnvVar(envPrefix, "NETWORK"),
},
&cli.BoolFlag{
Name: InteropEnabledInForkModeFlagName,
Value: false,
Usage: "Enable interop in fork mode",
EnvVars: opservice.PrefixEnvVar(envPrefix, "FORK_WITH_INTEROP"),
Name: InteropEnabledFlagName,
Value: true, // enabled by default
Usage: "enable interop predeploy and functionality",
EnvVars: opservice.PrefixEnvVar(envPrefix, "INTEROP_ENABLED"),
},
}
}
Expand All @@ -83,21 +83,24 @@ type ForkCLIConfig struct {
L1ForkHeight uint64
Network string
Chains []string
UseInterop bool

InteropEnabled bool
}

type CLIConfig struct {
L1Port uint64
L2StartingPort uint64
L1Port uint64
L2StartingPort uint64

InteropAutoRelay bool

ForkConfig *ForkCLIConfig
}

func ReadCLIConfig(ctx *cli.Context) (*CLIConfig, error) {
cfg := &CLIConfig{
L1Port: ctx.Uint64(L1PortFlagName),
L2StartingPort: ctx.Uint64(L2StartingPortFlagName),
L1Port: ctx.Uint64(L1PortFlagName),
L2StartingPort: ctx.Uint64(L2StartingPortFlagName),

InteropAutoRelay: ctx.Bool(InteropAutoRelayFlagName),
}

Expand All @@ -106,7 +109,8 @@ func ReadCLIConfig(ctx *cli.Context) (*CLIConfig, error) {
L1ForkHeight: ctx.Uint64(L1ForkHeightFlagName),
Network: ctx.String(NetworkFlagName),
Chains: ctx.StringSlice(ChainsFlagName),
UseInterop: ctx.Bool(InteropEnabledInForkModeFlagName),

InteropEnabled: ctx.Bool(InteropEnabledFlagName),
}
}

Expand All @@ -117,12 +121,17 @@ func ReadCLIConfig(ctx *cli.Context) (*CLIConfig, error) {
func (c *CLIConfig) Check() error {
if c.ForkConfig != nil {
forkCfg := c.ForkConfig

superchain, ok := registry.Superchains[forkCfg.Network]
if !ok {
return fmt.Errorf("unrecognized superchain network `%s`, available networks: [%s]",
forkCfg.Network, strings.Join(superchainNetworks(), ", "))
}

if len(forkCfg.Chains) == 0 {
return fmt.Errorf("no chains specified! available chains: [%s]", strings.Join(superchainMemberChains(superchain), ","))
}

// ensure every chain is apart of the network
for _, chain := range forkCfg.Chains {
if !isInSuperchain(chain, superchain) {
Expand Down
Loading

0 comments on commit 5352b1d

Please sign in to comment.