Unverified Commit 3b54276e authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Update substrate and add some sensible values (#387)

* Update substrate

* Update substrate and some chain spec

* Undo old change

* Use hex ser/de for ethereum addresses

* Add docs.

* Accidental line

* incorrect fix

* Fix build
parent edd87def
Pipeline #49741 passed with stages
in 17 minutes and 53 seconds
This diff is collapsed.
...@@ -54,6 +54,7 @@ tiny-keccak = "1.4.2" ...@@ -54,6 +54,7 @@ tiny-keccak = "1.4.2"
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie-db = "0.15" trie-db = "0.15"
serde_json = "1.0"
[build-dependencies] [build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1" } wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1" }
......
...@@ -23,6 +23,8 @@ use srml_support::traits::{Currency, Get}; ...@@ -23,6 +23,8 @@ use srml_support::traits::{Currency, Get};
use system::ensure_none; use system::ensure_none;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
#[cfg(feature = "std")]
use sr_primitives::traits::Zero; use sr_primitives::traits::Zero;
use sr_primitives::{ use sr_primitives::{
weights::SimpleDispatchInfo, weights::SimpleDispatchInfo,
...@@ -41,7 +43,37 @@ pub trait Trait: system::Trait { ...@@ -41,7 +43,37 @@ pub trait Trait: system::Trait {
type Prefix: Get<&'static [u8]>; type Prefix: Get<&'static [u8]>;
} }
type EthereumAddress = [u8; 20]; /// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account).
///
/// This gets serialized to the 0x-prefixed hex representation.
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct EthereumAddress([u8; 20]);
#[cfg(feature = "std")]
impl Serialize for EthereumAddress {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
let hex: String = rustc_hex::ToHex::to_hex(&self.0[..]);
serializer.serialize_str(&format!("0x{}", hex))
}
}
#[cfg(feature = "std")]
impl<'de> Deserialize<'de> for EthereumAddress {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
let base_string = String::deserialize(deserializer)?;
let offset = if base_string.starts_with("0x") { 2 } else { 0 };
let s = &base_string[offset..];
if s.len() != 40 {
Err(serde::de::Error::custom("Bad length of Ethereum address (should be 42 including '0x')"))?;
}
let raw: Vec<u8> = rustc_hex::FromHex::from_hex(s)
.map_err(|e| serde::de::Error::custom(format!("{:?}", e)))?;
let mut r = Self::default();
r.0.copy_from_slice(&raw);
Ok(r)
}
}
#[derive(Encode, Decode, Clone)] #[derive(Encode, Decode, Clone)]
pub struct EcdsaSignature(pub [u8; 65]); pub struct EcdsaSignature(pub [u8; 65]);
...@@ -154,7 +186,7 @@ impl<T: Trait> Module<T> { ...@@ -154,7 +186,7 @@ impl<T: Trait> Module<T> {
fn eth_recover(s: &EcdsaSignature, what: &[u8]) -> Option<EthereumAddress> { fn eth_recover(s: &EcdsaSignature, what: &[u8]) -> Option<EthereumAddress> {
let msg = keccak_256(&Self::ethereum_signable_message(what)); let msg = keccak_256(&Self::ethereum_signable_message(what));
let mut res = EthereumAddress::default(); let mut res = EthereumAddress::default();
res.copy_from_slice(&keccak_256(&secp256k1_ecdsa_recover(&s.0, &msg).ok()?[..])[12..]); res.0.copy_from_slice(&keccak_256(&secp256k1_ecdsa_recover(&s.0, &msg).ok()?[..])[12..]);
Some(res) Some(res)
} }
} }
...@@ -290,7 +322,7 @@ mod tests { ...@@ -290,7 +322,7 @@ mod tests {
} }
fn alice_eth() -> EthereumAddress { fn alice_eth() -> EthereumAddress {
let mut res = EthereumAddress::default(); let mut res = EthereumAddress::default();
res.copy_from_slice(&keccak256(&alice_public().serialize()[1..65])[12..]); res.0.copy_from_slice(&keccak256(&alice_public().serialize()[1..65])[12..]);
res res
} }
fn alice_sig(what: &[u8]) -> EcdsaSignature { fn alice_sig(what: &[u8]) -> EcdsaSignature {
...@@ -330,10 +362,19 @@ mod tests { ...@@ -330,10 +362,19 @@ mod tests {
with_externalities(&mut new_test_ext(), || { with_externalities(&mut new_test_ext(), || {
assert_eq!(Claims::total(), 100); assert_eq!(Claims::total(), 100);
assert_eq!(Claims::claims(&alice_eth()), Some(100)); assert_eq!(Claims::claims(&alice_eth()), Some(100));
assert_eq!(Claims::claims(&[0; 20]), None); assert_eq!(Claims::claims(&Default::default()), None);
}); });
} }
#[test]
fn serde_works() {
let x = EthereumAddress(hex!["0123456789abcdef0123456789abcdef01234567"]);
let y = serde_json::to_string(&x).unwrap();
assert_eq!(y, "\"0x0123456789abcdef0123456789abcdef01234567\"");
let z: EthereumAddress = serde_json::from_str(&y).unwrap();
assert_eq!(x, z);
}
#[test] #[test]
fn claiming_works() { fn claiming_works() {
with_externalities(&mut new_test_ext(), || { with_externalities(&mut new_test_ext(), || {
...@@ -385,7 +426,7 @@ mod tests { ...@@ -385,7 +426,7 @@ mod tests {
let sig = EcdsaSignature(sig); let sig = EcdsaSignature(sig);
let who = 42u64.using_encoded(to_ascii_hex); let who = 42u64.using_encoded(to_ascii_hex);
let signer = Claims::eth_recover(&sig, &who).unwrap(); let signer = Claims::eth_recover(&sig, &who).unwrap();
assert_eq!(signer, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]); assert_eq!(signer.0, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]);
}); });
} }
......
...@@ -394,8 +394,8 @@ parameter_types! { ...@@ -394,8 +394,8 @@ parameter_types! {
impl treasury::Trait for Runtime { impl treasury::Trait for Runtime {
type Currency = Balances; type Currency = Balances;
type ApproveOrigin = collective::EnsureMembers<_4, AccountId, CouncilCollective>; type ApproveOrigin = collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
type RejectOrigin = collective::EnsureMembers<_2, AccountId, CouncilCollective>; type RejectOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type Event = Event; type Event = Event;
type MintedForSpending = (); type MintedForSpending = ();
type ProposalRejection = (); type ProposalRejection = ();
......
...@@ -120,7 +120,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig { ...@@ -120,7 +120,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
}), }),
staking: Some(StakingConfig { staking: Some(StakingConfig {
current_era: 0, current_era: 0,
validator_count: 7, validator_count: 50,
minimum_validator_count: 4, minimum_validator_count: 4,
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(), stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
...@@ -140,8 +140,8 @@ fn staging_testnet_config_genesis() -> GenesisConfig { ...@@ -140,8 +140,8 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
elections: Some(ElectionsConfig { elections: Some(ElectionsConfig {
members: vec![], members: vec![],
presentation_duration: 1 * DAYS, presentation_duration: 1 * DAYS,
term_duration: 28 * DAYS, term_duration: 49 * DAYS,
desired_seats: 0, desired_seats: 7,
}), }),
membership_Instance1: Some(Default::default()), membership_Instance1: Some(Default::default()),
babe: Some(Default::default()), babe: Some(Default::default()),
...@@ -276,8 +276,8 @@ pub fn testnet_genesis( ...@@ -276,8 +276,8 @@ pub fn testnet_genesis(
.find(|&(_, controller, _, _, _, _)| controller == endowed) .find(|&(_, controller, _, _, _, _)| controller == endowed)
.is_none() .is_none()
).map(|a| (a.clone(), 1000000)).collect(), ).map(|a| (a.clone(), 1000000)).collect(),
presentation_duration: 10, presentation_duration: 10 * MINUTES,
term_duration: 1000000, term_duration: 1 * DAYS,
desired_seats, desired_seats,
}), }),
membership_Instance1: Some(Default::default()), membership_Instance1: Some(Default::default()),
......
...@@ -407,5 +407,6 @@ service::construct_service_factory! { ...@@ -407,5 +407,6 @@ service::construct_service_factory! {
FinalityProofProvider = { |client: Arc<FullClient<Self>>| { FinalityProofProvider = { |client: Arc<FullClient<Self>>| {
Ok(Some(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _)) Ok(Some(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _))
}}, }},
RpcExtensions = (),
} }
} }
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