run.sh: Use default client keypair for the faucet (bp #13614) (#13618)

* Use default client keypair if --keypair argument is not provided

(cherry picked from commit e9e5ee4362)

# Conflicts:
#	faucet/Cargo.toml

* Use default client keypair if --faucet-keypair is not provided

(cherry picked from commit 4069e7b663)

# Conflicts:
#	genesis/Cargo.toml

* Cargo.lock

(cherry picked from commit ab5814cd90)

# Conflicts:
#	Cargo.lock

* Use default client keypair for faucet to avoid the need for airdrops

(cherry picked from commit b5820f9325)

* Fix conflicts

Co-authored-by: Michael Vines <mvines@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
mergify[bot]
2020-11-17 02:23:01 +00:00
committed by GitHub
parent 719f162229
commit a77fce465a
7 changed files with 34 additions and 20 deletions

2
Cargo.lock generated
View File

@ -4075,6 +4075,7 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"solana-clap-utils", "solana-clap-utils",
"solana-cli-config",
"solana-logger 1.4.9", "solana-logger 1.4.9",
"solana-metrics", "solana-metrics",
"solana-sdk", "solana-sdk",
@ -4157,6 +4158,7 @@ dependencies = [
"serde_yaml", "serde_yaml",
"solana-budget-program", "solana-budget-program",
"solana-clap-utils", "solana-clap-utils",
"solana-cli-config",
"solana-exchange-program", "solana-exchange-program",
"solana-ledger", "solana-ledger",
"solana-logger 1.4.9", "solana-logger 1.4.9",

View File

@ -17,6 +17,7 @@ log = "0.4.8"
serde = "1.0.112" serde = "1.0.112"
serde_derive = "1.0.103" serde_derive = "1.0.103"
solana-clap-utils = { path = "../clap-utils", version = "1.4.9" } solana-clap-utils = { path = "../clap-utils", version = "1.4.9" }
solana-cli-config = { path = "../cli-config", version = "1.4.9" }
solana-logger = { path = "../logger", version = "1.4.9" } solana-logger = { path = "../logger", version = "1.4.9" }
solana-metrics = { path = "../metrics", version = "1.4.9" } solana-metrics = { path = "../metrics", version = "1.4.9" }
solana-sdk = { path = "../sdk", version = "1.4.9" } solana-sdk = { path = "../sdk", version = "1.4.9" }

View File

@ -13,6 +13,8 @@ use std::{
}; };
fn main() -> Result<(), Box<dyn error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let default_keypair = solana_cli_config::Config::default().keypair_path;
solana_logger::setup_with_default("solana=info"); solana_logger::setup_with_default("solana=info");
solana_metrics::set_panic_hook("faucet"); solana_metrics::set_panic_hook("faucet");
let matches = App::new(crate_name!()) let matches = App::new(crate_name!())
@ -25,7 +27,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.value_name("PATH") .value_name("PATH")
.takes_value(true) .takes_value(true)
.required(true) .required(true)
.help("File from which to read the mint's keypair"), .default_value(&default_keypair)
.help("File from which to read the faucet's keypair"),
) )
.arg( .arg(
Arg::with_name("slice") Arg::with_name("slice")
@ -51,7 +54,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
) )
.get_matches(); .get_matches();
let mint_keypair = read_keypair_file(matches.value_of("keypair").unwrap()) let faucet_keypair = read_keypair_file(matches.value_of("keypair").unwrap())
.expect("failed to read client keypair"); .expect("failed to read client keypair");
let time_slice = value_of(&matches, "slice"); let time_slice = value_of(&matches, "slice");
@ -61,7 +64,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let faucet_addr = socketaddr!(0, FAUCET_PORT); let faucet_addr = socketaddr!(0, FAUCET_PORT);
let faucet = Arc::new(Mutex::new(Faucet::new( let faucet = Arc::new(Mutex::new(Faucet::new(
mint_keypair, faucet_keypair,
time_slice, time_slice,
per_time_cap, per_time_cap,
per_request_cap, per_request_cap,

View File

@ -59,7 +59,7 @@ pub enum FaucetRequest {
} }
pub struct Faucet { pub struct Faucet {
mint_keypair: Keypair, faucet_keypair: Keypair,
ip_cache: Vec<IpAddr>, ip_cache: Vec<IpAddr>,
pub time_slice: Duration, pub time_slice: Duration,
per_time_cap: u64, per_time_cap: u64,
@ -69,7 +69,7 @@ pub struct Faucet {
impl Faucet { impl Faucet {
pub fn new( pub fn new(
mint_keypair: Keypair, faucet_keypair: Keypair,
time_input: Option<u64>, time_input: Option<u64>,
per_time_cap: Option<u64>, per_time_cap: Option<u64>,
per_request_cap: Option<u64>, per_request_cap: Option<u64>,
@ -77,7 +77,7 @@ impl Faucet {
let time_slice = Duration::new(time_input.unwrap_or(TIME_SLICE), 0); let time_slice = Duration::new(time_input.unwrap_or(TIME_SLICE), 0);
let per_time_cap = per_time_cap.unwrap_or(REQUEST_CAP); let per_time_cap = per_time_cap.unwrap_or(REQUEST_CAP);
Faucet { Faucet {
mint_keypair, faucet_keypair,
ip_cache: Vec::new(), ip_cache: Vec::new(),
time_slice, time_slice,
per_time_cap, per_time_cap,
@ -133,11 +133,15 @@ impl Faucet {
); );
info!("Requesting airdrop of {} to {:?}", lamports, to); info!("Requesting airdrop of {} to {:?}", lamports, to);
let mint_pubkey = self.mint_keypair.pubkey(); let mint_pubkey = self.faucet_keypair.pubkey();
let create_instruction = let create_instruction =
system_instruction::transfer(&mint_pubkey, &to, lamports); system_instruction::transfer(&mint_pubkey, &to, lamports);
let message = Message::new(&[create_instruction], Some(&mint_pubkey)); let message = Message::new(&[create_instruction], Some(&mint_pubkey));
Ok(Transaction::new(&[&self.mint_keypair], message, blockhash)) Ok(Transaction::new(
&[&self.faucet_keypair],
message,
blockhash,
))
} else { } else {
Err(Error::new( Err(Error::new(
ErrorKind::Other, ErrorKind::Other,
@ -254,14 +258,14 @@ pub fn request_airdrop_transaction(
// For integration tests. Listens on random open port and reports port to Sender. // For integration tests. Listens on random open port and reports port to Sender.
pub fn run_local_faucet( pub fn run_local_faucet(
mint_keypair: Keypair, faucet_keypair: Keypair,
sender: Sender<SocketAddr>, sender: Sender<SocketAddr>,
per_time_cap: Option<u64>, per_time_cap: Option<u64>,
) { ) {
thread::spawn(move || { thread::spawn(move || {
let faucet_addr = socketaddr!(0, 0); let faucet_addr = socketaddr!(0, 0);
let faucet = Arc::new(Mutex::new(Faucet::new( let faucet = Arc::new(Mutex::new(Faucet::new(
mint_keypair, faucet_keypair,
None, None,
per_time_cap, per_time_cap,
None, None,
@ -280,6 +284,11 @@ pub fn run_faucet(
send_addr.send(socket.local_addr().unwrap()).unwrap(); send_addr.send(socket.local_addr().unwrap()).unwrap();
} }
info!("Faucet started. Listening on: {}", faucet_addr); info!("Faucet started. Listening on: {}", faucet_addr);
info!(
"Faucet account address: {}",
faucet.lock().unwrap().faucet_keypair.pubkey()
);
let done = socket let done = socket
.incoming() .incoming()
.map_err(|e| debug!("failed to accept socket; error = {:?}", e)) .map_err(|e| debug!("failed to accept socket; error = {:?}", e))

View File

@ -17,6 +17,7 @@ serde_json = "1.0.56"
serde_yaml = "0.8.13" serde_yaml = "0.8.13"
solana-budget-program = { path = "../programs/budget", version = "1.4.9" } solana-budget-program = { path = "../programs/budget", version = "1.4.9" }
solana-clap-utils = { path = "../clap-utils", version = "1.4.9" } solana-clap-utils = { path = "../clap-utils", version = "1.4.9" }
solana-cli-config = { path = "../cli-config", version = "1.4.9" }
solana-exchange-program = { path = "../programs/exchange", version = "1.4.9" } solana-exchange-program = { path = "../programs/exchange", version = "1.4.9" }
solana-ledger = { path = "../ledger", version = "1.4.9" } solana-ledger = { path = "../ledger", version = "1.4.9" }
solana-logger = { path = "../logger", version = "1.4.9" } solana-logger = { path = "../logger", version = "1.4.9" }

View File

@ -99,6 +99,7 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) ->
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
fn main() -> Result<(), Box<dyn error::Error>> { fn main() -> Result<(), Box<dyn error::Error>> {
let default_faucet_pubkey = solana_cli_config::Config::default().keypair_path;
let fee_rate_governor = FeeRateGovernor::default(); let fee_rate_governor = FeeRateGovernor::default();
let ( let (
default_target_lamports_per_signature, default_target_lamports_per_signature,
@ -178,7 +179,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("faucet-lamports") .long("faucet-lamports")
.value_name("LAMPORTS") .value_name("LAMPORTS")
.takes_value(true) .takes_value(true)
.requires("faucet_pubkey")
.help("Number of lamports to assign to the faucet"), .help("Number of lamports to assign to the faucet"),
) )
.arg( .arg(
@ -189,6 +189,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.takes_value(true) .takes_value(true)
.validator(is_pubkey_or_keypair) .validator(is_pubkey_or_keypair)
.requires("faucet_lamports") .requires("faucet_lamports")
.default_value(&default_faucet_pubkey)
.help("Path to file containing the faucet's pubkey"), .help("Path to file containing the faucet's pubkey"),
) )
.arg( .arg(
@ -364,7 +365,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
) )
.get_matches(); .get_matches();
let faucet_lamports = value_t!(matches, "faucet_lamports", u64).unwrap_or(0);
let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap()); let ledger_path = PathBuf::from(matches.value_of("ledger_path").unwrap());
let rent = Rent { let rent = Rent {
@ -414,6 +414,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let bootstrap_stake_authorized_pubkey = let bootstrap_stake_authorized_pubkey =
pubkey_of(&matches, "bootstrap_stake_authorized_pubkey"); pubkey_of(&matches, "bootstrap_stake_authorized_pubkey");
let faucet_lamports = value_t!(matches, "faucet_lamports", u64).unwrap_or(0);
let faucet_pubkey = pubkey_of(&matches, "faucet_pubkey"); let faucet_pubkey = pubkey_of(&matches, "faucet_pubkey");
let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64); let ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64);

13
run.sh
View File

@ -37,6 +37,10 @@ ledgerDir=$PWD/config/ledger
SOLANA_RUN_SH_CLUSTER_TYPE=${SOLANA_RUN_SH_CLUSTER_TYPE:-development} SOLANA_RUN_SH_CLUSTER_TYPE=${SOLANA_RUN_SH_CLUSTER_TYPE:-development}
set -x set -x
if ! solana address; then
echo Generating default keypair
solana-keygen new --no-passphrase
fi
validator_identity="$dataDir/validator-identity.json" validator_identity="$dataDir/validator-identity.json"
if [[ -e $validator_identity ]]; then if [[ -e $validator_identity ]]; then
echo "Use existing validator keypair" echo "Use existing validator keypair"
@ -55,12 +59,6 @@ if [[ -e $validator_stake_account ]]; then
else else
solana-keygen new --no-passphrase -so "$validator_stake_account" solana-keygen new --no-passphrase -so "$validator_stake_account"
fi fi
faucet="$dataDir"/faucet.json
if [[ -e $faucet ]]; then
echo "Use existing faucet keypair"
else
solana-keygen new --no-passphrase -fso "$faucet"
fi
if [[ -e "$ledgerDir"/genesis.bin || -e "$ledgerDir"/genesis.tar.bz2 ]]; then if [[ -e "$ledgerDir"/genesis.bin || -e "$ledgerDir"/genesis.tar.bz2 ]]; then
echo "Use existing genesis" echo "Use existing genesis"
@ -73,7 +71,6 @@ else
# shellcheck disable=SC2086 # shellcheck disable=SC2086
solana-genesis \ solana-genesis \
--hashes-per-tick sleep \ --hashes-per-tick sleep \
--faucet-pubkey "$dataDir"/faucet.json \
--faucet-lamports 500000000000000000 \ --faucet-lamports 500000000000000000 \
--bootstrap-validator \ --bootstrap-validator \
"$dataDir"/validator-identity.json \ "$dataDir"/validator-identity.json \
@ -92,7 +89,7 @@ abort() {
} }
trap abort INT TERM EXIT trap abort INT TERM EXIT
solana-faucet --keypair "$dataDir"/faucet.json & solana-faucet &
faucet=$! faucet=$!
args=( args=(