mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 20:21:03 +00:00
BlockId removal: refactor: Backend::justifications (#12602)
* BlockId removal: refactor: Backend::justifications It changes the arguments of `Backend::justifications` method from: `BlockId<Block>` to: `&Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * trigger CI job * trigger CI job * bug fix * match -> if Co-authored-by: Adrian Catangiu <adrian@parity.io> Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
committed by
GitHub
parent
8b8675df23
commit
84167bd7d4
@@ -183,10 +183,12 @@ where
|
||||
}
|
||||
},
|
||||
AuthoritySetChangeId::Set(_, last_block_for_set) => {
|
||||
let last_block_for_set_id = BlockId::Number(last_block_for_set);
|
||||
let last_block_for_set_id = backend
|
||||
.blockchain()
|
||||
.expect_block_hash_from_id(&BlockId::Number(last_block_for_set))?;
|
||||
let justification = if let Some(grandpa_justification) = backend
|
||||
.blockchain()
|
||||
.justifications(last_block_for_set_id)?
|
||||
.justifications(&last_block_for_set_id)?
|
||||
.and_then(|justifications| justifications.into_justification(GRANDPA_ENGINE_ID))
|
||||
{
|
||||
grandpa_justification
|
||||
|
||||
@@ -363,9 +363,11 @@ fn finalize_3_voters_no_observers() {
|
||||
runtime.spawn(initialize_grandpa(&mut net, peers));
|
||||
net.peer(0).push_blocks(20, false);
|
||||
net.block_until_sync();
|
||||
let hashof20 = net.peer(0).client().info().best_hash;
|
||||
|
||||
for i in 0..3 {
|
||||
assert_eq!(net.peer(i).client().info().best_number, 20, "Peer #{} failed to sync", i);
|
||||
assert_eq!(net.peer(i).client().info().best_hash, hashof20, "Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
@@ -373,12 +375,7 @@ fn finalize_3_voters_no_observers() {
|
||||
|
||||
// normally there's no justification for finalized blocks
|
||||
assert!(
|
||||
net.lock()
|
||||
.peer(0)
|
||||
.client()
|
||||
.justifications(&BlockId::Number(20))
|
||||
.unwrap()
|
||||
.is_none(),
|
||||
net.lock().peer(0).client().justifications(&hashof20).unwrap().is_none(),
|
||||
"Extra justification for block#1",
|
||||
);
|
||||
}
|
||||
@@ -616,19 +613,15 @@ fn justification_is_generated_periodically() {
|
||||
net.peer(0).push_blocks(32, false);
|
||||
net.block_until_sync();
|
||||
|
||||
let hashof32 = net.peer(0).client().info().best_hash;
|
||||
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
run_to_completion(&mut runtime, 32, net.clone(), peers);
|
||||
|
||||
// when block#32 (justification_period) is finalized, justification
|
||||
// is required => generated
|
||||
for i in 0..3 {
|
||||
assert!(net
|
||||
.lock()
|
||||
.peer(i)
|
||||
.client()
|
||||
.justifications(&BlockId::Number(32))
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(net.lock().peer(i).client().justifications(&hashof32).unwrap().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +641,7 @@ fn sync_justifications_on_change_blocks() {
|
||||
net.peer(0).push_blocks(20, false);
|
||||
|
||||
// at block 21 we do add a transition which is instant
|
||||
net.peer(0).generate_blocks(1, BlockOrigin::File, |builder| {
|
||||
let hashof21 = net.peer(0).generate_blocks(1, BlockOrigin::File, |builder| {
|
||||
let mut block = builder.build().unwrap().block;
|
||||
add_scheduled_change(
|
||||
&mut block,
|
||||
@@ -672,25 +665,12 @@ fn sync_justifications_on_change_blocks() {
|
||||
// the first 3 peers are grandpa voters and therefore have already finalized
|
||||
// block 21 and stored a justification
|
||||
for i in 0..3 {
|
||||
assert!(net
|
||||
.lock()
|
||||
.peer(i)
|
||||
.client()
|
||||
.justifications(&BlockId::Number(21))
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(net.lock().peer(i).client().justifications(&hashof21).unwrap().is_some());
|
||||
}
|
||||
|
||||
// the last peer should get the justification by syncing from other peers
|
||||
futures::executor::block_on(futures::future::poll_fn(move |cx| {
|
||||
if net
|
||||
.lock()
|
||||
.peer(3)
|
||||
.client()
|
||||
.justifications(&BlockId::Number(21))
|
||||
.unwrap()
|
||||
.is_none()
|
||||
{
|
||||
if net.lock().peer(3).client().justifications(&hashof21).unwrap().is_none() {
|
||||
net.lock().poll(cx);
|
||||
Poll::Pending
|
||||
} else {
|
||||
@@ -1686,7 +1666,7 @@ fn imports_justification_for_regular_blocks_on_import() {
|
||||
);
|
||||
|
||||
// the justification should be imported and available from the client
|
||||
assert!(client.justifications(&BlockId::Hash(block_hash)).unwrap().is_some());
|
||||
assert!(client.justifications(&block_hash).unwrap().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -130,7 +130,7 @@ impl<Block: BlockT> WarpSyncProof<Block> {
|
||||
}
|
||||
|
||||
let justification = blockchain
|
||||
.justifications(BlockId::Number(*last_block))?
|
||||
.justifications(&header.hash())?
|
||||
.and_then(|just| just.into_justification(GRANDPA_ENGINE_ID))
|
||||
.expect(
|
||||
"header is last in set and contains standard change signal; \
|
||||
|
||||
Reference in New Issue
Block a user