Skip to content

Commit

Permalink
update generate staking files
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed Aug 19, 2024
1 parent d946844 commit bf6aa31
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 8 additions & 0 deletions node/add_validator_primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package node

import (
"fmt"
"github.com/ava-labs/avalanche-tooling-sdk-go/subnet"

Check failure on line 8 in node/add_validator_primary.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
"os"
"time"

Check failure on line 10 in node/add_validator_primary.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 11 in node/add_validator_primary.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
Expand All @@ -23,6 +24,7 @@ import (
)

type PrimaryNetworkValidatorParams struct {
// NodeID is the unique identifier of the node to be added as a validator on the Primary Network.
NodeID ids.NodeID

Duration time.Duration
Expand Down Expand Up @@ -64,6 +66,12 @@ func (h *Node) ValidatePrimaryNetwork(
validator PrimaryNetworkValidatorParams,
wallet wallet.Wallet,
) (ids.ID, error) {
if validator.NodeID == ids.EmptyNodeID {
return ids.Empty, subnet.ErrEmptyValidatorNodeID
}
if validator.Duration == 0 {
return ids.Empty, subnet.ErrEmptyValidatorDuration
}
minValStake, err := GetMinStakingAmount(network)
if err != nil {
return ids.Empty, err
Expand Down
2 changes: 1 addition & 1 deletion node/add_validator_primary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestNodesValidatePrimaryNetwork(_ *testing.T) {
Roles: []SupportedRole{Validator},
}

err = node.ProvideStakingCertAndKey(fmt.Sprintf("/Users/raymondsukanto/.avalanche-cli/nodes/%s", node.NodeID))
err = node.ProvideStakingFiles(fmt.Sprintf("/Users/raymondsukanto/.avalanche-cli/nodes/%s", node.NodeID))
if err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type Node struct {
// Logger for node
Logger avalanche.LeveledLogger

// BLS provides a way to aggregate signatures off chain into a single signature that can be efficiently verified on chain.
// To set BlsSecretKey of a node, use SetNodeBLSKey
// For more information about how BLS is used on the P-Chain, please head to https://docs.avax.network/cross-chain/avalanche-warp-messaging/deep-dive#bls-multi-signatures-with-public-key-aggregation
BlsSecretKey *bls.SecretKey
}

Expand Down
16 changes: 12 additions & 4 deletions node/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ import (
"github.com/ava-labs/avalanchego/staking"
)

func (h *Node) ProvideStakingCertAndKey(keyPath string) error {
if nodeID, err := GenerateNodeCertAndKeys(keyPath); err != nil {
// ProvideStakingFiles generates the files needed to validate the primary network:
// - staker.crt, staker.key, more information can be found at https://docs.avax.network/nodes/validate/how-to-stake#secret-management
// - The file containing the node's BLS information: signer.key (more information can be found at https://docs.avax.network/cross-chain/avalanche-warp-messaging/deep-dive#bls-multi-signatures-with-public-key-aggregation)
//
// and stores them in the provided directory in argument in local machine
// and subsequently uploads these files into the remote host in /home/ubuntu/.avalanchego/staking/
// directory
func (h *Node) ProvideStakingFiles(keyPath string) error {
if nodeID, err := GenerateStakingFiles(keyPath); err != nil {
return err
} else {
h.Logger.Infof("Generated Staking Cert and Key for NodeID: %s in folder %s", nodeID.String(), keyPath)
}
return h.RunSSHUploadStakingFiles(keyPath)
}

// GenerateNodeCertAndKeys generates a node certificate and keys and return nodeID
func GenerateNodeCertAndKeys(keyPath string) (ids.NodeID, error) {
// GenerateStakingFiles generates the following files: staker.crt, staker.key and signer.key
// and stores them in the provided directory in argument in local machine
func GenerateStakingFiles(keyPath string) (ids.NodeID, error) {
if err := os.MkdirAll(keyPath, constants.DefaultPerms755); err != nil {
return ids.EmptyNodeID, err
}
Expand Down

0 comments on commit bf6aa31

Please sign in to comment.