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

[hotfix 0.107.x] fix: p2p alerts are not filterred in block chain info #3803

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
2 changes: 1 addition & 1 deletion util/launcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl Launcher {

let alert_signature_config = self.args.config.alert_signature.clone().unwrap_or_default();
let alert_relayer = AlertRelayer::new(
self.version.to_string(),
self.version.short(),
shared.notify_controller().clone(),
alert_signature_config,
);
Expand Down
35 changes: 28 additions & 7 deletions util/network-alert/src/notifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! notifier module
use ckb_logger::debug;
use ckb_logger::{debug, error};
use ckb_notify::NotifyController;
use ckb_types::{packed::Alert, prelude::*};
use lru::LruCache;
use semver::Version;
use std::collections::HashMap;

const CANCEL_FILTER_SIZE: usize = 128;
Expand All @@ -15,25 +16,35 @@ pub struct Notifier {
received_alerts: HashMap<u32, Alert>,
/// alerts that self node should notice
noticed_alerts: Vec<Alert>,
client_version: String,
client_version: Option<Version>,
notify_controller: NotifyController,
}

impl Notifier {
/// Init
pub fn new(client_version: String, notify_controller: NotifyController) -> Self {
let parsed_client_version = match Version::parse(&client_version) {
Ok(version) => Some(version),
Err(err) => {
error!(
"Invalid version {} for alert notifier: {}",
client_version, err
);
None
}
};

Notifier {
cancel_filter: LruCache::new(CANCEL_FILTER_SIZE),
received_alerts: Default::default(),
noticed_alerts: Vec::new(),
client_version,
client_version: parsed_client_version,
notify_controller,
}
}

fn is_version_effective(&self, alert: &Alert) -> bool {
use semver::Version;
if let Ok(client_version) = Version::parse(&self.client_version) {
if let Some(client_version) = &self.client_version {
let test_min_ver_failed = alert
.as_reader()
.raw()
Expand All @@ -42,7 +53,12 @@ impl Notifier {
.and_then(|v| {
v.as_utf8()
.ok()
.and_then(|v| Version::parse(v).map(|min_v| client_version < min_v).ok())
.and_then(|v| {
Version::parse(v)
.as_ref()
.map(|min_v| client_version < min_v)
.ok()
})
.or(Some(true))
})
.unwrap_or(false);
Expand All @@ -57,7 +73,12 @@ impl Notifier {
.and_then(|v| {
v.as_utf8()
.ok()
.and_then(|v| Version::parse(v).map(|max_v| client_version > max_v).ok())
.and_then(|v| {
Version::parse(v)
.as_ref()
.map(|max_v| client_version > max_v)
.ok()
})
.or(Some(true))
})
.unwrap_or(false);
Expand Down