erigon-pulse/cmd/devnet/models/model.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

78 lines
2.7 KiB
Go

package models
import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/rpc"
)
type (
// TransactionType is the type of transaction attempted to be made, can be regular or contract
TransactionType string
)
const (
// MaxNumberOfBlockChecks is the max number of blocks to look for a transaction in
MaxNumberOfBlockChecks = 3
// hexPrivateKey is the hex value for the private key
hexPrivateKey = "26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48"
// DevAddress is the developer address for sending
DevAddress = "0x67b1d87101671b127f5f8714789C7192f7ad340e"
// NonContractTx is the transaction type for sending ether
NonContractTx TransactionType = "non-contract"
// ContractTx is the transaction type for sending ether
ContractTx TransactionType = "contract"
// DynamicFee is the transaction type for dynamic fee
DynamicFee TransactionType = "dynamic-fee"
// SolContractMethodSignature is the function signature for the event in the solidity contract definition
SolContractMethodSignature = "SubscriptionEvent()"
)
var (
// DevSignedPrivateKey is the signed private key for signing transactions
DevSignedPrivateKey, _ = crypto.HexToECDSA(hexPrivateKey)
// gspec is the geth dev genesis block
gspec = core.DeveloperGenesisBlock(uint64(0), libcommon.HexToAddress(DevAddress))
// ContractBackend is a simulated backend created using a simulated blockchain
ContractBackend = backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, 1_000_000)
// MethodSubscriptionMap is a container for all the subscription methods
MethodSubscriptionMap *map[requests.SubMethod]*MethodSubscription
// NewHeadsChan is the block cache the eth_NewHeads
NewHeadsChan chan interface{}
//QuitNodeChan is the channel for receiving a quit signal on all nodes
QuitNodeChan chan bool
)
// MethodSubscription houses the client subscription, name and channel for its delivery
type MethodSubscription struct {
Client *rpc.Client
ClientSub *rpc.ClientSubscription
Name requests.SubMethod
SubChan chan interface{}
}
// NewMethodSubscription returns a new MethodSubscription instance
func NewMethodSubscription(name requests.SubMethod) *MethodSubscription {
return &MethodSubscription{
Name: name,
SubChan: make(chan interface{}),
}
}
// Block represents a simple block for queries
type Block struct {
Number *hexutil.Big
Transactions []libcommon.Hash
BlockHash libcommon.Hash
}