Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

Commit 8e4cdcd

Browse files
Alex Sedbkchr
andauthored
Fix transaction payment runtime api (#131)
Cherry-pick substrate commit #54e6298523ea896f2129546c26dd7a47dbbeedc9 The transaction payment runtime api used its own extrinsic generic parameter. This is wrong, because this resulted in using always the native extrinsic. If there was a runtime upgrade that changed the extrinsic in some way, it would result in the api breaking. The correct way is to use the `Extrinsic` from the `Block` parameter. This is on the node side the opaque extrinsic and on the runtime side the real extrinsic. Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
1 parent 94086b4 commit 8e4cdcd

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

bin/node/rpc/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use std::{sync::Arc, fmt};
3333

3434
use node_primitives::{Block, BlockNumber, AccountId, Index, Balance, AssetId};
35-
use node_runtime::UncheckedExtrinsic;
3635
use sp_api::ProvideRuntimeApi;
3736
use sp_transaction_pool::TransactionPool;
3837
use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};
@@ -86,7 +85,7 @@ pub fn create_full<C, P, M, SC>(
8685
C: Send + Sync + 'static,
8786
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
8887
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
89-
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UncheckedExtrinsic>,
88+
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
9089
C::Api: pallet_generic_asset_rpc::AssetMetaApi<Block, AssetId>,
9190
C::Api: BabeApi<Block>,
9291
<C::Api as sp_api::ApiErrorExt>::Error: fmt::Debug,

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,8 @@ impl_runtime_apis! {
888888
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
889889
Block,
890890
Balance,
891-
UncheckedExtrinsic,
892891
> for Runtime {
893-
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
892+
fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
894893
TransactionPayment::query_info(uxt, len)
895894
}
896895
}

frame/transaction-payment/rpc/runtime-api/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(dese
5555
}
5656

5757
sp_api::decl_runtime_apis! {
58-
pub trait TransactionPaymentApi<Balance, Extrinsic> where
58+
pub trait TransactionPaymentApi<Balance> where
5959
Balance: Codec + MaybeDisplay + MaybeFromStr,
60-
Extrinsic: Codec,
6160
{
62-
fn query_info(uxt: Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance>;
61+
fn query_info(uxt: Block::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance>;
6362
}
6463
}
6564

frame/transaction-payment/rpc/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ impl From<Error> for i64 {
6868
}
6969
}
7070

71-
impl<C, Block, Balance, Extrinsic> TransactionPaymentApi<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>>
72-
for TransactionPayment<C, (Block, Extrinsic)>
71+
impl<C, Block, Balance> TransactionPaymentApi<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>>
72+
for TransactionPayment<C, Block>
7373
where
7474
Block: BlockT,
7575
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
76-
C::Api: TransactionPaymentRuntimeApi<Block, Balance, Extrinsic>,
76+
C::Api: TransactionPaymentRuntimeApi<Block, Balance>,
7777
Balance: Codec + MaybeDisplay + MaybeFromStr,
78-
Extrinsic: Codec + Send + Sync + 'static,
7978
{
8079
fn query_info(
8180
&self,
@@ -90,7 +89,7 @@ where
9089

9190
let encoded_len = encoded_xt.len() as u32;
9291

93-
let uxt: Extrinsic = Decode::decode(&mut &*encoded_xt).map_err(|e| RpcError {
92+
let uxt: Block::Extrinsic = Decode::decode(&mut &*encoded_xt).map_err(|e| RpcError {
9493
code: ErrorCode::ServerError(Error::DecodeError.into()),
9594
message: "Unable to query dispatch info.".into(),
9695
data: Some(format!("{:?}", e).into()),

0 commit comments

Comments
 (0)