Rewrite multinode-demo/replicator.sh to avoid fullnode.sh (#5299)

This commit is contained in:
Michael Vines
2019-07-26 19:00:34 -07:00
committed by GitHub
parent e2c9d87d91
commit 252257fe66
4 changed files with 163 additions and 158 deletions

View File

@ -20,7 +20,7 @@ fullnode_usage() {
Fullnode Usage: Fullnode Usage:
usage: $0 [--config-dir PATH] [--blockstream PATH] [--init-complete-file FILE] [--label LABEL] [--stake LAMPORTS] [--no-voting] [--rpc-port port] [rsync network path to bootstrap leader configuration] [cluster entry point] usage: $0 [--config-dir PATH] [--blockstream PATH] [--init-complete-file FILE] [--label LABEL] [--stake LAMPORTS] [--no-voting] [--rpc-port port] [rsync network path to bootstrap leader configuration] [cluster entry point]
Start a validator or a replicator Start a validator
--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
@ -136,43 +136,6 @@ setup_validator_accounts() {
return 0 return 0
} }
setup_replicator_account() {
declare entrypoint_ip=$1
declare node_lamports=$2
if [[ -f $configured_flag ]]; then
echo "Replicator account has already been configured"
else
if ((airdrops_enabled)); then
(
set -x
$solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899"
airdrop "$node_lamports"
) || return $?
else
echo "current account balance is "
$solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" balance || return $?
fi
echo "Create replicator storage account"
(
set -x
$solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
create-replicator-storage-account "$identity_pubkey" "$storage_pubkey"
) || return $?
touch "$configured_flag"
fi
(
set -x
$solana_wallet --keypair "$identity_keypair_path" --url "http://$entrypoint_ip:8899" \
show-storage-account "$storage_pubkey"
)
return 0
}
ledger_not_setup() { ledger_not_setup() {
echo "Error: $*" echo "Error: $*"
echo echo
@ -213,9 +176,6 @@ while [[ -n $1 ]]; do
elif [[ $1 = --no-snapshot ]]; then elif [[ $1 = --no-snapshot ]]; then
boot_from_snapshot=0 boot_from_snapshot=0
shift shift
elif [[ $1 = --replicator ]]; then
node_type=replicator
shift
elif [[ $1 = --validator ]]; then elif [[ $1 = --validator ]]; then
node_type=validator node_type=validator
shift shift
@ -303,34 +263,7 @@ fi
setup_secondary_mount setup_secondary_mount
if [[ $node_type = replicator ]]; then if [[ $node_type = bootstrap_leader ]]; then
if [[ ${#positional_args[@]} -gt 2 ]]; then
fullnode_usage "$@"
fi
read -r entrypoint entrypoint_address shift < <(find_entrypoint "${positional_args[@]}")
shift "$shift"
mkdir -p "$SOLANA_CONFIG_DIR"
: "${identity_keypair_path:=$SOLANA_CONFIG_DIR/replicator-keypair$label.json}"
[[ -r "$identity_keypair_path" ]] || $solana_keygen new -o "$identity_keypair_path"
: "${storage_keypair_path="$SOLANA_CONFIG_DIR"/replicator-storage-keypair$label.json}"
[[ -r "$storage_keypair_path" ]] || $solana_keygen new -o "$storage_keypair_path"
ledger_config_dir=$SOLANA_CONFIG_DIR/replicator-ledger$label
configured_flag=$SOLANA_CONFIG_DIR/replicator$label.configured
program=$solana_replicator
default_arg --entrypoint "$entrypoint_address"
default_arg --identity "$identity_keypair_path"
default_arg --storage-keypair "$storage_keypair_path"
default_arg --ledger "$ledger_config_dir"
rsync_entrypoint_url=$(rsync_url "$entrypoint")
elif [[ $node_type = bootstrap_leader ]]; then
if [[ ${#positional_args[@]} -ne 0 ]]; then if [[ ${#positional_args[@]} -ne 0 ]]; then
fullnode_usage "Unknown argument: ${positional_args[0]}" fullnode_usage "Unknown argument: ${positional_args[0]}"
fi fi
@ -397,22 +330,20 @@ fi
identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path") identity_pubkey=$($solana_keygen pubkey "$identity_keypair_path")
export SOLANA_METRICS_HOST_ID="$identity_pubkey" export SOLANA_METRICS_HOST_ID="$identity_pubkey"
if [[ $node_type != replicator ]]; then accounts_config_dir="$state_dir"/accounts
accounts_config_dir="$state_dir"/accounts snapshot_config_dir="$state_dir"/snapshots
snapshot_config_dir="$state_dir"/snapshots
default_arg --identity "$identity_keypair_path" default_arg --identity "$identity_keypair_path"
default_arg --voting-keypair "$voting_keypair_path" default_arg --voting-keypair "$voting_keypair_path"
default_arg --storage-keypair "$storage_keypair_path" default_arg --storage-keypair "$storage_keypair_path"
default_arg --ledger "$ledger_config_dir" default_arg --ledger "$ledger_config_dir"
default_arg --accounts "$accounts_config_dir" default_arg --accounts "$accounts_config_dir"
default_arg --snapshot-path "$snapshot_config_dir" default_arg --snapshot-path "$snapshot_config_dir"
if [[ -n $SOLANA_CUDA ]]; then if [[ -n $SOLANA_CUDA ]]; then
program=$solana_validator_cuda program=$solana_validator_cuda
else else
program=$solana_validator program=$solana_validator
fi
fi fi
if [[ -z $CI ]]; then # Skip in CI if [[ -z $CI ]]; then # Skip in CI
@ -471,75 +402,61 @@ while true; do
) )
fi fi
if [[ $node_type = replicator ]]; then if [[ $node_type = bootstrap_leader && ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist"
setup_replicator_account "${entrypoint_address%:*}" \ fi
"$node_lamports"
cat <<EOF
======================[ $node_type configuration ]======================
replicator pubkey: $identity_pubkey
storage pubkey: $storage_pubkey
ledger: $ledger_config_dir
======================================================================
EOF
else
if [[ $node_type = bootstrap_leader && ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then
ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist"
fi
if [[ ! -d "$ledger_config_dir" ]]; then
if [[ $node_type = validator ]]; then
(
cd "$SOLANA_RSYNC_CONFIG_DIR"
echo "Rsyncing genesis ledger from ${rsync_entrypoint_url:?}..."
SECONDS=
while ! $rsync -Pr "${rsync_entrypoint_url:?}"/config/ledger .; do
echo "Genesis ledger rsync failed"
sleep 5
done
echo "Fetched genesis ledger in $SECONDS seconds"
if ((boot_from_snapshot)); then
SECONDS=
echo "Rsyncing state snapshot ${rsync_entrypoint_url:?}..."
if ! $rsync -P "${rsync_entrypoint_url:?}"/config/state.tgz .; then
echo "State snapshot rsync failed"
rm -f "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz
exit
fi
echo "Fetched snapshot in $SECONDS seconds"
SECONDS=
mkdir -p "$state_dir"
(
set -x
tar -C "$state_dir" -zxf "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz
)
echo "Extracted snapshot in $SECONDS seconds"
fi
)
fi
if [[ ! -d "$ledger_config_dir" ]]; then
if [[ $node_type = validator ]]; then
( (
set -x cd "$SOLANA_RSYNC_CONFIG_DIR"
cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir"
echo "Rsyncing genesis ledger from ${rsync_entrypoint_url:?}..."
SECONDS=
while ! $rsync -Pr "${rsync_entrypoint_url:?}"/config/ledger .; do
echo "Genesis ledger rsync failed"
sleep 5
done
echo "Fetched genesis ledger in $SECONDS seconds"
if ((boot_from_snapshot)); then
SECONDS=
echo "Rsyncing state snapshot ${rsync_entrypoint_url:?}..."
if ! $rsync -P "${rsync_entrypoint_url:?}"/config/state.tgz .; then
echo "State snapshot rsync failed"
rm -f "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz
exit
fi
echo "Fetched snapshot in $SECONDS seconds"
SECONDS=
mkdir -p "$state_dir"
(
set -x
tar -C "$state_dir" -zxf "$SOLANA_RSYNC_CONFIG_DIR"/state.tgz
)
echo "Extracted snapshot in $SECONDS seconds"
fi
) )
fi fi
vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path") (
stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path") set -x
storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path") cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir"
)
fi
if [[ $node_type = validator ]] && ((stake_lamports)); then vote_pubkey=$($solana_keygen pubkey "$voting_keypair_path")
setup_validator_accounts "${entrypoint_address%:*}" \ stake_pubkey=$($solana_keygen pubkey "$stake_keypair_path")
"$node_lamports" \ storage_pubkey=$($solana_keygen pubkey "$storage_keypair_path")
"$stake_lamports"
fi
cat <<EOF if [[ $node_type = validator ]] && ((stake_lamports)); then
setup_validator_accounts "${entrypoint_address%:*}" \
"$node_lamports" \
"$stake_lamports"
fi
cat <<EOF
======================[ $node_type configuration ]====================== ======================[ $node_type configuration ]======================
identity pubkey: $identity_pubkey identity pubkey: $identity_pubkey
vote pubkey: $vote_pubkey vote pubkey: $vote_pubkey
@ -550,7 +467,6 @@ accounts: $accounts_config_dir
snapshots: $snapshot_config_dir snapshots: $snapshot_config_dir
======================================================================== ========================================================================
EOF EOF
fi
echo "$PS4$program ${args[*]}" echo "$PS4$program ${args[*]}"

View File

@ -1,4 +1,85 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# A thin wrapper around `solana-replicator` that automatically provisions the
# replicator's identity and/or storage keypair if not provided by the caller.
#
set -e
here=$(dirname "$0") here=$(dirname "$0")
exec "$here"/fullnode.sh --replicator "$@" # shellcheck source=multinode-demo/common.sh
source "$here"/common.sh
entrypoint=127.0.0.0:8001
label=
while [[ -n $1 ]]; do
if [[ ${1:0:1} = - ]]; then
if [[ $1 = --entrypoint ]]; then
entrypoint=$2
args+=("$1" "$2")
shift 2
elif [[ $1 = --identity ]]; then
identity_keypair=$2
[[ -r $identity_keypair ]] || {
echo "$identity_keypair does not exist"
exit 1
}
args+=("$1" "$2")
shift 2
elif [[ $1 = --label ]]; then
label="-$2"
shift 2
elif [[ $1 = --ledger ]]; then
args+=("$1" "$2")
shift 2
elif [[ $1 = --storage-keypair ]]; then
storage_keypair=$2
[[ -r $storage_keypair ]] || {
echo "$storage_keypair does not exist"
exit 1
}
args+=("$1" "$2")
shift 2
else
echo "Unknown argument: $1"
$solana_replicator --help
exit 1
fi
else
echo "Unknown argument: $1"
$solana_replicator --help
exit 1
fi
done
: "${identity_keypair:="$SOLANA_ROOT"/farf/replicator-identity-keypair"$label".json}"
: "${storage_keypair:="$SOLANA_ROOT"/farf/storage-keypair"$label".json}"
ledger="$SOLANA_ROOT"/farf/replicator-ledger"$label"
rpc_url=$("$here"/rpc-url.sh "$entrypoint")
if [[ ! -r $identity_keypair ]]; then
$solana_keygen new -o "$identity_keypair"
# TODO: https://github.com/solana-labs/solminer/blob/9cd2289/src/replicator.js#L17-L18
$solana_wallet --keypair "$identity_keypair" --url "$rpc_url" \
airdrop 100000
fi
identity_pubkey=$($solana_keygen pubkey "$identity_keypair")
if [[ ! -r $storage_keypair ]]; then
$solana_keygen new -o "$storage_keypair"
storage_pubkey=$($solana_keygen pubkey "$storage_keypair")
$solana_wallet --keypair "$identity_keypair" --url "$rpc_url" \
create-replicator-storage-account "$identity_pubkey" "$storage_pubkey"
fi
default_arg --entrypoint "$entrypoint"
default_arg --identity "$identity_keypair"
default_arg --storage-keypair "$storage_keypair"
default_arg --ledger "$ledger"
set -x
# shellcheck disable=SC2086 # Don't want to double quote $solana_replicator
exec $solana_replicator "${args[@]}"

14
multinode-demo/rpc-url.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
#
# Given a gossip entrypoint derive the entrypoint's RPC address
#
entrypoint_address=$1
if [[ -z $entrypoint_address ]]; then
echo "Error: entrypoint address not specified" >&2
exit 1
fi
# TODO: Rather than hard coding, add a `solana-gossip rpc-address` command that
# actually asks the entrypoint itself for its RPC address
echo "http://${entrypoint_address%:*}:8899"

View File

@ -273,22 +273,16 @@ local|tar|skip)
fi fi
args=( args=(
"$entrypointIp":~/solana "$entrypointIp:8001" --entrypoint "$entrypointIp:8001"
) )
if [[ $airdropsEnabled != true ]]; then if [[ $airdropsEnabled != true ]]; then
args+=(--no-airdrop) echo "TODO: replicators not supported without airdrops"
# TODO: need to provide the `--identity` argument to an existing system
# account with lamports in it
exit 1
fi fi
if [[ -n $internalNodesLamports ]] ; then
args+=(--node-lamports "$internalNodesLamports")
fi
if [[ $skipSetup != true ]]; then
./multinode-demo/clear-config.sh
fi
# shellcheck disable=SC2206 # Don't want to double quote $extraNodeArgs
args+=($extraNodeArgs)
nohup ./multinode-demo/replicator.sh "${args[@]}" > fullnode.log 2>&1 & nohup ./multinode-demo/replicator.sh "${args[@]}" > fullnode.log 2>&1 &
sleep 1 sleep 1
;; ;;