[devnet] Always select first node, fix configuration mess up between nodes (#7863)

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
This commit is contained in:
ledgerwatch 2023-07-10 11:37:55 +01:00 committed by GitHub
parent e6c642b568
commit a9c86ab887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 71 deletions

View File

@ -26,7 +26,7 @@ func GetBalance(ctx context.Context, addr string, blockNum requests.BlockNumber,
logger.Info("Getting balance", "addeess", addr)
address := libcommon.HexToAddress(addr)
bal, err := devnet.SelectBlockProducer(ctx).GetBalance(address, blockNum)
bal, err := devnet.SelectNode(ctx).GetBalance(address, blockNum)
if err != nil {
logger.Error("FAILURE", "error", err)

View File

@ -3,7 +3,6 @@ package devnet
import (
go_context "context"
"github.com/ledgerwatch/erigon/cmd/devnet/devnetutils"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"
)
@ -87,7 +86,7 @@ func SelectNode(ctx go_context.Context, selector ...interface{}) Node {
return current
}
return network.AnyNode(ctx)
return network.FirstNode()
}
return nil
@ -116,7 +115,7 @@ func SelectBlockProducer(ctx go_context.Context, selector ...interface{}) Node {
}
if blockProducers := network.BlockProducers(); len(blockProducers) > 0 {
return blockProducers[devnetutils.RandomInt(len(blockProducers)-1)]
return blockProducers[0]
}
}
@ -146,7 +145,7 @@ func SelectNonBlockProducer(ctx go_context.Context, selector ...interface{}) Nod
}
if nonBlockProducers := network.NonBlockProducers(); len(nonBlockProducers) > 0 {
return nonBlockProducers[devnetutils.RandomInt(len(nonBlockProducers)-1)]
return nonBlockProducers[0]
}
}

View File

@ -7,7 +7,6 @@ import (
"net"
"net/url"
"os"
"strconv"
"strings"
"sync"
"time"
@ -28,36 +27,25 @@ type Network struct {
Chain string
Logger log.Logger
BasePrivateApiAddr string
BaseRPCAddr string
BaseRPCHost string
BaseRPCPort int
Snapshots bool
Nodes []Node
wg sync.WaitGroup
peers []string
}
// Start starts the process for two erigon nodes running on the dev chain
// Start starts the process for multiple erigon nodes running on the dev chain
func (nw *Network) Start(ctx *cli.Context) error {
type configurable interface {
Configure(baseNode args.Node, nodeNumber int) (int, interface{}, error)
}
apiHost, apiPort, err := net.SplitHostPort(nw.BaseRPCAddr)
if err != nil {
return err
}
apiPortNo, err := strconv.Atoi(apiPort)
if err != nil {
return err
}
baseNode := args.Node{
DataDir: nw.DataDir,
Chain: nw.Chain,
HttpPort: apiPortNo,
HttpPort: nw.BaseRPCPort,
PrivateApiAddr: nw.BasePrivateApiAddr,
Snapshots: nw.Snapshots,
}
@ -78,7 +66,7 @@ func (nw *Network) Start(ctx *cli.Context) error {
nodePort, args, err := configurable.Configure(base, i)
if err == nil {
node, err = nw.startNode(fmt.Sprintf("http://%s:%d", apiHost, nodePort), args, i)
node, err = nw.startNode(fmt.Sprintf("http://%s:%d", nw.BaseRPCHost, nodePort), args, i)
}
if err != nil {
@ -231,8 +219,8 @@ func (nw *Network) Wait() {
nw.wg.Wait()
}
func (nw *Network) AnyNode(ctx go_context.Context) Node {
return nw.SelectNode(ctx, devnetutils.RandomInt(len(nw.Nodes)-1))
func (nw *Network) FirstNode() Node {
return nw.Nodes[0]
}
func (nw *Network) SelectNode(ctx go_context.Context, selector interface{}) Node {

View File

@ -233,9 +233,17 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
Chain: networkname.BorDevnetChainName,
Logger: logger,
BasePrivateApiAddr: "localhost:10090",
BaseRPCAddr: "localhost:8545",
BaseRPCHost: "localhost",
BaseRPCPort: 8545,
//Snapshots: true,
Nodes: []devnet.Node{
args.NonBlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
WithoutHeimdall: true,
},
},
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
@ -244,13 +252,6 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
},
AccountSlots: 200,
},
args.NonBlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
WithoutHeimdall: true,
},
},
},
}, nil
} else {
@ -259,28 +260,29 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
Chain: networkname.BorDevnetChainName,
Logger: logger,
BasePrivateApiAddr: "localhost:10090",
BaseRPCAddr: "localhost:8545",
BaseRPCHost: "localhost",
BaseRPCPort: 8545,
Nodes: []devnet.Node{
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
AccountSlots: 200,
},
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
AccountSlots: 200,
},
args.NonBlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
},
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
AccountSlots: 200,
},
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
AccountSlots: 200,
},
},
}, nil
}
@ -291,8 +293,15 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
Chain: networkname.DevChainName,
Logger: logger,
BasePrivateApiAddr: "localhost:10090",
BaseRPCAddr: "localhost:8545",
BaseRPCHost: "localhost",
BaseRPCPort: 8545,
Nodes: []devnet.Node{
args.NonBlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
},
args.BlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
@ -300,12 +309,6 @@ func selectNetwork(ctx *cli.Context, logger log.Logger) (*devnet.Network, error)
},
AccountSlots: 200,
},
args.NonBlockProducer{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
},
},
}, nil
}

View File

@ -7,7 +7,7 @@ import (
)
func CheckTxPoolContent(ctx context.Context, expectedPendingSize, expectedQueuedSize, expectedBaseFeeSize int) {
pendingSize, queuedSize, baseFeeSize, err := devnet.SelectBlockProducer(ctx).TxpoolContent()
pendingSize, queuedSize, baseFeeSize, err := devnet.SelectNode(ctx).TxpoolContent()
logger := devnet.Logger(ctx)

View File

@ -14,6 +14,8 @@ import (
"github.com/ledgerwatch/log/v3"
)
var devnetSigner = libcommon.HexToAddress("0x67b1d87101671b127f5f8714789c7192f7ad340e")
type ChainSpanner struct {
validatorSet abi.ABI
chainConfig *chain.Config
@ -69,10 +71,11 @@ func (c *ChainSpanner) GetCurrentSpan(syscall consensus.SystemCall) (*Span, erro
func (c *ChainSpanner) GetCurrentValidators(blockNumber uint64, signer libcommon.Address, getSpanForBlock func(blockNum uint64) (*HeimdallSpan, error)) ([]*valset.Validator, error) {
// Use signer as validator in case of bor devent
if c.chainConfig.ChainName == networkname.BorDevnetChainName {
c.logger.Info("Spanner returning pre-set validator set")
validators := []*valset.Validator{
{
ID: 1,
Address: signer,
Address: devnetSigner,
VotingPower: 1000,
ProposerPriority: 1,
},
@ -95,7 +98,7 @@ func (c *ChainSpanner) GetCurrentProducers(blockNumber uint64, signer libcommon.
validators := []*valset.Validator{
{
ID: 1,
Address: signer,
Address: devnetSigner,
VotingPower: 1000,
ProposerPriority: 1,
},

View File

@ -387,8 +387,8 @@ func processChanges(origChanges []*Validator) (updates, removals []*Validator, e
var prevAddr libcommon.Address
// Scan changes by address and append valid validators to updates or removals lists.
for _, valUpdate := range changes {
if bytes.Equal(valUpdate.Address.Bytes(), prevAddr.Bytes()) {
for i, valUpdate := range changes {
if i > 0 && bytes.Equal(valUpdate.Address.Bytes(), prevAddr.Bytes()) {
err = fmt.Errorf("duplicate entry %v in %v", valUpdate, changes)
return nil, nil, err
}

View File

@ -390,5 +390,5 @@ func StartNode(stack *Node) {
utils.Fatalf("Error starting protocol stack: %v", err)
}
go debug.ListenSignals(stack)
go debug.ListenSignals(stack, stack.logger)
}

View File

@ -122,7 +122,7 @@ func SetupCobra(cmd *cobra.Command, filePrefix string) log.Logger {
}
}
go ListenSignals(nil)
go ListenSignals(nil, logger)
pprof, err := flags.GetBool(pprofFlag.Name)
if err != nil {
log.Error("failed setting config flags from yaml/toml file", "err", err)

View File

@ -13,7 +13,7 @@ import (
"golang.org/x/sys/unix"
)
func ListenSignals(stack io.Closer) {
func ListenSignals(stack io.Closer, logger log.Logger) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, unix.SIGINT, unix.SIGTERM)
_debug.GetSigC(&sigc)
@ -24,14 +24,14 @@ func ListenSignals(stack io.Closer) {
for {
select {
case <-sigc:
log.Info("Got interrupt, shutting down...")
logger.Info("Got interrupt, shutting down...")
if stack != nil {
go stack.Close()
}
for i := 10; i > 0; i-- {
<-sigc
if i > 1 {
log.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
logger.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
}
}
Exit() // ensure trace and CPU profile data is flushed.

View File

@ -11,21 +11,21 @@ import (
"github.com/ledgerwatch/log/v3"
)
func ListenSignals(stack io.Closer) {
func ListenSignals(stack io.Closer, logger log.Logger) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt)
_debug.GetSigC(&sigc)
defer signal.Stop(sigc)
<-sigc
log.Info("Got interrupt, shutting down...")
logger.Info("Got interrupt, shutting down...")
if stack != nil {
go stack.Close()
}
for i := 10; i > 0; i-- {
<-sigc
if i > 1 {
log.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
logger.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
}
}
Exit() // ensure trace and CPU profile data is flushed.

View File

@ -84,11 +84,11 @@ func NewNodConfigUrfave(ctx *cli.Context, logger log.Logger) *nodecfg.Config {
return nodeConfig
}
func NewEthConfigUrfave(ctx *cli.Context, nodeConfig *nodecfg.Config, logger log.Logger) *ethconfig.Config {
ethConfig := &ethconfig.Defaults
utils.SetEthConfig(ctx, nodeConfig, ethConfig, logger)
erigoncli.ApplyFlagsForEthConfig(ctx, ethConfig, logger)
ethConfig := ethconfig.Defaults // Needs to be a copy, not pointer
utils.SetEthConfig(ctx, nodeConfig, &ethConfig, logger)
erigoncli.ApplyFlagsForEthConfig(ctx, &ethConfig, logger)
return ethConfig
return &ethConfig
}
// New creates a new `ErigonNode`.