mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 03:17:56 +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
@@ -246,15 +246,16 @@ fn sync_justifications() {
|
||||
net.peer(0).push_blocks(20, false);
|
||||
net.block_until_sync();
|
||||
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&BlockId::Number(10)).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&BlockId::Number(10)).unwrap(), None);
|
||||
|
||||
// we finalize block #10, #15 and #20 for peer 0 with a justification
|
||||
let backend = net.peer(0).client().as_backend();
|
||||
let hashof10 = backend.blockchain().expect_block_hash_from_id(&BlockId::Number(10)).unwrap();
|
||||
let hashof15 = backend.blockchain().expect_block_hash_from_id(&BlockId::Number(15)).unwrap();
|
||||
let hashof20 = backend.blockchain().expect_block_hash_from_id(&BlockId::Number(20)).unwrap();
|
||||
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&hashof10).unwrap(), None);
|
||||
|
||||
// we finalize block #10, #15 and #20 for peer 0 with a justification
|
||||
let just = (*b"FRNK", Vec::new());
|
||||
net.peer(0)
|
||||
.client()
|
||||
@@ -269,25 +270,25 @@ fn sync_justifications() {
|
||||
.finalize_block(&hashof20, Some(just.clone()), true)
|
||||
.unwrap();
|
||||
|
||||
let h1 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap();
|
||||
let h2 = net.peer(1).client().header(&BlockId::Number(15)).unwrap().unwrap();
|
||||
let h3 = net.peer(1).client().header(&BlockId::Number(20)).unwrap().unwrap();
|
||||
let hashof10 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap().hash();
|
||||
let hashof15 = net.peer(1).client().header(&BlockId::Number(15)).unwrap().unwrap().hash();
|
||||
let hashof20 = net.peer(1).client().header(&BlockId::Number(20)).unwrap().unwrap().hash();
|
||||
|
||||
// peer 1 should get the justifications from the network
|
||||
net.peer(1).request_justification(&h1.hash().into(), 10);
|
||||
net.peer(1).request_justification(&h2.hash().into(), 15);
|
||||
net.peer(1).request_justification(&h3.hash().into(), 20);
|
||||
net.peer(1).request_justification(&hashof10, 10);
|
||||
net.peer(1).request_justification(&hashof15, 15);
|
||||
net.peer(1).request_justification(&hashof20, 20);
|
||||
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
|
||||
for height in (10..21).step_by(5) {
|
||||
if net.peer(0).client().justifications(&BlockId::Number(height)).unwrap() !=
|
||||
for hash in [hashof10, hashof15, hashof20] {
|
||||
if net.peer(0).client().justifications(&hash).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
}
|
||||
if net.peer(1).client().justifications(&BlockId::Number(height)).unwrap() !=
|
||||
if net.peer(1).client().justifications(&hash).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
@@ -321,9 +322,9 @@ fn sync_justifications_across_forks() {
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
|
||||
if net.peer(0).client().justifications(&BlockId::Number(10)).unwrap() ==
|
||||
if net.peer(0).client().justifications(&f1_best).unwrap() ==
|
||||
Some(Justifications::from((*b"FRNK", Vec::new()))) &&
|
||||
net.peer(1).client().justifications(&BlockId::Number(10)).unwrap() ==
|
||||
net.peer(1).client().justifications(&f1_best).unwrap() ==
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
Poll::Ready(())
|
||||
@@ -952,14 +953,14 @@ fn multiple_requests_are_accepted_as_long_as_they_are_not_fulfilled() {
|
||||
net.peer(0).push_blocks(10, false);
|
||||
net.block_until_sync();
|
||||
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&BlockId::Number(10)).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&BlockId::Number(10)).unwrap(), None);
|
||||
let hashof10 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap().hash();
|
||||
|
||||
let h1 = net.peer(1).client().header(&BlockId::Number(10)).unwrap().unwrap();
|
||||
// there's currently no justification for block #10
|
||||
assert_eq!(net.peer(0).client().justifications(&hashof10).unwrap(), None);
|
||||
assert_eq!(net.peer(1).client().justifications(&hashof10).unwrap(), None);
|
||||
|
||||
// Let's assume block 10 was finalized, but we still need the justification from the network.
|
||||
net.peer(1).request_justification(&h1.hash().into(), 10);
|
||||
net.peer(1).request_justification(&hashof10, 10);
|
||||
|
||||
// Let's build some more blocks and wait always for the network to have synced them
|
||||
for _ in 0..5 {
|
||||
@@ -987,7 +988,7 @@ fn multiple_requests_are_accepted_as_long_as_they_are_not_fulfilled() {
|
||||
block_on(futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
|
||||
if net.peer(1).client().justifications(&BlockId::Number(10)).unwrap() !=
|
||||
if net.peer(1).client().justifications(&hashof10).unwrap() !=
|
||||
Some(Justifications::from((*b"FRNK", Vec::new())))
|
||||
{
|
||||
return Poll::Pending
|
||||
|
||||
Reference in New Issue
Block a user