CLI: Plumb nonce-stored fees (#8750)

automerge

(cherry picked from commit 0422af2aae)
This commit is contained in:
Trent Nelson
2020-03-11 12:14:15 -06:00
committed by Michael Vines
parent 7501e1b0f0
commit 18067dcb55
8 changed files with 660 additions and 415 deletions

View File

@@ -2,7 +2,7 @@ use crate::{
cluster_query::*,
display::{println_name_value, println_signers},
nonce::{self, *},
offline::*,
offline::{blockhash_query::BlockhashQuery, *},
stake::*,
storage::*,
validator_info::*,
@@ -986,7 +986,7 @@ pub fn check_unique_pubkeys(
}
}
pub fn get_blockhash_fee_calculator(
pub fn get_blockhash_and_fee_calculator(
rpc_client: &RpcClient,
sign_only: bool,
blockhash: Option<Hash>,
@@ -1279,7 +1279,8 @@ fn process_pay(
(to, "to".to_string()),
)?;
let (blockhash, fee_calculator) = blockhash_query.get_blockhash_fee_calculator(rpc_client)?;
let (blockhash, fee_calculator) =
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
let cancelable = if cancelable {
Some(config.signers[0].pubkey())
@@ -1467,7 +1468,7 @@ fn process_transfer(
)?;
let (recent_blockhash, fee_calculator) =
blockhash_query.get_blockhash_fee_calculator(rpc_client)?;
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
let ixs = vec![system_instruction::transfer(&from.pubkey(), to, lamports)];
let nonce_authority = config.signers[nonce_authority];
@@ -2478,20 +2479,13 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
mod tests {
use super::*;
use serde_json::Value;
use solana_client::{
mock_rpc_client_request::SIGNATURE,
rpc_request::RpcRequest,
rpc_response::{Response, RpcAccount, RpcResponseContext},
};
use solana_client::mock_rpc_client_request::SIGNATURE;
use solana_sdk::{
account::Account,
nonce,
pubkey::Pubkey,
signature::{keypair_from_seed, read_keypair_file, write_keypair_file, Presigner},
system_program,
transaction::TransactionError,
};
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;
fn make_tmp_path(name: &str) -> String {
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
@@ -2848,7 +2842,7 @@ mod tests {
command: CliCommand::Pay(PayCommand {
lamports: 50_000_000_000,
to: pubkey,
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
blockhash_query: BlockhashQuery::None(blockhash),
sign_only: true,
..PayCommand::default()
}),
@@ -2871,7 +2865,10 @@ mod tests {
command: CliCommand::Pay(PayCommand {
lamports: 50_000_000_000,
to: pubkey,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::Cluster,
blockhash
),
..PayCommand::default()
}),
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
@@ -2897,7 +2894,10 @@ mod tests {
command: CliCommand::Pay(PayCommand {
lamports: 50_000_000_000,
to: pubkey,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::NonceAccount(pubkey),
blockhash
),
nonce_account: Some(pubkey),
..PayCommand::default()
}),
@@ -2927,7 +2927,10 @@ mod tests {
command: CliCommand::Pay(PayCommand {
lamports: 50_000_000_000,
to: pubkey,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::NonceAccount(pubkey),
blockhash
),
nonce_account: Some(pubkey),
nonce_authority: 0,
..PayCommand::default()
@@ -2962,7 +2965,10 @@ mod tests {
command: CliCommand::Pay(PayCommand {
lamports: 50_000_000_000,
to: pubkey,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::NonceAccount(pubkey),
blockhash
),
nonce_account: Some(pubkey),
nonce_authority: 0,
..PayCommand::default()
@@ -3144,7 +3150,7 @@ mod tests {
},
lamports: 1234,
sign_only: false,
blockhash_query: BlockhashQuery::All,
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
nonce_account: None,
nonce_authority: 0,
fee_payer: 0,
@@ -3162,7 +3168,7 @@ mod tests {
lamports: 100,
withdraw_authority: 0,
sign_only: false,
blockhash_query: BlockhashQuery::All,
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
nonce_account: None,
nonce_authority: 0,
fee_payer: 0,
@@ -3262,64 +3268,6 @@ mod tests {
SIGNATURE.to_string()
);
// Nonced pay
let blockhash = Hash::default();
let data =
nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
authority: config.signers[0].pubkey(),
blockhash,
fee_calculator: FeeCalculator::default(),
}));
let nonce_response = json!(Response {
context: RpcResponseContext { slot: 1 },
value: json!(RpcAccount::encode(
Account::new_data(1, &data, &system_program::ID,).unwrap()
)),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetAccountInfo, nonce_response);
config.rpc_client = Some(RpcClient::new_mock_with_mocks("".to_string(), mocks));
config.command = CliCommand::Pay(PayCommand {
lamports: 10,
to: bob_pubkey,
nonce_account: Some(bob_pubkey),
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
..PayCommand::default()
});
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
// Nonced pay w/ non-payer authority
let bob_keypair = Keypair::new();
let bob_pubkey = bob_keypair.pubkey();
let blockhash = Hash::default();
let data =
nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
authority: bob_pubkey,
blockhash,
fee_calculator: FeeCalculator::default(),
}));
let nonce_authority_response = json!(Response {
context: RpcResponseContext { slot: 1 },
value: json!(RpcAccount::encode(
Account::new_data(1, &data, &system_program::ID,).unwrap()
)),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetAccountInfo, nonce_authority_response);
config.rpc_client = Some(RpcClient::new_mock_with_mocks("".to_string(), mocks));
config.command = CliCommand::Pay(PayCommand {
lamports: 10,
to: bob_pubkey,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
nonce_account: Some(bob_pubkey),
nonce_authority: 1,
..PayCommand::default()
});
config.signers = vec![&keypair, &bob_keypair];
let signature = process_command(&config);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
let process_id = Pubkey::new_rand();
config.command = CliCommand::TimeElapsed(bob_pubkey, process_id, dt);
config.signers = vec![&keypair];
@@ -3521,7 +3469,7 @@ mod tests {
to: to_pubkey,
from: 0,
sign_only: false,
blockhash_query: BlockhashQuery::All,
blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster),
nonce_account: None,
nonce_authority: 0,
fee_payer: 0,
@@ -3550,7 +3498,7 @@ mod tests {
to: to_pubkey,
from: 0,
sign_only: true,
blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()),
blockhash_query: BlockhashQuery::None(blockhash),
nonce_account: None,
nonce_authority: 0,
fee_payer: 0,
@@ -3584,7 +3532,10 @@ mod tests {
to: to_pubkey,
from: 0,
sign_only: false,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::Cluster,
blockhash
),
nonce_account: None,
nonce_authority: 0,
fee_payer: 0,
@@ -3619,7 +3570,10 @@ mod tests {
to: to_pubkey,
from: 0,
sign_only: false,
blockhash_query: BlockhashQuery::FeeCalculator(blockhash),
blockhash_query: BlockhashQuery::FeeCalculator(
blockhash_query::Source::NonceAccount(nonce_address),
blockhash
),
nonce_account: Some(nonce_address.into()),
nonce_authority: 1,
fee_payer: 0,