Skip to content

Commit

Permalink
Remove banning system from warp_sync.rs and optimistic.rs (#1498)
Browse files Browse the repository at this point in the history
* Remove banning system from warp_sync.rs

* Remove ban system from optimistic.rs

* CHANGELOG
  • Loading branch information
tomaka authored Dec 20, 2023
1 parent b9214cd commit 2ef17df
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 180 deletions.
4 changes: 1 addition & 3 deletions lib/src/sync/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2924,9 +2924,7 @@ impl<TRq> Shared<TRq> {
}
};

if let Some(finalized_block_height) = finalized_block_height {
all_forks.update_source_finality_state(updated_source_id, finalized_block_height);
}
all_forks.update_source_finality_state(updated_source_id, finalized_block_height);

self.sources[source.outer_source_id.0] = SourceMapping::AllForks(updated_source_id);
}
Expand Down
53 changes: 1 addition & 52 deletions lib/src/sync/optimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ struct Source<TSrc> {
/// Best block that the source has reported having.
best_block_number: u64,

/// If `true`, this source is banned and shouldn't use be used to request blocks.
/// Note that the ban is lifted if the source is removed. This ban isn't meant to be a line of
/// defense against malicious peers but rather an optimization.
banned: bool,

/// Number of requests that use this source.
num_ongoing_requests: u32,
}
Expand Down Expand Up @@ -384,7 +379,6 @@ impl<TRq, TSrc, TBl> OptimisticSync<TRq, TSrc, TBl> {
Source {
user_data: source,
best_block_number,
banned: false,
num_ongoing_requests: 0,
},
);
Expand Down Expand Up @@ -658,15 +652,6 @@ impl<TRq, TSrc, TBl> OptimisticSync<TRq, TSrc, TBl> {
.unwrap()
.num_ongoing_requests -= 1;

self.inner.sources.get_mut(&source_id).unwrap().banned = true;

// If all sources are banned, unban them.
if self.inner.sources.iter().all(|(_, s)| s.banned) {
for src in self.inner.sources.values_mut() {
src.banned = false;
}
}

user_data
}

Expand Down Expand Up @@ -870,24 +855,12 @@ impl<TRq, TSrc, TBl> BlockVerify<TRq, TSrc, TBl> {
scale_encoded_extrinsics: block.scale_encoded_extrinsics,
verified_header,
scale_encoded_justifications: block.scale_encoded_justifications,
source_id,
},
new_best_hash,
new_best_number,
}
}
Err(reason) => {
if let Some(src) = self.inner.sources.get_mut(&source_id) {
src.banned = true;
}

// If all sources are banned, unban them.
if self.inner.sources.iter().all(|(_, s)| s.banned) {
for src in self.inner.sources.values_mut() {
src.banned = false;
}
}

self.inner.make_requests_obsolete(&self.chain);

let previous_best_height = self.chain.best_block_header().number;
Expand Down Expand Up @@ -944,7 +917,6 @@ pub struct BlockVerifySuccess<TRq, TSrc, TBl> {
verified_header: blocks_tree::VerifiedHeader,
scale_encoded_extrinsics: Vec<Vec<u8>>,
scale_encoded_justifications: Vec<([u8; 4], Vec<u8>)>,
source_id: SourceId,
}

impl<TRq, TSrc, TBl> BlockVerifySuccess<TRq, TSrc, TBl> {
Expand Down Expand Up @@ -1014,19 +986,7 @@ impl<TRq, TSrc, TBl> BlockVerifySuccess<TRq, TSrc, TBl> {

/// Reject the block and mark it as bad.
pub fn reject_bad_block(mut self) -> OptimisticSync<TRq, TSrc, TBl> {
if let Some(src) = self.parent.inner.sources.get_mut(&self.source_id) {
src.banned = true;
}

// If all sources are banned, unban them.
if self.parent.inner.sources.iter().all(|(_, s)| s.banned) {
for src in self.parent.inner.sources.values_mut() {
src.banned = false;
}
}

self.parent.inner.make_requests_obsolete(&self.parent.chain);

self.parent
}

Expand Down Expand Up @@ -1083,7 +1043,7 @@ impl<TRq, TSrc, TBl> JustificationVerify<TRq, TSrc, TBl> {
OptimisticSync<TRq, TSrc, TBl>,
JustificationVerification<TBl>,
) {
let (consensus_engine_id, justification, source_id) =
let (consensus_engine_id, justification, _) =
self.inner.pending_encoded_justifications.next().unwrap();

let mut apply = match self.chain.verify_justification(
Expand All @@ -1093,17 +1053,6 @@ impl<TRq, TSrc, TBl> JustificationVerify<TRq, TSrc, TBl> {
) {
Ok(a) => a,
Err(error) => {
if let Some(source) = self.inner.sources.get_mut(&source_id) {
source.banned = true;
}

// If all sources are banned, unban them.
if self.inner.sources.iter().all(|(_, s)| s.banned) {
for src in self.inner.sources.values_mut() {
src.banned = false;
}
}

let chain = blocks_tree::NonFinalizedTree::new(
self.inner.finalized_chain_information.clone(),
);
Expand Down
Loading

0 comments on commit 2ef17df

Please sign in to comment.