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

Add Transaction Fee RPC to Statemint/Statemine #559

Merged
merged 11 commits into from
Aug 17, 2021
59 changes: 32 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ members = [
"polkadot-parachains/pallets/ping",
"polkadot-parachains/rococo",
"polkadot-parachains/shell",
"polkadot-parachains/statemint-common",
"polkadot-parachains/parachains-common",
"polkadot-parachains/statemint",
"polkadot-parachains/statemine",
"polkadot-parachains/westmint",
Expand Down
5 changes: 4 additions & 1 deletion polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ shell-runtime = { path = "shell" }
statemint-runtime = { path = "statemint" }
statemine-runtime = { path = "statemine" }
westmint-runtime = { path = "westmint" }
statemint-common = { path = "statemint-common" }
parachains-common = { path = "parachains-common" }

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

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

# Cumulus dependencies
cumulus-client-cli = { path = "../client/cli" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "statemint-common"
name = "parachains-common"
version = "1.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
description = "Logic which is common to all Statemint variant runtimes"
description = "Logic which is common to all parachain runtimes"

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Auxillary struct/enums for Statemint runtime.
//! Taken from polkadot/runtime/common (at a21cd64) and adapted for Statemint.
//! Auxillary struct/enums for parachain runtimes.
//! Taken from polkadot/runtime/common (at a21cd64) and adapted for parachains.

use frame_support::traits::{Currency, Imbalance, OnUnbalanced};

pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;

/// Logic for the author to get a portion of fees.
pub struct ToStakingPot<R>(sp_std::marker::PhantomData<R>);
Expand All @@ -32,10 +34,7 @@ where
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
let numeric_amount = amount.peek();
let staking_pot = <pallet_collator_selection::Pallet<R>>::account_id();
<pallet_balances::Pallet<R>>::resolve_creating(
&staking_pot,
amount,
);
<pallet_balances::Pallet<R>>::resolve_creating(&staking_pot, amount);
<frame_system::Pallet<R>>::deposit_event(pallet_balances::Event::Deposit(
staking_pot,
numeric_amount,
Expand Down Expand Up @@ -64,17 +63,20 @@ where
#[cfg(test)]
mod tests {
use super::*;
use frame_support::traits::FindAuthor;
use frame_support::{parameter_types, PalletId, traits::ValidatorRegistration};
use frame_support::{
parameter_types,
traits::{FindAuthor, ValidatorRegistration},
PalletId,
};
use frame_system::{limits, EnsureRoot};
use pallet_collator_selection::IdentityCollator;
use polkadot_primitives::v1::AccountId;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Perbill,
};
use pallet_collator_selection::IdentityCollator;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod impls;
pub use types::*;
pub use constants::*;

/// Common types of statemint and statemine.
pub use opaque::*;
pub use types::*;
/// Common types of parachains.
mod types {
use sp_runtime::traits::{Verify, IdentifyAccount, BlakeTwo256};
use sp_runtime::traits::{IdentifyAccount, Verify};

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

/// Block header type as expected by this runtime.
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;

/// Digest item type.
pub type DigestItem = sp_runtime::generic::DigestItem<Hash>;

// Aura consensus authority.
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
}

/// Common constants of statemint and statemine
/// Common constants of parachains.
mod constants {
use super::types::BlockNumber;
use frame_support::weights::{constants::WEIGHT_PER_SECOND, Weight};
use sp_runtime::Perbill;
use frame_support::weights::{Weight, constants::WEIGHT_PER_SECOND};
/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
Expand All @@ -85,3 +82,20 @@ mod constants {
/// We allow for 0.5 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
pub mod opaque {
use super::*;
use sp_runtime::{generic, traits::BlakeTwo256};

pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
/// Opaque block header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Opaque block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Opaque block identifier type.
pub type BlockId = generic::BlockId<Block>;
}
2 changes: 2 additions & 0 deletions polkadot-parachains/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-f
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

# Cumulus dependencies
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }
Expand Down
21 changes: 21 additions & 0 deletions polkadot-parachains/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,27 @@ impl_runtime_apis! {
}
}

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
fn query_info(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
fn query_fee_details(
uxt: <Block as BlockT>::Extrinsic,
len: u32,
) -> pallet_transaction_payment::FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
}

impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info()
Expand Down
Loading