Commit 4434b3a9 authored by Kian Paimani's avatar Kian Paimani Committed by Bastian Köcher
Browse files

integrate minor weight/fee changes (#482)

* Update cargo files

* Make it build again.

* Fix build

* revert cargo file

* New lockfile

* Bump.
parent d4250bb5
This diff is collapsed.
......@@ -10,6 +10,6 @@ log = "0.4.6"
tokio = "0.1.7"
futures = "0.1.17"
exit-future = "0.1"
structopt = "0.2"
structopt = "0.3.3"
cli = { package = "substrate-cli", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
service = { package = "polkadot-service", path = "../service" }
......@@ -72,7 +72,7 @@ pub trait Worker: IntoExit {
#[derive(Debug, StructOpt, Clone)]
enum PolkadotSubCommands {
#[structopt(name = "validation-worker", raw(setting = "structopt::clap::AppSettings::Hidden"))]
#[structopt(name = "validation-worker", setting = structopt::clap::AppSettings::Hidden)]
ValidationWorker(ValidationWorkerCommand),
}
......
......@@ -32,6 +32,7 @@ authority-discovery = { package = "srml-authority-discovery", git = "https://git
authorship = { package = "srml-authorship", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
babe = { package = "srml-babe", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
transaction-payment = { package = "srml-transaction-payment", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
collective = { package = "srml-collective", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
democracy = { package = "srml-democracy", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
elections = { package = "srml-elections", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......@@ -57,7 +58,7 @@ polkadot-parachain = { path = "../parachain", default-features = false }
[dev-dependencies]
hex-literal = "0.2.0"
libsecp256k1 = "0.2.1"
libsecp256k1 = "0.3.1"
tiny-keccak = "1.4.2"
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......@@ -88,6 +89,7 @@ std = [
"srml-support/std",
"authorship/std",
"balances/std",
"transaction-payment/std",
"collective/std",
"elections/std",
"democracy/std",
......
......@@ -240,7 +240,7 @@ mod tests {
use codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sr_primitives::{Perbill, traits::{BlakeTwo256, IdentityLookup, ConvertInto}, testing::Header};
use sr_primitives::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use balances;
use srml_support::{impl_outer_origin, assert_ok, assert_err, assert_noop, parameter_types};
......@@ -267,7 +267,6 @@ mod tests {
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type WeightMultiplierUpdate = ();
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
......@@ -281,8 +280,6 @@ mod tests {
pub const ExistentialDeposit: u64 = 0;
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
pub const TransactionBaseFee: u64 = 0;
pub const TransactionByteFee: u64 = 0;
}
impl balances::Trait for Test {
......@@ -290,15 +287,11 @@ mod tests {
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
parameter_types!{
......@@ -326,7 +319,7 @@ mod tests {
}
fn alice_sig(what: &[u8]) -> EcdsaSignature {
let msg = keccak256(&Claims::ethereum_signable_message(&to_ascii_hex(what)[..]));
let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), &alice_secret()).unwrap();
let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), &alice_secret());
let mut r = [0u8; 65];
r[0..64].copy_from_slice(&sig.serialize()[..]);
r[64] = recovery_id.serialize();
......@@ -337,7 +330,7 @@ mod tests {
}
fn bob_sig(what: &[u8]) -> EcdsaSignature {
let msg = keccak256(&Claims::ethereum_signable_message(&to_ascii_hex(what)[..]));
let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), &bob_secret()).unwrap();
let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), &bob_secret());
let mut r = [0u8; 65];
r[0..64].copy_from_slice(&sig.serialize()[..]);
r[64] = recovery_id.serialize();
......
......@@ -508,7 +508,7 @@ mod tests {
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sr_primitives::{
Perbill, Permill, testing::Header,
traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup, ConvertInto},
traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup},
};
use crate::registrar::Registrar;
......@@ -537,7 +537,6 @@ mod tests {
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type WeightMultiplierUpdate = ();
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
......@@ -551,23 +550,17 @@ mod tests {
// that our module correctly avoids these fees :)
pub const TransferFee: u64 = 10;
pub const CreationFee: u64 = 10;
pub const TransactionBaseFee: u64 = 0;
pub const TransactionByteFee: u64 = 0;
}
impl balances::Trait for Test {
type Balance = u64;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
parameter_types! {
......
......@@ -17,7 +17,7 @@
//! Auxillary struct/enums for polkadot runtime.
use primitives::Balance;
use sr_primitives::weights::{Weight, WeightMultiplier};
use sr_primitives::weights::Weight;
use sr_primitives::traits::{Convert, Saturating};
use sr_primitives::Fixed64;
use srml_support::traits::{OnUnbalanced, Currency};
......@@ -81,10 +81,10 @@ impl Convert<Weight, Balance> for WeightToFee {
/// next_weight = weight * (1 + (v . diff) + (v . diff)^2 / 2)
///
/// https://research.web3.foundation/en/latest/polkadot/Token%20Economics/#relay-chain-transaction-fees
pub struct WeightMultiplierUpdateHandler;
pub struct FeeMultiplierUpdateHandler;
impl Convert<(Weight, WeightMultiplier), WeightMultiplier> for WeightMultiplierUpdateHandler {
fn convert(previous_state: (Weight, WeightMultiplier)) -> WeightMultiplier {
impl Convert<(Weight, Fixed64), Fixed64> for FeeMultiplierUpdateHandler {
fn convert(previous_state: (Weight, Fixed64)) -> Fixed64 {
let (block_weight, multiplier) = previous_state;
let max_weight = MaximumBlockWeight::get();
let target_weight = (TARGET_BLOCK_FULLNESS * max_weight) as u128;
......@@ -112,17 +112,17 @@ impl Convert<(Weight, WeightMultiplier), WeightMultiplier> for WeightMultiplierU
// Note: this is merely bounded by how big the multiplier and the inner value can go,
// not by any economical reasoning.
let excess = first_term.saturating_add(second_term);
multiplier.saturating_add(WeightMultiplier::from_fixed(excess))
multiplier.saturating_add(excess)
} else {
// first_term > second_term
// Proof: first_term > second_term. Safe subtraction.
let negative = first_term - second_term;
multiplier.saturating_sub(WeightMultiplier::from_fixed(negative))
multiplier.saturating_sub(negative)
// despite the fact that apply_to saturates weight (final fee cannot go below 0)
// it is crucially important to stop here and don't further reduce the weight fee
// multiplier. While at -1, it means that the network is so un-congested that all
// transactions have no weight fee. We stop here and only increase if the network
// became more busy.
.max(WeightMultiplier::from_rational(-1, 1))
.max(Fixed64::from_rational(-1, 1))
}
}
}
......@@ -71,7 +71,7 @@ pub use parachains::{Call as ParachainsCall, NEW_HEADS_IDENTIFIER};
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{CurrencyToVoteHandler, WeightMultiplierUpdateHandler, ToAuthor, WeightToFee};
use impls::{CurrencyToVoteHandler, FeeMultiplierUpdateHandler, ToAuthor, WeightToFee};
/// Constant values used within the runtime.
pub mod constants;
......@@ -100,7 +100,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 1,
spec_version: 1004,
spec_version: 1005,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
......@@ -158,7 +158,6 @@ impl system::Trait for Runtime {
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type WeightMultiplierUpdate = WeightMultiplierUpdateHandler;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
......@@ -191,8 +190,6 @@ parameter_types! {
pub const ExistentialDeposit: Balance = 100 * CENTS;
pub const TransferFee: Balance = 1 * CENTS;
pub const CreationFee: Balance = 1 * CENTS;
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
/// Splits fees 80/20 between treasury and block author.
......@@ -208,15 +205,25 @@ impl balances::Trait for Runtime {
type OnFreeBalanceZero = Staking;
type OnNewAccount = Indices;
type Event = Event;
type TransactionPayment = DealWithFees;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = FeeMultiplierUpdateHandler;
}
parameter_types! {
......@@ -549,6 +556,7 @@ construct_runtime!(
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Indices: indices,
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: transaction_payment::{Module, Storage},
// Consensus support.
Authorship: authorship::{Module, Call, Storage},
......@@ -603,7 +611,7 @@ pub type SignedExtra = (
system::CheckEra<Runtime>,
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
balances::TakeFees<Runtime>,
transaction_payment::ChargeTransactionPayment::<Runtime>,
registrar::LimitParathreadCommits<Runtime>
);
/// Unchecked extrinsic type as expected by this runtime.
......
......@@ -892,7 +892,7 @@ mod tests {
use substrate_trie::NodeCodec;
use sr_primitives::{
Perbill,
traits::{BlakeTwo256, IdentityLookup, ConvertInto, OnInitialize, OnFinalize},
traits::{BlakeTwo256, IdentityLookup, OnInitialize, OnFinalize},
testing::{UintAuthorityId, Header},
curve::PiecewiseLinear,
};
......@@ -939,7 +939,6 @@ mod tests {
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type WeightMultiplierUpdate = ();
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
......@@ -997,8 +996,6 @@ mod tests {
pub const ExistentialDeposit: Balance = 0;
pub const TransferFee: Balance = 0;
pub const CreationFee: Balance = 0;
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 0;
}
impl balances::Trait for Test {
......@@ -1006,15 +1003,11 @@ mod tests {
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
srml_staking_reward_curve::build! {
......
......@@ -578,7 +578,7 @@ mod tests {
use substrate_primitives::{H256, Pair};
use sr_primitives::{
traits::{
BlakeTwo256, IdentityLookup, ConvertInto, OnInitialize, OnFinalize, Dispatchable,
BlakeTwo256, IdentityLookup, OnInitialize, OnFinalize, Dispatchable,
AccountIdConversion,
}, testing::{UintAuthorityId, Header}, Perbill
};
......@@ -629,7 +629,6 @@ mod tests {
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type WeightMultiplierUpdate = ();
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
......@@ -642,8 +641,6 @@ mod tests {
pub const ExistentialDeposit: Balance = 0;
pub const TransferFee: Balance = 0;
pub const CreationFee: Balance = 0;
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 0;
}
impl balances::Trait for Test {
......@@ -651,15 +648,11 @@ mod tests {
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
parameter_types!{
......
......@@ -820,7 +820,7 @@ mod tests {
use substrate_primitives::H256;
use sr_primitives::{
Perbill, testing::Header,
traits::{ConvertInto, BlakeTwo256, Hash, IdentityLookup, OnInitialize, OnFinalize},
traits::{BlakeTwo256, Hash, IdentityLookup, OnInitialize, OnFinalize},
};
use srml_support::{impl_outer_origin, parameter_types, assert_ok, assert_noop};
use balances;
......@@ -850,7 +850,6 @@ mod tests {
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type WeightMultiplierUpdate = ();
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
......@@ -864,8 +863,6 @@ mod tests {
pub const ExistentialDeposit: u64 = 0;
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
pub const TransactionBaseFee: u64 = 0;
pub const TransactionByteFee: u64 = 0;
}
impl balances::Trait for Test {
......@@ -873,15 +870,11 @@ mod tests {
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
thread_local! {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment