2022-09-30 20:04:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-15 14:30:56 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-05-21 14:33:11 +00:00
|
|
|
"path/filepath"
|
2023-05-17 12:39:21 +00:00
|
|
|
dbg "runtime/debug"
|
|
|
|
"sync"
|
2022-10-11 12:34:32 +00:00
|
|
|
"time"
|
2022-10-06 19:06:03 +00:00
|
|
|
|
2023-01-10 17:43:58 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/commands"
|
2022-10-06 19:06:03 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/devnetutils"
|
2023-01-12 02:58:21 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/models"
|
2022-10-06 19:06:03 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/node"
|
2023-05-29 19:35:45 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
|
2023-01-10 17:43:58 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/services"
|
2023-05-16 09:53:50 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2023-05-15 14:30:56 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils/flags"
|
|
|
|
"github.com/ledgerwatch/erigon/params"
|
|
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
|
|
|
"github.com/ledgerwatch/erigon/turbo/logging"
|
|
|
|
"github.com/urfave/cli/v2"
|
2022-09-30 20:04:34 +00:00
|
|
|
)
|
|
|
|
|
2023-05-15 14:30:56 +00:00
|
|
|
var DataDirFlag = flags.DirectoryFlag{
|
|
|
|
Name: "datadir",
|
|
|
|
Usage: "Data directory for the devnet",
|
|
|
|
Value: flags.DirectoryString(""),
|
|
|
|
Required: true,
|
|
|
|
}
|
|
|
|
|
2023-05-16 09:53:50 +00:00
|
|
|
type PanicHandler struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ph PanicHandler) Log(r *log.Record) error {
|
|
|
|
fmt.Printf("Stack: %s\n", dbg.Stack())
|
|
|
|
os.Exit(1)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-30 20:04:34 +00:00
|
|
|
func main() {
|
2023-01-10 17:43:58 +00:00
|
|
|
|
2023-05-15 14:30:56 +00:00
|
|
|
debug.RaiseFdLimit()
|
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Version = params.VersionWithCommit(params.GitCommit)
|
|
|
|
app.Action = func(ctx *cli.Context) error {
|
|
|
|
return action(ctx)
|
|
|
|
}
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
&DataDirFlag,
|
|
|
|
}
|
|
|
|
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
|
|
|
// unsubscribe from all the subscriptions made
|
|
|
|
services.UnsubscribeAll()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 17:43:58 +00:00
|
|
|
|
2023-05-15 14:30:56 +00:00
|
|
|
func action(ctx *cli.Context) error {
|
|
|
|
dataDir := ctx.String("datadir")
|
2023-05-21 14:33:11 +00:00
|
|
|
logsDir := filepath.Join(dataDir, "logs")
|
2023-05-31 19:29:36 +00:00
|
|
|
if err := os.MkdirAll(logsDir, 0755); err != nil {
|
2023-05-21 14:33:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-05-16 09:53:50 +00:00
|
|
|
logger := logging.SetupLoggerCtx("devnet", ctx, false /* rootLogger */)
|
2023-05-29 19:35:45 +00:00
|
|
|
reqGen := requests.NewRequestGenerator(logger)
|
2023-05-16 09:53:50 +00:00
|
|
|
|
|
|
|
// Make root logger fail
|
2023-05-20 13:48:16 +00:00
|
|
|
log.Root().SetHandler(PanicHandler{})
|
2023-05-16 09:53:50 +00:00
|
|
|
|
2023-05-15 14:30:56 +00:00
|
|
|
// clear all the dev files
|
|
|
|
if err := devnetutils.ClearDevDB(dataDir, logger); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-30 20:04:34 +00:00
|
|
|
// wait group variable to prevent main function from terminating until routines are finished
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
// start the first erigon node in a go routine
|
2023-05-29 19:35:45 +00:00
|
|
|
node.Start(reqGen, &wg, dataDir, logger)
|
2022-09-30 20:04:34 +00:00
|
|
|
|
2023-01-16 18:59:01 +00:00
|
|
|
// send a quit signal to the quit channels when done making checks
|
|
|
|
node.QuitOnSignal(&wg)
|
|
|
|
|
2022-10-11 12:34:32 +00:00
|
|
|
// sleep for seconds to allow the nodes fully start up
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
|
2023-01-10 17:43:58 +00:00
|
|
|
// start up the subscription services for the different sub methods
|
2023-05-20 13:48:16 +00:00
|
|
|
services.InitSubscriptions([]models.SubMethod{models.ETHNewHeads}, logger)
|
2023-01-10 17:43:58 +00:00
|
|
|
|
2022-10-11 12:34:32 +00:00
|
|
|
// execute all rpc methods amongst the two nodes
|
2023-05-29 19:35:45 +00:00
|
|
|
commands.ExecuteAllMethods(reqGen, logger)
|
2022-10-11 12:34:32 +00:00
|
|
|
|
2022-09-30 20:04:34 +00:00
|
|
|
// wait for all goroutines to complete before exiting
|
|
|
|
wg.Wait()
|
2023-05-15 14:30:56 +00:00
|
|
|
return nil
|
2022-09-30 20:04:34 +00:00
|
|
|
}
|