Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3bb7bb1
Clean up session key rotation
gavofyork Mar 2, 2019
5888bcc
Fix build
gavofyork Mar 3, 2019
872270b
Bump version
gavofyork Mar 3, 2019
854fb05
Introduce feature to balances.
gavofyork Mar 3, 2019
f384e2e
Move staking locking logic over to central point
gavofyork Mar 4, 2019
1b16151
^^^ rest
gavofyork Mar 4, 2019
974c21e
Merge branch 'master' into gav-central-locking
gavofyork Mar 4, 2019
896ead7
First part of assimilation
gavofyork Mar 4, 2019
58c4fd7
More assimilation
gavofyork Mar 4, 2019
3f7f5f3
More assimilation
gavofyork Mar 4, 2019
404f04a
Fix most tests
gavofyork Mar 4, 2019
fb8181c
Fix build
gavofyork Mar 4, 2019
79c92a5
Move Balances to new locking system
gavofyork Mar 4, 2019
8ce86c8
:q!
gavofyork Mar 4, 2019
3d22b37
Bump runtime version
gavofyork Mar 4, 2019
a8e5342
Build runtime
gavofyork Mar 4, 2019
7f0ffeb
Convenience function
gavofyork Mar 4, 2019
8acad46
Test fix.
gavofyork Mar 4, 2019
64c642b
Whitespace
gavofyork Mar 4, 2019
b7c9470
Merge remote-tracking branch 'origin/master' into gav-central-locking
gavofyork Mar 5, 2019
93877f2
Improve type legibility.
gavofyork Mar 5, 2019
7bc8185
Fix comment.
gavofyork Mar 5, 2019
aca555a
More tests.
gavofyork Mar 5, 2019
0fc7a98
More tests.
gavofyork Mar 5, 2019
17390ca
devops-parity updated wasm runtime blobs 39ac5376 and merged in maste…
devops-parity Mar 5, 2019
2429e06
Merge remote-tracking branch 'origin/master' into gav-central-locking
gavofyork Mar 5, 2019
dd1bc3b
Merge branch 'gav-central-locking' of github.com:paritytech/substrate…
gavofyork Mar 5, 2019
b7e49fe
Bump version
gavofyork Mar 6, 2019
d949f94
Caps
gavofyork Mar 6, 2019
3ea4771
Whitespace
gavofyork Mar 6, 2019
e1fd0a4
Whitespace
gavofyork Mar 6, 2019
60715ba
Remove unneeded function.
gavofyork Mar 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/executor/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
parity-codec = { version = "3.1", default-features = false, features = ["derive"] }
rustc-hex = { version = "2.0", default-features = false }
serde = { version = "1.0", default-features = false }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
twox-hash = { version = "1.1.0", optional = true }
byteorder = { version = "1.1", default-features = false }
Expand Down Expand Up @@ -46,7 +46,7 @@ std = [
"hash256-std-hasher/std",
"hash-db/std",
"rstd/std",
"serde/std",
"serde",
"rustc-hex/std",
"twox-hash",
"blake2-rfc",
Expand Down
2 changes: 1 addition & 1 deletion core/serializer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
serde = { version = "1.0", default-features = false }
serde = "1.0"
serde_json = "1.0"
39 changes: 30 additions & 9 deletions core/sr-io/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@
#[doc(hidden)]
pub use parity_codec as codec;
// re-export hashing functions.
pub use primitives::{blake2_256, twox_128, twox_256, ed25519, Blake2Hasher, sr25519};
pub use primitives::{
blake2_256, twox_128, twox_256, ed25519, Blake2Hasher, sr25519
};
pub use tiny_keccak::keccak256 as keccak_256;
// Switch to this after PoC-3
// pub use primitives::BlakeHasher;
pub use substrate_state_machine::{Externalities, TestExternalities};
pub use substrate_state_machine::{Externalities, BasicExternalities, TestExternalities};

use environmental::{environmental, thread_local_impl};
use primitives::hexdisplay::HexDisplay;
use primitives::H256;
use primitives::{hexdisplay::HexDisplay, H256};
use hash_db::Hasher;

#[cfg(feature = "std")]
use std::collections::HashMap;

environmental!(ext: trait Externalities<Blake2Hasher>);

/// A set of key value pairs for storage.
pub type StorageOverlay = HashMap<Vec<u8>, Vec<u8>>;

/// A set of key value pairs for children storage;
pub type ChildrenStorageOverlay = HashMap<Vec<u8>, StorageOverlay>;

/// Get `key` from storage and return a `Vec`, empty if there's a problem.
pub fn storage(key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext| ext.storage(key).map(|s| s.to_vec()))
Expand Down Expand Up @@ -196,7 +206,7 @@ pub fn sr25519_verify<P: AsRef<[u8]>>(sig: &[u8; 64], msg: &[u8], pubkey: P) ->

/// Verify and recover a SECP256k1 ECDSA signature.
/// - `sig` is passed in RSV format. V should be either 0/1 or 27/28.
/// - returns `Err` if the signatue is bad, otherwise the 64-byte pubkey (doesn't include the 0x04 prefix).
/// - returns `Err` if the signature is bad, otherwise the 64-byte pubkey (doesn't include the 0x04 prefix).
pub fn secp256k1_ecdsa_recover(sig: &[u8; 65], msg: &[u8; 32]) -> Result<[u8; 64], EcdsaVerifyError> {
let rs = secp256k1::Signature::parse_slice(&sig[0..64]).map_err(|_| EcdsaVerifyError::BadRS)?;
let v = secp256k1::RecoveryId::parse(if sig[64] > 26 { sig[64] - 27 } else { sig[64] } as u8).map_err(|_| EcdsaVerifyError::BadV)?;
Expand All @@ -213,6 +223,17 @@ pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities<Blake2Has
ext::using(ext, f)
}

/// Execute the given closure with global functions available whose functionality routes into
/// externalities that draw from and populate `storage`. Forwards the value that the closure returns.
pub fn with_storage<R, F: FnOnce() -> R>(storage: &mut StorageOverlay, f: F) -> R {
let mut alt_storage = Default::default();
rstd::mem::swap(&mut alt_storage, storage);
let mut ext: BasicExternalities = alt_storage.into();
let r = ext::using(&mut ext, f);
*storage = ext.into();
r
}

/// Trait for things which can be printed.
pub trait Printable {
fn print(self);
Expand Down Expand Up @@ -248,7 +269,7 @@ mod std_tests {

#[test]
fn storage_works() {
let mut t = TestExternalities::<Blake2Hasher>::default();
let mut t = BasicExternalities::default();
assert!(with_externalities(&mut t, || {
assert_eq!(storage(b"hello"), None);
set_storage(b"hello", b"world");
Expand All @@ -258,7 +279,7 @@ mod std_tests {
true
}));

t = TestExternalities::new(map![b"foo".to_vec() => b"bar".to_vec()]);
t = BasicExternalities::new(map![b"foo".to_vec() => b"bar".to_vec()]);

assert!(!with_externalities(&mut t, || {
assert_eq!(storage(b"hello"), None);
Expand All @@ -269,7 +290,7 @@ mod std_tests {

#[test]
fn read_storage_works() {
let mut t = TestExternalities::<Blake2Hasher>::new(map![
let mut t = BasicExternalities::new(map![
b":test".to_vec() => b"\x0b\0\0\0Hello world".to_vec()
]);

Expand All @@ -285,7 +306,7 @@ mod std_tests {

#[test]
fn clear_prefix_works() {
let mut t = TestExternalities::<Blake2Hasher>::new(map![
let mut t = BasicExternalities::new(map![
b":a".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
b":abcd".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
b":abc".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion core/sr-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ parity-codec = { version = "3.1", default-features = false, features = ["derive"
substrate-primitives = { path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
log = {version = "0.4", optional = true }
log = { version = "0.4", optional = true }

[dev-dependencies]
serde_json = "1.0"
Expand Down
40 changes: 29 additions & 11 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use parity_codec as codec;
pub use serde_derive;

#[cfg(feature = "std")]
use std::collections::HashMap;
pub use runtime_io::{StorageOverlay, ChildrenStorageOverlay};

use rstd::prelude::*;
use substrate_primitives::hash::{H256, H512};
Expand Down Expand Up @@ -87,17 +87,9 @@ pub use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};

/// A set of key value pairs for storage.
#[cfg(feature = "std")]
pub type StorageOverlay = HashMap<Vec<u8>, Vec<u8>>;

/// A set of key value pairs for children storage;
#[cfg(feature = "std")]
pub type ChildrenStorageOverlay = HashMap<Vec<u8>, StorageOverlay>;

/// Complex storage builder stuff.
#[cfg(feature = "std")]
pub trait BuildStorage {
pub trait BuildStorage: Sized {
/// Hash given slice.
///
/// Default to xx128 hashing.
Expand All @@ -107,14 +99,32 @@ pub trait BuildStorage {
r
}
/// Build the storage out of this builder.
fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String>;
fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
let mut storage = Default::default();
let mut child_storage = Default::default();
self.assimilate_storage(&mut storage, &mut child_storage)?;
Ok((storage, child_storage))
}
/// Assimilate the storage for this module into pre-existing overlays.
fn assimilate_storage(self, storage: &mut StorageOverlay, child_storage: &mut ChildrenStorageOverlay) -> Result<(), String> {
let (s, cs) = self.build_storage()?;
storage.extend(s);
for (other_child_key, other_child_map) in cs {
child_storage.entry(other_child_key).or_default().extend(other_child_map);
}
Ok(())
}
}

#[cfg(feature = "std")]
impl BuildStorage for StorageOverlay {
fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
Ok((self, Default::default()))
}
fn assimilate_storage(self, storage: &mut StorageOverlay, _child_storage: &mut ChildrenStorageOverlay) -> Result<(), String> {
storage.extend(self);
Ok(())
}
}

/// Permill is parts-per-million (i.e. after multiplying by this, divide by 1000000).
Expand Down Expand Up @@ -411,6 +421,14 @@ macro_rules! impl_outer_config {
}
#[cfg(any(feature = "std", test))]
impl $crate::BuildStorage for $main {
fn assimilate_storage(self, top: &mut $crate::StorageOverlay, children: &mut $crate::ChildrenStorageOverlay) -> ::std::result::Result<(), String> {
$(
if let Some(extra) = self.$snake {
extra.assimilate_storage(top, children)?;
}
)*
Ok(())
}
fn build_storage(self) -> ::std::result::Result<($crate::StorageOverlay, $crate::ChildrenStorageOverlay), String> {
let mut top = $crate::StorageOverlay::new();
let mut children = $crate::ChildrenStorageOverlay::new();
Expand Down
17 changes: 12 additions & 5 deletions core/sr-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use runtime_io;
#[cfg(feature = "std")] use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};
use substrate_primitives;
use substrate_primitives::Blake2Hasher;
use substrate_primitives::{self, Hasher, Blake2Hasher};
use crate::codec::{Codec, Encode, HasCompact};
pub use integer_sqrt::IntegerSquareRoot;
pub use num_traits::{
Expand Down Expand Up @@ -84,6 +83,8 @@ pub trait StaticLookup {
type Target;
/// Attempt a lookup.
fn lookup(s: Self::Source) -> result::Result<Self::Target, &'static str>;
/// Convert from Target back to Source.
fn unlookup(t: Self::Target) -> Self::Source;
}

/// A lookup implementation returning the input value.
Expand All @@ -93,6 +94,7 @@ impl<T: Codec + Clone + PartialEq + MaybeDebug> StaticLookup for IdentityLookup<
type Source = T;
type Target = T;
fn lookup(x: T) -> result::Result<T, &'static str> { Ok(x) }
fn unlookup(x: T) -> T { x }
}
impl<T> Lookup for IdentityLookup<T> {
type Source = T;
Expand Down Expand Up @@ -184,7 +186,7 @@ pub trait SimpleArithmetic:
CheckedMul +
CheckedDiv +
Saturating +
PartialOrd<Self> + Ord +
PartialOrd<Self> + Ord + Bounded +
HasCompact
{}
impl<T:
Expand All @@ -202,7 +204,7 @@ impl<T:
CheckedMul +
CheckedDiv +
Saturating +
PartialOrd<Self> + Ord +
PartialOrd<Self> + Ord + Bounded +
HasCompact
> SimpleArithmetic for T {}

Expand Down Expand Up @@ -298,7 +300,10 @@ tuple_impl!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W,
pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // Stupid bug in the Rust compiler believes derived
// traits must be fulfilled by all type parameters.
/// The hash type produced.
type Output: Member + MaybeSerializeDebug + AsRef<[u8]> + AsMut<[u8]>;
type Output: Member + MaybeSerializeDebug + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]> + Copy + Default;

/// The associated hash_db Hasher type.
type Hasher: Hasher<Out=Self::Output>;

/// Produce the hash of some byte-slice.
fn hash(s: &[u8]) -> Self::Output;
Expand Down Expand Up @@ -338,6 +343,7 @@ pub struct BlakeTwo256;

impl Hash for BlakeTwo256 {
type Output = substrate_primitives::H256;
type Hasher = Blake2Hasher;
fn hash(s: &[u8]) -> Self::Output {
runtime_io::blake2_256(s).into()
}
Expand Down Expand Up @@ -480,6 +486,7 @@ pub trait MaybeHash {}
#[cfg(not(feature = "std"))]
impl<T> MaybeHash for T {}


/// A type that can be used in runtime structures.
pub trait Member: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static {}
impl<T: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static> Member for T {}
Expand Down
4 changes: 2 additions & 2 deletions core/sr-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
impl-serde = { version = "0.1", optional = true }
serde = { version = "1.0", default-features = false }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
parity-codec = { version = "3.1", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
Expand All @@ -16,7 +16,7 @@ runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", def
default = ["std"]
std = [
"impl-serde",
"serde/std",
"serde",
"serde_derive",
"parity-codec/std",
"rstd/std",
Expand Down
Loading