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_derive",
"solana-clap-utils",
"solana-cli-config",
"solana-logger 1.4.9",
"solana-metrics",
"solana-sdk",
@ -4157,6 +4158,7 @@ dependencies = [
"serde_yaml",
"solana-budget-program",
"solana-clap-utils",
"solana-cli-config",
"solana-exchange-program",
"solana-ledger",
"solana-logger 1.4.9",

View File

@ -17,6 +17,7 @@ log = "0.4.8"
serde = "1.0.112"
serde_derive = "1.0.103"
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-metrics = { path = "../metrics", 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>> {
let default_keypair = solana_cli_config::Config::default().keypair_path;
solana_logger::setup_with_default("solana=info");
solana_metrics::set_panic_hook("faucet");
let matches = App::new(crate_name!())
@ -25,7 +27,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.value_name("PATH")
.takes_value(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::with_name("slice")
@ -51,7 +54,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.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");
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 = Arc::new(Mutex::new(Faucet::new(
mint_keypair,
faucet_keypair,
time_slice,
per_time_cap,
per_request_cap,

View File

@ -59,7 +59,7 @@ pub enum FaucetRequest {
}
pub struct Faucet {
mint_keypair: Keypair,
faucet_keypair: Keypair,
ip_cache: Vec<IpAddr>,
pub time_slice: Duration,
per_time_cap: u64,
@ -69,7 +69,7 @@ pub struct Faucet {
impl Faucet {
pub fn new(
mint_keypair: Keypair,
faucet_keypair: Keypair,
time_input: Option<u64>,
per_time_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 per_time_cap = per_time_cap.unwrap_or(REQUEST_CAP);
Faucet {
mint_keypair,
faucet_keypair,
ip_cache: Vec::new(),
time_slice,
per_time_cap,
@ -133,11 +133,15 @@ impl Faucet {
);
info!("Requesting airdrop of {} to {:?}", lamports, to);
let mint_pubkey = self.mint_keypair.pubkey();
let mint_pubkey = self.faucet_keypair.pubkey();
let create_instruction =
system_instruction::transfer(&mint_pubkey, &to, lamports);
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 {
Err(Error::new(
ErrorKind::Other,
@ -254,14 +258,14 @@ pub fn request_airdrop_transaction(
// For integration tests. Listens on random open port and reports port to Sender.
pub fn run_local_faucet(
mint_keypair: Keypair,
faucet_keypair: Keypair,
sender: Sender<SocketAddr>,
per_time_cap: Option<u64>,
) {
thread::spawn(move || {
let faucet_addr = socketaddr!(0, 0);
let faucet = Arc::new(Mutex::new(Faucet::new(
mint_keypair,
faucet_keypair,
None,
per_time_cap,
None,
@ -280,6 +284,11 @@ pub fn run_faucet(
send_addr.send(socket.local_addr().unwrap()).unwrap();
}
info!("Faucet started. Listening on: {}", faucet_addr);
info!(
"Faucet account address: {}",
faucet.lock().unwrap().faucet_keypair.pubkey()
);
let done = socket
.incoming()
.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"
solana-budget-program = { path = "../programs/budget", 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-ledger = { path = "../ledger", 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)]
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 (
default_target_lamports_per_signature,
@ -178,7 +179,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("faucet-lamports")
.value_name("LAMPORTS")
.takes_value(true)
.requires("faucet_pubkey")
.help("Number of lamports to assign to the faucet"),
)
.arg(
@ -189,6 +189,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.takes_value(true)
.validator(is_pubkey_or_keypair)
.requires("faucet_lamports")
.default_value(&default_faucet_pubkey)
.help("Path to file containing the faucet's pubkey"),
)
.arg(
@ -364,7 +365,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.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 rent = Rent {
@ -414,6 +414,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
let 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 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}
set -x
if ! solana address; then
echo Generating default keypair
solana-keygen new --no-passphrase
fi
validator_identity="$dataDir/validator-identity.json"
if [[ -e $validator_identity ]]; then
echo "Use existing validator keypair"
@ -55,12 +59,6 @@ if [[ -e $validator_stake_account ]]; then
else
solana-keygen new --no-passphrase -so "$validator_stake_account"
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
echo "Use existing genesis"
@ -73,7 +71,6 @@ else
# shellcheck disable=SC2086
solana-genesis \
--hashes-per-tick sleep \
--faucet-pubkey "$dataDir"/faucet.json \
--faucet-lamports 500000000000000000 \
--bootstrap-validator \
"$dataDir"/validator-identity.json \
@ -92,7 +89,7 @@ abort() {
}
trap abort INT TERM EXIT
solana-faucet --keypair "$dataDir"/faucet.json &
solana-faucet &
faucet=$!
args=(