Transaction Fee Module (#1648)

* wip

* Split bytes fee charging and charging by amount into different traits.

* Move to edition 2018.

* Implemented charge fee traits for fees module.

* Implemented 'on_finalise' for fee module.

* Updated fees finalize impl.

* Renaming and documentation update.

* Added overflow & underflow check for fee calculation.

* Added mock and unit tests for fee module.

* More unit tests for fees module.

* Fixed srml-executive unit tests.

* Remove transaction base/bytes fee from balances module, fix unit tests.

* fix compile error

* Fixed unit test.

* Minor fixes.

* Bump spec version.

* Bump spec version.

* Updated fees module and runtime wasm.

* Fees module code style improvement; updated runtime wasm.

* Bump spec and impl version.
This commit is contained in:
Xiliang Chen
2019-02-15 23:21:38 +13:00
committed by Bastian Köcher
parent 6a6c3155a6
commit fafffdb771
31 changed files with 672 additions and 90 deletions
@@ -16,6 +16,7 @@ version = { package = "sr-version", path = "../../core/sr-version", default_feat
support = { package = "srml-support", path = "../../srml/support", default_features = false }
primitives = { package = "substrate-primitives", path = "../../core/primitives", default_features = false }
balances = { package = "srml-balances", path = "../../srml/balances", default_features = false }
fees = { package = "srml-fees", path = "../../srml/fees", default_features = false }
consensus = { package = "srml-consensus", path = "../../srml/consensus", default_features = false }
aura = { package = "srml-aura", path = "../../srml/aura", default_features = false }
executive = { package = "srml-executive", path = "../../srml/executive", default_features = false }
@@ -38,6 +39,7 @@ std = [
"runtime-io/std",
"support/std",
"balances/std",
"fees/std",
"executive/std",
"aura/std",
"indices/std",
+8 -1
View File
@@ -164,6 +164,12 @@ impl balances::Trait for Runtime {
type Event = Event;
}
impl fees::Trait for Runtime {
type Amount = u128;
type TransferAsset = Balances;
type Event = Event;
}
impl sudo::Trait for Runtime {
/// The uniquitous event type.
type Event = Event;
@@ -188,6 +194,7 @@ construct_runtime!(
Indices: indices,
Balances: balances,
Sudo: sudo,
Fees: fees::{Module, Storage, Config<T>, Event<T>},
// Used for the module template in `./template.rs`
TemplateModule: template::{Module, Call, Storage, Event<T>},
}
@@ -208,7 +215,7 @@ pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Context, Balances, AllModules>;
pub type Executive = executive::Executive<Runtime, Block, Context, Fees, AllModules>;
// Implement our runtime API endpoints. This is just a bunch of proxying.
impl_runtime_apis! {
+17
View File
@@ -655,6 +655,7 @@ dependencies = [
"srml-balances 0.1.0",
"srml-consensus 0.1.0",
"srml-executive 0.1.0",
"srml-fees 0.1.0",
"srml-indices 0.1.0",
"srml-sudo 0.1.0",
"srml-support 0.1.0",
@@ -1333,6 +1334,22 @@ dependencies = [
"srml-system 0.1.0",
]
[[package]]
name = "srml-fees"
version = "0.1.0"
dependencies = [
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-io 0.1.0",
"sr-primitives 0.1.0",
"sr-std 0.1.0",
"srml-support 0.1.0",
"srml-system 0.1.0",
"substrate-primitives 0.1.0",
]
[[package]]
name = "srml-indices"
version = "0.1.0"
+5 -3
View File
@@ -1,7 +1,7 @@
use primitives::{Ed25519AuthorityId, ed25519};
use node_template_runtime::{
AccountId, GenesisConfig, ConsensusConfig, TimestampConfig, BalancesConfig,
SudoConfig, IndicesConfig
SudoConfig, IndicesConfig, FeesConfig,
};
use substrate_service;
@@ -90,8 +90,6 @@ fn testnet_genesis(initial_authorities: Vec<Ed25519AuthorityId>, endowed_account
ids: endowed_accounts.clone(),
}),
balances: Some(BalancesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
existential_deposit: 500,
transfer_fee: 0,
creation_fee: 0,
@@ -101,5 +99,9 @@ fn testnet_genesis(initial_authorities: Vec<Ed25519AuthorityId>, endowed_account
sudo: Some(SudoConfig {
key: root_key,
}),
fees: Some(FeesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
})
}
}