mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-10 21:11:20 +00:00
415cf86250
This branch is intended to allow the devnet to be used for testing multiple consents types beyond the default clique. It is initially being used to test Bor consensus for polygon. It also has the following refactoring: ### 1. Network configuration The two node arg building functions miningNodeArgs and nonMiningNodeArgs have been replaced with a configuration struct which is used to configure: ```go network := &node.Network{ DataDir: dataDir, Chain: networkname.DevChainName, //Chain: networkname.BorDevnetChainName, Logger: logger, BasePrivateApiAddr: "localhost:9090", BaseRPCAddr: "localhost:8545", Nodes: []node.NetworkNode{ &node.Miner{}, &node.NonMiner{}, }, } ``` and start multiple nodes ```go network.Start() ``` Network start will create a network of nodes ensuring that all nodes are configured with non clashing network ports set via command line arguments on start-up. ### 2. Request Routing The `RequestRouter` has been updated to take a 'target' rather than using a static dispatcher which routes to a single node on the network. Each node in the network has its own request generator so command and services have more flexibility in request routing and `ExecuteAllMethods` currently takes the `node.Network` as an argument and can pick which node (node 0 for the moment) to send requests to.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package node
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/models"
|
|
"github.com/ledgerwatch/log/v3"
|
|
)
|
|
|
|
type Network struct {
|
|
DataDir string
|
|
Chain string
|
|
Logger log.Logger
|
|
BasePrivateApiAddr string
|
|
BaseRPCAddr string
|
|
Nodes []NetworkNode
|
|
wg sync.WaitGroup
|
|
peers []string
|
|
}
|
|
|
|
// Start starts the process for two erigon nodes running on the dev chain
|
|
func (nw *Network) Start() {
|
|
for i, node := range nw.Nodes {
|
|
node.Start(nw, i)
|
|
|
|
// get the enode of the node
|
|
// - note this has the side effect of waiting for the node to start
|
|
if enode, err := node.getEnode(); err != nil {
|
|
nw.peers = append(nw.peers, enode)
|
|
|
|
// TODO we need to call AddPeer to the nodes to make them aware of this one
|
|
// the current model only works for a 2 node network
|
|
}
|
|
|
|
}
|
|
|
|
quitOnSignal(&nw.wg)
|
|
}
|
|
|
|
func (nw *Network) Wait() {
|
|
nw.wg.Wait()
|
|
}
|
|
|
|
func (nw *Network) Node(nodeNumber int) *Node {
|
|
return nw.Nodes[nodeNumber].node()
|
|
}
|
|
|
|
// QuitOnSignal stops the node goroutines after all checks have been made on the devnet
|
|
func quitOnSignal(wg *sync.WaitGroup) {
|
|
models.QuitNodeChan = make(chan bool)
|
|
go func() {
|
|
for <-models.QuitNodeChan {
|
|
// TODO this assumes 2 nodes and it should be node.Stop()
|
|
wg.Done()
|
|
wg.Done()
|
|
}
|
|
}()
|
|
}
|