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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
```
#### Validator Metrics
Metrics are available for local monitoring of your validator.
@ -282,3 +281,33 @@ Keybase:
`https://keybase.pub/<KEYBASE_USERNAME>/solana/validator-<PUBKEY>`
3. Add or update your `solana-validator-info` with your Keybase username. The
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
source "$here"/common.sh
fullnode_usage() {
usage() {
if [[ -n $1 ]]; then
echo "$*"
echo
fi
cat <<EOF
Fullnode Usage:
usage: $0 [--config-dir PATH] [--blockstream PATH] [--init-complete-file FILE] [--label LABEL] [--stake LAMPORTS] [--no-voting] [--rpc-port port] [cluster entry point hostname]
usage: $0 [OPTIONS] [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
--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
--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
--node-lamports LAMPORTS - Number of lamports this node has been funded from the genesis block
--no-voting - start node without vote signer
@ -36,7 +36,6 @@ EOF
setup_validator_accounts() {
declare node_lamports=$1
declare stake_lamports=$2
if [[ -f $configured_flag ]]; then
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
set -x
$solana_wallet --keypair "$identity_keypair_path" --url "$rpc_url" \
airdrop $((node_lamports+stake_lamports+fees))
airdrop $((node_lamports+fees))
) || return $?
else
echo "current account balance is "
@ -61,13 +60,6 @@ setup_validator_accounts() {
create-vote-account "$vote_pubkey" "$identity_pubkey" 1 --commission 127
) || 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"
(
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" \
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" \
show-storage-account "$storage_pubkey"
)
@ -94,7 +84,6 @@ setup_validator_accounts() {
args=()
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
label=
identity_keypair_path=
@ -121,7 +110,6 @@ while [[ -n $1 ]]; do
poll_for_new_genesis_block=1
shift
elif [[ $1 = --blockstream ]]; then
stake_lamports=0
args+=("$1" "$2")
shift 2
elif [[ $1 = --entrypoint ]]; then
@ -146,9 +134,6 @@ while [[ -n $1 ]]; do
elif [[ $1 = --init-complete-file ]]; then
args+=("$1" "$2")
shift 2
elif [[ $1 = --stake ]]; then
stake_lamports="$2"
shift 2
elif [[ $1 = --node-lamports ]]; then
node_lamports="$2"
shift 2
@ -183,7 +168,7 @@ while [[ -n $1 ]]; do
config_dir=$2
shift 2
elif [[ $1 = -h ]]; then
fullnode_usage "$@"
usage "$@"
else
echo "Unknown argument: $1"
exit 1
@ -195,12 +180,12 @@ while [[ -n $1 ]]; do
done
if [[ ${#positional_args[@]} -gt 1 ]]; then
fullnode_usage "$@"
usage "$@"
fi
if [[ -n $REQUIRE_CONFIG_DIR ]]; then
if [[ -z $config_dir ]]; then
fullnode_usage "Error: --config-dir not specified"
usage "Error: --config-dir not specified"
fi
SOLANA_CONFIG_DIR="$config_dir"
fi
@ -215,7 +200,7 @@ setup_secondary_mount
if [[ -n $gossip_entrypoint ]]; then
# Prefer the --entrypoint argument if supplied...
if [[ ${#positional_args[@]} -gt 0 ]]; then
fullnode_usage "$@"
usage "$@"
fi
else
# ...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}"
[[ -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
state_dir="$config_dir"/state
configured_flag=$config_dir/.configured
@ -375,18 +357,14 @@ while true; do
fi
vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path")
stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path")
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")
if ((stake_lamports)); then
setup_validator_accounts "$node_lamports" "$stake_lamports"
fi
setup_validator_accounts "$node_lamports"
cat <<EOF
======================[ validator configuration ]======================
identity pubkey: $identity_pubkey
vote pubkey: $vote_pubkey
stake pubkey: $stake_pubkey
storage pubkey: $storage_pubkey
ledger: $ledger_config_dir
accounts: $accounts_config_dir

View File

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