Browse Source

substrate upgrade: fix runtime configuration

Mokhtar Naamani 6 years ago
parent
commit
787aaed189
7 changed files with 56 additions and 49 deletions
  1. 3 2
      src/governance/mock.rs
  2. 4 3
      src/governance/mod.rs
  3. 3 1
      src/governance/proposals.rs
  4. 29 29
      src/lib.rs
  5. 3 2
      src/membership/mock.rs
  6. 11 10
      src/roles/actors.rs
  7. 3 2
      src/roles/mock.rs

+ 3 - 2
src/governance/mock.rs

@@ -90,8 +90,9 @@ impl balances::Trait for Test {
     /// Handler for when a new account is created.
     type OnNewAccount = ();
 
-    /// A function that returns true iff a given account can transfer its funds to another account.
-    type EnsureAccountLiquid = ();
+    type TransactionPayment = ();
+	type DustRemoval = ();
+	type TransferPayment = ();
 }
 
 impl GovernanceCurrency for Test {

+ 4 - 3
src/governance/mod.rs

@@ -1,6 +1,6 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 
-use srml_support::traits::{Currency, ArithmeticType};
+use srml_support::traits::{Currency, LockableCurrency};
 use system;
 
 pub mod election;
@@ -11,9 +11,10 @@ mod stake;
 mod sealed_vote;
 
 pub trait GovernanceCurrency: system::Trait + Sized {
-    type Currency: ArithmeticType + Currency<<Self as system::Trait>::AccountId, Balance=BalanceOf<Self>>;
+    type Currency: Currency<Self::AccountId> +
+		LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
 }
 
-pub type BalanceOf<T> = <<T as GovernanceCurrency>::Currency as ArithmeticType>::Type;
+pub type BalanceOf<T> = <<T as GovernanceCurrency>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
 
 mod mock;

+ 3 - 1
src/governance/proposals.rs

@@ -595,8 +595,10 @@ mod tests {
         type Balance = u64;
         type OnFreeBalanceZero = ();
         type OnNewAccount = ();
-        type EnsureAccountLiquid = ();
         type Event = ();
+        type TransactionPayment = ();
+	    type DustRemoval = ();
+	    type TransferPayment = ();
     }
 
     impl timestamp::Trait for Test {

+ 29 - 29
src/lib.rs

@@ -29,10 +29,10 @@ use roles::actors;
 use rstd::prelude::*;
 #[cfg(feature = "std")]
 use primitives::bytes;
-use primitives::{Ed25519AuthorityId, OpaqueMetadata};
+use primitives::{ed25519, OpaqueMetadata};
 use runtime_primitives::{
-	ApplyResult, transaction_validity::TransactionValidity, Ed25519Signature, generic,
-	traits::{self as runtime_traits, Convert, BlakeTwo256, Block as BlockT, StaticLookup}, create_runtime_str
+	ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str,
+	traits::{self as runtime_traits, Convert, BlakeTwo256, Block as BlockT, StaticLookup, Verify},
 };
 use client::{
 	block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
@@ -52,8 +52,17 @@ pub use runtime_primitives::{Permill, Perbill};
 pub use timestamp::BlockPeriod;
 pub use srml_support::{StorageValue, construct_runtime};
 
-/// Alias to Ed25519 pubkey that identifies an account on the chain.
-pub type AccountId = primitives::H256;
+/// The type that is used for identifying authorities.
+pub type AuthorityId = <AuthoritySignature as Verify>::Signer;
+
+/// The type used by authorities to prove their ID.
+pub type AuthoritySignature = ed25519::Signature;
+
+/// Alias to pubkey that identifies an account on the chain.
+pub type AccountId = <AccountSignature as Verify>::Signer;
+
+/// The type used by accounts to prove their ID.
+pub type AccountSignature = ed25519::Signature;
 
 /// A hash of some data used by the chain.
 pub type Hash = primitives::H256;
@@ -81,13 +90,13 @@ pub mod opaque {
 		}
 	}
 	/// Opaque block header type.
-	pub type Header = generic::Header<BlockNumber, BlakeTwo256, generic::DigestItem<Hash, Ed25519AuthorityId>>;
+	pub type Header = generic::Header<BlockNumber, BlakeTwo256, generic::DigestItem<Hash, AuthorityId, AuthoritySignature>>;
 	/// Opaque block type.
 	pub type Block = generic::Block<Header, UncheckedExtrinsic>;
 	/// Opaque block identifier type.
 	pub type BlockId = generic::BlockId<Block>;
 	/// Opaque session key type.
-	pub type SessionKey = Ed25519AuthorityId;
+	pub type SessionKey = AuthorityId;
 }
 
 /// This runtime version.
@@ -140,7 +149,7 @@ impl aura::Trait for Runtime {
 
 impl consensus::Trait for Runtime {
 	/// The identifier we use to refer to authorities.
-	type SessionKey = Ed25519AuthorityId;
+	type SessionKey = AuthorityId;
 	// The aura module handles offline-reports internally
 	// rather than using an explicit report system.
 	type InherentOfflineReport = ();
@@ -148,16 +157,8 @@ impl consensus::Trait for Runtime {
 	type Log = Log;
 }
 
-/// Session key conversion.
-pub struct SessionKeyConversion;
-impl Convert<AccountId, Ed25519AuthorityId> for SessionKeyConversion {
-	fn convert(a: AccountId) -> Ed25519AuthorityId {
-		a.to_fixed_bytes().into()
-	}
-}
-
 impl session::Trait for Runtime {
-	type ConvertAccountIdToSessionKey = SessionKeyConversion;
+	type ConvertAccountIdToSessionKey = ();
 	type OnSessionChange = (Staking, );
 	type Event = Event;
 }
@@ -184,18 +185,15 @@ impl balances::Trait for Runtime {
 	/// The type for recording an account's balance.
 	type Balance = u128;
 	/// What to do if an account's free balance gets zeroed.
-	type OnFreeBalanceZero = Staking;
+	type OnFreeBalanceZero = (Staking, Session);
 	/// What to do if a new account is created.
 	type OnNewAccount = Indices;
-	/// Restrict whether an account can transfer funds. We don't place any further restrictions.
-	type EnsureAccountLiquid = (Staking, Actors);
 	/// The uniquitous event type.
 	type Event = Event;
-}
 
-impl fees::Trait for Runtime {
-	type TransferAsset = Balances;
-	type Event = Event;
+	type TransactionPayment = ();
+	type DustRemoval = ();
+	type TransferPayment = ();
 }
 
 impl sudo::Trait for Runtime {
@@ -206,8 +204,11 @@ impl sudo::Trait for Runtime {
 
 impl staking::Trait for Runtime {
 	type Currency = balances::Module<Self>;
+	//type CurrencyToVote = CurrencyToVoteHandler;
 	type OnRewardMinted = ();
 	type Event = Event;
+	type Slash = ();
+	type Reward = ();
 }
 
 impl governance::GovernanceCurrency for Runtime {
@@ -257,7 +258,7 @@ impl actors::Trait for Runtime {
 }
 
 construct_runtime!(
-	pub enum Runtime with Log(InternalLog: DigestItem<Hash, Ed25519AuthorityId>) where
+	pub enum Runtime with Log(InternalLog: DigestItem<Hash, AuthorityId, AuthoritySignature>) where
 		Block = Block,
 		NodeBlock = opaque::Block,
 		UncheckedExtrinsic = UncheckedExtrinsic
@@ -270,7 +271,6 @@ construct_runtime!(
 		Balances: balances,
 		Session: session,
 		Staking: staking::{default, OfflineWorker},
-		Fees: fees::{Module, Storage, Config<T>, Event<T>},
 		Sudo: sudo,
 		Proposals: proposals::{Module, Call, Storage, Event<T>, Config<T>},
 		CouncilElection: election::{Module, Call, Storage, Event<T>, Config<T>},
@@ -294,11 +294,11 @@ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
 /// BlockId type as expected by this runtime.
 pub type BlockId = generic::BlockId<Block>;
 /// Unchecked extrinsic type as expected by this runtime.
-pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address, Nonce, Call, Ed25519Signature>;
+pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address, Nonce, Call, AccountSignature>;
 /// 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, Fees, AllModules>;
+pub type Executive = executive::Executive<Runtime, Block, Context, Balances, AllModules>;
 
 // Implement our runtime API endpoints. This is just a bunch of proxying.
 impl_runtime_apis! {
@@ -307,7 +307,7 @@ impl_runtime_apis! {
 			VERSION
 		}
 
-		fn authorities() -> Vec<Ed25519AuthorityId> {
+		fn authorities() -> Vec<AuthorityId> {
 			Consensus::authorities()
 		}
 

+ 3 - 2
src/membership/mock.rs

@@ -61,8 +61,9 @@ impl balances::Trait for Test {
     /// Handler for when a new account is created.
     type OnNewAccount = ();
 
-    /// A function that returns true iff a given account can transfer its funds to another account.
-    type EnsureAccountLiquid = ();
+    type TransactionPayment = ();
+	type DustRemoval = ();
+	type TransferPayment = ();
 }
 
 impl GovernanceCurrency for Test {

+ 11 - 10
src/roles/actors.rs

@@ -6,7 +6,7 @@ use rstd::prelude::*;
 use runtime_primitives::traits::{
     As, Bounded, MaybeDebug, Zero,
 };
-use srml_support::traits::{Currency, EnsureAccountLiquid};
+use srml_support::traits::{Currency};
 use srml_support::{
     decl_event, decl_module, decl_storage, dispatch, ensure, StorageMap, StorageValue,
 };
@@ -370,12 +370,13 @@ decl_module! {
     }
 }
 
-impl<T: Trait> EnsureAccountLiquid<T::AccountId> for Module<T> {
-    fn ensure_account_liquid(who: &T::AccountId) -> dispatch::Result {
-        if Self::bondage(who) <= <system::Module<T>>::block_number() {
-            Ok(())
-        } else {
-            Err("cannot transfer illiquid funds")
-        }
-    }
-}
+// TODO: Find how balances module checks account liquidity state
+// impl<T: Trait> EnsureAccountLiquid<T::AccountId> for Module<T> {
+//     fn ensure_account_liquid(who: &T::AccountId) -> dispatch::Result {
+//         if Self::bondage(who) <= <system::Module<T>>::block_number() {
+//             Ok(())
+//         } else {
+//             Err("cannot transfer illiquid funds")
+//         }
+//     }
+// }

+ 3 - 2
src/roles/mock.rs

@@ -61,8 +61,9 @@ impl balances::Trait for Test {
     /// Handler for when a new account is created.
     type OnNewAccount = ();
 
-    /// A function that returns true iff a given account can transfer its funds to another account.
-    type EnsureAccountLiquid = ();
+    type TransactionPayment = ();
+	type DustRemoval = ();
+	type TransferPayment = ();
 }
 
 impl GovernanceCurrency for Test {