run.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env bash
  2. #
  3. # Run a minimal Solana cluster. Ctrl-C to exit.
  4. #
  5. # Before running this script ensure standard Solana programs are available
  6. # in the PATH, or that `cargo build` ran successfully
  7. #
  8. set -e
  9. # Prefer possible `cargo build` binaries over PATH binaries
  10. script_dir="$(readlink -f "$(dirname "$0")")"
  11. if [[ "$script_dir" =~ /scripts$ ]]; then
  12. cd "$script_dir/.."
  13. else
  14. cd "$script_dir"
  15. fi
  16. profile=debug
  17. if [[ -n $CARGO_BUILD_PROFILE ]]; then
  18. profile=$CARGO_BUILD_PROFILE
  19. fi
  20. PATH=$PWD/target/$profile:$PATH
  21. ok=true
  22. for program in solana-{faucet,genesis,keygen}; do
  23. $program -V || ok=false
  24. done
  25. agave-validator -V || ok=false
  26. $ok || {
  27. echo
  28. echo "Unable to locate required programs. Try building them first with:"
  29. echo
  30. echo " $ cargo build --all"
  31. echo
  32. exit 1
  33. }
  34. export RUST_LOG=${RUST_LOG:-solana=info,agave=info,solana_runtime::message_processor=debug} # if RUST_LOG is unset, default to info
  35. export RUST_BACKTRACE=1
  36. dataDir=$PWD/config/"$(basename "$0" .sh)"
  37. ledgerDir=$PWD/config/ledger
  38. SOLANA_RUN_SH_CLUSTER_TYPE=${SOLANA_RUN_SH_CLUSTER_TYPE:-development}
  39. set -x
  40. if ! solana address; then
  41. echo Generating default keypair
  42. solana-keygen new --no-passphrase
  43. fi
  44. validator_identity="$dataDir/validator-identity.json"
  45. if [[ -e $validator_identity ]]; then
  46. echo "Use existing validator keypair"
  47. else
  48. solana-keygen new --no-passphrase -so "$validator_identity"
  49. fi
  50. validator_vote_account="$dataDir/validator-vote-account.json"
  51. if [[ -e $validator_vote_account ]]; then
  52. echo "Use existing validator vote account keypair"
  53. else
  54. solana-keygen new --no-passphrase -so "$validator_vote_account"
  55. fi
  56. validator_stake_account="$dataDir/validator-stake-account.json"
  57. if [[ -e $validator_stake_account ]]; then
  58. echo "Use existing validator stake account keypair"
  59. else
  60. solana-keygen new --no-passphrase -so "$validator_stake_account"
  61. fi
  62. if [[ -e "$ledgerDir"/genesis.bin || -e "$ledgerDir"/genesis.tar.bz2 ]]; then
  63. echo "Use existing genesis"
  64. else
  65. ./fetch-core-bpf.sh
  66. if [[ -r core-bpf-genesis-args.sh ]]; then
  67. CORE_BPF_GENESIS_ARGS=$(cat core-bpf-genesis-args.sh)
  68. fi
  69. ./fetch-spl.sh
  70. if [[ -r spl-genesis-args.sh ]]; then
  71. SPL_GENESIS_ARGS=$(cat spl-genesis-args.sh)
  72. fi
  73. # shellcheck disable=SC2086
  74. solana-genesis \
  75. --hashes-per-tick sleep \
  76. --faucet-lamports 500000000000000000 \
  77. --bootstrap-validator \
  78. "$validator_identity" \
  79. "$validator_vote_account" \
  80. "$validator_stake_account" \
  81. --ledger "$ledgerDir" \
  82. --cluster-type "$SOLANA_RUN_SH_CLUSTER_TYPE" \
  83. $CORE_BPF_GENESIS_ARGS \
  84. $SPL_GENESIS_ARGS \
  85. $SOLANA_RUN_SH_GENESIS_ARGS
  86. fi
  87. abort() {
  88. set +e
  89. kill "$faucet" "$validator"
  90. wait "$validator"
  91. }
  92. trap abort INT TERM EXIT
  93. solana-faucet &
  94. faucet=$!
  95. args=(
  96. --identity "$validator_identity"
  97. --vote-account "$validator_vote_account"
  98. --ledger "$ledgerDir"
  99. --gossip-port 8001
  100. --full-rpc-api
  101. --rpc-port 8899
  102. --rpc-faucet-address 127.0.0.1:9900
  103. --log -
  104. --enable-rpc-transaction-history
  105. --enable-extended-tx-metadata-storage
  106. --init-complete-file "$dataDir"/init-completed
  107. --require-tower
  108. --no-wait-for-vote-to-start-leader
  109. --no-os-network-limits-test
  110. )
  111. # shellcheck disable=SC2086
  112. agave-validator "${args[@]}" $SOLANA_RUN_SH_VALIDATOR_ARGS &
  113. validator=$!
  114. wait "$validator"