Merge branch 'main' into main

This commit is contained in:
abdelkrim boutkhil
2022-11-29 09:40:58 +01:00
committed by GitHub
11 changed files with 73 additions and 68 deletions
+19 -54
View File
@@ -11,74 +11,51 @@ This tool may be especially useful for development and testing.
## Installation
### Using install script
This is the preferred way. Does not require golang to be installed on the system.
To download a binary for the latest release, run:
```sh
curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s
```
The binary will be installed inside the `./bin` directory (relative to where the install command was run).
_Downloading binaries from the Github UI will cause permission errors on Mac._
The binary will be installed inside the `~/bin` directory.
To add the binary to your path, run
```sh
cd bin
export PATH=$PWD:$PATH
export PATH=~/bin:$PATH
```
To add it to your path permanently, add an export command to your shell initialization script (ex: .bashrc).
#### Installing in Custom Location
## Build from source code
To download the binary into a specific directory, run:
```sh
curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s -- -b <relative directory>
```
### Install using golang
This is only needed by advanced users who want to modify or test Avalanche Network Runner in specific ways.
Requires golang to be installed on the system ([https://go.dev/doc/install](https://go.dev/doc/install)).
```sh
go install github.com/ava-labs/avalanche-network-runner@latest
```
After that, the `avalanche-network-runner` binary should be present under the `$HOME/go/bin/` directory. Consider adding this directory to the `PATH` environment variable.
### Install by release download
Does not require golang to be installed on the system.
Download the desired distribution from [https://github.com/ava-labs/avalanche-network-runner/releases](https://github.com/ava-labs/avalanche-network-runner/releases).
Uncompress and locate where is convenient. Consider adding the target bin directory to the `PATH` environment variable.
### Install from source code and execute tests
#### Download
### Download
```sh
git clone https://github.com/ava-labs/avalanche-network-runner.git
```
#### Install
### Build
From inside the cloned directory:
```sh
go install
./scripts/build.sh
```
After that, `avalanche-network-runner` binary should be present under `$HOME/go/bin/` directory. Consider adding this directory to the `PATH` environment variable.
The binary will be installed inside the `./bin` directory.
#### Run Unit Tests
To add the binary to your path, run
```sh
export PATH=$PWD/bin:$PATH
```
### Run Unit Tests
Inside the directory cloned above:
@@ -86,7 +63,7 @@ Inside the directory cloned above:
go test ./...
```
#### Run E2E tests
### Run E2E tests
The E2E test checks `avalanche-network-runner` RPC communication and control. It starts a network against a fresh RPC
server and executes a set of query and control operations on it.
@@ -94,23 +71,9 @@ server and executes a set of query and control operations on it.
To start it, execute inside the cloned directory:
```sh
./scripts/tests.e2e.sh AVALANCHEGO_VERSION1 AVALANCHEGO_VERSION2
./scripts/tests.e2e.sh
```
The E2E test checks whether a node can be restarted with a different binary version. Provide two
different versions as arguments. For Example:
```sh
./scripts/tests.e2e.sh 1.7.9 1.7.10
```
##### `RUN_E2E` environment variable
To specify that the E2E test should be run with `go test`, set environment variable `RUN_E2E` to any non-empty value.
This environment variable is correctly set when executing `./scripts/tests.e2e.sh`, but the user should consider
setting it if trying to execute E2E tests without using that script.
## Using `avalanche-network-runner`
You can import this repository as a library in your Go program, but we recommend running `avalanche-network-runner` as a binary. This creates an RPC server that you can send requests to in order to start a network, add nodes to the network, remove nodes from the network, restart nodes, etc.. You can make requests through the `avalanche-network-runner` command or by making API calls. Requests are "translated" into gRPC and sent to the server.
@@ -815,6 +778,8 @@ type Config struct {
StakingKey string `json:"stakingKey"`
// Must not be nil.
StakingCert string `json:"stakingCert"`
// Must not be nil.
StakingSigningKey string `json:"stakingSigningKey"`
// May be nil.
ConfigFile string `json:"configFile"`
// May be nil.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
<]ŮÇŃvvź…ˇ’A)/Đ#^?Óľ—¨ňfUc:
+1
View File
@@ -0,0 +1 @@
*a®ý^‡­ i}?ýóöŠü×0t¤a¿¯j
+1
View File
@@ -0,0 +1 @@
DŐóby/łŢSvžÉJź ;;
+1
View File
@@ -0,0 +1 @@
Ðxb†# ψïêÝA}%¥6˜¦f2ʼnZ¼÷·Ë$ƒ
+11
View File
@@ -1,6 +1,7 @@
package local
import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
@@ -20,6 +21,10 @@ func writeFiles(genesis []byte, nodeRootDir string, nodeConfig *node.Config) ([]
path string
contents []byte
}
decodedStakingSigningKey, err := base64.StdEncoding.DecodeString(nodeConfig.StakingSigningKey)
if err != nil {
return nil, err
}
files := []file{
{
flagValue: filepath.Join(nodeRootDir, stakingKeyFileName),
@@ -33,6 +38,12 @@ func writeFiles(genesis []byte, nodeRootDir string, nodeConfig *node.Config) ([]
pathKey: config.StakingCertPathKey,
contents: []byte(nodeConfig.StakingCert),
},
{
flagValue: filepath.Join(nodeRootDir, stakingSigningKeyFileName),
path: filepath.Join(nodeRootDir, stakingSigningKeyFileName),
pathKey: config.StakingSignerKeyPathKey,
contents: decodedStakingSigningKey,
},
{
flagValue: filepath.Join(nodeRootDir, genesisFileName),
path: filepath.Join(nodeRootDir, genesisFileName),
+31 -13
View File
@@ -3,6 +3,7 @@ package local
import (
"context"
"embed"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
@@ -23,6 +24,7 @@ import (
"github.com/ava-labs/avalanchego/network/peer"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/utils/beacon"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/ips"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/wrappers"
@@ -31,19 +33,20 @@ import (
)
const (
defaultNodeNamePrefix = "node"
configFileName = "config.json"
upgradeConfigFileName = "upgrade.json"
stakingKeyFileName = "staking.key"
stakingCertFileName = "staking.crt"
genesisFileName = "genesis.json"
stopTimeout = 30 * time.Second
healthCheckFreq = 3 * time.Second
DefaultNumNodes = 5
snapshotPrefix = "anr-snapshot-"
rootDirPrefix = "network-runner-root-data"
defaultDbSubdir = "db"
defaultLogsSubdir = "logs"
defaultNodeNamePrefix = "node"
configFileName = "config.json"
upgradeConfigFileName = "upgrade.json"
stakingKeyFileName = "staking.key"
stakingCertFileName = "staking.crt"
stakingSigningKeyFileName = "signer.key"
genesisFileName = "genesis.json"
stopTimeout = 30 * time.Second
healthCheckFreq = 3 * time.Second
DefaultNumNodes = 5
snapshotPrefix = "anr-snapshot-"
rootDirPrefix = "network-runner-root-data"
defaultDbSubdir = "db"
defaultLogsSubdir = "logs"
// difference between unlock schedule locktime and startime in original genesis
genesisLocktimeStartimeDelta = 2836800
)
@@ -211,6 +214,12 @@ func init() {
panic(err)
}
defaultNetworkConfig.NodeConfigs[i].StakingCert = string(stakingCert)
stakingSigningKey, err := fs.ReadFile(configsDir, fmt.Sprintf("node%d/signer.key", i+1))
if err != nil {
panic(err)
}
encodedStakingSigningKey := base64.StdEncoding.EncodeToString(stakingSigningKey)
defaultNetworkConfig.NodeConfigs[i].StakingSigningKey = encodedStakingSigningKey
defaultNetworkConfig.NodeConfigs[i].IsBeacon = true
}
@@ -517,6 +526,15 @@ func (ln *localNetwork) addNode(nodeConfig node.Config) (node.Node, error) {
nodeConfig.StakingCert = string(stakingCert)
nodeConfig.StakingKey = string(stakingKey)
}
if nodeConfig.StakingSigningKey == "" {
key, err := bls.NewSecretKey()
if err != nil {
return nil, fmt.Errorf("couldn't generate new signing key: %w", err)
}
keyBytes := bls.SecretKeyToBytes(key)
encodedKey := base64.StdEncoding.EncodeToString(keyBytes)
nodeConfig.StakingSigningKey = encodedKey
}
if err := ln.setNodeName(&nodeConfig); err != nil {
return nil, err
+5
View File
@@ -1137,6 +1137,8 @@ func TestWriteFiles(t *testing.T) {
stakingKeyFlag := fmt.Sprintf("--%s=%v", config.StakingTLSKeyPathKey, stakingKeyPath)
stakingCertPath := filepath.Join(tmpDir, stakingCertFileName)
stakingCertFlag := fmt.Sprintf("--%s=%v", config.StakingCertPathKey, stakingCertPath)
stakingSigningKeyPath := filepath.Join(tmpDir, stakingSigningKeyFileName)
stakingSigningKeyFlag := fmt.Sprintf("--%s=%v", config.StakingSignerKeyPathKey, stakingSigningKeyPath)
genesisPath := filepath.Join(tmpDir, genesisFileName)
genesisFlag := fmt.Sprintf("--%s=%v", config.GenesisConfigFileKey, genesisPath)
configFilePath := filepath.Join(tmpDir, configFileName)
@@ -1167,6 +1169,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
chainConfigDirFlag,
subnetConfigDirFlag,
@@ -1184,6 +1187,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
configFileFlag,
chainConfigDirFlag,
@@ -1203,6 +1207,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
configFileFlag,
chainConfigDirFlag,
+2
View File
@@ -68,6 +68,8 @@ type Config struct {
StakingKey string `json:"stakingKey"`
// Must not be nil.
StakingCert string `json:"stakingCert"`
// Must not be nil.
StakingSigningKey string `json:"stakingSigningKey"`
// May be nil.
ConfigFile string `json:"configFile"`
// May be nil.
+1 -1
View File
@@ -29,7 +29,7 @@ parse_args() {
#BINDIR is ./bin unless set be ENV
# over-ridden by flag below
BINDIR=${BINDIR:-~/bin}
BINDIR=${BINDIR:-$DEFAULT_INSTALL}
while getopts "b:dh?x" arg; do
case "$arg" in
b) BINDIR="$OPTARG" ;;