RPC getPerformanceSamples: Add `numNonVoteTransaction` (#29388)
Allow interested parties to see both total and non-vote transaction counts in each performance sample. Fixes https://github.com/solana-labs/solana/issues/29159
This commit is contained in:
parent
55d743c49a
commit
6e4ecc6758
|
@ -2060,8 +2060,9 @@ Result:
|
|||
|
||||
### getRecentPerformanceSamples
|
||||
|
||||
Returns a list of recent performance samples, in reverse slot order. Performance samples are taken every 60 seconds and
|
||||
include the number of transactions and slots that occur in a given time window.
|
||||
Returns a list of recent performance samples, in reverse slot order. Performance
|
||||
samples are taken every 60 seconds and include the number of transactions and
|
||||
slots that occur in a given time window.
|
||||
|
||||
#### Parameters:
|
||||
|
||||
|
@ -2074,6 +2075,11 @@ An array of:
|
|||
- `RpcPerfSample<object>`
|
||||
- `slot: <u64>` - Slot in which sample was taken at
|
||||
- `numTransactions: <u64>` - Number of transactions in sample
|
||||
- `numNonVoteTransaction: <u64>` - Number of non-vote transactions in
|
||||
sample.<br/>
|
||||
To get a number of voting transactions compute `numTransactions -
|
||||
numNonVoteTransaction`.<br/>
|
||||
This field is present starting with v1.15.
|
||||
- `numSlots: <u64>` - Number of slots in sample
|
||||
- `samplePeriodSecs: <u16>` - Number of seconds in a sample window
|
||||
|
||||
|
@ -2097,24 +2103,28 @@ Result:
|
|||
{
|
||||
"numSlots": 126,
|
||||
"numTransactions": 126,
|
||||
"numNonVoteTransaction": 1,
|
||||
"samplePeriodSecs": 60,
|
||||
"slot": 348125
|
||||
},
|
||||
{
|
||||
"numSlots": 126,
|
||||
"numTransactions": 126,
|
||||
"numNonVoteTransaction": 1,
|
||||
"samplePeriodSecs": 60,
|
||||
"slot": 347999
|
||||
},
|
||||
{
|
||||
"numSlots": 125,
|
||||
"numTransactions": 125,
|
||||
"numNonVoteTransaction": 0,
|
||||
"samplePeriodSecs": 60,
|
||||
"slot": 347873
|
||||
},
|
||||
{
|
||||
"numSlots": 125,
|
||||
"numTransactions": 125,
|
||||
"numNonVoteTransaction": 0,
|
||||
"samplePeriodSecs": 60,
|
||||
"slot": 347748
|
||||
}
|
||||
|
|
|
@ -487,6 +487,7 @@ pub struct RpcConfirmedTransactionStatusWithSignature {
|
|||
pub struct RpcPerfSample {
|
||||
pub slot: Slot,
|
||||
pub num_transactions: u64,
|
||||
pub num_non_vote_transactions: Option<u64>,
|
||||
pub num_slots: u64,
|
||||
pub sample_period_secs: u16,
|
||||
}
|
||||
|
@ -549,3 +550,68 @@ pub struct RpcPrioritizationFee {
|
|||
pub slot: Slot,
|
||||
pub prioritization_fee: u64,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
|
||||
use {super::*, serde_json::json};
|
||||
|
||||
// Make sure that `RpcPerfSample` can read previous version JSON, one without the
|
||||
// `num_non_vote_transactions` field.
|
||||
#[test]
|
||||
fn rpc_perf_sample_deserialize_old() {
|
||||
let slot = 424;
|
||||
let num_transactions = 2597;
|
||||
let num_slots = 2783;
|
||||
let sample_period_secs = 398;
|
||||
|
||||
let input = json!({
|
||||
"slot": slot,
|
||||
"numTransactions": num_transactions,
|
||||
"numSlots": num_slots,
|
||||
"samplePeriodSecs": sample_period_secs,
|
||||
})
|
||||
.to_string();
|
||||
|
||||
let actual: RpcPerfSample =
|
||||
serde_json::from_str(&input).expect("Can parse RpcPerfSample from string as JSON");
|
||||
let expected = RpcPerfSample {
|
||||
slot,
|
||||
num_transactions,
|
||||
num_non_vote_transactions: None,
|
||||
num_slots,
|
||||
sample_period_secs,
|
||||
};
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
// Make sure that `RpcPerfSample` serializes into the new `num_non_vote_transactions` field.
|
||||
#[test]
|
||||
fn rpc_perf_sample_serializes_num_non_vote_transactions() {
|
||||
let slot = 1286;
|
||||
let num_transactions = 1732;
|
||||
let num_non_vote_transactions = Some(757);
|
||||
let num_slots = 393;
|
||||
let sample_period_secs = 197;
|
||||
|
||||
let input = RpcPerfSample {
|
||||
slot,
|
||||
num_transactions,
|
||||
num_non_vote_transactions,
|
||||
num_slots,
|
||||
sample_period_secs,
|
||||
};
|
||||
let actual =
|
||||
serde_json::to_value(&input).expect("Can convert RpcPerfSample into a JSON value");
|
||||
let expected = json!({
|
||||
"slot": slot,
|
||||
"numTransactions": num_transactions,
|
||||
"numNonVoteTransactions": num_non_vote_transactions,
|
||||
"numSlots": num_slots,
|
||||
"samplePeriodSecs": sample_period_secs,
|
||||
});
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,6 +417,7 @@ impl RpcSender for MockSender {
|
|||
"getRecentPerformanceSamples" => serde_json::to_value(vec![RpcPerfSample {
|
||||
slot: 347873,
|
||||
num_transactions: 125,
|
||||
num_non_vote_transactions: Some(1),
|
||||
num_slots: 123,
|
||||
sample_period_secs: 60,
|
||||
}])?,
|
||||
|
|
|
@ -4020,17 +4020,19 @@ fn rpc_perf_sample_from_perf_sample(slot: u64, sample: PerfSample) -> RpcPerfSam
|
|||
}) => RpcPerfSample {
|
||||
slot,
|
||||
num_transactions,
|
||||
num_non_vote_transactions: None,
|
||||
num_slots,
|
||||
sample_period_secs,
|
||||
},
|
||||
PerfSample::V2(PerfSampleV2 {
|
||||
num_transactions,
|
||||
num_non_vote_transactions: _,
|
||||
num_non_vote_transactions,
|
||||
num_slots,
|
||||
sample_period_secs,
|
||||
}) => RpcPerfSample {
|
||||
slot,
|
||||
num_transactions,
|
||||
num_non_vote_transactions: Some(num_non_vote_transactions),
|
||||
num_slots,
|
||||
sample_period_secs,
|
||||
},
|
||||
|
@ -5162,6 +5164,7 @@ pub mod tests {
|
|||
"slot": slot,
|
||||
"numSlots": num_slots,
|
||||
"numTransactions": num_transactions,
|
||||
"numNonVoteTransactions": num_non_vote_transactions,
|
||||
"samplePeriodSecs": sample_period_secs,
|
||||
}]);
|
||||
assert_eq!(result, expected);
|
||||
|
|
Loading…
Reference in New Issue