Skip to content

Commit

Permalink
Add get-recent-prioritization-fees command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed Apr 22, 2024
1 parent 8d4f2e6 commit b0e3eaa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ pub enum CliCommand {
GetBlock {
slot: Option<Slot>,
},
GetRecentPrioritizationFees {
accounts: Vec<Pubkey>,
num_slots: Option<Slot>,
},
GetBlockTime {
slot: Option<Slot>,
},
Expand Down Expand Up @@ -609,6 +613,9 @@ pub fn parse_command(
}
// Cluster Query Commands
("block", Some(matches)) => parse_get_block(matches),
("recent-prioritization-fees", Some(matches)) => {
parse_get_recent_prioritization_fees(matches)
}
("block-height", Some(matches)) => parse_get_block_height(matches),
("block-production", Some(matches)) => parse_show_block_production(matches),
("block-time", Some(matches)) => parse_get_block_time(matches),
Expand Down Expand Up @@ -905,6 +912,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::FirstAvailableBlock => process_first_available_block(&rpc_client),
CliCommand::GetBlock { slot } => process_get_block(&rpc_client, config, *slot),
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, config, *slot),
CliCommand::GetRecentPrioritizationFees {
accounts,
num_slots,
} => process_get_recent_priority_fees(&rpc_client, config, accounts, *num_slots),
CliCommand::GetEpoch => process_get_epoch(&rpc_client, config),
CliCommand::GetEpochInfo => process_get_epoch_info(&rpc_client, config),
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
Expand Down
66 changes: 66 additions & 0 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ impl ClusterQuerySubCommands for App<'_, '_> {
.index(1),
),
)
.subcommand(
SubCommand::with_name("recent-prioritization-fees")
.about("Get recent prioritization fees")
.arg(
Arg::with_name("accounts")
.long("accounts")
.value_name("ACCOUNTS")
.takes_value(true)
.multiple(true)
.index(1),
)
.arg(
Arg::with_name("num_slots")
.long("num-slots")
.value_name("SLOTS")
.takes_value(true),
),
)
.subcommand(
SubCommand::with_name("catchup")
.about("Wait for a validator to catch up to the cluster")
Expand Down Expand Up @@ -573,6 +591,19 @@ pub fn parse_get_block(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliEr
}))
}

pub fn parse_get_recent_prioritization_fees(
matches: &ArgMatches<'_>,
) -> Result<CliCommandInfo, CliError> {
let accounts = values_of(matches, "accounts").unwrap_or(vec![]);
let num_slots = value_of(matches, "num_slots");
Ok(CliCommandInfo::without_signers(
CliCommand::GetRecentPrioritizationFees {
accounts,
num_slots,
},
))
}

pub fn parse_get_block_time(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let slot = value_of(matches, "slot");
Ok(CliCommandInfo::without_signers(CliCommand::GetBlockTime {
Expand Down Expand Up @@ -1044,6 +1075,41 @@ pub fn process_leader_schedule(
}))
}

pub fn process_get_recent_priority_fees(
rpc_client: &RpcClient,
config: &CliConfig,
accounts: &[Pubkey],
num_slots: Option<Slot>,
) -> ProcessResult {
let mut ret = String::new();
if let Ok(fees) = rpc_client.get_recent_prioritization_fees(accounts) {
let mut min = u64::MAX;
let mut max = 0;
let mut total = 0;
if config.verbose {
ret.push_str(&format!("{:<11} {}\n", "slot", "prioritization_fee"));
}
let num_slots = num_slots
.unwrap_or(fees.len() as u64)
.min(fees.len() as u64) as usize;
for fee in fees.iter().skip(fees.len() - num_slots).take(num_slots) {
min = min.min(fee.prioritization_fee);
max = max.max(fee.prioritization_fee);
total += fee.prioritization_fee;
if config.verbose {
ret.push_str(&format!("{:<11} {}\n", fee.slot, fee.prioritization_fee));
}
}
ret.push_str(&format!(
"Fees: Min: {} Max: {} Average: {:.2}",
min,
max,
total as f32 / fees.len() as f32
));
}
Ok(ret)
}

pub fn process_get_block(
rpc_client: &RpcClient,
config: &CliConfig,
Expand Down

0 comments on commit b0e3eaa

Please sign in to comment.