erigon-pulse/cmd/devnet/commands/all.go
Mark Holt 415cf86250
refactor to allow switchable consensus and multiple communicating nodes (#7646)
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.
2023-06-04 20:53:05 +01:00

62 lines
1.8 KiB
Go

package commands
import (
"github.com/ledgerwatch/erigon/cmd/devnet/models"
"github.com/ledgerwatch/erigon/cmd/devnet/node"
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
"github.com/ledgerwatch/erigon/cmd/devnet/services"
"github.com/ledgerwatch/log/v3"
)
// ExecuteAllMethods runs all the simulation tests for erigon devnet
func ExecuteAllMethods(nw *node.Network, logger log.Logger) {
// test connection to JSON RPC
logger.Info("PINGING JSON RPC...")
if err := pingErigonRpc(nw.Node(0), logger); err != nil {
return
}
logger.Info("")
// get balance of the receiver's account
callGetBalance(nw.Node(0), addr, requests.BlockNumbers.Latest, 0, logger)
logger.Info("")
// confirm that the txpool is empty
logger.Info("CONFIRMING TXPOOL IS EMPTY BEFORE SENDING TRANSACTION...")
services.CheckTxPoolContent(nw.Node(0), 0, 0, 0, logger)
logger.Info("")
/*
* Cannot run contract tx after running regular tx because contract tx simulates a new backend
* and it expects the nonce to be 0.
* So it is best to run them separately by commenting and uncommenting the different code blocks.
*/
// send a token from the dev address to the recipient address
//_, err := callSendTx(sendValue, recipientAddress, models.DevAddress)
//if err != nil {
// fmt.Printf("callSendTx error: %v\n", err)
// return
//}
//fmt.Println()
_, err := callSendTxWithDynamicFee(nw.Node(0), recipientAddress, models.DevAddress, logger)
if err != nil {
logger.Error("callSendTxWithDynamicFee", "error", err)
return
}
logger.Info("")
// initiate a contract transaction
//fmt.Println("INITIATING A CONTRACT TRANSACTION...")
//_, err := callContractTx()
//if err != nil {
// fmt.Printf("callContractTx error: %v\n", err)
// return
//}
//fmt.Println()
logger.Info("SEND SIGNAL TO QUIT ALL RUNNING NODES")
models.QuitNodeChan <- true
}