Skip to content

Commit

Permalink
Fix transaction payment (#613)
Browse files Browse the repository at this point in the history
* Fix transaction payment

* Remove CustomOnRuntimeUpgrades

Co-authored-by: icodezjb <[email protected]>
  • Loading branch information
icodezjb and icodezjb authored Mar 13, 2022
1 parent 28094fa commit b88d151
Show file tree
Hide file tree
Showing 55 changed files with 387 additions and 499 deletions.
519 changes: 177 additions & 342 deletions Cargo.lock

Large diffs are not rendered by default.

69 changes: 1 addition & 68 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"
description = "Fully Decentralized Interchain Crypto Asset Management on Polkadot"
Expand All @@ -11,73 +11,6 @@ cli = { package = "chainx-cli", path = "cli" }
[target.'cfg(target_arch="x86_64")'.dependencies]
cli = { package = "chainx-cli", path = "cli", features = ["wasmtime"] }

[patch."https://github.com/paritytech/substrate"]

sp-api = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-application-crypto = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-arithmetic = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-authority-discovery = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-blockchain = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-block-builder = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-consensus = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-consensus-babe = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-consensus-slots = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-consensus-vrf = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-core = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-database = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-externalities = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-finality-grandpa = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-inherents = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-io = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-keystore = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-offchain = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-runtime = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-runtime-interface = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-session = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-staking = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-state-machine = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-std = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-storage = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-timestamp = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-tracing = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-transaction-pool = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-trie = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-version = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sp-wasm-interface = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }

sc-client-api = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sc-transaction-pool-api = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
sc-utils = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }


frame-executive = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
frame-support = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
frame-system = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
frame-system-rpc-runtime-api = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }

pallet-authorship = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-babe = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-balances = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-collective = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-democracy = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-elections-phragmen = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-grandpa = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-identity = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-im-online = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-indices = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-membership = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-multisig = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-offences = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-proxy = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-scheduler = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-session = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-sudo = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-timestamp = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-transaction-payment = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-treasury = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }
pallet-utility = { git = "https://github.com/chainx-org/substrate", rev = "79f50470dadedec5c54461eea5ce7d468d054371" }

[workspace]
members = [
"cli",
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx-cli"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
description = "Implementation of protocol https://chainx.org in Rust based on the Substrate framework."
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx-executor"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx-primitives"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/assets-registrar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-assets-registrar"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/gateway/bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-gateway-bitcoin"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/gateway/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-gateway-common"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/genesis-builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-genesis-builder"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-io"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/mining/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-mining-common"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/mining/staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-mining-staking"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-protocol"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-rpc"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xp-runtime"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx-rpc"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion runtime/chainx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainx-runtime"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
41 changes: 41 additions & 0 deletions runtime/chainx/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,44 @@ pub mod time {
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

/// Fee-related.
pub mod fee {
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use smallvec::smallvec;
pub use sp_runtime::Perbill;

use chainx_primitives::Balance;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, frame_system::MaximumBlockWeight]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = super::currency::CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
}
9 changes: 4 additions & 5 deletions runtime/chainx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub use frame_support::{
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
Weight,
},
StorageValue,
};
Expand Down Expand Up @@ -103,14 +103,13 @@ mod migrations;

use self::constants::{currency::*, time::*};
use self::impls::{ChargeExtraFee, DealWithFees, SlowAdjustingFeeUpdate};
use self::migrations::*;

/// This runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("chainx"),
impl_name: create_runtime_str!("chainx-net"),
authoring_version: 1,
spec_version: 12,
spec_version: 13,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down Expand Up @@ -417,7 +416,7 @@ parameter_types! {
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type WeightToFee = self::constants::fee::WeightToFee;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
}
Expand Down Expand Up @@ -1194,7 +1193,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
CustomOnRuntimeUpgrades,
(),
>;

impl_runtime_apis! {
Expand Down
20 changes: 10 additions & 10 deletions runtime/chainx/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ impl frame_support::traits::OnRuntimeUpgrade for PhragmenElectionDepositRuntimeU
}
}

pub struct SystemToTripleRefCount;
impl frame_support::traits::OnRuntimeUpgrade for SystemToTripleRefCount {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
frame_system::migrations::migrate_from_unique_to_triple_ref_count::<Runtime>()
}
}
// pub struct SystemToTripleRefCount;
// impl frame_support::traits::OnRuntimeUpgrade for SystemToTripleRefCount {
// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// frame_system::migrations::migrate_from_unique_to_triple_ref_count::<Runtime>()
// }
// }

impl pallet_babe::migrations::BabePalletPrefix for Runtime {
fn pallet_prefix() -> &'static str {
Expand Down Expand Up @@ -249,10 +249,10 @@ impl OnRuntimeUpgrade for CustomOnRuntimeUpgrades {
weight += <PhragmenElectionDepositRuntimeUpgrade as OnRuntimeUpgrade>::on_runtime_upgrade();
frame_support::log::info!("🚀 PhragmenElectionDepositRuntimeUpgrade end");

// 4. SystemToTripleRefCount
frame_support::log::info!("🔍️ SystemToTripleRefCount start");
weight += <SystemToTripleRefCount as OnRuntimeUpgrade>::on_runtime_upgrade();
frame_support::log::info!("🚀 SystemToTripleRefCount end");
// // 4. SystemToTripleRefCount
// frame_support::log::info!("🔍️ SystemToTripleRefCount start");
// weight += <SystemToTripleRefCount as OnRuntimeUpgrade>::on_runtime_upgrade();
// frame_support::log::info!("🚀 SystemToTripleRefCount end");

// 5. BabeEpochConfigMigrations
frame_support::log::info!("🔍️ BabeEpochConfigMigrations start");
Expand Down
2 changes: 1 addition & 1 deletion runtime/dev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dev-runtime"
version = "4.0.0"
version = "4.1.0"
authors = ["The ChainX Authors"]
edition = "2018"

Expand Down
41 changes: 41 additions & 0 deletions runtime/dev/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,44 @@ pub mod time {
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

/// Fee-related.
pub mod fee {
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use smallvec::smallvec;
pub use sp_runtime::Perbill;

use chainx_primitives::Balance;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, frame_system::MaximumBlockWeight]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = super::currency::CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
}
Loading

0 comments on commit b88d151

Please sign in to comment.