Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 333cfdf

Browse files
hamidrabkchrshawntabrizi
authored
Add Transaction Fee RPC to Statemint/Statemine (#559)
* add payment rpc to parachains * connect payment rpc to parachains clients * fix the rumtime_api bound/ add separate start node implementation for shell * use cumulus/parachain specific primitives * Update polkadot-parachains/src/rpc.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * rename txpool dependency * fix the package name * move parachain primitives to separate module * Refactor Shared Primitves for Payment Info (#577) * rename to parachains-common * refactor shared opaque * remove primitives * Update service.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
1 parent db125d2 commit 333cfdf

File tree

18 files changed

+560
-261
lines changed

18 files changed

+560
-261
lines changed

Cargo.lock

+32-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ members = [
2424
"polkadot-parachains/pallets/ping",
2525
"polkadot-parachains/rococo",
2626
"polkadot-parachains/shell",
27-
"polkadot-parachains/statemint-common",
27+
"polkadot-parachains/parachains-common",
2828
"polkadot-parachains/statemint",
2929
"polkadot-parachains/statemine",
3030
"polkadot-parachains/westmint",

polkadot-parachains/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ shell-runtime = { path = "shell" }
2828
statemint-runtime = { path = "statemint" }
2929
statemine-runtime = { path = "statemine" }
3030
westmint-runtime = { path = "westmint" }
31-
statemint-common = { path = "statemint-common" }
31+
parachains-common = { path = "parachains-common" }
3232

3333
# Substrate dependencies
3434
frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch = "master" }
@@ -64,6 +64,9 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate
6464

6565
# RPC related dependencies
6666
jsonrpc-core = "15.1.0"
67+
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
68+
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" }
69+
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
6770

6871
# Cumulus dependencies
6972
cumulus-client-cli = { path = "../client/cli" }

polkadot-parachains/statemint-common/Cargo.toml polkadot-parachains/parachains-common/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "statemint-common"
2+
name = "parachains-common"
33
version = "1.0.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2018"
6-
description = "Logic which is common to all Statemint variant runtimes"
6+
description = "Logic which is common to all parachain runtimes"
77

88
[package.metadata.docs.rs]
99
targets = ['x86_64-unknown-linux-gnu']

polkadot-parachains/statemint-common/src/impls.rs polkadot-parachains/parachains-common/src/impls.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
//! Auxillary struct/enums for Statemint runtime.
17-
//! Taken from polkadot/runtime/common (at a21cd64) and adapted for Statemint.
16+
//! Auxillary struct/enums for parachain runtimes.
17+
//! Taken from polkadot/runtime/common (at a21cd64) and adapted for parachains.
1818
1919
use frame_support::traits::{Currency, Imbalance, OnUnbalanced};
2020

21-
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
21+
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<
22+
<T as frame_system::Config>::AccountId,
23+
>>::NegativeImbalance;
2224

2325
/// Logic for the author to get a portion of fees.
2426
pub struct ToStakingPot<R>(sp_std::marker::PhantomData<R>);
@@ -32,10 +34,7 @@ where
3234
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
3335
let numeric_amount = amount.peek();
3436
let staking_pot = <pallet_collator_selection::Pallet<R>>::account_id();
35-
<pallet_balances::Pallet<R>>::resolve_creating(
36-
&staking_pot,
37-
amount,
38-
);
37+
<pallet_balances::Pallet<R>>::resolve_creating(&staking_pot, amount);
3938
<frame_system::Pallet<R>>::deposit_event(pallet_balances::Event::Deposit(
4039
staking_pot,
4140
numeric_amount,
@@ -64,17 +63,20 @@ where
6463
#[cfg(test)]
6564
mod tests {
6665
use super::*;
67-
use frame_support::traits::FindAuthor;
68-
use frame_support::{parameter_types, PalletId, traits::ValidatorRegistration};
66+
use frame_support::{
67+
parameter_types,
68+
traits::{FindAuthor, ValidatorRegistration},
69+
PalletId,
70+
};
6971
use frame_system::{limits, EnsureRoot};
72+
use pallet_collator_selection::IdentityCollator;
7073
use polkadot_primitives::v1::AccountId;
7174
use sp_core::H256;
7275
use sp_runtime::{
7376
testing::Header,
7477
traits::{BlakeTwo256, IdentityLookup},
7578
Perbill,
7679
};
77-
use pallet_collator_selection::IdentityCollator;
7880

7981
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
8082
type Block = frame_system::mocking::MockBlock<Test>;

polkadot-parachains/statemint-common/src/lib.rs polkadot-parachains/parachains-common/src/lib.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#![cfg_attr(not(feature = "std"), no_std)]
1717

1818
pub mod impls;
19-
pub use types::*;
2019
pub use constants::*;
21-
22-
/// Common types of statemint and statemine.
20+
pub use opaque::*;
21+
pub use types::*;
22+
/// Common types of parachains.
2323
mod types {
24-
use sp_runtime::traits::{Verify, IdentifyAccount, BlakeTwo256};
24+
use sp_runtime::traits::{IdentifyAccount, Verify};
2525

2626
/// An index to a block.
2727
pub type BlockNumber = u32;
@@ -46,21 +46,18 @@ mod types {
4646
/// A hash of some data used by the chain.
4747
pub type Hash = sp_core::H256;
4848

49-
/// Block header type as expected by this runtime.
50-
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
51-
5249
/// Digest item type.
5350
pub type DigestItem = sp_runtime::generic::DigestItem<Hash>;
54-
51+
5552
// Aura consensus authority.
5653
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
5754
}
5855

59-
/// Common constants of statemint and statemine
56+
/// Common constants of parachains.
6057
mod constants {
6158
use super::types::BlockNumber;
59+
use frame_support::weights::{constants::WEIGHT_PER_SECOND, Weight};
6260
use sp_runtime::Perbill;
63-
use frame_support::weights::{Weight, constants::WEIGHT_PER_SECOND};
6461
/// This determines the average expected block time that we are targeting. Blocks will be
6562
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
6663
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
@@ -85,3 +82,20 @@ mod constants {
8582
/// We allow for 0.5 seconds of compute with a 6 second average block time.
8683
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;
8784
}
85+
86+
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
87+
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
88+
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
89+
/// to even the core data structures.
90+
pub mod opaque {
91+
use super::*;
92+
use sp_runtime::{generic, traits::BlakeTwo256};
93+
94+
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
95+
/// Opaque block header type.
96+
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
97+
/// Opaque block type.
98+
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
99+
/// Opaque block identifier type.
100+
pub type BlockId = generic::BlockId<Block>;
101+
}

polkadot-parachains/rococo/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-f
2828
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
2929
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3030
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
31+
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3132
pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3233
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3334
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3435
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3536
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3637
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3738
pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
39+
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
3840

3941
# Cumulus dependencies
4042
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }

polkadot-parachains/rococo/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,27 @@ impl_runtime_apis! {
590590
}
591591
}
592592

593+
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
594+
fn account_nonce(account: AccountId) -> Index {
595+
System::account_nonce(account)
596+
}
597+
}
598+
599+
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
600+
fn query_info(
601+
uxt: <Block as BlockT>::Extrinsic,
602+
len: u32,
603+
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
604+
TransactionPayment::query_info(uxt, len)
605+
}
606+
fn query_fee_details(
607+
uxt: <Block as BlockT>::Extrinsic,
608+
len: u32,
609+
) -> pallet_transaction_payment::FeeDetails<Balance> {
610+
TransactionPayment::query_fee_details(uxt, len)
611+
}
612+
}
613+
593614
impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
594615
fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {
595616
ParachainSystem::collect_collation_info()

0 commit comments

Comments
 (0)