-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Enable download of future forks #10739
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,8 +378,12 @@ fn own_blocks_are_announced() { | |
sp_tracing::try_init_simple(); | ||
let mut net = TestNet::new(3); | ||
net.block_until_sync(); // connect'em | ||
net.peer(0) | ||
.generate_blocks(1, BlockOrigin::Own, |builder| builder.build().unwrap().block); | ||
net.peer(0).generate_blocks( | ||
1, | ||
BlockOrigin::Own, | ||
|builder| builder.build().unwrap().block, | ||
ForkChoiceStrategy::LongestChain, | ||
); | ||
|
||
net.block_until_sync(); | ||
|
||
|
@@ -453,6 +457,38 @@ fn can_sync_small_non_best_forks() { | |
})); | ||
} | ||
|
||
#[test] | ||
fn can_sync_forks_ahead_of_the_best_chain() { | ||
sp_tracing::try_init_simple(); | ||
let mut net = TestNet::new(2); | ||
net.peer(0).push_blocks(1, false); | ||
net.peer(1).push_blocks(1, false); | ||
|
||
net.block_until_connected(); | ||
// Peer 0 is on 2-block fork which is announced with is_best=false | ||
let fork_hash = net.peer(0).generate_blocks( | ||
2, | ||
BlockOrigin::Own, | ||
|builder| builder.build().unwrap().block, | ||
ForkChoiceStrategy::Custom(false), | ||
); | ||
// Peer 1 is on 1-block fork | ||
net.peer(1).push_blocks(1, false); | ||
assert!(net.peer(0).client().header(&BlockId::Hash(fork_hash)).unwrap().is_some()); | ||
assert_eq!(net.peer(0).client().info().best_number, 1); | ||
assert_eq!(net.peer(1).client().info().best_number, 2); | ||
|
||
// after announcing, peer 1 downloads the block. | ||
block_on(futures::future::poll_fn::<(), _>(|cx| { | ||
net.poll(cx); | ||
|
||
if net.peer(1).client().header(&BlockId::Hash(fork_hash)).unwrap().is_none() { | ||
return Poll::Pending | ||
} | ||
Poll::Ready(()) | ||
})); | ||
} | ||
|
||
#[test] | ||
fn can_sync_explicit_forks() { | ||
sp_tracing::try_init_simple(); | ||
|
@@ -678,7 +714,7 @@ impl BlockAnnounceValidator<Block> for FailingBlockAnnounceValidator { | |
#[test] | ||
fn sync_blocks_when_block_announce_validator_says_it_is_new_best() { | ||
sp_tracing::try_init_simple(); | ||
let mut net = TestNet::with_fork_choice(ForkChoiceStrategy::Custom(false)); | ||
let mut net = TestNet::new(0); | ||
net.add_full_peer_with_config(Default::default()); | ||
net.add_full_peer_with_config(Default::default()); | ||
net.add_full_peer_with_config(FullPeerConfig { | ||
|
@@ -688,16 +724,17 @@ fn sync_blocks_when_block_announce_validator_says_it_is_new_best() { | |
|
||
net.block_until_connected(); | ||
|
||
let block_hash = net.peer(0).push_blocks(1, false); | ||
// Add blocks but don't set them as best | ||
let block_hash = net.peer(0).generate_blocks( | ||
1, | ||
BlockOrigin::Own, | ||
|builder| builder.build().unwrap().block, | ||
ForkChoiceStrategy::Custom(false), | ||
); | ||
|
||
while !net.peer(2).has_block(&block_hash) { | ||
net.block_until_idle(); | ||
} | ||
|
||
// Peer1 should not have the block, because peer 0 did not reported the block | ||
// as new best. However, peer2 has a special block announcement validator | ||
// that flags all blocks as `is_new_best` and thus, it should have synced the blocks. | ||
assert!(!net.peer(1).has_block(&block_hash)); | ||
} | ||
|
||
/// Waits for some time until the validation is successfull. | ||
|
@@ -721,7 +758,7 @@ impl BlockAnnounceValidator<Block> for DeferredBlockAnnounceValidator { | |
#[test] | ||
fn wait_until_deferred_block_announce_validation_is_ready() { | ||
sp_tracing::try_init_simple(); | ||
let mut net = TestNet::with_fork_choice(ForkChoiceStrategy::Custom(false)); | ||
let mut net = TestNet::new(0); | ||
net.add_full_peer_with_config(Default::default()); | ||
net.add_full_peer_with_config(FullPeerConfig { | ||
block_announce_validator: Some(Box::new(NewBestBlockAnnounceValidator)), | ||
|
@@ -730,7 +767,13 @@ fn wait_until_deferred_block_announce_validation_is_ready() { | |
|
||
net.block_until_connected(); | ||
|
||
let block_hash = net.peer(0).push_blocks(1, true); | ||
// Add blocks but don't set them as best | ||
let block_hash = net.peer(0).generate_blocks( | ||
1, | ||
BlockOrigin::Own, | ||
|builder| builder.build().unwrap().block, | ||
ForkChoiceStrategy::Custom(false), | ||
); | ||
|
||
while !net.peer(1).has_block(&block_hash) { | ||
net.block_until_idle(); | ||
|
@@ -847,7 +890,10 @@ fn block_announce_data_is_propagated() { | |
// Wait until peer 1 is connected to both nodes. | ||
block_on(futures::future::poll_fn::<(), _>(|cx| { | ||
net.poll(cx); | ||
if net.peer(1).num_peers() == 2 { | ||
if net.peer(1).num_peers() == 2 && | ||
net.peer(0).num_peers() == 1 && | ||
net.peer(2).num_peers() == 1 | ||
Comment on lines
+890
to
+891
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the consequence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aka we don't need it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is unrelated to the fix. Just noticed that a test is racing. Peers register connections asynchronously. So if peers0 considers peer1 to be connected, peer1 might not yet register peer0 as connected and will miss the block announcement that follows. Resulting in occasional test failure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay :) |
||
{ | ||
Poll::Ready(()) | ||
} else { | ||
Poll::Pending | ||
|
@@ -1109,6 +1155,7 @@ fn syncs_indexed_blocks() { | |
false, | ||
true, | ||
true, | ||
ForkChoiceStrategy::LongestChain, | ||
); | ||
let indexed_key = sp_runtime::traits::BlakeTwo256::hash(&42u64.to_le_bytes()); | ||
assert!(net | ||
|
@@ -1178,19 +1225,29 @@ fn syncs_huge_blocks() { | |
let mut net = TestNet::new(2); | ||
|
||
// Increase heap space for bigger blocks. | ||
net.peer(0).generate_blocks(1, BlockOrigin::Own, |mut builder| { | ||
builder.push_storage_change(HEAP_PAGES.to_vec(), Some(256u64.encode())).unwrap(); | ||
builder.build().unwrap().block | ||
}); | ||
net.peer(0).generate_blocks( | ||
1, | ||
BlockOrigin::Own, | ||
|mut builder| { | ||
builder.push_storage_change(HEAP_PAGES.to_vec(), Some(256u64.encode())).unwrap(); | ||
builder.build().unwrap().block | ||
}, | ||
ForkChoiceStrategy::LongestChain, | ||
); | ||
|
||
net.peer(0).generate_blocks(32, BlockOrigin::Own, |mut builder| { | ||
// Add 32 extrinsics 32k each = 1MiB total | ||
for _ in 0..32 { | ||
let ex = Extrinsic::IncludeData([42u8; 32 * 1024].to_vec()); | ||
builder.push(ex).unwrap(); | ||
} | ||
builder.build().unwrap().block | ||
}); | ||
net.peer(0).generate_blocks( | ||
32, | ||
BlockOrigin::Own, | ||
|mut builder| { | ||
// Add 32 extrinsics 32k each = 1MiB total | ||
for _ in 0..32 { | ||
let ex = Extrinsic::IncludeData([42u8; 32 * 1024].to_vec()); | ||
builder.push(ex).unwrap(); | ||
} | ||
builder.build().unwrap().block | ||
}, | ||
ForkChoiceStrategy::LongestChain, | ||
); | ||
|
||
net.block_until_sync(); | ||
assert_eq!(net.peer(0).client.info().best_number, 33); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eskimor let's hope disputes travel & resolve quickly! Haha
Seriously, though, this seems brittle so kind of OK for a dirty patch but we should have a think about doing this 'right' which will involve changes outside of sync about fork-choice.