Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove banning system from warp_sync.rs and optimistic.rs #1498

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading