mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
Default block announce validation should reject additional data (#7726)
If we are using the default block announce validator and receive additional data alongside the block announcement, we should disconnect this peer.
This commit is contained in:
@@ -1148,7 +1148,11 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
self.update_peer_info(&who);
|
||||
(header, is_best, who)
|
||||
}
|
||||
sync::PollBlockAnnounceValidation::Failure { who } => {
|
||||
sync::PollBlockAnnounceValidation::Failure { who, disconnect } => {
|
||||
if disconnect {
|
||||
self.disconnect_peer(&who);
|
||||
}
|
||||
|
||||
self.report_peer(who, rep::BAD_BLOCK_ANNOUNCEMENT);
|
||||
return CustomMessageOutcome::None
|
||||
}
|
||||
|
||||
@@ -324,6 +324,8 @@ pub enum PollBlockAnnounceValidation<H> {
|
||||
Failure {
|
||||
/// Who sent the processed block announcement?
|
||||
who: PeerId,
|
||||
/// Should the peer be disconnected?
|
||||
disconnect: bool,
|
||||
},
|
||||
/// The announcement does not require further handling.
|
||||
Nothing {
|
||||
@@ -354,6 +356,8 @@ enum PreValidateBlockAnnounce<H> {
|
||||
Failure {
|
||||
/// Who sent the processed block announcement?
|
||||
who: PeerId,
|
||||
/// Should the peer be disconnected?
|
||||
disconnect: bool,
|
||||
},
|
||||
/// The announcement does not require further handling.
|
||||
Nothing {
|
||||
@@ -1215,14 +1219,14 @@ impl<B: BlockT> ChainSync<B> {
|
||||
announce,
|
||||
who,
|
||||
},
|
||||
Ok(Validation::Failure) => {
|
||||
Ok(Validation::Failure { disconnect }) => {
|
||||
debug!(
|
||||
target: "sync",
|
||||
"Block announcement validation of block {} from {} failed",
|
||||
hash,
|
||||
who,
|
||||
);
|
||||
PreValidateBlockAnnounce::Failure { who }
|
||||
PreValidateBlockAnnounce::Failure { who, disconnect }
|
||||
}
|
||||
Err(e) => {
|
||||
error!(target: "sync", "💔 Block announcement validation errored: {}", e);
|
||||
@@ -1280,9 +1284,9 @@ impl<B: BlockT> ChainSync<B> {
|
||||
self.peer_block_announce_validation_finished(&who);
|
||||
return PollBlockAnnounceValidation::Nothing { is_best, who, header: announce.header }
|
||||
},
|
||||
PreValidateBlockAnnounce::Failure { who } => {
|
||||
PreValidateBlockAnnounce::Failure { who, disconnect } => {
|
||||
self.peer_block_announce_validation_finished(&who);
|
||||
return PollBlockAnnounceValidation::Failure { who }
|
||||
return PollBlockAnnounceValidation::Failure { who, disconnect }
|
||||
},
|
||||
PreValidateBlockAnnounce::Process { announce, is_new_best, who } => {
|
||||
self.peer_block_announce_validation_finished(&who);
|
||||
|
||||
@@ -42,7 +42,12 @@ pub enum Validation {
|
||||
is_new_best: bool,
|
||||
},
|
||||
/// Invalid block announcement.
|
||||
Failure,
|
||||
Failure {
|
||||
/// Should we disconnect from this peer?
|
||||
///
|
||||
/// This should be used if the peer for example send junk to spam us.
|
||||
disconnect: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Type which checks incoming block announcements.
|
||||
@@ -68,8 +73,20 @@ impl<B: Block> BlockAnnounceValidator<B> for DefaultBlockAnnounceValidator {
|
||||
fn validate(
|
||||
&mut self,
|
||||
_: &B::Header,
|
||||
_: &[u8],
|
||||
data: &[u8],
|
||||
) -> Pin<Box<dyn Future<Output = Result<Validation, Box<dyn Error + Send>>> + Send>> {
|
||||
async { Ok(Validation::Success { is_new_best: false }) }.boxed()
|
||||
let is_empty = data.is_empty();
|
||||
|
||||
async move {
|
||||
if !is_empty {
|
||||
log::debug!(
|
||||
target: "sync",
|
||||
"Received unknown data alongside the block announcement.",
|
||||
);
|
||||
Ok(Validation::Failure { disconnect: true })
|
||||
} else {
|
||||
Ok(Validation::Success { is_new_best: false })
|
||||
}
|
||||
}.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user