diff --git a/demo/executor/src/lib.rs b/demo/executor/src/lib.rs index 50515bd6055c7..19f0764f4bdf1 100644 --- a/demo/executor/src/lib.rs +++ b/demo/executor/src/lib.rs @@ -229,7 +229,7 @@ mod tests { validator_count: 3, minimum_validator_count: 0, bonding_duration: 0, - early_era_slash: 0, + offline_slash: 0, session_reward: 0, offline_slash_grace: 0, }), @@ -262,7 +262,7 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("b7d85f23689ae4ae7951eda80e817dffb1c0925e77f5c0de8c94b265df80b9cf").into(), + hex!("efdd1840ae46b687fc59fc730892d412a0fb051ef120f9e6dfcf1c416d0fc2cb").into(), vec![ CheckedExtrinsic { signed: None, @@ -282,7 +282,7 @@ mod tests { construct_block( 2, block1().1, - hex!("a17d6006e9bb4292b8ebea3b14995672a88caff2c99eeef1d84aeb234e5a0534").into(), + hex!("e360ad4a43929e521fd41cdabf8d772eb39f9cbf71fe95bada685e24bd3bbbbb").into(), vec![ CheckedExtrinsic { signed: None, @@ -307,7 +307,7 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("27555b6e51bfdb689457fc076a54153a4f5188f47a17607da75e180d844db527").into(), + hex!("989ebec4920fe4a99edcd3766eee35a31de92dff20427920ae68d15471afba9a").into(), vec![ CheckedExtrinsic { signed: None, diff --git a/demo/service/src/chain_spec.rs b/demo/service/src/chain_spec.rs index 5cabbac58c593..bd232ce1a124c 100644 --- a/demo/service/src/chain_spec.rs +++ b/demo/service/src/chain_spec.rs @@ -61,7 +61,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig { staking: Some(StakingConfig { current_era: 0, intentions: initial_authorities.iter().cloned().map(Into::into).collect(), - early_era_slash: 10000, + offline_slash: 10000, session_reward: 100, validator_count: 12, sessions_per_era: 12, // 1 hour per era @@ -148,7 +148,7 @@ fn testnet_genesis(initial_authorities: Vec) -> GenesisConfig { validator_count: 2, sessions_per_era: 5, bonding_duration: 2 * 60 * 12, - early_era_slash: 0, + offline_slash: 0, session_reward: 0, offline_slash_grace: 0, }), diff --git a/substrate/runtime-support/src/storage/generator.rs b/substrate/runtime-support/src/storage/generator.rs index 90398cdcc7407..7c820cc5ccecf 100644 --- a/substrate/runtime-support/src/storage/generator.rs +++ b/substrate/runtime-support/src/storage/generator.rs @@ -764,12 +764,6 @@ macro_rules! __decl_storage_item { #[doc(hidden)] macro_rules! __decl_store_items { // simple values - ($(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { - __decl_store_item!($name); __decl_store_items!($($t)*); - }; - ($(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { - __decl_store_item!($name); __decl_store_items!($($t)*); - }; ($(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; @@ -782,13 +776,13 @@ macro_rules! __decl_store_items { ($(#[$doc:meta])* pub $name:ident : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - - ($(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + ($(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + ($(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; + ($(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; @@ -801,14 +795,14 @@ macro_rules! __decl_store_items { ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - - // maps - ($(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; + + // maps ($(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; @@ -821,13 +815,13 @@ macro_rules! __decl_store_items { ($(#[$doc:meta])* pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - - ($(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; + ($(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; @@ -840,6 +834,12 @@ macro_rules! __decl_store_items { ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; + ($(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_store_item!($name); __decl_store_items!($($t)*); + }; + ($(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_store_item!($name); __decl_store_items!($($t)*); + }; // exit () => () @@ -855,12 +855,6 @@ macro_rules! __decl_store_item { #[doc(hidden)] macro_rules! __impl_store_fns { // simple values - ($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { - __impl_store_fns!($traitinstance $($t)*); - }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { - __impl_store_fns!($traitinstance $($t)*); - }; ($traitinstance:ident $(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; @@ -873,15 +867,13 @@ macro_rules! __impl_store_fns { ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : required $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - - ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty); + ($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty); + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); @@ -898,14 +890,16 @@ macro_rules! __impl_store_fns { __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); }; - - // maps - ($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty); __impl_store_fns!($traitinstance $($t)*); }; + + // maps ($traitinstance:ident $(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; @@ -918,15 +912,13 @@ macro_rules! __impl_store_fns { ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - - ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); + ($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); @@ -943,6 +935,14 @@ macro_rules! __impl_store_fns { __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); + __impl_store_fns!($traitinstance $($t)*); + }; + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); + __impl_store_fns!($traitinstance $($t)*); + }; // exit ($traitinstance:ident) => () @@ -967,14 +967,6 @@ macro_rules! __impl_store_fn { #[doc(hidden)] macro_rules! __impl_store_items { // simple values - ($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { - __impl_store_item!($name $traitinstance); - __impl_store_items!($traitinstance $($t)*); - }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { - __impl_store_item!($name $traitinstance); - __impl_store_items!($traitinstance $($t)*); - }; ($traitinstance:ident $(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); @@ -991,15 +983,15 @@ macro_rules! __impl_store_items { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - - ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); @@ -1016,16 +1008,16 @@ macro_rules! __impl_store_items { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - - // maps - ($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; + + // maps ($traitinstance:ident $(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); @@ -1042,15 +1034,15 @@ macro_rules! __impl_store_items { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - - ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); @@ -1067,6 +1059,14 @@ macro_rules! __impl_store_items { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; + ($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_item!($name $traitinstance); + __impl_store_items!($traitinstance $($t)*); + }; + ($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_item!($name $traitinstance); + __impl_store_items!($traitinstance $($t)*); + }; // exit ($traitinstance:ident) => () @@ -1095,35 +1095,6 @@ macro_rules! __impl_store_json_metadata { #[macro_export] #[doc(hidden)] macro_rules! __store_functions_to_json { - // simple values - ( - $prefix_str:tt; - $(#[doc = $doc_attr:tt])* - $name:ident : - $ty:ty; $($t:tt)* - ) => { - concat!( - __store_function_to_json!($prefix_str, - __function_doc_to_json!(""; $($doc_attr)*), - $name, __store_type_to_json!($ty) - ), - __store_functions_to_json!(","; $($t)*) - ) - }; - ( - $prefix_str:tt; - $(#[doc = $doc_attr:tt])* - pub $name:ident : - $ty:ty; $($t:tt)* - ) => { - concat!( - __store_function_to_json!($prefix_str, - __function_doc_to_json!(""; $($doc_attr)*), - $name, __store_type_to_json!($ty) - ), - __store_functions_to_json!(","; $($t)*) - ) - }; ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* @@ -1180,11 +1151,11 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; - + // simple values ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - $name:ident get($getfn:ident) : + $name:ident : $ty:ty; $($t:tt)* ) => { concat!( @@ -1198,7 +1169,7 @@ macro_rules! __store_functions_to_json { ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - pub $name:ident get($getfn:ident) : + pub $name:ident : $ty:ty; $($t:tt)* ) => { concat!( @@ -1209,6 +1180,7 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; + ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* @@ -1265,18 +1237,16 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; - - // maps ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - $name:ident : - map [$kty:ty => $ty:ty]; $($t:tt)* + $name:ident get($getfn:ident) : + $ty:ty; $($t:tt)* ) => { concat!( __store_function_to_json!($prefix_str, __function_doc_to_json!(""; $($doc_attr)*), - $name, __store_type_to_json!($kty, $ty) + $name, __store_type_to_json!($ty) ), __store_functions_to_json!(","; $($t)*) ) @@ -1284,17 +1254,19 @@ macro_rules! __store_functions_to_json { ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - pub $name:ident : - map [$kty:ty => $ty:ty]; $($t:tt)* + pub $name:ident get($getfn:ident) : + $ty:ty; $($t:tt)* ) => { concat!( __store_function_to_json!($prefix_str, __function_doc_to_json!(""; $($doc_attr)*), - $name, __store_type_to_json!($kty, $ty) + $name, __store_type_to_json!($ty) ), __store_functions_to_json!(","; $($t)*) ) }; + + // maps ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* @@ -1351,11 +1323,10 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; - ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - $name:ident get($getfn:ident) : + $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)* ) => { concat!( @@ -1369,8 +1340,8 @@ macro_rules! __store_functions_to_json { ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* - pub $name:ident get($getfn:ident) : - map [$kty:ty => $ty:ty]; $($t:tt)* + pub $name:ident : + map [$kty:ty => $ty:ty]; $($t:tt)* ) => { concat!( __store_function_to_json!($prefix_str, @@ -1380,6 +1351,7 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; + ( $prefix_str:tt; $(#[doc = $doc_attr:tt])* $name:ident get($getfn:ident) : @@ -1434,6 +1406,34 @@ macro_rules! __store_functions_to_json { __store_functions_to_json!(","; $($t)*) ) }; + ( + $prefix_str:tt; + $(#[doc = $doc_attr:tt])* + $name:ident get($getfn:ident) : + map [$kty:ty => $ty:ty]; $($t:tt)* + ) => { + concat!( + __store_function_to_json!($prefix_str, + __function_doc_to_json!(""; $($doc_attr)*), + $name, __store_type_to_json!($kty, $ty) + ), + __store_functions_to_json!(","; $($t)*) + ) + }; + ( + $prefix_str:tt; + $(#[doc = $doc_attr:tt])* + pub $name:ident get($getfn:ident) : + map [$kty:ty => $ty:ty]; $($t:tt)* + ) => { + concat!( + __store_function_to_json!($prefix_str, + __function_doc_to_json!(""; $($doc_attr)*), + $name, __store_type_to_json!($kty, $ty) + ), + __store_functions_to_json!(","; $($t)*) + ) + }; ($prefix_str:tt;) => { "" } } @@ -1627,3 +1627,33 @@ mod tests { serde_json::from_str(metadata).expect("Is valid json syntax"); } } + +#[cfg(test)] +// Do not complain about unused `dispatch` and `dispatch_aux`. +#[allow(dead_code)] +mod test2 { + pub trait Trait { + type Origin; + } + + decl_module! { + pub struct Module for enum Call where origin: T::Origin {} + } + + type PairOf = (T, T); + + decl_storage! { + trait Store for Module as TestStorage { + SingleDef : default u32; + PairDef : default PairOf; + Single : u32; + Pair : (u32, u32); + } + } + + struct TraitImpl {} + + impl Trait for TraitImpl { + type Origin = u32; + } +} diff --git a/substrate/runtime/balances/src/genesis_config.rs b/substrate/runtime/balances/src/genesis_config.rs index 677db1aaec20e..30331b24645a8 100644 --- a/substrate/runtime/balances/src/genesis_config.rs +++ b/substrate/runtime/balances/src/genesis_config.rs @@ -58,7 +58,7 @@ impl Default for GenesisConfig { impl primitives::BuildStorage for GenesisConfig { fn build_storage(self) -> ::std::result::Result, Vec>, String> { - let total_stake: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n); + let total_issuance: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n); let mut r: runtime_io::TestExternalities = map![ Self::hash(>::key()).to_vec() => T::AccountIndex::sa(self.balances.len() / ENUM_SET_SIZE).encode(), @@ -68,7 +68,7 @@ impl primitives::BuildStorage for GenesisConfig { Self::hash(>::key()).to_vec() => self.creation_fee.encode(), Self::hash(>::key()).to_vec() => self.existential_deposit.encode(), Self::hash(>::key()).to_vec() => self.reclaim_rebate.encode(), - Self::hash(>::key()).to_vec() => total_stake.encode() + Self::hash(>::key()).to_vec() => total_issuance.encode() ]; let ids: Vec<_> = self.balances.iter().map(|x| x.0.clone()).collect(); diff --git a/substrate/runtime/balances/src/lib.rs b/substrate/runtime/balances/src/lib.rs index d7588289b8898..a35ec3227f220 100644 --- a/substrate/runtime/balances/src/lib.rs +++ b/substrate/runtime/balances/src/lib.rs @@ -93,14 +93,15 @@ impl< } } -/// Trait for a hook to get called when some balance has been minted. -pub trait OnMinted { - /// Some balance `b` was minted. - fn on_minted(b: Balance); +/// Trait for a hook to get called when some balance has been minted, causing dilution. +pub trait OnDilution { + /// Some `portion` of the total balance just "grew" by `minted`. `portion` is the pre-growth + /// amount (it doesn't take account of the recent growth). + fn on_dilution(minted: Balance, portion: Balance); } -impl OnMinted for () { - fn on_minted(_b: Balance) {} +impl OnDilution for () { + fn on_dilution(_minted: Balance, _portion: Balance) {} } /// Determinator for whether a given account is able to transfer balance. @@ -159,7 +160,7 @@ impl From> for () { decl_storage! { trait Store for Module as Balances { /// The total amount of stake on the system. - pub TotalIssuance get(total_stake): required T::Balance; + pub TotalIssuance get(total_issuance): required T::Balance; /// The minimum amount allowed to keep an account open. pub ExistentialDeposit get(existential_deposit): required T::Balance; /// The amount credited to a destination's account whose index was reclaimed. @@ -627,13 +628,13 @@ impl Module { /// Increase TotalIssuance by Value. pub fn increase_total_stake_by(value: T::Balance) { - if let Some(v) = >::total_stake().checked_add(&value) { + if let Some(v) = >::total_issuance().checked_add(&value) { >::put(v); } } /// Decrease TotalIssuance by Value. pub fn decrease_total_stake_by(value: T::Balance) { - if let Some(v) = >::total_stake().checked_sub(&value) { + if let Some(v) = >::total_issuance().checked_sub(&value) { >::put(v); } } diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index ed3faf95b57fd..b9bb2f3802400 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -305,9 +305,9 @@ impl Module { // tally up votes for any expiring referenda. for (index, _, proposal, vote_threshold) in Self::maturing_referendums_at(now) { let (approve, against) = Self::tally(index); - let total_stake = >::total_stake(); + let total_issuance = >::total_issuance(); Self::clear_referendum(index); - if vote_threshold.approved(approve, against, total_stake) { + if vote_threshold.approved(approve, against, total_issuance) { Self::deposit_event(RawEvent::Passed(index)); let ok = proposal.dispatch(system::RawOrigin::Root.into()).is_ok(); Self::deposit_event(RawEvent::Executed(index, ok)); @@ -454,7 +454,7 @@ mod tests { assert_eq!(Democracy::minimum_deposit(), 1); assert_eq!(Democracy::referendum_count(), 0); assert_eq!(Balances::free_balance(&42), 0); - assert_eq!(Balances::total_stake(), 210); + assert_eq!(Balances::total_issuance(), 210); }); } @@ -670,7 +670,7 @@ mod tests { fn passing_low_turnout_voting_should_work() { with_externalities(&mut new_test_ext(), || { assert_eq!(Balances::free_balance(&42), 0); - assert_eq!(Balances::total_stake(), 210); + assert_eq!(Balances::total_issuance(), 210); System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); diff --git a/substrate/runtime/staking/src/genesis_config.rs b/substrate/runtime/staking/src/genesis_config.rs index 7577e125c259d..38be260dfbed1 100644 --- a/substrate/runtime/staking/src/genesis_config.rs +++ b/substrate/runtime/staking/src/genesis_config.rs @@ -26,7 +26,7 @@ use primitives::traits::As; use substrate_primitives::KeccakHasher; use {runtime_io, primitives}; use super::{Trait, Intentions, CurrentEra, OfflineSlashGrace, MinimumValidatorCount, - BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, EarlyEraSlash}; + BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, OfflineSlash}; #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -39,7 +39,7 @@ pub struct GenesisConfig { pub minimum_validator_count: u32, pub bonding_duration: T::BlockNumber, pub session_reward: T::Balance, - pub early_era_slash: T::Balance, + pub offline_slash: T::Balance, pub offline_slash_grace: u32, } @@ -53,7 +53,7 @@ impl Default for GenesisConfig { minimum_validator_count: 0, bonding_duration: T::BlockNumber::sa(1000), session_reward: T::Balance::sa(0), - early_era_slash: T::Balance::sa(0), + offline_slash: T::Balance::sa(0), offline_slash_grace: 0, } } @@ -69,7 +69,7 @@ impl primitives::BuildStorage for GenesisConfig { Self::hash(>::key()).to_vec() => self.bonding_duration.encode(), Self::hash(>::key()).to_vec() => self.current_era.encode(), Self::hash(>::key()).to_vec() => self.session_reward.encode(), - Self::hash(>::key()).to_vec() => self.early_era_slash.encode(), + Self::hash(>::key()).to_vec() => self.offline_slash.encode(), Self::hash(>::key()).to_vec() => self.offline_slash_grace.encode() ]; Ok(r.into()) diff --git a/substrate/runtime/staking/src/lib.rs b/substrate/runtime/staking/src/lib.rs index 9b25ecb4d9c54..6a0d19deefba6 100644 --- a/substrate/runtime/staking/src/lib.rs +++ b/substrate/runtime/staking/src/lib.rs @@ -51,7 +51,7 @@ use runtime_support::dispatch::Result; use session::OnSessionChange; use primitives::traits::{Zero, One, Bounded, OnFinalise, As, Lookup}; -use balances::{address::Address, OnMinted}; +use balances::{address::Address, OnDilution}; use system::{ensure_root, ensure_signed}; mod mock; @@ -98,7 +98,7 @@ impl Default for ValidatorPrefs { pub trait Trait: balances::Trait + session::Trait { /// Some tokens minted. - type OnRewardMinted: OnMinted<::Balance>; + type OnRewardMinted: OnDilution<::Balance>; /// The overarching event type. type Event: From> + Into<::Event>; @@ -137,6 +137,8 @@ impl From> for () { fn from(_: RawEvent) -> () { () } } +pub type PairOf = (T, T); + decl_storage! { trait Store for Module as Staking { @@ -148,8 +150,8 @@ decl_storage! { pub SessionsPerEra get(sessions_per_era): required T::BlockNumber; /// Maximum reward, per validator, that is provided per acceptable session. pub SessionReward get(session_reward): required T::Balance; - /// Slash, per validator that is taken per abnormal era end. - pub EarlyEraSlash get(early_era_slash): required T::Balance; + /// Slash, per validator that is taken for the first time they are found to be offline. + pub OfflineSlash get(offline_slash): required T::Balance; /// Number of instances of offline reports before slashing begins for validators. pub OfflineSlashGrace get(offline_slash_grace): default u32; /// The length of the bonding duration in blocks. @@ -172,8 +174,8 @@ decl_storage! { /// The session index at which the era length last changed. pub LastEraLengthChange get(last_era_length_change): default T::BlockNumber; - /// The current era stake threshold - unused at present. Consider for removal. - pub StakeThreshold get(stake_threshold): required T::Balance; + /// The highest and lowest staked validator slashable balances. + pub StakeRange get(stake_range): default PairOf; /// The block at which the `who`'s funds become entirely liquid. pub Bondage get(bondage): default map [ T::AccountId => T::BlockNumber ]; @@ -446,7 +448,9 @@ impl Module { Self::reward_validator(v, reward); } Self::deposit_event(RawEvent::Reward(reward)); - T::OnRewardMinted::on_minted(reward * >::sa(validators.len())); + let total_minted = reward * >::sa(validators.len()); + let total_rewarded_stake = Self::stake_range().0 * >::sa(validators.len()); + T::OnRewardMinted::on_dilution(total_minted, total_rewarded_stake); } let session_index = >::current_index(); @@ -491,11 +495,13 @@ impl Module { intentions.sort_unstable_by(|&(ref b1, _), &(ref b2, _)| b2.cmp(&b1)); - >::put( + >::put( if !intentions.is_empty() { - let i = (>::get() as usize).min(intentions.len() - 1); - intentions[i].0.clone() - } else { Zero::zero() } + let n = >::get() as usize; + (intentions[0].0, intentions[n - 1].0) + } else { + (Zero::zero(), Zero::zero()) + } ); let vals = &intentions.into_iter() .map(|(_, v)| v) @@ -551,7 +557,7 @@ impl consensus::OnOfflineValidator for Module { let event = if slash_count >= grace { let instances = slash_count - grace; - let slash = Self::early_era_slash() << instances; + let slash = Self::offline_slash() << instances; let next_slash = slash << 1u32; let _ = Self::slash_validator(&v, slash); if instances >= Self::validator_preferences(&v).unstake_threshold diff --git a/substrate/runtime/staking/src/mock.rs b/substrate/runtime/staking/src/mock.rs index d603e372f272e..4fbc64419a8ce 100644 --- a/substrate/runtime/staking/src/mock.rs +++ b/substrate/runtime/staking/src/mock.rs @@ -110,7 +110,7 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64 minimum_validator_count: 0, bonding_duration: sessions_per_era * session_length * 3, session_reward: reward, - early_era_slash: if monied { 20 } else { 0 }, + offline_slash: if monied { 20 } else { 0 }, offline_slash_grace: 0, }.build_storage().unwrap()); t.extend(timestamp::GenesisConfig::{ diff --git a/substrate/runtime/treasury/src/lib.rs b/substrate/runtime/treasury/src/lib.rs index 7d533fa46a5f2..6826782a54c86 100644 --- a/substrate/runtime/treasury/src/lib.rs +++ b/substrate/runtime/treasury/src/lib.rs @@ -45,7 +45,7 @@ use rstd::prelude::*; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; use runtime_primitives::{Permill, traits::{OnFinalise, Zero, EnsureOrigin}}; -use balances::OnMinted; +use balances::OnDilution; use system::{ensure_signed, ensure_root}; /// Our module's configuration trait. All our types and consts go in here. If the @@ -278,9 +278,15 @@ impl Module { } } -impl OnMinted for Module { - fn on_minted(b: T::Balance) { - >::put(Self::pot() + b); +impl OnDilution for Module { + fn on_dilution(minted: T::Balance, portion: T::Balance) { + // Mint extra funds for the treasury to keep the ratio of portion to total_issuance equal + // pre dilution and post-dilution. + if !minted.is_zero() && !portion.is_zero() { + let total_issuance = >::total_issuance(); + let funding = (total_issuance - portion) / portion * minted; + >::mutate(|x| *x += funding); + } } } @@ -377,7 +383,7 @@ mod tests { fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(balances::GenesisConfig::{ - balances: vec![(0, 100), (1, 10), (2, 1)], + balances: vec![(0, 100), (1, 99), (2, 1)], transaction_base_fee: 0, transaction_byte_fee: 0, transfer_fee: 0, @@ -410,7 +416,7 @@ mod tests { fn minting_works() { with_externalities(&mut new_test_ext(), || { // Check that accumulate works when we have Some value in Dummy already. - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_eq!(Treasury::pot(), 100); }); } @@ -443,7 +449,7 @@ mod tests { #[test] fn accepted_spend_proposal_ignored_outside_spend_period() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); @@ -457,7 +463,7 @@ mod tests { #[test] fn unused_pot_should_diminish() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); >::on_finalise(2); assert_eq!(Treasury::pot(), 50); @@ -467,7 +473,7 @@ mod tests { #[test] fn rejected_spend_proposal_ignored_on_spend_period() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); @@ -481,7 +487,7 @@ mod tests { #[test] fn reject_already_rejected_spend_proposal_fails() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); @@ -506,7 +512,7 @@ mod tests { #[test] fn accept_already_rejected_spend_proposal_fails() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0)); @@ -517,7 +523,7 @@ mod tests { #[test] fn accepted_spend_proposal_enacted_on_spend_period() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3)); assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); @@ -531,7 +537,7 @@ mod tests { #[test] fn pot_underflow_should_not_diminish() { with_externalities(&mut new_test_ext(), || { - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3)); assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0)); @@ -539,7 +545,7 @@ mod tests { >::on_finalise(2); assert_eq!(Treasury::pot(), 100); - Treasury::on_minted(100); + Treasury::on_dilution(100, 100); >::on_finalise(4); assert_eq!(Balances::free_balance(&3), 150); assert_eq!(Treasury::pot(), 25);