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

Commit f3a830d

Browse files
expensesbkchr
authored andcommitted
Split off System random functions into a new Randomness module (#3699)
* split off system randomness functions into a new module * bump spec and impl version * Move randomness to bottom of construct_runtime calls, move initialization into on_initialize * Update srml/randomness/Cargo.toml Co-Authored-By: Kian Paimani <[email protected]> * Update srml/randomness/src/lib.rs Co-Authored-By: Kian Paimani <[email protected]> * Update srml/randomness/src/lib.rs Co-Authored-By: Bastian Köcher <[email protected]> * Update srml/randomness/Cargo.toml Co-Authored-By: Bastian Köcher <[email protected]> * Improve system example * Update Cargo.lock * Fix randomness example * Get rid of the stored index * Add tests * Add a random test * Improve docs * Fix executive test :^) * Add a utility function to tests * Update srml/randomness/Cargo.toml Co-Authored-By: Gavin Wood <[email protected]> * Update srml/randomness/src/lib.rs Co-Authored-By: Bastian Köcher <[email protected]> * Update srml/randomness/src/lib.rs Co-Authored-By: Bastian Köcher <[email protected]> * Change interpretation of block numbers * rename crate * refactor randomess module usage * change random material len to a const * Update srml/randomness-collective-flip/src/lib.rs Co-Authored-By: Bastian Köcher <[email protected]> * Update srml/randomness-collective-flip/src/lib.rs Co-Authored-By: Bastian Köcher <[email protected]>
1 parent 348d27b commit f3a830d

File tree

12 files changed

+352
-81
lines changed

12 files changed

+352
-81
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ members = [
9595
"srml/membership",
9696
"srml/metadata",
9797
"srml/offences",
98+
"srml/randomness-collective-flip",
9899
"srml/scored-pool",
99100
"srml/session",
100101
"srml/staking",

node-template/runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../
2020
executive = { package = "srml-executive", path = "../../srml/executive", default_features = false }
2121
indices = { package = "srml-indices", path = "../../srml/indices", default_features = false }
2222
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
23+
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../../srml/randomness-collective-flip", default_features = false }
2324
system = { package = "srml-system", path = "../../srml/system", default_features = false }
2425
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default_features = false }
2526
sudo = { package = "srml-sudo", path = "../../srml/sudo", default_features = false }
@@ -46,6 +47,7 @@ std = [
4647
"grandpa/std",
4748
"primitives/std",
4849
"sr-primitives/std",
50+
"randomness-collective-flip/std",
4951
"system/std",
5052
"timestamp/std",
5153
"sudo/std",

node-template/runtime/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ construct_runtime!(
272272
Sudo: sudo,
273273
// Used for the module template in `./template.rs`
274274
TemplateModule: template::{Module, Call, Storage, Event<T>},
275+
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
275276
}
276277
);
277278

@@ -340,7 +341,7 @@ impl_runtime_apis! {
340341
}
341342

342343
fn random_seed() -> <Block as BlockT>::Hash {
343-
System::random_seed()
344+
RandomnessCollectiveFlip::random_seed()
344345
}
345346
}
346347

node/runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ im-online = { package = "srml-im-online", path = "../../srml/im-online", default
4040
indices = { package = "srml-indices", path = "../../srml/indices", default-features = false }
4141
membership = { package = "srml-membership", path = "../../srml/membership", default-features = false }
4242
offences = { package = "srml-offences", path = "../../srml/offences", default-features = false }
43+
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../../srml/randomness-collective-flip", default-features = false }
4344
session = { package = "srml-session", path = "../../srml/session", default-features = false, features = ["historical"] }
4445
staking = { package = "srml-staking", path = "../../srml/staking", default-features = false }
4546
srml-staking-reward-curve = { path = "../../srml/staking/reward-curve"}
@@ -78,6 +79,7 @@ std = [
7879
"offchain-primitives/std",
7980
"offences/std",
8081
"primitives/std",
82+
"randomness-collective-flip/std",
8183
"rstd/std",
8284
"rustc-hex",
8385
"safe-mix/std",

node/runtime/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
8484
// and set impl_version to equal spec_version. If only runtime
8585
// implementation changes and behavior does not, then leave spec_version as
8686
// is and increment impl_version.
87-
spec_version: 172,
88-
impl_version: 172,
87+
spec_version: 173,
88+
impl_version: 173,
8989
apis: RUNTIME_API_VERSIONS,
9090
};
9191

@@ -518,6 +518,7 @@ construct_runtime!(
518518
ImOnline: im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
519519
AuthorityDiscovery: authority_discovery::{Module, Call, Config<T>},
520520
Offences: offences::{Module, Call, Storage, Event},
521+
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
521522
}
522523
);
523524

@@ -589,7 +590,7 @@ impl_runtime_apis! {
589590
}
590591

591592
fn random_seed() -> <Block as BlockT>::Hash {
592-
System::random_seed()
593+
RandomnessCollectiveFlip::random_seed()
593594
}
594595
}
595596

srml/contracts/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ rstd = { package = "sr-std", path = "../../core/sr-std", default-features = fals
1717
sandbox = { package = "sr-sandbox", path = "../../core/sr-sandbox", default-features = false }
1818
support = { package = "srml-support", path = "../support", default-features = false }
1919
system = { package = "srml-system", path = "../system", default-features = false }
20+
randomness-collective-flip = { package = "srml-randomness-collective-flip", path = "../randomness-collective-flip", default-features = false }
21+
timestamp = { package = "srml-timestamp", path = "../timestamp", default-features = false }
2022

2123
[dev-dependencies]
2224
wabt = "0.9.2"
@@ -33,6 +35,7 @@ std = [
3335
"codec/std",
3436
"primitives/std",
3537
"sr-primitives/std",
38+
"randomness-collective-flip/std",
3639
"runtime-io/std",
3740
"rstd/std",
3841
"sandbox/std",

srml/contracts/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ where
753753
}
754754

755755
fn random(&self, subject: &[u8]) -> SeedOf<T> {
756-
system::Module::<T>::random(subject)
756+
randomness_collective_flip::Module::<T>::random(subject)
757757
}
758758

759759
fn now(&self) -> &MomentOf<T> {

srml/executive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ mod tests {
451451
header: Header {
452452
parent_hash: [69u8; 32].into(),
453453
number: 1,
454-
state_root: hex!("3e51b47b6cc8449eece93eee4b01f03b00a0ca7981c0b6c0447b6e0d50ca886d").into(),
454+
state_root: hex!("a6378d7fdd31029d13718d54bdff10a370e75cc624aaf94a90e7e7d4a24e0bcc").into(),
455455
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
456456
digest: Digest { logs: vec![], },
457457
},
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "srml-randomness-collective-flip"
3+
version = "2.0.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
safe-mix = { version = "1.0", default-features = false }
9+
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
10+
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
11+
support = { package = "srml-support", path = "../support", default-features = false }
12+
system = { package = "srml-system", path = "../system", default-features = false }
13+
rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false }
14+
15+
[dev-dependencies]
16+
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
17+
runtime-io = { package = "sr-io", path = "../../core/sr-io" }
18+
19+
[features]
20+
default = ["std"]
21+
std = [
22+
"safe-mix/std",
23+
"system/std",
24+
"codec/std",
25+
"support/std",
26+
"sr-primitives/std",
27+
"rstd/std",
28+
]

0 commit comments

Comments
 (0)