multinode-demo/ grooming (#4226)
* Rename leader to entrypoint * The fullnode identity keypair can now be provided * Rename _id to _keypair
This commit is contained in:
@ -31,24 +31,24 @@ EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
find_leader() {
|
||||
declare leader leader_address
|
||||
find_entrypoint() {
|
||||
declare entrypoint entrypoint_address
|
||||
declare shift=0
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
leader=$PWD # Default to local tree for rsync
|
||||
leader_address=127.0.0.1:8001 # Default to local leader
|
||||
entrypoint=$PWD # Default to local tree for rsync
|
||||
entrypoint_address=127.0.0.1:8001 # Default to local entrypoint
|
||||
elif [[ -z $2 ]]; then
|
||||
leader=$1
|
||||
leader_address=$leader:8001
|
||||
entrypoint=$1
|
||||
entrypoint_address=$entrypoint:8001
|
||||
shift=1
|
||||
else
|
||||
leader=$1
|
||||
leader_address=$2
|
||||
entrypoint=$1
|
||||
entrypoint_address=$2
|
||||
shift=2
|
||||
fi
|
||||
|
||||
echo "$leader" "$leader_address" "$shift"
|
||||
echo "$entrypoint" "$entrypoint_address" "$shift"
|
||||
}
|
||||
|
||||
rsync_url() { # adds the 'rsync://` prefix to URLs that need it
|
||||
@ -101,30 +101,30 @@ airdrop() {
|
||||
|
||||
setup_vote_account() {
|
||||
declare entrypoint_ip=$1
|
||||
declare node_id_path=$2
|
||||
declare vote_id_path=$3
|
||||
declare node_keypair_path=$2
|
||||
declare vote_keypair_path=$3
|
||||
declare stake=$4
|
||||
|
||||
declare node_id
|
||||
node_id=$($solana_wallet --keypair "$node_id_path" address)
|
||||
declare node_keypair
|
||||
node_keypair=$($solana_wallet --keypair "$node_keypair_path" address)
|
||||
|
||||
declare vote_id
|
||||
vote_id=$($solana_wallet --keypair "$vote_id_path" address)
|
||||
declare vote_keypair
|
||||
vote_keypair=$($solana_wallet --keypair "$vote_keypair_path" address)
|
||||
|
||||
if [[ -f "$vote_id_path".configured ]]; then
|
||||
if [[ -f "$vote_keypair_path".configured ]]; then
|
||||
echo "Vote account has already been configured"
|
||||
else
|
||||
airdrop "$node_id_path" "$entrypoint_ip" "$stake" || return $?
|
||||
airdrop "$node_keypair_path" "$entrypoint_ip" "$stake" || return $?
|
||||
|
||||
# Fund the vote account from the node, with the node as the node_id
|
||||
$solana_wallet --keypair "$node_id_path" --url "http://$entrypoint_ip:8899" \
|
||||
create-vote-account "$vote_id" "$node_id" $((stake - 1)) || return $?
|
||||
# Fund the vote account from the node, with the node as the node_keypair
|
||||
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
|
||||
create-vote-account "$vote_keypair" "$node_keypair" $((stake - 1)) || return $?
|
||||
|
||||
touch "$vote_id_path".configured
|
||||
touch "$vote_keypair_path".configured
|
||||
fi
|
||||
|
||||
$solana_wallet --keypair "$node_id_path" --url "http://$entrypoint_ip:8899" \
|
||||
show-vote-account "$vote_id"
|
||||
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
|
||||
show-vote-account "$vote_keypair"
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -137,9 +137,10 @@ ledger_not_setup() {
|
||||
|
||||
args=()
|
||||
bootstrap_leader=false
|
||||
stake=42 # number of lamports to assign as stake
|
||||
stake=42 # number of lamports to assign as stake by default
|
||||
poll_for_new_genesis_block=0
|
||||
label=
|
||||
fullnode_keypair_path=
|
||||
|
||||
positional_args=()
|
||||
while [[ -n $1 ]]; do
|
||||
@ -157,6 +158,10 @@ while [[ -n $1 ]]; do
|
||||
stake=0
|
||||
args+=("$1" "$2")
|
||||
shift 2
|
||||
elif [[ $1 = --identity ]]; then
|
||||
fullnode_keypair_path=$2
|
||||
args+=("$1" "$2")
|
||||
shift 2
|
||||
elif [[ $1 = --enable-rpc-exit ]]; then
|
||||
args+=("$1")
|
||||
shift
|
||||
@ -198,13 +203,13 @@ if $bootstrap_leader; then
|
||||
fullnode_usage "Unknown argument: ${positional_args[0]}"
|
||||
fi
|
||||
|
||||
[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json ]] ||
|
||||
ledger_not_setup "$SOLANA_CONFIG_DIR/bootstrap-leader-id.json not found"
|
||||
[[ -f "$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json ]] ||
|
||||
ledger_not_setup "$SOLANA_CONFIG_DIR/bootstrap-leader-keypair.json not found"
|
||||
|
||||
$solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify
|
||||
|
||||
fullnode_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-id.json
|
||||
fullnode_vote_id_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-id.json
|
||||
: "${fullnode_keypair_path:="$SOLANA_CONFIG_DIR"/bootstrap-leader-keypair.json}"
|
||||
fullnode_vote_keypair_path="$SOLANA_CONFIG_DIR"/bootstrap-leader-vote-keypair.json
|
||||
ledger_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger
|
||||
accounts_config_dir="$SOLANA_CONFIG_DIR"/bootstrap-leader-accounts
|
||||
|
||||
@ -212,34 +217,33 @@ if $bootstrap_leader; then
|
||||
default_arg --rpc-drone-address 127.0.0.1:9900
|
||||
default_arg --gossip-port 8001
|
||||
else
|
||||
|
||||
if [[ ${#positional_args[@]} -gt 2 ]]; then
|
||||
fullnode_usage "$@"
|
||||
fi
|
||||
|
||||
read -r leader leader_address shift < <(find_leader "${positional_args[@]}")
|
||||
read -r entrypoint entrypoint_address shift < <(find_entrypoint "${positional_args[@]}")
|
||||
shift "$shift"
|
||||
|
||||
fullnode_id_path=$SOLANA_CONFIG_DIR/fullnode-id$label.json
|
||||
fullnode_vote_id_path=$SOLANA_CONFIG_DIR/fullnode-vote-id$label.json
|
||||
: "${fullnode_keypair_path:=$SOLANA_CONFIG_DIR/fullnode-id$label.json}"
|
||||
fullnode_vote_keypair_path=$SOLANA_CONFIG_DIR/fullnode-vote-id$label.json
|
||||
ledger_config_dir=$SOLANA_CONFIG_DIR/fullnode-ledger$label
|
||||
accounts_config_dir=$SOLANA_CONFIG_DIR/fullnode-accounts$label
|
||||
|
||||
mkdir -p "$SOLANA_CONFIG_DIR"
|
||||
[[ -r "$fullnode_id_path" ]] || $solana_keygen -o "$fullnode_id_path"
|
||||
[[ -r "$fullnode_vote_id_path" ]] || $solana_keygen -o "$fullnode_vote_id_path"
|
||||
[[ -r "$fullnode_keypair_path" ]] || $solana_keygen -o "$fullnode_keypair_path"
|
||||
[[ -r "$fullnode_vote_keypair_path" ]] || $solana_keygen -o "$fullnode_vote_keypair_path"
|
||||
|
||||
default_arg --entrypoint "$leader_address"
|
||||
default_arg --rpc-drone-address "${leader_address%:*}:9900"
|
||||
default_arg --entrypoint "$entrypoint_address"
|
||||
default_arg --rpc-drone-address "${entrypoint_address%:*}:9900"
|
||||
fi
|
||||
|
||||
fullnode_id=$($solana_keygen pubkey "$fullnode_id_path")
|
||||
fullnode_vote_id=$($solana_keygen pubkey "$fullnode_vote_id_path")
|
||||
fullnode_keypair=$($solana_keygen pubkey "$fullnode_keypair_path")
|
||||
fullnode_vote_keypair=$($solana_keygen pubkey "$fullnode_vote_keypair_path")
|
||||
|
||||
cat <<EOF
|
||||
======================[ Fullnode configuration ]======================
|
||||
node id: $fullnode_id
|
||||
vote id: $fullnode_vote_id
|
||||
node pubkey: $fullnode_keypair
|
||||
vote pubkey: $fullnode_vote_keypair
|
||||
ledger: $ledger_config_dir
|
||||
accounts: $accounts_config_dir
|
||||
======================================================================
|
||||
@ -250,9 +254,9 @@ if [[ -z $CI ]]; then # Skip in CI
|
||||
source "$here"/../scripts/tune-system.sh
|
||||
fi
|
||||
|
||||
default_arg --identity "$fullnode_id_path"
|
||||
default_arg --voting-keypair "$fullnode_vote_id_path"
|
||||
default_arg --vote-account "$fullnode_vote_id"
|
||||
default_arg --identity "$fullnode_keypair_path"
|
||||
default_arg --voting-keypair "$fullnode_vote_keypair_path"
|
||||
default_arg --vote-account "$fullnode_vote_keypair"
|
||||
default_arg --ledger "$ledger_config_dir"
|
||||
default_arg --accounts "$accounts_config_dir"
|
||||
|
||||
@ -270,8 +274,8 @@ while true; do
|
||||
if $bootstrap_leader; then
|
||||
ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist"
|
||||
fi
|
||||
rsync_leader_url=$(rsync_url "$leader")
|
||||
$rsync -vPr "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR"
|
||||
rsync_entrypoint_url=$(rsync_url "$entrypoint")
|
||||
$rsync -vPr "$rsync_entrypoint_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$ledger_config_dir" ]]; then
|
||||
@ -282,7 +286,7 @@ while true; do
|
||||
trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR
|
||||
|
||||
if ! $bootstrap_leader && ((stake)); then
|
||||
setup_vote_account "${leader_address%:*}" "$fullnode_id_path" "$fullnode_vote_id_path" "$stake"
|
||||
setup_vote_account "${entrypoint_address%:*}" "$fullnode_keypair_path" "$fullnode_vote_keypair_path" "$stake"
|
||||
fi
|
||||
|
||||
echo "$PS4$program ${args[*]}"
|
||||
@ -305,7 +309,7 @@ while true; do
|
||||
((poll_for_new_genesis_block)) || continue
|
||||
((secs_to_next_genesis_poll--)) && continue
|
||||
|
||||
$rsync -r "$rsync_leader_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" || true
|
||||
$rsync -r "$rsync_entrypoint_url"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" || true
|
||||
diff -q "$SOLANA_RSYNC_CONFIG_DIR"/ledger/genesis.json "$ledger_config_dir"/genesis.json >/dev/null 2>&1 || break
|
||||
secs_to_next_genesis_poll=60
|
||||
|
||||
@ -314,7 +318,7 @@ while true; do
|
||||
echo "############## New genesis detected, restarting fullnode ##############"
|
||||
kill "$pid" || true
|
||||
wait "$pid" || true
|
||||
rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_id_path".configured
|
||||
rm -rf "$ledger_config_dir" "$accounts_config_dir" "$fullnode_vote_keypair_path".configured
|
||||
sleep 60 # give the network time to come back up
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user