mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
* updating the goethereum dependency * fixing dependencies * reverting workspace * more fixes, work in progress * trying with upgraded geth version * fixing deprecated functions except for the time related ones on eth1 distance due to time issues * fixing time issues * gaz * fixing test and upgrading some dependencies and reverting others * Disable cgo in hid, delete old vendored usb library * changelog * rolling back dependencies * fixing go mod tidy * Geth v1.13.6 * fix tests * Add ping interval, set to 500ms for tests. This didnt work * Update to v1.14.8 * Spread it out to different bootnodes * Fix it * Remove Memsize * Update all out of date dependencies * Fix geth body change * Fix Test * Fix Build * Fix Tests * Fix Tests Again * Fix Tests Again * Fix Tests * Fix Test * Copy USB Package for HID * Push it up * Finally fix all tests with felix's changes * updating geth dependency * Update go-ethereum to v1.14.11 * fixing import * reverting blob change * fixing Implicit memory aliasing in for loop. * WIP changes * wip getting a little further on e2e runs * getting a little further * getting a little further * setting everything to capella * more partial fixes * more fixes but still WIP * fixing access list transactions" * some cleanup * making configs dynamic * reverting time * skip lower bound in builder * updating to geth v1.14.12 * fixing verify blob to pointer * go mod tidy * fixing linting * missed removing another terminal difficulty item * another missed update * updating more dependencies to fix cicd * fixing holiman dependency update * downgrading geth to 1.14.11 due to p2p loop issue * reverting builder middleware caused by downgrade * fixing more rollback issues * upgrading back to 1.14.12 after discussing with preston * mod tidy * gofmt * partial review feedback * trying to start e2e from bellatrix instead * reverting some changes --------- Co-authored-by: Preston Van Loon <preston@pvl.dev> Co-authored-by: nisdas <nishdas93@gmail.com>
179 lines
5.2 KiB
Go
179 lines
5.2 KiB
Go
package eth1
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path"
|
|
"strconv"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
"github.com/prysmaticlabs/prysm/v5/io/file"
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/endtoend/helpers"
|
|
e2e "github.com/prysmaticlabs/prysm/v5/testing/endtoend/params"
|
|
e2etypes "github.com/prysmaticlabs/prysm/v5/testing/endtoend/types"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Node represents an ETH1 node.
|
|
type Node struct {
|
|
e2etypes.ComponentRunner
|
|
started chan struct{}
|
|
index int
|
|
enr string
|
|
cmd *exec.Cmd
|
|
}
|
|
|
|
// NewNode creates and returns ETH1 node.
|
|
func NewNode(index int, enr string) *Node {
|
|
return &Node{
|
|
started: make(chan struct{}, 1),
|
|
index: index,
|
|
enr: enr,
|
|
}
|
|
}
|
|
|
|
// Start runs a non-mining ETH1 node.
|
|
// To connect to a miner and start working properly, this node should be a part of a NodeSet.
|
|
func (node *Node) Start(ctx context.Context) error {
|
|
binaryPath, found := bazel.FindBinary("cmd/geth", "geth")
|
|
if !found {
|
|
return errors.New("go-ethereum binary not found")
|
|
}
|
|
|
|
eth1Path := path.Join(e2e.TestParams.TestPath, "eth1data/"+strconv.Itoa(node.index)+"/")
|
|
// Clear out potentially existing dir to prevent issues.
|
|
if _, err := os.Stat(eth1Path); !os.IsNotExist(err) {
|
|
if err = os.RemoveAll(eth1Path); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if err := file.MkdirAll(eth1Path); err != nil {
|
|
return err
|
|
}
|
|
gethJsonPath := path.Join(eth1Path, "genesis.json")
|
|
|
|
gen := interop.GethTestnetGenesis(e2e.TestParams.Eth1GenesisTime, params.BeaconConfig())
|
|
b, err := json.Marshal(gen)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := file.WriteFile(gethJsonPath, b); err != nil {
|
|
return err
|
|
}
|
|
copyPath := path.Join(e2e.TestParams.LogPath, "eth1-genesis.json")
|
|
if err := file.WriteFile(copyPath, b); err != nil {
|
|
return err
|
|
}
|
|
|
|
initCmd := exec.CommandContext(ctx, binaryPath, "init", fmt.Sprintf("--datadir=%s", eth1Path), gethJsonPath) // #nosec G204 -- Safe
|
|
initFile, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, "eth1-init_"+strconv.Itoa(node.index)+".log")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
initCmd.Stderr = initFile
|
|
if err = initCmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
if err = initCmd.Wait(); err != nil {
|
|
return err
|
|
}
|
|
|
|
args := []string{
|
|
"--nat=none", // disable nat traversal in e2e, it is failure prone and not needed
|
|
fmt.Sprintf("--datadir=%s", eth1Path),
|
|
fmt.Sprintf("--http.port=%d", e2e.TestParams.Ports.Eth1RPCPort+node.index),
|
|
fmt.Sprintf("--ws.port=%d", e2e.TestParams.Ports.Eth1WSPort+node.index),
|
|
fmt.Sprintf("--authrpc.port=%d", e2e.TestParams.Ports.Eth1AuthRPCPort+node.index),
|
|
fmt.Sprintf("--bootnodes=%s", node.enr),
|
|
fmt.Sprintf("--port=%d", e2e.TestParams.Ports.Eth1Port+node.index),
|
|
fmt.Sprintf("--networkid=%d", NetworkId),
|
|
"--http",
|
|
"--http.api=engine,net,eth",
|
|
"--http.addr=127.0.0.1",
|
|
"--http.corsdomain=\"*\"",
|
|
"--http.vhosts=\"*\"",
|
|
"--rpc.allow-unprotected-txs",
|
|
"--ws",
|
|
"--ws.api=net,eth,engine",
|
|
"--ws.addr=127.0.0.1",
|
|
"--ws.origins=\"*\"",
|
|
"--ipcdisable",
|
|
"--verbosity=4",
|
|
"--syncmode=full",
|
|
fmt.Sprintf("--txpool.locals=%s", EthAddress),
|
|
}
|
|
|
|
// give the miner start a couple of tries, since the p2p networking check is flaky
|
|
var retryErr error
|
|
for retries := 0; retries < 3; retries++ {
|
|
retryErr = nil
|
|
log.Infof("Starting eth1 node %d, attempt %d with flags: %s", node.index, retries, strings.Join(args[2:], " "))
|
|
runCmd := exec.CommandContext(ctx, binaryPath, args...) // #nosec G204 -- Safe
|
|
errLog, err := os.Create(path.Join(e2e.TestParams.LogPath, "eth1_"+strconv.Itoa(node.index)+".log"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
runCmd.Stderr = errLog
|
|
if err = runCmd.Start(); err != nil {
|
|
return fmt.Errorf("failed to start eth1 chain: %w", err)
|
|
}
|
|
// TODO: the log is not very descriptive but it's always the first log where the chain has
|
|
// - a peer
|
|
// - http server started
|
|
// - genesis synced
|
|
if err = helpers.WaitForTextInFile(errLog, "Node revalidated"); err != nil {
|
|
kerr := runCmd.Process.Kill()
|
|
if kerr != nil {
|
|
log.WithError(kerr).Error("error sending kill to failed node command process")
|
|
}
|
|
retryErr = fmt.Errorf("the first node revalidated log not found, this means the eth1 chain had issues starting: %w", err)
|
|
continue
|
|
}
|
|
node.cmd = runCmd
|
|
log.Infof("eth1 node started after %d retries", retries)
|
|
break
|
|
}
|
|
if retryErr != nil {
|
|
return retryErr
|
|
}
|
|
|
|
// Mark node as ready.
|
|
close(node.started)
|
|
|
|
return node.cmd.Wait()
|
|
}
|
|
|
|
// Started checks whether ETH1 node is started and ready to be queried.
|
|
func (node *Node) Started() <-chan struct{} {
|
|
return node.started
|
|
}
|
|
|
|
// Pause pauses the component and its underlying process.
|
|
func (node *Node) Pause() error {
|
|
return node.cmd.Process.Signal(syscall.SIGSTOP)
|
|
}
|
|
|
|
// Resume resumes the component and its underlying process.
|
|
func (node *Node) Resume() error {
|
|
return node.cmd.Process.Signal(syscall.SIGCONT)
|
|
}
|
|
|
|
// Stop kills the component and its underlying process.
|
|
func (node *Node) Stop() error {
|
|
return node.cmd.Process.Kill()
|
|
}
|
|
|
|
func (node *Node) UnderlyingProcess() *os.Process {
|
|
return node.cmd.Process
|
|
}
|