Revert "Remove Old Service, 2nd try (#1732)" (#1758)

This reverts commit 96f2615582.
This commit is contained in:
Peter Goodspeed-Niklaus
2020-09-28 12:57:29 +02:00
committed by GitHub
parent 96f2615582
commit 9a0f08bfe1
31 changed files with 3152 additions and 1298 deletions
+28 -8
View File
@@ -25,8 +25,7 @@ use sp_runtime::traits::{Block as BlockT, NumberFor};
/// `N` + `M`, the voter will keep voting for block `N`.
pub(crate) struct PauseAfterBlockFor<N>(pub(crate) N, pub(crate) N);
impl<Block, B> grandpa::VotingRule<Block, B> for PauseAfterBlockFor<NumberFor<Block>>
where
impl<Block, B> grandpa::VotingRule<Block, B> for PauseAfterBlockFor<NumberFor<Block>> where
Block: BlockT,
B: sp_blockchain::HeaderBackend<Block>,
{
@@ -41,7 +40,10 @@ where
use sp_runtime::traits::Header as _;
// walk backwards until we find the target block
let find_target = |target_number: NumberFor<Block>, current_header: &Block::Header| {
let find_target = |
target_number: NumberFor<Block>,
current_header: &Block::Header
| {
let mut target_hash = current_header.hash();
let mut target_header = current_header.clone();
@@ -231,10 +233,10 @@ pub(crate) fn kusama_hard_forks() -> Vec<(
#[cfg(test)]
mod tests {
use grandpa::VotingRule;
use polkadot_test_runtime_client::prelude::*;
use polkadot_test_runtime_client::sp_consensus::BlockOrigin;
use sc_block_builder::BlockBuilderProvider;
use grandpa::VotingRule;
use sp_blockchain::HeaderBackend;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::Header;
@@ -277,12 +279,20 @@ mod tests {
// add 10 blocks
push_blocks(10);
assert_eq!(client.info().best_number, 10);
assert_eq!(
client.info().best_number,
10,
);
// we have not reached the pause block
// therefore nothing should be restricted
assert_eq!(
voting_rule.restrict_vote(&*client, &get_header(0), &get_header(10), &get_header(10)),
voting_rule.restrict_vote(
&*client,
&get_header(0),
&get_header(10),
&get_header(10),
),
None,
);
@@ -293,7 +303,12 @@ mod tests {
// we are targeting the pause block,
// the vote should not be restricted
assert_eq!(
voting_rule.restrict_vote(&*client, &get_header(10), &get_header(20), &get_header(20)),
voting_rule.restrict_vote(
&*client,
&get_header(10),
&get_header(20),
&get_header(20),
),
None,
);
@@ -301,7 +316,12 @@ mod tests {
// be limited to the pause block.
let pause_block = get_header(20);
assert_eq!(
voting_rule.restrict_vote(&*client, &get_header(10), &get_header(21), &get_header(21)),
voting_rule.restrict_vote(
&*client,
&get_header(10),
&get_header(21),
&get_header(21),
),
Some((pause_block.hash(), *pause_block.number())),
);