From a37ca68937fa87eb535ce8501e25e3ec924fee19 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 10:58:27 -0600 Subject: [PATCH 1/6] Add rpc endpoint to get blockhash queue length --- client/src/rpc_response.rs | 7 +++++ core/src/rpc.rs | 55 ++++++++++++++++++++++++++++++++++ runtime/src/bank.rs | 4 +++ runtime/src/blockhash_queue.rs | 4 +++ 4 files changed, 70 insertions(+) diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index 1fbed4e7a9666f..eab7174bb4d0b6 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -47,6 +47,13 @@ pub struct RpcFeeRateGovernor { pub fee_rate_governor: FeeRateGovernor, } +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct RpcBlockhashQueueLength { + pub epoch: Epoch, + pub blockhash_queue_length: usize, +} + #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct RpcKeyedAccount { diff --git a/core/src/rpc.rs b/core/src/rpc.rs index e1fc60127bf820..0e8a1dbebd5bb0 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -227,6 +227,19 @@ impl JsonRpcRequestProcessor { ) } + fn get_blockhash_queue_length(&self) -> RpcResponse { + let bank = &*self.bank(None)?; + let epoch = bank.epoch(); + let blockhash_queue_length = bank.get_blockhash_queue_length(); + new_response( + bank, + RpcBlockhashQueueLength { + epoch, + blockhash_queue_length, + }, + ) + } + pub fn confirm_transaction( &self, signature: Result, @@ -796,6 +809,12 @@ pub trait RpcSol { #[rpc(meta, name = "getFeeRateGovernor")] fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse; + #[rpc(meta, name = "getBlockhashQueueLength")] + fn get_blockhash_queue_length( + &self, + meta: Self::Metadata, + ) -> RpcResponse; + #[rpc(meta, name = "getSignatureStatuses")] fn get_signature_statuses( &self, @@ -1141,6 +1160,17 @@ impl RpcSol for RpcSolImpl { .get_fee_rate_governor() } + fn get_blockhash_queue_length( + &self, + meta: Self::Metadata, + ) -> RpcResponse { + debug!("get_blockhash_length rpc request received"); + meta.request_processor + .read() + .unwrap() + .get_blockhash_queue_length() + } + fn get_signature_confirmation( &self, meta: Self::Metadata, @@ -1561,6 +1591,7 @@ pub mod tests { get_tmp_ledger_path, }; use solana_sdk::{ + clock::MAX_RECENT_BLOCKHASHES, fee_calculator::DEFAULT_BURN_PERCENT, hash::{hash, Hash}, instruction::InstructionError, @@ -2584,6 +2615,30 @@ pub mod tests { assert_eq!(expected, result); } + #[test] + fn test_rpc_get_blockhash_queue_length() { + let bob_pubkey = Pubkey::new_rand(); + let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey); + + let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockhashQueueLength"}"#; + let res = io.handle_request_sync(&req, meta); + let expected = json!({ + "jsonrpc": "2.0", + "result": { + "context":{"slot":0}, + "value":{ + "epoch": 0, + "blockhashQueueLength": MAX_RECENT_BLOCKHASHES, + }}, + "id": 1 + }); + let expected: Response = + serde_json::from_value(expected).expect("expected response deserialization"); + let result: Response = serde_json::from_str(&res.expect("actual response")) + .expect("actual response deserialization"); + assert_eq!(expected, result); + } + #[test] fn test_rpc_fail_request_airdrop() { let bob_pubkey = Pubkey::new_rand(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index acc6b61325a7a3..07264da9963e77 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -985,6 +985,10 @@ impl Bank { &self.fee_rate_governor } + pub fn get_blockhash_queue_length(&self) -> usize { + self.blockhash_queue.read().unwrap().len() + } + pub fn confirmed_last_blockhash(&self) -> (Hash, FeeCalculator) { const NUM_BLOCKHASH_CONFIRMATIONS: usize = 3; diff --git a/runtime/src/blockhash_queue.rs b/runtime/src/blockhash_queue.rs index 16020d1a83c0b3..f2ecce69e36788 100644 --- a/runtime/src/blockhash_queue.rs +++ b/runtime/src/blockhash_queue.rs @@ -119,6 +119,10 @@ impl BlockhashQueue { .iter() .map(|(k, v)| recent_blockhashes::IterItem(v.hash_height, k, &v.fee_calculator)) } + + pub fn len(&self) -> usize { + self.max_age + } } #[cfg(test)] mod tests { From 5cf242c5e29d67ff90c8c1d6f681e6a844d31a37 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 12:24:46 -0600 Subject: [PATCH 2/6] Add docs --- docs/src/apps/jsonrpc-api.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/src/apps/jsonrpc-api.md b/docs/src/apps/jsonrpc-api.md index 3957f9513c99f4..9f19248bec232b 100644 --- a/docs/src/apps/jsonrpc-api.md +++ b/docs/src/apps/jsonrpc-api.md @@ -17,6 +17,7 @@ To interact with a Solana node inside a JavaScript application, use the [solana- * [getAccountInfo](jsonrpc-api.md#getaccountinfo) * [getBalance](jsonrpc-api.md#getbalance) * [getBlockCommitment](jsonrpc-api.md#getblockcommitment) +* [getBlockhashQueueLength](jsonrpc-api.md#getblockhashqueuelength) * [getBlockTime](jsonrpc-api.md#getblocktime) * [getClusterNodes](jsonrpc-api.md#getclusternodes) * [getConfirmedBlock](jsonrpc-api.md#getconfirmedblock) @@ -213,6 +214,32 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "m {"jsonrpc":"2.0","result":{"commitment":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,32],"totalStake": 42},"id":1} ``` +### getBlockhashQueueLength + +Returns the blockhash queue length for the current epoch. + +#### Parameters: + +None + +#### Results: + +The result will be an RpcResponse JSON object with `value` equal to and object +with the following fields: + +* `epoch: ` - epoch +* `blockhashQueueLength: ` - length of the blockhash queue + +#### Example: + +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockhashQueueLength"}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":{"context":{"slot":221},"value":{"epoch":0,"blockhashQueueLength":300}},"id":1} +``` + ### getBlockTime Returns the estimated production time of a block. @@ -390,7 +417,7 @@ The signatures will be ordered based on the Slot in which they were confirmed in curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getConfirmedSignaturesForAddress","params":["6H94zdiaYfRfPfKjYLjyr2VFBg6JHXygy84r3qhc3NsC", 0, 100]}' localhost:8899 // Result -{"jsonrpc":"2.0","result":{["35YGay1Lwjwgxe9zaH6APSHbt9gYQUCtBWTNL3aVwVGn9xTFw2fgds7qK5AL29mP63A9j3rh8KpN1TgSR62XCaby","4bJdGN8Tt2kLWZ3Fa1dpwPSEkXWWTSszPSf1rRVsCwNjxbbUdwTeiWtmi8soA26YmwnKD4aAxNp8ci1Gjpdv4gsr","4LQ14a7BYY27578Uj8LPCaVhSdJGLn9DJqnUJHpy95FMqdKf9acAhUhecPQNjNUy6VoNFUbvwYkPociFSf87cWbG"]},"id":1} +{"jsonrpc":"2.0","result":["35YGay1Lwjwgxe9zaH6APSHbt9gYQUCtBWTNL3aVwVGn9xTFw2fgds7qK5AL29mP63A9j3rh8KpN1TgSR62XCaby","4bJdGN8Tt2kLWZ3Fa1dpwPSEkXWWTSszPSf1rRVsCwNjxbbUdwTeiWtmi8soA26YmwnKD4aAxNp8ci1Gjpdv4gsr","4LQ14a7BYY27578Uj8LPCaVhSdJGLn9DJqnUJHpy95FMqdKf9acAhUhecPQNjNUy6VoNFUbvwYkPociFSf87cWbG"],"id":1} ``` ### getConfirmedTransaction From 6debe725e555993ac17994c544a6f46f304c187d Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 11:44:14 -0600 Subject: [PATCH 3/6] Plumb blockhash-queue-length into client --- client/src/rpc_client.rs | 8 ++++++++ client/src/rpc_request.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 9fc267d261c71b..78dcb2a0bdb9d4 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -693,6 +693,14 @@ impl RpcClient { }) } + pub fn get_blockhash_queue_length(&self) -> RpcResult { + self.send::>( + RpcRequest::GetBlockhashQueueLength, + Value::Null, + 0, + ) + } + pub fn get_new_blockhash(&self, blockhash: &Hash) -> ClientResult<(Hash, FeeCalculator)> { let mut num_retries = 0; let start = Instant::now(); diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index 2edd88ec100baa..1ed970504976ed 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -8,6 +8,7 @@ pub enum RpcRequest { ValidatorExit, GetAccountInfo, GetBalance, + GetBlockhashQueueLength, GetBlockTime, GetClusterNodes, GetConfirmedBlock, @@ -53,6 +54,7 @@ impl fmt::Display for RpcRequest { RpcRequest::ValidatorExit => "validatorExit", RpcRequest::GetAccountInfo => "getAccountInfo", RpcRequest::GetBalance => "getBalance", + RpcRequest::GetBlockhashQueueLength => "getBlockhashQueueLength", RpcRequest::GetBlockTime => "getBlockTime", RpcRequest::GetClusterNodes => "getClusterNodes", RpcRequest::GetConfirmedBlock => "getConfirmedBlock", From 3d0c9e5d5c161c1fb9448d41c95d054d4afaf699 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 11:45:27 -0600 Subject: [PATCH 4/6] Add blockhash-queue-length to solana fees --- cli/src/cli.rs | 2 +- cli/src/cli_output.rs | 33 ++++++++++++++++++++++++++++++++- cli/src/cluster_query.rs | 18 +++++++++++------- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 40a6c53eb24399..8964c37980095b 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1655,7 +1655,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { seed, program_id, } => process_create_address_with_seed(config, from_pubkey.as_ref(), &seed, &program_id), - CliCommand::Fees => process_fees(&rpc_client), + CliCommand::Fees => process_fees(&rpc_client, config), CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, config, *slot), CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client), CliCommand::GetEpochInfo { commitment_config } => { diff --git a/cli/src/cli_output.rs b/cli/src/cli_output.rs index 10653372b59ec7..4ab8367ef887bd 100644 --- a/cli/src/cli_output.rs +++ b/cli/src/cli_output.rs @@ -5,7 +5,7 @@ use inflector::cases::titlecase::to_title_case; use serde::Serialize; use serde_json::{Map, Value}; use solana_client::rpc_response::{ - RpcAccountBalance, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo, + RpcAccountBalance, RpcBlockhashQueueLength, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo, }; use solana_sdk::{ clock::{self, Epoch, Slot, UnixTimestamp}, @@ -981,3 +981,34 @@ impl fmt::Display for CliSupply { Ok(()) } } + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CliFees { + pub slot: Slot, + pub blockhash: String, + pub lamports_per_signature: u64, + pub blockhash_queue_length: RpcBlockhashQueueLength, +} + +impl fmt::Display for CliFees { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + writeln_name_value(f, "Blockhash:", &self.blockhash)?; + writeln_name_value( + f, + "Lamports per signature:", + &self.lamports_per_signature.to_string(), + )?; + writeln_name_value(f, "Slot:", &self.slot.to_string())?; + writeln_name_value( + f, + "Blockhash queue length:", + &format!( + "{} (epoch {})", + &self.blockhash_queue_length.blockhash_queue_length, + &self.blockhash_queue_length.epoch + ), + )?; + Ok(()) + } +} diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index c5d8ec4d09def5..16b428c32e063d 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -599,13 +599,17 @@ pub fn process_cluster_version(rpc_client: &RpcClient) -> ProcessResult { Ok(remote_version.solana_core) } -pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult { - let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; - - Ok(format!( - "blockhash: {}\nlamports per signature: {}", - recent_blockhash, fee_calculator.lamports_per_signature - )) +pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { + let result = rpc_client.get_recent_blockhash_with_commitment(CommitmentConfig::default())?; + let (recent_blockhash, fee_calculator) = result.value; + let blockhash_queue_length = rpc_client.get_blockhash_queue_length()?; + let fees = CliFees { + slot: result.context.slot, + blockhash: recent_blockhash.to_string(), + lamports_per_signature: fee_calculator.lamports_per_signature, + blockhash_queue_length: blockhash_queue_length.value, + }; + Ok(config.output_format.formatted_string(&fees)) } pub fn process_leader_schedule(rpc_client: &RpcClient) -> ProcessResult { From 86c21323d463ed1859765d3e0f34028423815d77 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 12:07:35 -0600 Subject: [PATCH 5/6] Add camelCase --- cli/src/cli_output.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/src/cli_output.rs b/cli/src/cli_output.rs index 4ab8367ef887bd..6c735ddf4f628e 100644 --- a/cli/src/cli_output.rs +++ b/cli/src/cli_output.rs @@ -900,6 +900,7 @@ impl fmt::Display for CliSignOnlyData { } #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct CliSignature { pub signature: String, } @@ -913,6 +914,7 @@ impl fmt::Display for CliSignature { } #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct CliAccountBalances { pub accounts: Vec, } @@ -937,6 +939,7 @@ impl fmt::Display for CliAccountBalances { } #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct CliSupply { pub total: u64, pub circulating: u64, From a4257eede4576dff58ed705717dbbae00018102a Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 21 May 2020 13:12:17 -0600 Subject: [PATCH 6/6] Rename to blockhashLifespan, and add more descriptive docs --- cli/src/cli_output.rs | 11 +++++------ cli/src/cluster_query.rs | 4 ++-- client/src/rpc_client.rs | 6 +++--- client/src/rpc_request.rs | 4 ++-- client/src/rpc_response.rs | 4 ++-- core/src/rpc.rs | 28 +++++++++++----------------- docs/src/apps/jsonrpc-api.md | 13 +++++++------ runtime/src/bank.rs | 2 +- 8 files changed, 33 insertions(+), 39 deletions(-) diff --git a/cli/src/cli_output.rs b/cli/src/cli_output.rs index 6c735ddf4f628e..f4627a13cb6807 100644 --- a/cli/src/cli_output.rs +++ b/cli/src/cli_output.rs @@ -5,7 +5,7 @@ use inflector::cases::titlecase::to_title_case; use serde::Serialize; use serde_json::{Map, Value}; use solana_client::rpc_response::{ - RpcAccountBalance, RpcBlockhashQueueLength, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo, + RpcAccountBalance, RpcBlockhashLifespan, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo, }; use solana_sdk::{ clock::{self, Epoch, Slot, UnixTimestamp}, @@ -991,7 +991,7 @@ pub struct CliFees { pub slot: Slot, pub blockhash: String, pub lamports_per_signature: u64, - pub blockhash_queue_length: RpcBlockhashQueueLength, + pub blockhash_lifespan: RpcBlockhashLifespan, } impl fmt::Display for CliFees { @@ -1005,11 +1005,10 @@ impl fmt::Display for CliFees { writeln_name_value(f, "Slot:", &self.slot.to_string())?; writeln_name_value( f, - "Blockhash queue length:", + "Blockhash lifespan:", &format!( - "{} (epoch {})", - &self.blockhash_queue_length.blockhash_queue_length, - &self.blockhash_queue_length.epoch + "{} slots (epoch {})", + &self.blockhash_lifespan.blockhash_lifespan, &self.blockhash_lifespan.epoch ), )?; Ok(()) diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index 16b428c32e063d..24549cd023bb6c 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -602,12 +602,12 @@ pub fn process_cluster_version(rpc_client: &RpcClient) -> ProcessResult { pub fn process_fees(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult { let result = rpc_client.get_recent_blockhash_with_commitment(CommitmentConfig::default())?; let (recent_blockhash, fee_calculator) = result.value; - let blockhash_queue_length = rpc_client.get_blockhash_queue_length()?; + let blockhash_lifespan = rpc_client.get_blockhash_lifespan()?; let fees = CliFees { slot: result.context.slot, blockhash: recent_blockhash.to_string(), lamports_per_signature: fee_calculator.lamports_per_signature, - blockhash_queue_length: blockhash_queue_length.value, + blockhash_lifespan: blockhash_lifespan.value, }; Ok(config.output_format.formatted_string(&fees)) } diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 78dcb2a0bdb9d4..63643968d551c8 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -693,9 +693,9 @@ impl RpcClient { }) } - pub fn get_blockhash_queue_length(&self) -> RpcResult { - self.send::>( - RpcRequest::GetBlockhashQueueLength, + pub fn get_blockhash_lifespan(&self) -> RpcResult { + self.send::>( + RpcRequest::GetBlockhashLifespan, Value::Null, 0, ) diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index 1ed970504976ed..f460763fcff69e 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -8,7 +8,7 @@ pub enum RpcRequest { ValidatorExit, GetAccountInfo, GetBalance, - GetBlockhashQueueLength, + GetBlockhashLifespan, GetBlockTime, GetClusterNodes, GetConfirmedBlock, @@ -54,7 +54,7 @@ impl fmt::Display for RpcRequest { RpcRequest::ValidatorExit => "validatorExit", RpcRequest::GetAccountInfo => "getAccountInfo", RpcRequest::GetBalance => "getBalance", - RpcRequest::GetBlockhashQueueLength => "getBlockhashQueueLength", + RpcRequest::GetBlockhashLifespan => "getBlockhashLifespan", RpcRequest::GetBlockTime => "getBlockTime", RpcRequest::GetClusterNodes => "getClusterNodes", RpcRequest::GetConfirmedBlock => "getConfirmedBlock", diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index eab7174bb4d0b6..7cbf5553d545fa 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -49,9 +49,9 @@ pub struct RpcFeeRateGovernor { #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -pub struct RpcBlockhashQueueLength { +pub struct RpcBlockhashLifespan { pub epoch: Epoch, - pub blockhash_queue_length: usize, + pub blockhash_lifespan: usize, } #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 0e8a1dbebd5bb0..ae739029c7f0ff 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -227,15 +227,15 @@ impl JsonRpcRequestProcessor { ) } - fn get_blockhash_queue_length(&self) -> RpcResponse { + fn get_blockhash_lifespan(&self) -> RpcResponse { let bank = &*self.bank(None)?; let epoch = bank.epoch(); - let blockhash_queue_length = bank.get_blockhash_queue_length(); + let blockhash_lifespan = bank.get_blockhash_lifespan(); new_response( bank, - RpcBlockhashQueueLength { + RpcBlockhashLifespan { epoch, - blockhash_queue_length, + blockhash_lifespan, }, ) } @@ -809,11 +809,8 @@ pub trait RpcSol { #[rpc(meta, name = "getFeeRateGovernor")] fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse; - #[rpc(meta, name = "getBlockhashQueueLength")] - fn get_blockhash_queue_length( - &self, - meta: Self::Metadata, - ) -> RpcResponse; + #[rpc(meta, name = "getBlockhashLifespan")] + fn get_blockhash_lifespan(&self, meta: Self::Metadata) -> RpcResponse; #[rpc(meta, name = "getSignatureStatuses")] fn get_signature_statuses( @@ -1160,15 +1157,12 @@ impl RpcSol for RpcSolImpl { .get_fee_rate_governor() } - fn get_blockhash_queue_length( - &self, - meta: Self::Metadata, - ) -> RpcResponse { + fn get_blockhash_lifespan(&self, meta: Self::Metadata) -> RpcResponse { debug!("get_blockhash_length rpc request received"); meta.request_processor .read() .unwrap() - .get_blockhash_queue_length() + .get_blockhash_lifespan() } fn get_signature_confirmation( @@ -2616,11 +2610,11 @@ pub mod tests { } #[test] - fn test_rpc_get_blockhash_queue_length() { + fn test_rpc_get_blockhash_lifespan() { let bob_pubkey = Pubkey::new_rand(); let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey); - let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockhashQueueLength"}"#; + let req = r#"{"jsonrpc":"2.0","id":1,"method":"getBlockhashLifespan"}"#; let res = io.handle_request_sync(&req, meta); let expected = json!({ "jsonrpc": "2.0", @@ -2628,7 +2622,7 @@ pub mod tests { "context":{"slot":0}, "value":{ "epoch": 0, - "blockhashQueueLength": MAX_RECENT_BLOCKHASHES, + "blockhashLifespan": MAX_RECENT_BLOCKHASHES, }}, "id": 1 }); diff --git a/docs/src/apps/jsonrpc-api.md b/docs/src/apps/jsonrpc-api.md index 9f19248bec232b..98b3c0c8cd9e40 100644 --- a/docs/src/apps/jsonrpc-api.md +++ b/docs/src/apps/jsonrpc-api.md @@ -17,7 +17,7 @@ To interact with a Solana node inside a JavaScript application, use the [solana- * [getAccountInfo](jsonrpc-api.md#getaccountinfo) * [getBalance](jsonrpc-api.md#getbalance) * [getBlockCommitment](jsonrpc-api.md#getblockcommitment) -* [getBlockhashQueueLength](jsonrpc-api.md#getblockhashqueuelength) +* [getBlockhashLifespan](jsonrpc-api.md#getblockhashlifespan) * [getBlockTime](jsonrpc-api.md#getblocktime) * [getClusterNodes](jsonrpc-api.md#getclusternodes) * [getConfirmedBlock](jsonrpc-api.md#getconfirmedblock) @@ -214,9 +214,10 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "m {"jsonrpc":"2.0","result":{"commitment":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,32],"totalStake": 42},"id":1} ``` -### getBlockhashQueueLength +### getBlockhashLifespan -Returns the blockhash queue length for the current epoch. +Returns the blockhash lifespan for the current epoch. A particular blockhash +from slot M is valid until slot N, where N = `M + blockhashLifespan`. #### Parameters: @@ -228,16 +229,16 @@ The result will be an RpcResponse JSON object with `value` equal to and object with the following fields: * `epoch: ` - epoch -* `blockhashQueueLength: ` - length of the blockhash queue +* `blockhashLifespan: ` - blockhash lifespan, in slots #### Example: ```bash // Request -curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockhashQueueLength"}' http://localhost:8899 +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockhashLifespan"}' http://localhost:8899 // Result -{"jsonrpc":"2.0","result":{"context":{"slot":221},"value":{"epoch":0,"blockhashQueueLength":300}},"id":1} +{"jsonrpc":"2.0","result":{"context":{"slot":221},"value":{"epoch":0,"blockhashLifespan":300}},"id":1} ``` ### getBlockTime diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 07264da9963e77..bc8cde47362d03 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -985,7 +985,7 @@ impl Bank { &self.fee_rate_governor } - pub fn get_blockhash_queue_length(&self) -> usize { + pub fn get_blockhash_lifespan(&self) -> usize { self.blockhash_queue.read().unwrap().len() }