plumb staking_account and voting_keypair from multinode-demo to Vote (#3199)

* plumb staking_account and voting_keypair from bash to Vote
This commit is contained in:
Rob Walker
2019-03-08 18:29:08 -08:00
committed by Greg Fitzgerald
parent c8c85ff93b
commit 0acdbc0d03
21 changed files with 264 additions and 65 deletions

View File

@ -25,11 +25,19 @@ fi
tune_system
trap 'kill "$pid" && wait "$pid"' INT TERM
$solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify
bootstrap_leader_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json
bootstrap_leader_staker_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-staker-id.json
bootstrap_leader_staker_id=$($solana_wallet --keypair "$bootstrap_leader_staker_id_path" address)
set -x
trap 'kill "$pid" && wait "$pid"' INT TERM ERR
$program \
--identity "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json \
--identity "$bootstrap_leader_id_path" \
--voting-keypair "$bootstrap_leader_staker_id_path" \
--staking-account "$bootstrap_leader_staker_id" \
--ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger \
--accounts "$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts \
--rpc-port 8899 \
@ -38,4 +46,7 @@ $program \
> >($bootstrap_leader_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000
setup_fullnode_staking 127.0.0.1 "$bootstrap_leader_id_path" "$bootstrap_leader_staker_id_path"
wait "$pid"

View File

@ -110,6 +110,68 @@ tune_system() {
fi
}
airdrop() {
declare keypair_file=$1
declare host=$2
declare amount=$3
declare address
address=$($solana_wallet --keypair "$keypair_file" address)
# TODO: Until https://github.com/solana-labs/solana/issues/2355 is resolved
# a fullnode needs N lamports as its vote account gets re-created on every
# node restart, costing it lamports
declare retries=5
while ! $solana_wallet --keypair "$keypair_file" --host "$host" airdrop "$amount"; do
# TODO: Consider moving this retry logic into `solana-wallet airdrop`
# itself, currently it does not retry on "Connection refused" errors.
((retries--))
if [[ $retries -le 0 ]]; then
echo "Airdrop to $address failed."
return 1
fi
echo "Airdrop to $address failed. Remaining retries: $retries"
sleep 1
done
return 0
}
setup_fullnode_staking() {
declare drone_address=$1
declare fullnode_id_path=$2
declare staker_id_path=$3
declare fullnode_id
fullnode_id=$($solana_wallet --keypair "$fullnode_id_path" address)
declare staker_id
staker_id=$($solana_wallet --keypair "$staker_id_path" address)
# A fullnode requires 43 lamports to function:
# - one lamport to keep the node identity public key valid. TODO: really??
# - 42 more for the staker account we fund
airdrop "$fullnode_id_path" "$drone_address" 43 || return $?
# A little wrong, fund the staking account from the
# to the node. Maybe next time consider doing this the opposite
# way or use an ephemeral account
$solana_wallet --keypair "$fullnode_id_path" \
create-staking-account "$staker_id" 42 || return $?
# as the staker, set the node as the delegate and the staker as
# the vote-signer
$solana_wallet --keypair "$staker_id_path" \
configure-staking-account \
--delegate-account "$fullnode_id" \
--authorize-voter "$staker_id" || return $?
return 0
}
# The directory on the bootstrap leader that is rsynced by other full nodes as
# they boot (TODO: Eventually this should go away)
SOLANA_RSYNC_CONFIG_DIR=$PWD/config

View File

@ -28,7 +28,7 @@ usage() {
set -ex
trap 'kill "$pid" && wait "$pid"' INT TERM
trap 'kill "$pid" && wait "$pid"' INT TERM ERR
$solana_drone \
--keypair "$SOLANA_CONFIG_DIR"/mint-id.json \
> >($drone_logger) 2>&1 &

View File

@ -130,12 +130,16 @@ if ((!self_setup)); then
exit 1
}
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id.json
fullnode_staker_id_path=$SOLANA_CONFIG_DIR/fullnode-staker-id.json
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts
else
mkdir -p "$SOLANA_CONFIG_DIR"
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id-x$self_setup_label.json
fullnode_staker_id_path=$SOLANA_CONFIG_DIR/fullnode-staker-id-x$self_setup_label.json
[[ -f "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path"
[[ -f "$fullnode_staker_id_path" ]] || $solana_keygen -o "$fullnode_staker_id_path"
echo "Finding a port.."
# Find an available port in the range 9100-9899
@ -153,6 +157,10 @@ else
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts-x$self_setup_label
fi
fullnode_id=$($solana_wallet --keypair "$fullnode_id_path" address)
fullnode_staker_id=$($solana_wallet --keypair "$fullnode_staker_id_path" address)
[[ -r $fullnode_id_path ]] || {
echo "$fullnode_id_path does not exist"
exit 1
@ -179,6 +187,7 @@ rsync_url() { # adds the 'rsync://` prefix to URLs that need it
echo "rsync://$url"
}
rsync_leader_url=$(rsync_url "$leader")
set -ex
if [[ ! -d "$ledger_config_dir" ]]; then
@ -189,36 +198,14 @@ if [[ ! -d "$ledger_config_dir" ]]; then
}
$solana_ledger_tool --ledger "$ledger_config_dir" verify
$solana_wallet --keypair "$fullnode_id_path" address
# A fullnode requires 3 lamports to function:
# - one lamport to create an instance of the vote_program with
# - one lamport for the transaction fee
# - one lamport to keep the node identity public key valid.
retries=5
while true; do
# TODO: Until https://github.com/solana-labs/solana/issues/2355 is resolved
# a fullnode needs N lamports as its vote account gets re-created on every
# node restart, costing it lamports
if $solana_wallet --keypair "$fullnode_id_path" --host "${leader_address%:*}" airdrop 1000000; then
break
fi
# TODO: Consider moving this retry logic into `solana-wallet airdrop` itself,
# currently it does not retry on "Connection refused" errors.
retries=$((retries - 1))
if [[ $retries -le 0 ]]; then
exit 1
fi
echo "Airdrop failed. Remaining retries: $retries"
sleep 1
done
fi
trap 'kill "$pid" && wait "$pid"' INT TERM
trap 'kill "$pid" && wait "$pid"' INT TERM ERR
$program \
--gossip-port "$gossip_port" \
--identity "$fullnode_id_path" \
--voting-keypair "$fullnode_staker_id_path" \
--staking-account "$fullnode_staker_id" \
--network "$leader_address" \
--ledger "$ledger_config_dir" \
--accounts "$accounts_config_dir" \
@ -227,4 +214,7 @@ $program \
> >($fullnode_logger) 2>&1 &
pid=$!
oom_score_adj "$pid" 1000
setup_fullnode_staking "${leader_address%:*}" "$fullnode_id_path" "$fullnode_staker_id_path"
wait "$pid"

View File

@ -76,6 +76,7 @@ if $bootstrap_leader; then
set -x
$solana_keygen -o "$SOLANA_CONFIG_DIR"/mint-id.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/bootstrap-leader-staker-id.json
$solana_genesis \
--bootstrap-leader-keypair "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json \
--ledger "$SOLANA_RSYNC_CONFIG_DIR"/ledger \
@ -89,5 +90,6 @@ if $fullnode; then
(
set -x
$solana_keygen -o "$SOLANA_CONFIG_DIR"/fullnode-id.json
$solana_keygen -o "$SOLANA_CONFIG_DIR"/fullnode-staker-id.json
)
fi