Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions op-e2e/e2eutils/challenger/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"testing"
"time"

e2econfig "github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-service/crypto"

"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -32,16 +31,24 @@ import (
"github.com/ethereum-optimism/optimism/op-service/testlog"
)

type PrestateVariant string

const (
STCannonVariant PrestateVariant = ""
MTCannonVariant PrestateVariant = "mt64"
InteropVariant PrestateVariant = "interop"
)

type EndpointProvider interface {
NodeEndpoint(name string) endpoint.RPC
RollupEndpoint(name string) endpoint.RPC
L1BeaconEndpoint() endpoint.RestHTTP
}

type System interface {
RollupCfg() *rollup.Config
L2Genesis() *core.Genesis
AllocType() e2econfig.AllocType
RollupCfgs() []*rollup.Config
L2Geneses() []*core.Genesis
PrestateVariant() PrestateVariant
}
type Helper struct {
log log.Logger
Expand Down Expand Up @@ -120,43 +127,47 @@ func FindMonorepoRoot(t *testing.T) string {
return ""
}

func applyCannonConfig(c *config.Config, t *testing.T, rollupCfg *rollup.Config, l2Genesis *core.Genesis, allocType e2econfig.AllocType) {
func applyCannonConfig(c *config.Config, t *testing.T, rollupCfgs []*rollup.Config, l2Geneses []*core.Genesis, prestateVariant PrestateVariant) {
require := require.New(t)
root := FindMonorepoRoot(t)
c.Cannon.VmBin = root + "cannon/bin/cannon"
c.Cannon.Server = root + "op-program/bin/op-program"
if allocType == e2econfig.AllocTypeMTCannon {
t.Log("Using Cannon64 absolute prestate")
c.CannonAbsolutePreState = root + "op-program/bin/prestate-mt64.bin.gz"
t.Logf("Using absolute prestate variant %v", prestateVariant)
if prestateVariant != "" {
c.CannonAbsolutePreState = root + "op-program/bin/prestate-" + string(prestateVariant) + ".bin.gz"
} else {
c.CannonAbsolutePreState = root + "op-program/bin/prestate.bin.gz"
}
c.Cannon.SnapshotFreq = 10_000_000

genesisBytes, err := json.Marshal(l2Genesis)
require.NoError(err, "marshall l2 genesis config")
genesisFile := filepath.Join(c.Datadir, "l2-genesis.json")
require.NoError(os.WriteFile(genesisFile, genesisBytes, 0o644))
c.Cannon.L2GenesisPaths = []string{genesisFile}

rollupBytes, err := json.Marshal(rollupCfg)
require.NoError(err, "marshall rollup config")
rollupFile := filepath.Join(c.Datadir, "rollup.json")
require.NoError(os.WriteFile(rollupFile, rollupBytes, 0o644))
c.Cannon.RollupConfigPaths = []string{rollupFile}
for _, l2Genesis := range l2Geneses {
genesisBytes, err := json.Marshal(l2Genesis)
require.NoError(err, "marshall l2 genesis config")
genesisFile := filepath.Join(c.Datadir, "l2-genesis.json")
require.NoError(os.WriteFile(genesisFile, genesisBytes, 0o644))
c.Cannon.L2GenesisPaths = append(c.Cannon.L2GenesisPaths, genesisFile)
}

for _, rollupCfg := range rollupCfgs {
rollupBytes, err := json.Marshal(rollupCfg)
require.NoError(err, "marshall rollup config")
rollupFile := filepath.Join(c.Datadir, "rollup.json")
require.NoError(os.WriteFile(rollupFile, rollupBytes, 0o644))
c.Cannon.RollupConfigPaths = append(c.Cannon.RollupConfigPaths, rollupFile)
}
}

func WithCannon(t *testing.T, system System) Option {
return func(c *config.Config) {
c.TraceTypes = append(c.TraceTypes, types.TraceTypeCannon)
applyCannonConfig(c, t, system.RollupCfg(), system.L2Genesis(), system.AllocType())
applyCannonConfig(c, t, system.RollupCfgs(), system.L2Geneses(), system.PrestateVariant())
}
}

func WithPermissioned(t *testing.T, system System) Option {
return func(c *config.Config) {
c.TraceTypes = append(c.TraceTypes, types.TraceTypePermissioned)
applyCannonConfig(c, t, system.RollupCfg(), system.L2Genesis(), system.AllocType())
applyCannonConfig(c, t, system.RollupCfgs(), system.L2Geneses(), system.PrestateVariant())
}
}

Expand Down
Loading