more clear randomness API for BABE (#8180)

* more clear randomness API for BABE

* babe: move randomness utilities to its own file

* node: use babe::RandomnessFromOneEpochAgo in random_seed implementation

* frame-support: annotate randomness trait with block number

* pallet-randomness-collective-flip: fix for new randomness trait

* pallet-society: fix randomness usage

* pallet-lottery: fix randomness usage

* pallet-contracts: fix randomness usage

* pallet-babe: fix randomness usage

we need to track when the current and previous epoch started so that we
know the block number by each existing on-chain was known

* node: fix random_seed

* node-template: fix random_seed

* frame-support: extend docs

* babe: add test for epoch starting block number tracking

* babe: fix epoch randomness docs

* frame: add todos for dealing with randomness api changes

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Robert Habermeier
2021-03-10 10:31:49 -06:00
committed by GitHub
parent f3d4355a20
commit e2960c383e
18 changed files with 286 additions and 78 deletions
+25
View File
@@ -349,6 +349,31 @@ fn can_fetch_current_and_next_epoch_data() {
});
}
#[test]
fn tracks_block_numbers_when_current_and_previous_epoch_started() {
new_test_ext(5).execute_with(|| {
// an epoch is 3 slots therefore at block 8 we should be in epoch #3
// with the previous epochs having the following blocks:
// epoch 1 - [1, 2, 3]
// epoch 2 - [4, 5, 6]
// epoch 3 - [7, 8, 9]
progress_to_block(8);
let (last_epoch, current_epoch) = EpochStart::<Test>::get();
assert_eq!(last_epoch, 4);
assert_eq!(current_epoch, 7);
// once we reach block 10 we switch to epoch #4
progress_to_block(10);
let (last_epoch, current_epoch) = EpochStart::<Test>::get();
assert_eq!(last_epoch, 7);
assert_eq!(current_epoch, 10);
});
}
#[test]
fn report_equivocation_current_session_works() {
let (pairs, mut ext) = new_test_ext_with_pairs(3);