Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Update substrate master #171

Closed
wants to merge 1 commit into from

Conversation

gterzian
Copy link
Contributor

@gterzian gterzian commented Mar 5, 2019

No description provided.

@gterzian gterzian added the A3-in_progress Pull request is in progress. No review needed at this stage. label Mar 5, 2019
@gterzian gterzian force-pushed the update_to_substrate branch from abf1b60 to e79261e Compare March 5, 2019 12:38
@gterzian
Copy link
Contributor Author

gterzian commented Mar 5, 2019

Couple of questions for a few problems I ran into so far:

@thiolliere How to update in the light of paritytech/substrate@63388a4#diff-c41ce90d658462c61a0814b7279026a6 See https://github.com/paritytech/polkadot/pull/171/files#diff-05be5404b10959d460f8302423f24a49R119

@rphmeier What to go with as ConsensusEngineId? Export GRANDPA_ENGINE_ID?

@gui1117
Copy link
Contributor

gui1117 commented Mar 5, 2019

@thiolliere How to update in the light of paritytech/substrate@63388a4#diff-c41ce90d658462c61a0814b7279026a6 See https://github.com/paritytech/polkadot/pull/171/files#diff-05be5404b10959d460f8302423f24a49R119

@gterzian

Currency introduce a way to use balance module without inheriting from it directly.
The associated type Currency is the module itself. (hmm should it be renamed to something CurrencyModule to be more explicit ? I don't think so, no sure)

Here is the procedure:

  • lower balances::Trait bound to system::Trait
  • then T::Balance doesn't exist so introduce it with a type alias pub type BalanceOf<T> = <<T as Trait>::Currency>::Balance and replace usages.
  • but then Balance associated type in Currency trait lack bounds to Encode/Decode so we have to enforce more bounds to this associated type, this is done with arithmeticType trait this way: type Currency: ArithmeticType + Currency<Self::AccountId, Balance=BalanceOf<Self> (to ensure that this associated type has the correct bounds) >;
    and rewrite BalanceOf to this: type BalanceOf<T> = <<T as Trait>::Currency as ArithmeticType>::Type;

It result to the following diff:

diff --git a/runtime/src/claims.rs b/runtime/src/claims.rs
index 2e47e012..cce86360 100644
--- a/runtime/src/claims.rs
+++ b/runtime/src/claims.rs
@@ -19,18 +19,19 @@
 use rstd::prelude::*;
 use sr_io::{keccak_256, secp256k1_ecdsa_recover};
 use srml_support::{StorageValue, StorageMap};
-use srml_support::traits::Currency;
+use srml_support::traits::{Currency, ArithmeticType};
 use system::ensure_signed;
 use codec::Encode;
 #[cfg(feature = "std")]
 use sr_primitives::traits::Zero;
-use balances;
+
+type BalanceOf<T> = <<T as Trait>::Currency as ArithmeticType>::Type;
 
 /// Configuration trait.
-pub trait Trait: balances::Trait {
+pub trait Trait: system::Trait {
 	/// The overarching event type.
 	type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
-	type Currency: Currency<Self::AccountId>;
+	type Currency: ArithmeticType + Currency<Self::AccountId, Balance=BalanceOf<Self>>;
 }
 
 type EthereumAddress = [u8; 20];
@@ -60,7 +61,7 @@ impl EcdsaSignature {
 /// An event in this module.
 decl_event!(
 	pub enum Event<T> where
-		B = <T as balances::Trait>::Balance,
+		B = BalanceOf<T>,
 		A = <T as system::Trait>::AccountId
 	{
 		/// Someone claimed some DOTs.
@@ -75,13 +76,13 @@ decl_storage! {
 	trait Store for Module<T: Trait> as Claims {
 		Claims get(claims) build(|config: &GenesisConfig<T>| {
 			config.claims.iter().map(|(a, b)| (a.clone(), b.clone())).collect::<Vec<_>>()
-		}): map EthereumAddress => Option<T::Balance>;
+		}): map EthereumAddress => Option<BalanceOf<T>>;
 		Total get(total) build(|config: &GenesisConfig<T>| {
-			config.claims.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n)
-		}): T::Balance;
+			config.claims.iter().fold(Zero::zero(), |acc: BalanceOf<T>, &(_, n)| acc + n)
+		}): BalanceOf<T>;
 	}
 	add_extra_genesis {
-		config(claims): Vec<(EthereumAddress, T::Balance)>;
+		config(claims): Vec<(EthereumAddress, BalanceOf<T>)>;
 	}
 }
 
@@ -133,7 +134,7 @@ decl_module! {
 				*t -= balance_due
 			});
 
-			//T::Currency::increase_free_balance_creating(&sender, balance_due);
+			T::Currency::increase_free_balance_creating(&sender, balance_due);
 
 			// Let's deposit an event to let the outside world know this happened.
 			Self::deposit_event(RawEvent::Claimed(sender, signer, balance_due));

@gterzian
Copy link
Contributor Author

gterzian commented Mar 6, 2019

@thiolliere thanks for the write-up.

@rphmeier do I understand it correctly that you will be doing the udpate? Will that cover everything, including what is discussed above, or will you be focusing on the gossip part?

I mainly wanted to get started on #121

@rphmeier
Copy link
Contributor

rphmeier commented Mar 6, 2019

I have a branch for the gossip part, incomplete though.

@bkchr
Copy link
Member

bkchr commented Mar 6, 2019

Superseded by: #172

@bkchr bkchr closed this Mar 6, 2019
@gterzian gterzian deleted the update_to_substrate branch March 6, 2019 13:57
imstar15 pushed a commit to imstar15/polkadot that referenced this pull request Aug 25, 2021
* Fix block announce

* Fix compilation
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants