Skip to content

Commit

Permalink
Merge branch 'main' into simplify-install-instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero authored Nov 28, 2022
2 parents 088a25a + 3e03e70 commit 78e1cdd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,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

0 comments on commit 78e1cdd

Please sign in to comment.