Skip to content

Commit

Permalink
Add commitment parameter to getFeeCalculatorForBlockhash (solana-labs…
Browse files Browse the repository at this point in the history
…#10255)

* Accept commitment parameter on getFeeCalculatorForBlockhash

* Update docs

* Add get_fee_calculator_for_blockhash_with_commitment to rpc client
  • Loading branch information
CriesofCarrots authored May 26, 2020
1 parent 22a98bd commit 3f0995d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
22 changes: 19 additions & 3 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,28 @@ impl RpcClient {
&self,
blockhash: &Hash,
) -> ClientResult<Option<FeeCalculator>> {
let Response { value, .. } = self.send::<Response<Option<RpcFeeCalculator>>>(
Ok(self
.get_fee_calculator_for_blockhash_with_commitment(
blockhash,
CommitmentConfig::default(),
)?
.value)
}

pub fn get_fee_calculator_for_blockhash_with_commitment(
&self,
blockhash: &Hash,
commitment_config: CommitmentConfig,
) -> RpcResult<Option<FeeCalculator>> {
let Response { context, value } = self.send::<Response<Option<RpcFeeCalculator>>>(
RpcRequest::GetFeeCalculatorForBlockhash,
json!([blockhash.to_string()]),
json!([blockhash.to_string(), commitment_config]),
)?;

Ok(value.map(|rf| rf.fee_calculator))
Ok(Response {
context,
value: value.map(|rf| rf.fee_calculator),
})
}

pub fn get_fee_rate_governor(&self) -> RpcResult<FeeRateGovernor> {
Expand Down
7 changes: 5 additions & 2 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ impl JsonRpcRequestProcessor {
fn get_fee_calculator_for_blockhash(
&self,
blockhash: &Hash,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<RpcFeeCalculator>> {
let bank = &*self.bank(None)?;
let bank = &*self.bank(commitment)?;
let fee_calculator = bank.get_fee_calculator(blockhash);
new_response(
bank,
Expand Down Expand Up @@ -821,6 +822,7 @@ pub trait RpcSol {
&self,
meta: Self::Metadata,
blockhash: String,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<RpcFeeCalculator>>;

#[rpc(meta, name = "getFeeRateGovernor")]
Expand Down Expand Up @@ -1162,14 +1164,15 @@ impl RpcSol for RpcSolImpl {
&self,
meta: Self::Metadata,
blockhash: String,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<RpcFeeCalculator>> {
debug!("get_fee_calculator_for_blockhash rpc request received");
let blockhash =
Hash::from_str(&blockhash).map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
meta.request_processor
.read()
.unwrap()
.get_fee_calculator_for_blockhash(&blockhash)
.get_fee_calculator_for_blockhash(&blockhash, commitment)
}

fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse<RpcFeeRateGovernor> {
Expand Down
3 changes: 2 additions & 1 deletion docs/src/apps/jsonrpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ Returns the fee calculator associated with the query blockhash, or `null` if the

#### Parameters:

* `blockhash: <string>`, query blockhash as a Base58 encoded string
* `<string>` - query blockhash as a Base58 encoded string
* `<object>` - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment)

#### Results:

Expand Down

0 comments on commit 3f0995d

Please sign in to comment.