Skip to content

Commit

Permalink
Merge pull request #2394 from OffchainLabs/mach-fetcher
Browse files Browse the repository at this point in the history
Fetch Published Machine to test compatibility
  • Loading branch information
eljobe committed Jul 8, 2024
2 parents 44c00e5 + 84d2eaf commit 30b3857
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 56 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

require github.com/google/go-querystring v1.1.0 // indirect

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -110,6 +112,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-github/v62 v62.0.0
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,19 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4=
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
95 changes: 75 additions & 20 deletions system_tests/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/redisutil"
"github.com/offchainlabs/nitro/util/testhelpers/github"
"github.com/offchainlabs/nitro/validator/client/redis"
)

Expand All @@ -39,24 +40,34 @@ const (
upgradeArbOs
)

func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops int, workload workloadType, arbitrator bool, useRedisStreams bool) {
type Options struct {
dasModeString string
workloadLoops int
workload workloadType
arbitrator bool
useRedisStreams bool
wasmRootDir string
}

func testBlockValidatorSimple(t *testing.T, opts Options) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

chainConfig, l1NodeConfigA, lifecycleManager, _, dasSignerKey := setupConfigWithDAS(t, ctx, dasModeString)
chainConfig, l1NodeConfigA, lifecycleManager, _, dasSignerKey := setupConfigWithDAS(t, ctx, opts.dasModeString)
defer lifecycleManager.StopAndWaitUntil(time.Second)
if workload == upgradeArbOs {
if opts.workload == upgradeArbOs {
chainConfig.ArbitrumChainParams.InitialArbOSVersion = 10
}

var delayEvery int
if workloadLoops > 1 {
if opts.workloadLoops > 1 {
l1NodeConfigA.BatchPoster.MaxDelay = time.Millisecond * 500
delayEvery = workloadLoops / 3
delayEvery = opts.workloadLoops / 3
}

builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
builder = builder.WithWasmRootDir(opts.wasmRootDir)
builder.nodeConfig = l1NodeConfigA
builder.chainConfig = chainConfig
builder.L2Info = nil
Expand All @@ -70,15 +81,15 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
validatorConfig.DataAvailability = l1NodeConfigA.DataAvailability
validatorConfig.DataAvailability.RPCAggregator.Enable = false
redisURL := ""
if useRedisStreams {
if opts.useRedisStreams {
redisURL = redisutil.CreateTestRedis(ctx, t)
validatorConfig.BlockValidator.RedisValidationClientConfig = redis.TestValidationClientConfig
validatorConfig.BlockValidator.RedisValidationClientConfig.RedisURL = redisURL
} else {
validatorConfig.BlockValidator.RedisValidationClientConfig = redis.ValidationClientConfig{}
}

AddDefaultValNode(t, ctx, validatorConfig, !arbitrator, redisURL)
AddDefaultValNode(t, ctx, validatorConfig, !opts.arbitrator, redisURL, opts.wasmRootDir)

testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{nodeConfig: validatorConfig})
defer cleanupB()
Expand All @@ -87,17 +98,17 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
perTransfer := big.NewInt(1e12)

var simple *mocksgen.Simple
if workload != upgradeArbOs {
for i := 0; i < workloadLoops; i++ {
if opts.workload != upgradeArbOs {
for i := 0; i < opts.workloadLoops; i++ {
var tx *types.Transaction

if workload == ethSend {
if opts.workload == ethSend {
tx = builder.L2Info.PrepareTx("Owner", "User2", builder.L2Info.TransferGas, perTransfer, nil)
} else {
var contractCode []byte
var gas uint64

if workload == smallContract {
if opts.workload == smallContract {
contractCode = []byte{byte(vm.PUSH0)}
contractCode = append(contractCode, byte(vm.PUSH0))
contractCode = append(contractCode, byte(vm.PUSH1))
Expand Down Expand Up @@ -130,7 +141,7 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
err := builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
if workload != depleteGas {
if opts.workload != depleteGas {
Require(t, err)
}
if delayEvery > 0 && i%delayEvery == (delayEvery-1) {
Expand Down Expand Up @@ -184,7 +195,7 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
Require(t, err)
}

if workload != depleteGas {
if opts.workload != depleteGas {
delayedTx := builder.L2Info.PrepareTx("Owner", "User2", 30002, perTransfer, nil)
builder.L1.SendWaitTestTransactions(t, []*types.Transaction{
WrapL2ForDelayed(t, delayedTx, builder.L1Info, "User", 100000),
Expand All @@ -203,11 +214,11 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
Require(t, err)
}

if workload == ethSend {
if opts.workload == ethSend {
l2balance, err := testClientB.Client.BalanceAt(ctx, builder.L2Info.GetAddress("User2"), nil)
Require(t, err)

expectedBalance := new(big.Int).Mul(perTransfer, big.NewInt(int64(workloadLoops+1)))
expectedBalance := new(big.Int).Mul(perTransfer, big.NewInt(int64(opts.workloadLoops+1)))
if l2balance.Cmp(expectedBalance) != 0 {
Fatal(t, "Unexpected balance:", l2balance)
}
Expand Down Expand Up @@ -251,21 +262,65 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
}

func TestBlockValidatorSimpleOnchainUpgradeArbOs(t *testing.T) {
testBlockValidatorSimple(t, "onchain", 1, upgradeArbOs, true, false)
opts := Options{
dasModeString: "onchain",
workloadLoops: 1,
workload: upgradeArbOs,
arbitrator: true,
}
testBlockValidatorSimple(t, opts)
}

func TestBlockValidatorSimpleOnchain(t *testing.T) {
testBlockValidatorSimple(t, "onchain", 1, ethSend, true, false)
opts := Options{
dasModeString: "onchain",
workloadLoops: 1,
workload: ethSend,
arbitrator: true,
}
testBlockValidatorSimple(t, opts)
}

func TestBlockValidatorSimpleOnchainWithPublishedMachine(t *testing.T) {
cr, err := github.LatestConsensusRelease(context.Background())
Require(t, err)
machPath := populateMachineDir(t, cr)
opts := Options{
dasModeString: "onchain",
workloadLoops: 1,
workload: ethSend,
arbitrator: true,
wasmRootDir: machPath,
}
testBlockValidatorSimple(t, opts)
}

func TestBlockValidatorSimpleOnchainWithRedisStreams(t *testing.T) {
testBlockValidatorSimple(t, "onchain", 1, ethSend, true, true)
opts := Options{
dasModeString: "onchain",
workloadLoops: 1,
workload: ethSend,
arbitrator: true,
useRedisStreams: true,
}
testBlockValidatorSimple(t, opts)
}

func TestBlockValidatorSimpleLocalDAS(t *testing.T) {
testBlockValidatorSimple(t, "files", 1, ethSend, true, false)
opts := Options{
dasModeString: "files",
workloadLoops: 1,
workload: ethSend,
arbitrator: true,
}
testBlockValidatorSimple(t, opts)
}

func TestBlockValidatorSimpleJITOnchain(t *testing.T) {
testBlockValidatorSimple(t, "files", 8, smallContract, false, false)
opts := Options{
dasModeString: "files",
workloadLoops: 8,
workload: smallContract,
}
testBlockValidatorSimple(t, opts)
}
Loading

0 comments on commit 30b3857

Please sign in to comment.