mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Sync: Fix issue of not freeing a block announcement slot (#8006)
* Sync: Fix issue of not freeing a block announcement slot
There was a bug that when the block announcement validation returned an
error, the slot reserved for this validation wasn't freed. This could
lead to a situation where we rejected any block announcement from such a
peer for that the block announcement returned an error multiple times.
* Better logging
* Fuck I'm dumb
* 🤦
This commit is contained in:
@@ -897,3 +897,41 @@ fn block_announce_data_is_propagated() {
|
||||
net.block_until_idle();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn continue_to_sync_after_some_block_announcement_verifications_failed() {
|
||||
struct TestBlockAnnounceValidator;
|
||||
|
||||
impl BlockAnnounceValidator<Block> for TestBlockAnnounceValidator {
|
||||
fn validate(
|
||||
&mut self,
|
||||
header: &Header,
|
||||
_: &[u8],
|
||||
) -> Pin<Box<dyn Future<Output = Result<Validation, Box<dyn std::error::Error + Send>>> + Send>> {
|
||||
let number = *header.number();
|
||||
async move {
|
||||
if number < 100 {
|
||||
Err(Box::<dyn std::error::Error + Send + Sync>::from(String::from("error")) as Box<_>)
|
||||
} else {
|
||||
Ok(Validation::Success { is_new_best: false })
|
||||
}
|
||||
}.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
sp_tracing::try_init_simple();
|
||||
let mut net = TestNet::new(1);
|
||||
|
||||
net.add_full_peer_with_config(FullPeerConfig {
|
||||
block_announce_validator: Some(Box::new(TestBlockAnnounceValidator)),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
net.block_until_connected();
|
||||
net.block_until_idle();
|
||||
|
||||
let block_hash = net.peer(0).push_blocks(500, true);
|
||||
|
||||
net.block_until_sync();
|
||||
assert!(net.peer(1).has_block(&block_hash));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user