-
Notifications
You must be signed in to change notification settings - Fork 2.7k
payment_queryInfo: Make it work with WeightV2
#12633
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ use jsonrpsee::{ | |
| types::error::{CallError, ErrorCode, ErrorObject}, | ||
| }; | ||
| use pallet_transaction_payment_rpc_runtime_api::{FeeDetails, InclusionFee, RuntimeDispatchInfo}; | ||
| use sp_api::ProvideRuntimeApi; | ||
| use sp_api::{ApiExt, ProvideRuntimeApi}; | ||
| use sp_blockchain::HeaderBackend; | ||
| use sp_core::Bytes; | ||
| use sp_rpc::number::NumberOrHex; | ||
|
|
@@ -82,8 +82,10 @@ impl From<Error> for i32 { | |
| } | ||
|
|
||
| impl<C, Block, Balance> | ||
| TransactionPaymentApiServer<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>> | ||
| for TransactionPayment<C, Block> | ||
| TransactionPaymentApiServer< | ||
| <Block as BlockT>::Hash, | ||
| RuntimeDispatchInfo<Balance, sp_weights::OldWeight>, | ||
| > for TransactionPayment<C, Block> | ||
| where | ||
| Block: BlockT, | ||
| C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static, | ||
|
|
@@ -94,7 +96,7 @@ where | |
| &self, | ||
| encoded_xt: Bytes, | ||
| at: Option<Block::Hash>, | ||
| ) -> RpcResult<RuntimeDispatchInfo<Balance>> { | ||
| ) -> RpcResult<RuntimeDispatchInfo<Balance, sp_weights::OldWeight>> { | ||
| let api = self.client.runtime_api(); | ||
| let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); | ||
|
|
||
|
|
@@ -107,14 +109,41 @@ where | |
| Some(format!("{:?}", e)), | ||
| )) | ||
| })?; | ||
| api.query_info(&at, uxt, encoded_len).map_err(|e| { | ||
|
|
||
| fn map_err(error: impl ToString, desc: &'static str) -> CallError { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Unable to query dispatch info.", | ||
| Some(e.to_string()), | ||
| desc, | ||
| Some(error.to_string()), | ||
| )) | ||
| .into() | ||
| }) | ||
| } | ||
|
|
||
| let api_version = api | ||
| .api_version::<dyn TransactionPaymentRuntimeApi<Block, Balance>>(&at) | ||
| .map_err(|e| map_err(e, "Failed to get transaction payment runtime api version"))? | ||
| .ok_or_else(|| { | ||
| CallError::Custom(ErrorObject::owned( | ||
| Error::RuntimeError.into(), | ||
| "Transaction payment runtime api wasn't found in the runtime", | ||
| None::<String>, | ||
| )) | ||
| })?; | ||
|
|
||
| if api_version < 2 { | ||
| #[allow(deprecated)] | ||
| api.query_info_before_version_2(&at, uxt, encoded_len) | ||
| .map_err(|e| map_err(e, "Unable to query dispatch info.").into()) | ||
| } else { | ||
| let res = api | ||
| .query_info(&at, uxt, encoded_len) | ||
| .map_err(|e| map_err(e, "Unable to query dispatch info."))?; | ||
|
|
||
| Ok(RuntimeDispatchInfo { | ||
| weight: sp_weights::OldWeight(res.weight.ref_time()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this really should be using the new weight and not the old one, as it's already in V2.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. The RPC was always returning the old weight and we should stick to this. Otherwise this pr is useless, as downstream would still fail.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will we ever return the new weight from RPC then?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess since RPCs don't have versioning like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We want to deprecate these RPC calls anyway. |
||
| class: res.class, | ||
| partial_fee: res.partial_fee, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn query_fee_details( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.