Extend GetBlockHash RPC API to include the fee scehdule for using the returned blockhash (#4222)

This commit is contained in:
Michael Vines
2019-05-13 12:49:37 -07:00
committed by GitHub
parent 23c696706b
commit a2e3a92b01
17 changed files with 126 additions and 98 deletions

View File

@ -39,11 +39,12 @@ pub fn spend_and_verify_all_nodes(
.poll_get_balance(&funding_keypair.pubkey())
.expect("balance in source");
assert!(bal > 0);
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let mut transaction = system_transaction::transfer(
&funding_keypair,
&random_keypair.pubkey(),
1,
client.get_recent_blockhash().unwrap(),
blockhash,
0,
);
let confs = VOTE_THRESHOLD_DEPTH + 1;
@ -65,11 +66,12 @@ pub fn send_many_transactions(node: &ContactInfo, funding_keypair: &Keypair, num
.poll_get_balance(&funding_keypair.pubkey())
.expect("balance in source");
assert!(bal > 0);
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let mut transaction = system_transaction::transfer(
&funding_keypair,
&random_keypair.pubkey(),
1,
client.get_recent_blockhash().unwrap(),
blockhash,
0,
);
client
@ -187,11 +189,12 @@ pub fn kill_entry_and_spend_and_verify_rest(
}
let random_keypair = Keypair::new();
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let mut transaction = system_transaction::transfer(
&funding_keypair,
&random_keypair.pubkey(),
1,
client.get_recent_blockhash().unwrap(),
blockhash,
0,
);

View File

@ -338,7 +338,7 @@ impl LocalCluster {
lamports: u64,
) -> u64 {
trace!("getting leader blockhash");
let blockhash = client.get_recent_blockhash().unwrap();
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let mut tx = system_transaction::create_user_account(
&source_keypair,
dest_pubkey,
@ -378,10 +378,11 @@ impl LocalCluster {
0,
amount,
);
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let mut transaction = Transaction::new_signed_instructions(
&[from_account.as_ref()],
instructions,
client.get_recent_blockhash().unwrap(),
blockhash,
);
client

View File

@ -419,7 +419,7 @@ impl Replicator {
// check if the account exists
let bal = client.poll_get_balance(&storage_keypair.pubkey());
if bal.is_err() || bal.unwrap() == 0 {
let blockhash = client.get_recent_blockhash().expect("blockhash");
let (blockhash, _fee_calculator) = client.get_recent_blockhash().expect("blockhash");
//TODO the account space needs to be well defined somewhere
let tx = system_transaction::create_account(
keypair,

View File

@ -12,6 +12,7 @@ use jsonrpc_derive::rpc;
use solana_drone::drone::request_airdrop_transaction;
use solana_runtime::bank::Bank;
use solana_sdk::account::Account;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::transaction::{self, Transaction};
@ -74,9 +75,12 @@ impl JsonRpcRequestProcessor {
self.bank().get_balance(&pubkey)
}
fn get_recent_blockhash(&self) -> String {
fn get_recent_blockhash(&self) -> (String, FeeCalculator) {
let id = self.bank().confirmed_last_blockhash();
bs58::encode(id).into_string()
(
bs58::encode(id).into_string(),
self.bank().fee_calculator.clone(),
)
}
pub fn get_signature_status(&self, signature: Signature) -> Option<transaction::Result<()>> {
@ -199,7 +203,7 @@ pub trait RpcSol {
fn get_cluster_nodes(&self, _: Self::Metadata) -> Result<Vec<RpcContactInfo>>;
#[rpc(meta, name = "getRecentBlockhash")]
fn get_recent_blockhash(&self, _: Self::Metadata) -> Result<String>;
fn get_recent_blockhash(&self, _: Self::Metadata) -> Result<(String, FeeCalculator)>;
#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(
@ -303,7 +307,7 @@ impl RpcSol for RpcSolImpl {
.collect())
}
fn get_recent_blockhash(&self, meta: Self::Metadata) -> Result<String> {
fn get_recent_blockhash(&self, meta: Self::Metadata) -> Result<(String, FeeCalculator)> {
debug!("get_recent_blockhash rpc request received");
Ok(meta
.request_processor
@ -732,7 +736,10 @@ mod tests {
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getRecentBlockhash"}}"#);
let res = io.handle_request_sync(&req, meta);
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, blockhash);
let expected = format!(
r#"{{"jsonrpc":"2.0","result":["{}", {{"lamportsPerSignature": 0}}],"id":1}}"#,
blockhash
);
let expected: Response =
serde_json::from_str(&expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))