From d2e928a39fd29db90aaf606fe90a8d67530778f8 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 15 Nov 2018 18:09:03 +0100 Subject: [PATCH] more issues due to core API reshuffle --- substrate/core/finality-grandpa/src/lib.rs | 2 +- substrate/core/finality-grandpa/src/tests.rs | 27 +++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/substrate/core/finality-grandpa/src/lib.rs b/substrate/core/finality-grandpa/src/lib.rs index b4f4f077e2..60f56776da 100644 --- a/substrate/core/finality-grandpa/src/lib.rs +++ b/substrate/core/finality-grandpa/src/lib.rs @@ -490,7 +490,7 @@ impl, B, E, N, RA> grandpa::Chain: BlockNumberOps, { fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result, GrandpaError> { - if base == block { return Err(NotDescendent) } + if base == block { return Err(GrandpaError::NotDescendent) } let tree_route_res = ::client::blockchain::tree_route( self.inner.backend().blockchain(), diff --git a/substrate/core/finality-grandpa/src/tests.rs b/substrate/core/finality-grandpa/src/tests.rs index 1d8c7db7c5..f8ef67f4f7 100644 --- a/substrate/core/finality-grandpa/src/tests.rs +++ b/substrate/core/finality-grandpa/src/tests.rs @@ -181,17 +181,26 @@ impl TestApi { } } -impl ApiClient for TestApi { - fn genesis_authorities(&self) -> Result, ClientError> { - Ok(self.genesis_authorities.clone()) +impl GrandpaApi for TestApi { + fn grandpa_authorities(&self, at: &BlockId) -> Result, ClientError> { + if at == &BlockId::Number(0) { + Ok(self.genesis_authorities.clone()) + } else { + panic!("should generally only request genesis authorities") + } } - fn scheduled_change(&self, header: &::Header) + fn grandpa_pending_change(&self, at: &BlockId, _digest: DigestFor) -> Result>>, ClientError> { + let parent_hash = match at { + &BlockId::Hash(at) => at, + _ => panic!("not requested by block hash!!"), + }; + // we take only scheduled changes at given block number where there are no // extrinsics. - Ok(self.scheduled_changes.lock().get(&header.hash()).map(|c| c.clone())) + Ok(self.scheduled_changes.lock().get(&parent_hash).map(|c| c.clone())) } } @@ -349,8 +358,8 @@ fn transition_3_voters_twice_1_observer() { let api = TestApi::new(genesis_voters); let transitions = api.scheduled_changes.clone(); - let add_transition = move |hash, change| { - transitions.lock().insert(hash, change); + let add_transition = move |parent_hash, change| { + transitions.lock().insert(parent_hash, change); }; let mut net = GrandpaTestNet::new(api, 9); @@ -360,7 +369,7 @@ fn transition_3_voters_twice_1_observer() { net.peer(0).push_blocks(14, false); net.peer(0).generate_blocks(1, BlockOrigin::File, |builder| { let block = builder.bake().unwrap(); - add_transition(block.header.hash(), ScheduledChange { + add_transition(*block.header.parent_hash(), ScheduledChange { next_authorities: make_ids(peers_b), delay: 4, }); @@ -375,7 +384,7 @@ fn transition_3_voters_twice_1_observer() { { net.peer(0).generate_blocks(1, BlockOrigin::File, |builder| { let block = builder.bake().unwrap(); - add_transition(block.header.hash(), ScheduledChange { + add_transition(*block.header.parent_hash(), ScheduledChange { next_authorities: make_ids(peers_c), delay: 0, });