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

feat: ban a peer if its last state isn't changed after timeout #170

Conversation

yangby-cryptape
Copy link
Collaborator

@yangby-cryptape yangby-cryptape commented Dec 29, 2023

Description

If a peer sent the same state to light client again and again, light client should ban it.

Just let the light client don't update the update timestamp for cached last-state if it isn't changed, and ban the peer when do timeout checks.

for peer_index in self.peers().get_peers_which_have_timeout(now) {
self.peers().mark_fetching_headers_timeout(peer_index);
self.peers().mark_fetching_txs_timeout(peer_index);
warn!("peer {}: reach timeout", peer_index);
if let Err(err) = nc.disconnect(peer_index, "reach timeout") {

// Ban a peer if it reach any timeout.
pub const MESSAGE_TIMEOUT: u64 = 60 * 1000;

Commits:

  • test: test the cached state when received same last state from a peer more than once
  • feat: keep the update timestamp if the last state is as the same as the previous
  • feat: ban a peer if its last state isn't changed after timeout

@yangby-cryptape yangby-cryptape changed the title feature: ban peers if its last state isn't changed after timeout feature: ban a peer if its last state isn't changed after timeout Dec 29, 2023
@yangby-cryptape yangby-cryptape force-pushed the feature/ban-peers-if-state-not-changed-after-timeout branch from 1a8eb78 to fb5cd20 Compare December 29, 2023 13:49
@yangby-cryptape yangby-cryptape force-pushed the feature/ban-peers-if-state-not-changed-after-timeout branch from fb5cd20 to 79f56e8 Compare December 29, 2023 13:55
@yangby-cryptape yangby-cryptape changed the title feature: ban a peer if its last state isn't changed after timeout feat: ban a peer if its last state isn't changed after timeout Dec 29, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (86865db) 71.39% compared to head (b553660) 71.37%.

Files Patch % Lines
src/protocols/light_client/peers.rs 42.85% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #170      +/-   ##
===========================================
- Coverage    71.39%   71.37%   -0.03%     
===========================================
  Files           25       25              
  Lines         6479     6498      +19     
===========================================
+ Hits          4626     4638      +12     
- Misses        1853     1860       +7     
Flag Coverage Δ
unittests 71.37% <75.75%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yangby-cryptape yangby-cryptape force-pushed the feature/ban-peers-if-state-not-changed-after-timeout branch from d99ccb6 to 74cbc3c Compare December 29, 2023 15:09
@yangby-cryptape yangby-cryptape marked this pull request as ready for review December 29, 2023 18:22
@quake quake merged commit 99bd4b8 into nervosnetwork:develop Dec 30, 2023
6 checks passed
@yangby-cryptape yangby-cryptape deleted the feature/ban-peers-if-state-not-changed-after-timeout branch December 30, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants