Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/onsi/ginkgo…
Browse files Browse the repository at this point in the history
…/v2-2.5.1
  • Loading branch information
Connor Daly authored Nov 29, 2022
2 parents 8fa6fe2 + bdd736c commit 4a30271
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/ava-labs/projects/3
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
71 changes: 18 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,106 +11,69 @@ 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

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>
```
## Build from source code

### 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)).

### Download

```sh
go install github.com/ava-labs/avalanche-network-runner@latest
git clone https://github.com/ava-labs/avalanche-network-runner.git
```

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
### Build

#### Download
From inside the cloned directory:

```sh
git clone https://github.com/ava-labs/avalanche-network-runner.git
./scripts/build.sh
```

#### Install
The binary will be installed inside the `./bin` directory.

From inside the cloned directory:
To add the binary to your path, run

```sh
go install
export PATH=$PWD/bin:$PATH
```

After that, `avalanche-network-runner` binary should be present under `$HOME/go/bin/` directory. Consider adding this directory to the `PATH` environment variable.

#### Run Unit Tests
### Run Unit Tests

Inside the directory cloned above:

```sh
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.

To start it, execute inside the cloned directory:

```sh
./scripts/tests.e2e.sh AVALANCHEGO_VERSION1 AVALANCHEGO_VERSION2
```

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
./scripts/tests.e2e.sh
```

##### `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.
Expand Down Expand Up @@ -813,6 +776,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.
Expand Down
Binary file added local/default/node1/signer.key
Binary file not shown.
1 change: 1 addition & 0 deletions local/default/node2/signer.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<]���vv����A)/�#^?Ӿ���fUc:
1 change: 1 addition & 0 deletions local/default/node3/signer.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�5�*a��^�� i}?������0t�a��j
1 change: 1 addition & 0 deletions local/default/node4/signer.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D��by/��S�v��J� ;;����z�& ��!�
Expand Down
1 change: 1 addition & 0 deletions local/default/node5/signer.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�xb�# ψ���A}%�6˜�f2ʼnZ����$�
11 changes: 11 additions & 0 deletions local/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package local

import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
Expand All @@ -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),
Expand All @@ -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),
Expand Down
44 changes: 31 additions & 13 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package local
import (
"context"
"embed"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand All @@ -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"
Expand All @@ -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
)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions local/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1167,6 +1169,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
chainConfigDirFlag,
subnetConfigDirFlag,
Expand All @@ -1184,6 +1187,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
configFileFlag,
chainConfigDirFlag,
Expand All @@ -1203,6 +1207,7 @@ func TestWriteFiles(t *testing.T) {
expectedFlags: []string{
stakingKeyFlag,
stakingCertFlag,
stakingSigningKeyFlag,
genesisFlag,
configFileFlag,
chainConfigDirFlag,
Expand Down
2 changes: 2 additions & 0 deletions network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ;;
Expand Down

0 comments on commit 4a30271

Please sign in to comment.