Introduce delegate-stake.sh for adding stake to a validator.sh (#5380)

This commit is contained in:
Michael Vines
2019-08-01 13:48:00 -07:00
committed by GitHub
parent 4d14abbd04
commit 870503ee36
4 changed files with 150 additions and 36 deletions

View File

@ -222,7 +222,6 @@ $ solana-keygen pubkey ~/.local/share/solana/install/active_release/config/valid
$ solana-keygen pubkey ./config/validator-vote-keypair.json $ solana-keygen pubkey ./config/validator-vote-keypair.json
``` ```
#### Validator Metrics #### Validator Metrics
Metrics are available for local monitoring of your validator. Metrics are available for local monitoring of your validator.
@ -282,3 +281,33 @@ Keybase:
`https://keybase.pub/<KEYBASE_USERNAME>/solana/validator-<PUBKEY>` `https://keybase.pub/<KEYBASE_USERNAME>/solana/validator-<PUBKEY>`
3. Add or update your `solana-validator-info` with your Keybase username. The 3. Add or update your `solana-validator-info` with your Keybase username. The
CLI will verify the `validator-<PUBKEY>` file CLI will verify the `validator-<PUBKEY>` file
### Staking
When your validator starts it will have no stake, which means it will ineligible to become leader.
Adding stake can be accomplished by using the `solana-wallet` command. First
obtain the public key for your validator's vote account with:
```bash
$ solana-keygen pubkey ~/validator-config/vote-keypair.json
```
This will output a base58-encoded value that looks similar to
`DhUYZR98qFLLrnHg2HWeGhBQJ9tru7nwdEfYm8L8HdR9`. Then create a stake account
keypair with `solana-keygen`:
```bash
$ solana-keygen new -o ~/validator-config/stake-keypair.json
```
and use the wallet's `delegate-stake` command to stake your validator with 42 lamports:
```bash
$ solana-wallet delegate-stake ~/validator-config/stake-keypair.json [VOTE PUBKEY] 42
```
Note that stake changes are applied at Epoch boundaries so it can take an hour
or more for the change to take effect.
Stake can be deactivate by running:
```bash
$ solana-wallet deactivate-stake ~/validator-config/stake-keypair.json
```
Note that a stake account may only be used once, so after deactivation use the
wallet's `withdraw-stake` command to recover the previously staked lamports.

105
multinode-demo/delegate-stake.sh Executable file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env bash
#
# Delegate stake to a validator
#
set -e
here=$(dirname "$0")
# shellcheck source=multinode-demo/common.sh
source "$here"/common.sh
stake_lamports=42 # default number of lamports to assign as stake
url=http://127.0.0.1:8899 # default RPC url
usage() {
if [[ -n $1 ]]; then
echo "$*"
echo
fi
cat <<EOF
usage: $0 [OPTIONS] <lamports to stake ($stake_lamports)>
Add stake to a validator
OPTIONS:
--url RPC_URL - RPC URL to the cluster ($url)
--label LABEL - Append the given label to the configuration files, useful when running
multiple validators in the same workspace
--no-airdrop - Do not attempt to airdrop the stake
--keypair FILE - Keypair to fund the stake from
EOF
exit 1
}
common_args=()
label=
airdrops_enabled=1
positional_args=()
while [[ -n $1 ]]; do
if [[ ${1:0:1} = - ]]; then
if [[ $1 = --label ]]; then
label="-$2"
shift 2
elif [[ $1 = --keypair || $1 = -k ]]; then
common_args+=("$1" "$2")
shift 2
elif [[ $1 = --url || $1 = -u ]]; then
url=$2
shift 2
elif [[ $1 = --no-airdrop ]]; then
airdrops_enabled=0
shift
elif [[ $1 = -h ]]; then
usage "$@"
else
echo "Unknown argument: $1"
exit 1
fi
else
positional_args+=("$1")
shift
fi
done
common_args+=(--url "$url")
if [[ ${#positional_args[@]} -gt 1 ]]; then
usage "$@"
fi
if [[ -n ${positional_args[0]} ]]; then
stake_lamports=${positional_args[0]}
fi
config_dir="$SOLANA_CONFIG_DIR/validator$label"
vote_keypair_path="$config_dir"/vote-keypair.json
stake_keypair_path=$config_dir/stake-keypair.json
if [[ ! -f $vote_keypair_path ]]; then
echo "Error: $vote_keypair_path not found"
exit 1
fi
if [[ -f $stake_keypair_path ]]; then
# TODO: Add ability to add multiple stakes with this script?
echo "Error: $stake_keypair_path already exists"
exit 1
fi
vote_pubkey=$($solana_keygen pubkey "$vote_keypair_path")
if ((airdrops_enabled)); then
declare fees=100 # TODO: No hardcoded transaction fees, fetch the current cluster fees
$solana_wallet "${common_args[@]}" airdrop $((stake_lamports+fees))
fi
$solana_keygen new -o "$stake_keypair_path"
stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path")
set -x
$solana_wallet "${common_args[@]}" \
delegate-stake "$stake_keypair_path" "$vote_pubkey" "$stake_lamports"
$solana_wallet "${common_args[@]}" show-stake-account "$stake_pubkey"

View File

@ -6,23 +6,23 @@ here=$(dirname "$0")
# shellcheck source=multinode-demo/common.sh # shellcheck source=multinode-demo/common.sh
source "$here"/common.sh source "$here"/common.sh
fullnode_usage() { usage() {
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
echo "$*" echo "$*"
echo echo
fi fi
cat <<EOF cat <<EOF
Fullnode Usage: usage: $0 [OPTIONS] [cluster entry point hostname]
usage: $0 [--config-dir PATH] [--blockstream PATH] [--init-complete-file FILE] [--label LABEL] [--stake LAMPORTS] [--no-voting] [--rpc-port port] [cluster entry point hostname]
Start a validator Start a validator with no stake
OPTIONS:
--config-dir PATH - store configuration and data files under this PATH --config-dir PATH - store configuration and data files under this PATH
--blockstream PATH - open blockstream at this unix domain socket location --blockstream PATH - open blockstream at this unix domain socket location
--init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete --init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete
--label LABEL - Append the given label to the configuration files, useful when running --label LABEL - Append the given label to the configuration files, useful when running
multiple fullnodes in the same workspace multiple validators in the same workspace
--stake LAMPORTS - Number of lamports to stake --stake LAMPORTS - Number of lamports to stake
--node-lamports LAMPORTS - Number of lamports this node has been funded from the genesis block --node-lamports LAMPORTS - Number of lamports this node has been funded from the genesis block
--no-voting - start node without vote signer --no-voting - start node without vote signer
@ -36,7 +36,6 @@ EOF
setup_validator_accounts() { setup_validator_accounts() {
declare node_lamports=$1 declare node_lamports=$1
declare stake_lamports=$2
if [[ -f $configured_flag ]]; then if [[ -f $configured_flag ]]; then
echo "Vote and stake accounts have already been configured" echo "Vote and stake accounts have already been configured"
@ -47,7 +46,7 @@ setup_validator_accounts() {
declare fees=100 # TODO: No hardcoded transaction fees, fetch the current cluster fees declare fees=100 # TODO: No hardcoded transaction fees, fetch the current cluster fees
set -x set -x
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \ $solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
airdrop $((node_lamports+stake_lamports+fees)) airdrop $((node_lamports+fees))
) || return $? ) || return $?
else else
echo "current account balance is " echo "current account balance is "
@ -61,13 +60,6 @@ setup_validator_accounts() {
create-vote-account "$vote_pubkey" "$identity_pubkey" 1 --commission 127 create-vote-account "$vote_pubkey" "$identity_pubkey" 1 --commission 127
) || return $? ) || return $?
echo "Delegate the stake account to the node's vote account"
(
set -x
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
delegate-stake "$stake_keypair_path" "$vote_pubkey" "$stake_lamports"
) || return $?
echo "Create validator storage account" echo "Create validator storage account"
( (
set -x set -x
@ -84,8 +76,6 @@ setup_validator_accounts() {
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" balance $solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" balance
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \ $solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
show-vote-account "$vote_pubkey" show-vote-account "$vote_pubkey"
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
show-stake-account "$stake_pubkey"
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \ $solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
show-storage-account "$storage_pubkey" show-storage-account "$storage_pubkey"
) )
@ -94,7 +84,6 @@ setup_validator_accounts() {
args=() args=()
node_lamports=424242 # number of lamports to assign the node for transaction fees node_lamports=424242 # number of lamports to assign the node for transaction fees
stake_lamports=42 # number of lamports to assign as stake
poll_for_new_genesis_block=0 poll_for_new_genesis_block=0
label= label=
identity_keypair_path= identity_keypair_path=
@ -121,7 +110,6 @@ while [[ -n $1 ]]; do
poll_for_new_genesis_block=1 poll_for_new_genesis_block=1
shift shift
elif [[ $1 = --blockstream ]]; then elif [[ $1 = --blockstream ]]; then
stake_lamports=0
args+=("$1" "$2") args+=("$1" "$2")
shift 2 shift 2
elif [[ $1 = --entrypoint ]]; then elif [[ $1 = --entrypoint ]]; then
@ -146,9 +134,6 @@ while [[ -n $1 ]]; do
elif [[ $1 = --init-complete-file ]]; then elif [[ $1 = --init-complete-file ]]; then
args+=("$1" "$2") args+=("$1" "$2")
shift 2 shift 2
elif [[ $1 = --stake ]]; then
stake_lamports="$2"
shift 2
elif [[ $1 = --node-lamports ]]; then elif [[ $1 = --node-lamports ]]; then
node_lamports="$2" node_lamports="$2"
shift 2 shift 2
@ -183,7 +168,7 @@ while [[ -n $1 ]]; do
config_dir=$2 config_dir=$2
shift 2 shift 2
elif [[ $1 = -h ]]; then elif [[ $1 = -h ]]; then
fullnode_usage "$@" usage "$@"
else else
echo "Unknown argument: $1" echo "Unknown argument: $1"
exit 1 exit 1
@ -195,12 +180,12 @@ while [[ -n $1 ]]; do
done done
if [[ ${#positional_args[@]} -gt 1 ]]; then if [[ ${#positional_args[@]} -gt 1 ]]; then
fullnode_usage "$@" usage "$@"
fi fi
if [[ -n $REQUIRE_CONFIG_DIR ]]; then if [[ -n $REQUIRE_CONFIG_DIR ]]; then
if [[ -z $config_dir ]]; then if [[ -z $config_dir ]]; then
fullnode_usage "Error: --config-dir not specified" usage "Error: --config-dir not specified"
fi fi
SOLANA_CONFIG_DIR="$config_dir" SOLANA_CONFIG_DIR="$config_dir"
fi fi
@ -215,7 +200,7 @@ setup_secondary_mount
if [[ -n $gossip_entrypoint ]]; then if [[ -n $gossip_entrypoint ]]; then
# Prefer the --entrypoint argument if supplied... # Prefer the --entrypoint argument if supplied...
if [[ ${#positional_args[@]} -gt 0 ]]; then if [[ ${#positional_args[@]} -gt 0 ]]; then
fullnode_usage "$@" usage "$@"
fi fi
else else
# ...but also support providing the entrypoint's hostname as the first # ...but also support providing the entrypoint's hostname as the first
@ -239,9 +224,6 @@ drone_address="${gossip_entrypoint%:*}":9900
: "${storage_keypair_path:=$config_dir/storage-keypair.json}" : "${storage_keypair_path:=$config_dir/storage-keypair.json}"
[[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path" [[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path"
stake_keypair_path=$config_dir/stake-keypair.json
[[ -r "$stake_keypair_path" ]] || $solana_keygen new -o "$stake_keypair_path"
ledger_config_dir=$config_dir/ledger ledger_config_dir=$config_dir/ledger
state_dir="$config_dir"/state state_dir="$config_dir"/state
configured_flag=$config_dir/.configured configured_flag=$config_dir/.configured
@ -375,18 +357,14 @@ while true; do
fi fi
vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path") vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path")
stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path")
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")
if ((stake_lamports)); then setup_validator_accounts "$node_lamports"
setup_validator_accounts "$node_lamports" "$stake_lamports"
fi
cat <<EOF cat <<EOF
======================[ validator configuration ]====================== ======================[ validator configuration ]======================
identity pubkey: $identity_pubkey identity pubkey: $identity_pubkey
vote pubkey: $vote_pubkey vote pubkey: $vote_pubkey
stake pubkey: $stake_pubkey
storage pubkey: $storage_pubkey storage pubkey: $storage_pubkey
ledger: $ledger_config_dir ledger: $ledger_config_dir
accounts: $accounts_config_dir accounts: $accounts_config_dir

View File

@ -199,10 +199,8 @@ local|tar|skip)
args+=( args+=(
--blockstream /tmp/solana-blockstream.sock --blockstream /tmp/solana-blockstream.sock
--no-voting --no-voting
--stake 0
) )
else else
args+=(--stake "$stake")
args+=(--enable-rpc-exit) args+=(--enable-rpc-exit)
if [[ -n $internalNodesLamports ]]; then if [[ -n $internalNodesLamports ]]; then
args+=(--node-lamports "$internalNodesLamports") args+=(--node-lamports "$internalNodesLamports")
@ -261,6 +259,10 @@ local|tar|skip)
pid=$! pid=$!
oom_score_adj "$pid" 1000 oom_score_adj "$pid" 1000
waitForNodeToInit waitForNodeToInit
if [[ $skipSetup != true && $nodeType != blockstreamer ]]; then
./multinode-demo/delegate-stake.sh $stake
fi
;; ;;
replicator) replicator)
if [[ $deployMethod != skip ]]; then if [[ $deployMethod != skip ]]; then