Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'ledgerwatch:devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKrishna authored Jul 3, 2023
2 parents b084ad6 + 9fd1933 commit a049615
Show file tree
Hide file tree
Showing 115 changed files with 2,383 additions and 1,442 deletions.
12 changes: 12 additions & 0 deletions DEV_CHAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ On the terminal you can type the following command to start node1.

```bash
./erigon --datadir=dev --chain=dev --private.api.addr=localhost:9090 --mine
```
Or, you could start the rpcdaemon internally together
```bash
./erigon --datadir=dev --chain=dev --private.api.addr=localhost:9090 --mine --http.api=eth,erigon,web3,net,debug,trace,txpool,parity,admin --http.corsdomain="*"
```

Argument notes:
Expand All @@ -32,6 +36,7 @@ On the terminal you can type the following command to start node1.
* private.api.addr=localhost:9090 : Tells where Eigon is going to listen for connections.
* mine : Add this if you want the node to mine.
* dev.period <number-of-seconds>: Add this to specify the timing interval among blocks. Number of seconds MUST be > 0 (if you want empty blocks) otherwise the default value 0 does not allow mining of empty blocks.
* http.api: List of services to start on http (rpc) access

The result will be something like this:

Expand Down Expand Up @@ -62,11 +67,18 @@ To tell Node 2 where Node 1 is we will use the Enode info of Node 1 we saved bef

Open terminal 3 and navigate to erigon/build/bin folder. Paste in the following command the Enode info and run it, be careful to remove the last part ?discport=0.

The node info of the first peer can also be obtained with an admin RPC call
```bash
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "admin_nodeInfo", "params": [], "id":83}' localhost:8545
```

```bash
./erigon --datadir=dev2 --chain=dev --private.api.addr=localhost:9091 \
--staticpeers="enode://d30d079163d7b69fcb261c0538c0c3faba4fb4429652970e60fa25deb02a789b4811e98b468726ba0be63b9dc925a019f433177eb6b45c23bb78892f786d8f7a@127.0.0.1:53171" \
--nodiscover
```

You might face a conflict with ports if you run it on the same machine. To specify different ports use, for instance ``--torrent.port 42079``, you might consider specifying all the other flags too: ``--port --http.port --authrpc.port ``

To check if the nodes are connected, you can go to the log of both nodes and look for the line

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ clean:
## devtools: installs dev tools (and checks for npm installation etc.)
devtools:
# Notice! If you adding new binary - add it also to cmd/hack/binary-deps/main.go file
$(GOBUILD) -o $(GOBIN)/go-bindata github.com/kevinburke/go-bindata/go-bindata
$(GOBUILD) -o $(GOBIN)/gencodec github.com/fjl/gencodec
$(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen
$(GOBUILD) -o $(GOBIN)/codecgen github.com/ugorji/go/codec/codecgen
Expand Down
25 changes: 14 additions & 11 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"time"

"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
state2 "github.com/ledgerwatch/erigon-lib/state"
types2 "github.com/ledgerwatch/erigon-lib/types"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"

ethereum "github.com/ledgerwatch/erigon"
"github.com/ledgerwatch/erigon/accounts/abi"
Expand All @@ -42,13 +42,15 @@ import (
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/event"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/stages"
)

Expand Down Expand Up @@ -166,11 +168,11 @@ func (b *SimulatedBackend) Rollback() {
}

func (b *SimulatedBackend) emptyPendingBlock() {
chain, _ := core.GenerateChain(b.m.ChainConfig, b.prependBlock, b.m.Engine, b.m.DB, 1, func(int, *core.BlockGen) {}, false /* intermediateHashes */)
b.pendingBlock = chain.Blocks[0]
b.pendingReceipts = chain.Receipts[0]
b.pendingHeader = chain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(params.MaxDataGasPerBlock)
blockChain, _ := core.GenerateChain(b.m.ChainConfig, b.prependBlock, b.m.Engine, b.m.DB, 1, func(int, *core.BlockGen) {})
b.pendingBlock = blockChain.Blocks[0]
b.pendingReceipts = blockChain.Receipts[0]
b.pendingHeader = blockChain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(chain.MaxDataGasPerBlock)
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
Expand Down Expand Up @@ -750,7 +752,8 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
&b.pendingHeader.Coinbase, b.gasPool,
b.pendingState, state.NewNoopWriter(),
b.pendingHeader, tx,
&b.pendingHeader.GasUsed, vm.Config{}); err != nil {
&b.pendingHeader.GasUsed, b.pendingHeader.DataGasUsed,
vm.Config{}); err != nil {
return err
}
//fmt.Printf("==== Start producing block %d\n", (b.prependBlock.NumberU64() + 1))
Expand All @@ -759,7 +762,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}, false /* intermediateHashes */)
})
if err != nil {
return err
}
Expand Down Expand Up @@ -804,7 +807,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}
block.OffsetTime(int64(adjustment.Seconds()))
}, false /* intermediateHashes */)
})
if err != nil {
return err
}
Expand Down Expand Up @@ -832,6 +835,6 @@ func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsFree() bool { return false }

func (m callMsg) DataGas() uint64 { return params.DataGasPerBlob * uint64(len(m.CallMsg.DataHashes)) }
func (m callMsg) DataGas() uint64 { return misc.GetDataGasUsed(len(m.CallMsg.DataHashes)) }
func (m callMsg) MaxFeePerDataGas() *uint256.Int { return m.CallMsg.MaxFeePerDataGas }
func (m callMsg) DataHashes() []libcommon.Hash { return m.CallMsg.DataHashes }
3 changes: 2 additions & 1 deletion cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ func gnosisConfig() BeaconChainConfig {
cfg.BaseRewardFactor = 25
cfg.SlotsPerEpoch = 16
cfg.EpochsPerSyncCommitteePeriod = 512
cfg.CapellaForkEpoch = math.MaxUint64
cfg.CapellaForkEpoch = 648704
cfg.CapellaForkVersion = 0x03000064
cfg.DenebForkEpoch = math.MaxUint64
cfg.InitializeForkSchedule()
return cfg
Expand Down
128 changes: 127 additions & 1 deletion cmd/devnet/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,130 @@
# Devnet

This is an automated tool run on the devnet that simulates p2p connection between nodes and ultimately tests operations on them.
See [DEV_CHAIN](https://github.com/ledgerwatch/erigon/blob/devel/DEV_CHAIN.md) for a manual version.
See [DEV_CHAIN](https://github.com/ledgerwatch/erigon/blob/devel/DEV_CHAIN.md) for a manual version.

The devnet code performs 3 main functions:

* It runs a series of internal Erigon nodes which will connect to each other to form an internal P2P network
* It allows for the specification of a series of scenarios which will be run against the nodes on that internal network
* It can optionally run a `support` connection which allows the nodes on the network to be connected to the Erigon diagnostic system

The specification of both nodes and scenarios for the devenet is done by specifying configuraion objects. These objects are currently build in code using go `structs` but are cabable of being read as configuration.

## Devnet runtime start-up

The devnet runs as a single `go` process which can be started with the following arguments:

| Arg | Required | Default | Description |
| --- | -------- | ------- | ----------- |
| datadir | Y | | The data directory for the devnet contains all the devnet nodes data and logs |
| chain | N | dev | The devnet chain to run currently supported: dev or bor-devnet |
| bor.withoutheimdall | N | false | Bor specific - tells the devnet to run without a heimdall service. With this flag only a single validator is supported on the devnet |
| metrics | N | false | Enable metrics collection and reporting from devnet nodes |
| metrics.node | N | 0 | At the moment only one node on the network can produce metrics. This value specifies index of the node in the cluster to attach to |
| metrics.port | N | 6060 | The network port of the node to connect to for gather ing metrics |
| diagnostics.url | N | | URL of the diagnostics system provided by the support team, include unique session PIN, if this is specified the devnet will start a `support` tunnel and connect to the diagnostics platform to provide metrics from the specified node on the devnet |
| insecure | N | false | Used if `diagnostics.url` is set to allow communication with diagnostics system using self-signed TLS certificates |

## Network Configuration

Networks configurations are currently specified in code in `main.go` in the `selectNetwork` function. This contains a series of `structs` with the following structue, for eample:

```go
return &devnet.Network{
DataDir: dataDir,
Chain: networkname.DevChainName,
Logger: logger,
BasePrivateApiAddr: "localhost:10090",
BaseRPCAddr: "localhost:8545",
Nodes: []devnet.Node{
args.Miner{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
AccountSlots: 200,
},
args.NonMiner{
Node: args.Node{
ConsoleVerbosity: "0",
DirVerbosity: "5",
},
},
},
}, nil
```

Base IP's and addresses are iterated for each node in the network - to ensure that when the network starts there are no port clashes as the entire nework operates in a single process, hence shares a common host. Individual nodes will be configured with a default set of command line arguments dependent on type. To see the default arguments per node look at the `args\node.go` file where these are specified as tags on the struct members.

## Scenario Configuration

Scenarios are similarly specified in code in `main.go` in the `action` function. This is the initial configration:

```go
scenarios.Scenario{
Name: "all",
Steps: []*scenarios.Step{
{Text: "InitSubscriptions", Args: []any{[]requests.SubMethod{requests.Methods.ETHNewHeads}}},
{Text: "PingErigonRpc"},
{Text: "CheckTxPoolContent", Args: []any{0, 0, 0}},
{Text: "SendTxWithDynamicFee", Args: []any{recipientAddress, services.DevAddress, sendValue}},
{Text: "AwaitBlocks", Args: []any{2 * time.Second}},
},
})
```

Scenarios are created a groups of steps which are created by regestering a `step` handler too see an example of this take a look at the `commands\ping.go` file which adds a ping rpc method (see `PingErigonRpc` above).

This illustrates the registratio process. The `init` function in the file registers the method with the `scenarios` package - which uses the function name as the default step name. Others can be added with additional string arguments fo the `StepHandler` call where they will treated as regular expressions to be matched when processing scenario steps.

```go
func init() {
scenarios.MustRegisterStepHandlers(
scenarios.StepHandler(PingErigonRpc),
)
}
```
Each step method will be called with a `context.Context` as its initial argument. This context provides access to the underlying devnet - so the sptep handler can use it for processing.

```go
func PingErigonRpc(ctx context.Context) error {
...
}
```
The devnet currently supports the following context methods:

```go
func Logger(ctx go_context.Context) log.Logger
```

Fetch the devnet logger - which can be used for logging step processing.

```go
func SelectNode(ctx go_context.Context, selector ...interface{})
```

This method selects a node on the network the selector argument can be either an `int` index or an implementation of the `network.NodeSelector` interface. If no selector is specified a either the `current node` will be returned or a node will be selected at random from the network.

```go
func SelectMiner(ctx go_context.Context, selector ...interface{})
```

This method selects a mining node on the network the selector argument can be either an `int` index or an implementation of the `network.NodeSelector` interface. If no selector is specified a either the `current node` will be returned or a miner will be selected at random from the network.

```go
func SelectNonMiner(ctx go_context.Context, selector ...interface{})
```

This method selects a non mining node on the network the selector argument can be either an `int` index or an implementation of the `network.NodeSelector` interface. If no selector is specified a either the `current node` will be returned or a non-miner will be selected at random from the network.

```go
func WithCurrentNode(ctx go_context.Context, selector interface{}) Context
```
This method sets the `current node` on the network. This can be called to create a context with a fixed node which can be passed to subsequent step functions so that they will operate on a defined network node.

```go
func CurrentNode(ctx go_context.Context) Node
```

This method returns the current node from the network context.
74 changes: 42 additions & 32 deletions cmd/devnet/args/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@ import (

type Node struct {
requests.RequestGenerator `arg:"-"`
BuildDir string `arg:"positional" default:"./build/bin/devnet"`
DataDir string `arg:"--datadir" default:"./dev"`
Chain string `arg:"--chain" default:"dev"`
Port int `arg:"--port"`
AllowedPorts string `arg:"--p2p.allowed-ports"`
NAT string `arg:"--nat" default:"none"`
ConsoleVerbosity string `arg:"--log.console.verbosity" default:"0"`
DirVerbosity string `arg:"--log.dir.verbosity"`
LogDirPath string `arg:"--log.dir.path"`
LogDirPrefix string `arg:"--log.dir.prefix"`
P2PProtocol string `arg:"--p2p.protocol" default:"68"`
Downloader string `arg:"--no-downloader" default:"true"`
WS string `arg:"--ws" flag:"" default:"true"`
PrivateApiAddr string `arg:"--private.api.addr" default:"localhost:9090"`
HttpPort int `arg:"--http.port" default:"8545"`
HttpVHosts string `arg:"--http.vhosts"`
AuthRpcPort int `arg:"--authrpc.port" default:"8551"`
AuthRpcVHosts string `arg:"--authrpc.vhosts"`
WSPort int `arg:"-" default:"8546"` // flag not defined
GRPCPort int `arg:"-" default:"8547"` // flag not defined
TCPPort int `arg:"-" default:"8548"` // flag not defined
StaticPeers string `arg:"--staticpeers"`
WithoutHeimdall bool `arg:"--bor.withoutheimdall" flag:"" default:"false"`
BuildDir string `arg:"positional" default:"./build/bin/devnet" json:"builddir"`
DataDir string `arg:"--datadir" default:"./dev" json:"datadir"`
Chain string `arg:"--chain" default:"dev" json:"chain"`
Port int `arg:"--port" json:"port,omitempty"`
AllowedPorts string `arg:"--p2p.allowed-ports" json:"p2p.allowed-ports,omitempty"`
NAT string `arg:"--nat" default:"none" json:"nat"`
ConsoleVerbosity string `arg:"--log.console.verbosity" default:"0" json:"log.console.verbosity"`
DirVerbosity string `arg:"--log.dir.verbosity" json:"log.dir.verbosity,omitempty"`
LogDirPath string `arg:"--log.dir.path" json:"log.dir.path,omitempty"`
LogDirPrefix string `arg:"--log.dir.prefix" json:"log.dir.prefix,omitempty"`
P2PProtocol string `arg:"--p2p.protocol" default:"68" json:"p2p.protocol"`
Snapshots bool `arg:"--snapshots" flag:"" default:"false" json:"snapshots,omitempty"`
Downloader string `arg:"--no-downloader" default:"true" json:"no-downloader"`
WS string `arg:"--ws" flag:"" default:"true" json:"ws"`
PrivateApiAddr string `arg:"--private.api.addr" default:"localhost:9090" json:"private.api.addr"`
HttpPort int `arg:"--http.port" default:"8545" json:"http.port"`
HttpVHosts string `arg:"--http.vhosts" json:"http.vhosts"`
AuthRpcPort int `arg:"--authrpc.port" default:"8551" json:"authrpc.port"`
AuthRpcVHosts string `arg:"--authrpc.vhosts" json:"authrpc.vhosts"`
WSPort int `arg:"-" default:"8546" json:"-"` // flag not defined
GRPCPort int `arg:"-" default:"8547" json:"-"` // flag not defined
TCPPort int `arg:"-" default:"8548" json:"-"` // flag not defined
Metrics bool `arg:"--metrics" flag:"" default:"false" json:"metrics"`
MetricsPort int `arg:"--metrics.port" json:"metrics.port,omitempty"`
MetricsAddr string `arg:"--metrics.addr" json:"metrics.addr,omitempty"`
StaticPeers string `arg:"--staticpeers" json:"staticpeers,omitempty"`
WithoutHeimdall bool `arg:"--bor.withoutheimdall" flag:"" default:"false" json:"bor.withoutheimdall,omitempty"`
}

func (node *Node) configure(base Node, nodeNumber int) error {
Expand All @@ -47,6 +51,12 @@ func (node *Node) configure(base Node, nodeNumber int) error {

node.StaticPeers = base.StaticPeers

node.Metrics = base.Metrics
node.MetricsPort = base.MetricsPort
node.MetricsAddr = base.MetricsAddr

node.Snapshots = base.Snapshots

var err error

node.PrivateApiAddr, _, err = portFromBase(base.PrivateApiAddr, nodeNumber, 1)
Expand All @@ -68,12 +78,12 @@ func (node *Node) configure(base Node, nodeNumber int) error {

type Miner struct {
Node
Mine bool `arg:"--mine" flag:"true"`
DevPeriod int `arg:"--dev.period"`
BorPeriod int `arg:"--bor.period"`
BorMinBlockSize int `arg:"--bor.minblocksize"`
HttpApi string `arg:"--http.api" default:"admin,eth,erigon,web3,net,debug,trace,txpool,parity,ots"`
AccountSlots int `arg:"--txpool.accountslots" default:"16"`
Mine bool `arg:"--mine" flag:"true" json:"mine"`
DevPeriod int `arg:"--dev.period" json:"dev.period"`
BorPeriod int `arg:"--bor.period" json:"bor.period"`
BorMinBlockSize int `arg:"--bor.minblocksize" json:"bor.minblocksize"`
HttpApi string `arg:"--http.api" default:"admin,eth,erigon,web3,net,debug,trace,txpool,parity,ots" json:"http.api"`
AccountSlots int `arg:"--txpool.accountslots" default:"16" json:"txpool.accountslots"`
}

func (m Miner) Configure(baseNode Node, nodeNumber int) (int, interface{}, error) {
Expand All @@ -99,9 +109,9 @@ func (n Miner) IsMiner() bool {

type NonMiner struct {
Node
HttpApi string `arg:"--http.api" default:"admin,eth,debug,net,trace,web3,erigon,txpool"`
TorrentPort string `arg:"--torrent.port" default:"42070"`
NoDiscover string `arg:"--nodiscover" flag:"" default:"true"`
HttpApi string `arg:"--http.api" default:"admin,eth,debug,net,trace,web3,erigon,txpool" json:"http.api"`
TorrentPort string `arg:"--torrent.port" default:"42070" json:"torrent.port"`
NoDiscover string `arg:"--nodiscover" flag:"" default:"true" json:"nodiscover"`
}

func (n NonMiner) Configure(baseNode Node, nodeNumber int) (int, interface{}, error) {
Expand Down
Loading

0 comments on commit a049615

Please sign in to comment.