Skip to content
Merged
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
15 changes: 5 additions & 10 deletions anchor/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,8 @@ impl Discovery {
let local_domain_type = self.domain_type.clone();

let domain_type_predicate = move |enr: &Enr| {
if let Some(Ok(domain_type_str)) = enr.get_decodable::<String>("domaintype") {
if let Ok(domain_type_bytes) = <[u8; 4]>::try_from(domain_type_str.as_bytes()) {
local_domain_type == DomainType::from(domain_type_bytes)
} else {
trace!(
domain_type = domain_type_str.as_bytes(),
"ENR domain type is not 4 bytes",
);
false
}
if let Some(Ok(domain_type)) = enr.get_decodable::<[u8; 4]>("domaintype") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we handle the else case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? There is an else below. If the field can not decoded, the enr is not acceptable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have been clearer. We don't log if there's an error when decoding.

It was like that before but we also don't log if the field doesn't exist. Maybe we should if it's expected to always exist at this point.

Copy link
Member Author

@dknopik dknopik Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not expected to always exist. For example, non-SSV ENRs might arrive at this point, and they won't have this field. I will add a trace log for debugging anyway. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right!

local_domain_type.0 == domain_type
} else {
false
}
Expand Down Expand Up @@ -571,6 +563,9 @@ pub fn build_enr(enr_key: &CombinedKey, config: &Config) -> Result<Enr, Error> {
// set the "subnets" field on our ENR
builder.add_value::<Bytes>("subnets", &BitVector::<U128>::new().as_ssz_bytes().into());

// set the "subnets" field on our ENR
builder.add_value::<[u8; 4]>("domaintype", &config.domain_type.0);

let enr = builder.build(enr_key)?;
Ok(enr)
}
Expand Down