diff --git a/src/discv5.rs b/src/discv5.rs index 58b3f0755..d5937cc5d 100644 --- a/src/discv5.rs +++ b/src/discv5.rs @@ -119,7 +119,7 @@ pub struct Discv5 { impl Discv5 { pub fn new( - local_enr: Enr, + mut local_enr: Enr, enr_key: CombinedKey, mut config: Discv5Config, ) -> Result { @@ -145,6 +145,12 @@ impl Discv5 { (None, None) }; + // This node supports topic requests REGTOPIC and TOPICQUERY, and their responses. + if let Err(e) = local_enr.insert(ENR_KEY_FEATURES, &[Features::Topics as u8], &enr_key) { + error!("Failed writing to enr. Error {:?}", e); + return Err("Failed to insert field 'features' into local enr"); + } + let local_enr = Arc::new(RwLock::new(local_enr)); let enr_key = Arc::new(RwLock::new(enr_key)); let kbuckets = Arc::new(RwLock::new(KBucketsTable::new( @@ -155,16 +161,6 @@ impl Discv5 { bucket_filter, ))); - // This node supports topic requests REGTOPIC and TOPICQUERY, and their responses. - if let Err(e) = local_enr.write().insert( - ENR_KEY_FEATURES, - &[Features::Topics as u8], - &enr_key.write(), - ) { - error!("Failed writing to enr. Error {:?}", e); - return Err("Failed to insert field 'version' into local enr"); - } - println!("{:?}", local_enr.read().get(ENR_KEY_FEATURES).unwrap()); // Update the PermitBan list based on initial configuration @@ -879,7 +875,7 @@ pub fn supports_feature(peer: &Enr, feature: Features) -> bool { } } else { warn!( - "Enr of peer {} doesn't contain field 'version'", + "Enr of peer {} doesn't contain field 'features'", peer.node_id() ); false diff --git a/src/discv5/test.rs b/src/discv5/test.rs index ca3dae1f9..5182243a7 100644 --- a/src/discv5/test.rs +++ b/src/discv5/test.rs @@ -629,7 +629,7 @@ async fn test_bucket_limits() { } #[test] -fn test_version_check() { +fn test_features_check() { // Create the test values needed let port = 6666; let ip: std::net::IpAddr = "127.0.0.1".parse().unwrap(); @@ -639,9 +639,13 @@ fn test_version_check() { .udp4(port) .build(&key) .unwrap(); - let supported_versions = Features::Topics as u8 | 2; + + let supported_versions = Features::Topics as u8; + enr.insert(ENR_KEY_FEATURES, &[supported_versions], &key) .unwrap(); assert!(supports_feature(&enr, Features::Topics)); } + +