diff --git a/Dockerfile b/Dockerfile index 1b7998ee5..8c5ffc9fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,7 +75,7 @@ COPY --from=builder /app/build/bin/state /usr/local/bin/state COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle COPY --from=builder /app/build/bin/caplin-phase1 /usr/local/bin/caplin-phase1 - +COPY --from=builder /app/build/bin/caplin-regression /usr/local/bin/caplin-regression EXPOSE 8545 \ diff --git a/cmd/caplin-regression/main.go b/cmd/caplin-regression/main.go index 1b49af9c3..bbb455774 100644 --- a/cmd/caplin-regression/main.go +++ b/cmd/caplin-regression/main.go @@ -3,12 +3,14 @@ package main import ( "flag" "net/http" - _ "net/http/pprof" //nolint:gosec "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/phase1/forkchoice" "github.com/ledgerwatch/erigon/cmd/caplin-regression/regression" "github.com/ledgerwatch/log/v3" + "golang.org/x/exp/slices" + + _ "net/http/pprof" //nolint:gosec ) var nameTestsMap = map[string]func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error{ @@ -17,11 +19,16 @@ var nameTestsMap = map[string]func(*forkchoice.ForkChoiceStore, *cltypes.SignedB "TestRegressionBadBlocks": regression.TestRegressionBadBlocks, } +var excludeTests = []string{"TestRegressionBadBlocks"} + func main() { log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler)) test := flag.String("test", "TestRegressionWithValidation", "select test to run. can be TestRegressionWithValidation, TestRegressionWithoutValidation and TestRegressionBadBlocks") - step := flag.Int("step", 1, "how often to log performance") + step := flag.Int("step", 32, "how often to log performance") pprof := flag.Bool("pprof", true, "turn on profiling") + loop := flag.Bool("loop", true, "loop the test in an infinite loop") + all := flag.Bool("all", true, "loop trhough all the test") + flag.Parse() if _, ok := nameTestsMap[*test]; !ok { log.Error("Could not start regression tests", "err", "test not found") @@ -46,7 +53,20 @@ func main() { return } - if err := r.Run(*test, nameTestsMap[*test], *step); err != nil { - log.Error("Could not do regression tests", "err", err) + for val := true; val; val = *loop { + if *all { + for name, t := range nameTestsMap { + if slices.Contains(excludeTests, name) { + continue + } + if err := r.Run(name, t, *step); err != nil { + log.Error("Could not do regression tests", "err", err) + } + } + continue + } + if err := r.Run(*test, nameTestsMap[*test], *step); err != nil { + log.Error("Could not do regression tests", "err", err) + } } } diff --git a/cmd/caplin-regression/regression/tester.go b/cmd/caplin-regression/regression/tester.go index 8c7eb06ce..4003e04dd 100644 --- a/cmd/caplin-regression/regression/tester.go +++ b/cmd/caplin-regression/regression/tester.go @@ -34,44 +34,43 @@ func NewRegressionTester(testDirectory string) (*RegressionTester, error) { } func (r *RegressionTester) Run(name string, fn func(*forkchoice.ForkChoiceStore, *cltypes.SignedBeaconBlock) error, step int) error { - for true { - state, err := r.readStartingState() - if err != nil { - return err - } - store, err := forkchoice.NewForkChoiceStore(state, nil, nil, true) - if err != nil { - return err - } - log.Info("Loading public keys into memory") - bls.SetEnabledCaching(true) - state.ForEachValidator(func(v solid.Validator, idx, total int) bool { - pk := v.PublicKey() - if err := bls.LoadPublicKeyIntoCache(pk[:], false); err != nil { - panic(err) - } - return true - }) - store.OnTick(uint64(time.Now().Unix())) - begin := time.Now() - beginStep := time.Now() - log.Info("Starting test, CTRL+C to stop.", "name", name) - for _, block := range r.blockList { - if err := fn(store, block); err != nil { - return err - } - if block.Block.Slot%uint64(step) == 0 { - elapsed := time.Since(beginStep) - log.Info("Processed", "slot", block.Block.Slot, "elapsed", elapsed, "sec/blk", elapsed/time.Duration(step)) - beginStep = time.Now() - } - } - - var m runtime.MemStats - dbg.ReadMemStats(&m) - sum := time.Since(begin) - log.Info("Finished/Restarting test", "name", name, "averageBlockTime", sum/time.Duration(len(r.blockList)), "sys", common.ByteCount(m.Sys)) + state, err := r.readStartingState() + if err != nil { + return err } + store, err := forkchoice.NewForkChoiceStore(state, nil, nil, true) + if err != nil { + return err + } + log.Info("Loading public keys into memory") + bls.SetEnabledCaching(true) + state.ForEachValidator(func(v solid.Validator, idx, total int) bool { + pk := v.PublicKey() + if err := bls.LoadPublicKeyIntoCache(pk[:], false); err != nil { + panic(err) + } + return true + }) + store.OnTick(uint64(time.Now().Unix())) + begin := time.Now() + beginStep := time.Now() + log.Info("Starting test, CTRL+C to stop.", "name", name) + for _, block := range r.blockList { + if err := fn(store, block); err != nil { + return err + } + if block.Block.Slot%uint64(step) == 0 { + elapsed := time.Since(beginStep) + log.Info("Processed", "slot", block.Block.Slot, "elapsed", elapsed, "sec/blk", elapsed/time.Duration(step)) + beginStep = time.Now() + } + } + + var m runtime.MemStats + dbg.ReadMemStats(&m) + sum := time.Since(begin) + log.Info("Finished/Restarting test", "name", name, "averageBlockTime", sum/time.Duration(len(r.blockList)), "sys", common.ByteCount(m.Sys)) + return nil }