Cli: expose last valid block height (#18620)
* Add Fees struct to client * Add complete RpcClient::get_fees methods * Switch cli to last_valid_block_height
This commit is contained in:
		@@ -1720,6 +1720,7 @@ pub struct CliFeesInner {
 | 
				
			|||||||
    pub blockhash: String,
 | 
					    pub blockhash: String,
 | 
				
			||||||
    pub lamports_per_signature: u64,
 | 
					    pub lamports_per_signature: u64,
 | 
				
			||||||
    pub last_valid_slot: Option<Slot>,
 | 
					    pub last_valid_slot: Option<Slot>,
 | 
				
			||||||
 | 
					    pub last_valid_block_height: Option<Slot>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl QuietDisplay for CliFeesInner {}
 | 
					impl QuietDisplay for CliFeesInner {}
 | 
				
			||||||
@@ -1733,11 +1734,11 @@ impl fmt::Display for CliFeesInner {
 | 
				
			|||||||
            "Lamports per signature:",
 | 
					            "Lamports per signature:",
 | 
				
			||||||
            &self.lamports_per_signature.to_string(),
 | 
					            &self.lamports_per_signature.to_string(),
 | 
				
			||||||
        )?;
 | 
					        )?;
 | 
				
			||||||
        let last_valid_slot = self
 | 
					        let last_valid_block_height = self
 | 
				
			||||||
            .last_valid_slot
 | 
					            .last_valid_block_height
 | 
				
			||||||
            .map(|s| s.to_string())
 | 
					            .map(|s| s.to_string())
 | 
				
			||||||
            .unwrap_or_default();
 | 
					            .unwrap_or_default();
 | 
				
			||||||
        writeln_name_value(f, "Last valid slot:", &last_valid_slot)
 | 
					        writeln_name_value(f, "Last valid block height:", &last_valid_block_height)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1766,6 +1767,7 @@ impl CliFees {
 | 
				
			|||||||
        blockhash: Hash,
 | 
					        blockhash: Hash,
 | 
				
			||||||
        lamports_per_signature: u64,
 | 
					        lamports_per_signature: u64,
 | 
				
			||||||
        last_valid_slot: Option<Slot>,
 | 
					        last_valid_slot: Option<Slot>,
 | 
				
			||||||
 | 
					        last_valid_block_height: Option<Slot>,
 | 
				
			||||||
    ) -> Self {
 | 
					    ) -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            inner: Some(CliFeesInner {
 | 
					            inner: Some(CliFeesInner {
 | 
				
			||||||
@@ -1773,6 +1775,7 @@ impl CliFees {
 | 
				
			|||||||
                blockhash: blockhash.to_string(),
 | 
					                blockhash: blockhash.to_string(),
 | 
				
			||||||
                lamports_per_signature,
 | 
					                lamports_per_signature,
 | 
				
			||||||
                last_valid_slot,
 | 
					                last_valid_slot,
 | 
				
			||||||
 | 
					                last_valid_block_height,
 | 
				
			||||||
            }),
 | 
					            }),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -936,18 +936,19 @@ pub fn process_fees(
 | 
				
			|||||||
                *recent_blockhash,
 | 
					                *recent_blockhash,
 | 
				
			||||||
                fee_calculator.lamports_per_signature,
 | 
					                fee_calculator.lamports_per_signature,
 | 
				
			||||||
                None,
 | 
					                None,
 | 
				
			||||||
 | 
					                None,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            CliFees::none()
 | 
					            CliFees::none()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        let result = rpc_client.get_recent_blockhash_with_commitment(config.commitment)?;
 | 
					        let result = rpc_client.get_fees_with_commitment(config.commitment)?;
 | 
				
			||||||
        let (recent_blockhash, fee_calculator, last_valid_slot) = result.value;
 | 
					 | 
				
			||||||
        CliFees::some(
 | 
					        CliFees::some(
 | 
				
			||||||
            result.context.slot,
 | 
					            result.context.slot,
 | 
				
			||||||
            recent_blockhash,
 | 
					            result.value.blockhash,
 | 
				
			||||||
            fee_calculator.lamports_per_signature,
 | 
					            result.value.fee_calculator.lamports_per_signature,
 | 
				
			||||||
            Some(last_valid_slot),
 | 
					            None,
 | 
				
			||||||
 | 
					            Some(result.value.last_valid_block_height),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    Ok(config.output_format.formatted_string(&fees))
 | 
					    Ok(config.output_format.formatted_string(&fees))
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								client/src/fees.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								client/src/fees.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					use crate::{fee_calculator::FeeCalculator, hash::Hash};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize, Deserialize, Clone, Debug)]
 | 
				
			||||||
 | 
					#[serde(rename_all = "camelCase")]
 | 
				
			||||||
 | 
					pub struct Fees {
 | 
				
			||||||
 | 
					    pub blockhash: Hash,
 | 
				
			||||||
 | 
					    pub fee_calculator: FeeCalculator,
 | 
				
			||||||
 | 
					    pub last_valid_block_height: u64,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1247,6 +1247,34 @@ impl RpcClient {
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn get_fees(&self) -> ClientResult<Fees> {
 | 
				
			||||||
 | 
					        Ok(self.get_fees_with_commitment(self.commitment())?.value)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn get_fees_with_commitment(&self, commitment_config: CommitmentConfig) -> RpcResult<Fees> {
 | 
				
			||||||
 | 
					        let Response {
 | 
				
			||||||
 | 
					            context,
 | 
				
			||||||
 | 
					            value: fees,
 | 
				
			||||||
 | 
					        } = self.send::<Response<RpcFees>>(
 | 
				
			||||||
 | 
					            RpcRequest::GetFees,
 | 
				
			||||||
 | 
					            json!([self.maybe_map_commitment(commitment_config)?]),
 | 
				
			||||||
 | 
					        )?;
 | 
				
			||||||
 | 
					        let blockhash = fees.blockhash.parse().map_err(|_| {
 | 
				
			||||||
 | 
					            ClientError::new_with_request(
 | 
				
			||||||
 | 
					                RpcError::ParseError("Hash".to_string()).into(),
 | 
				
			||||||
 | 
					                RpcRequest::GetFees,
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        })?;
 | 
				
			||||||
 | 
					        Ok(Response {
 | 
				
			||||||
 | 
					            context,
 | 
				
			||||||
 | 
					            value: Fees {
 | 
				
			||||||
 | 
					                blockhash,
 | 
				
			||||||
 | 
					                fee_calculator: fees.fee_calculator,
 | 
				
			||||||
 | 
					                last_valid_block_height: fees.last_valid_block_height,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn get_recent_blockhash(&self) -> ClientResult<(Hash, FeeCalculator)> {
 | 
					    pub fn get_recent_blockhash(&self) -> ClientResult<(Hash, FeeCalculator)> {
 | 
				
			||||||
        let (blockhash, fee_calculator, _last_valid_slot) = self
 | 
					        let (blockhash, fee_calculator, _last_valid_slot) = self
 | 
				
			||||||
            .get_recent_blockhash_with_commitment(self.commitment())?
 | 
					            .get_recent_blockhash_with_commitment(self.commitment())?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ use {
 | 
				
			|||||||
    solana_sdk::{
 | 
					    solana_sdk::{
 | 
				
			||||||
        clock::{Epoch, Slot, UnixTimestamp},
 | 
					        clock::{Epoch, Slot, UnixTimestamp},
 | 
				
			||||||
        fee_calculator::{FeeCalculator, FeeRateGovernor},
 | 
					        fee_calculator::{FeeCalculator, FeeRateGovernor},
 | 
				
			||||||
 | 
					        hash::Hash,
 | 
				
			||||||
        inflation::Inflation,
 | 
					        inflation::Inflation,
 | 
				
			||||||
        transaction::{Result, TransactionError},
 | 
					        transaction::{Result, TransactionError},
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -57,6 +58,14 @@ pub struct DeprecatedRpcFees {
 | 
				
			|||||||
    pub last_valid_slot: Slot,
 | 
					    pub last_valid_slot: Slot,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize, Deserialize, Clone, Debug)]
 | 
				
			||||||
 | 
					#[serde(rename_all = "camelCase")]
 | 
				
			||||||
 | 
					pub struct Fees {
 | 
				
			||||||
 | 
					    pub blockhash: Hash,
 | 
				
			||||||
 | 
					    pub fee_calculator: FeeCalculator,
 | 
				
			||||||
 | 
					    pub last_valid_block_height: u64,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
 | 
					#[derive(Serialize, Deserialize, Clone, Debug)]
 | 
				
			||||||
#[serde(rename_all = "camelCase")]
 | 
					#[serde(rename_all = "camelCase")]
 | 
				
			||||||
pub struct RpcFeeCalculator {
 | 
					pub struct RpcFeeCalculator {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user