Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: enr signature changes on restart even if enr content is the same #952

Merged
merged 5 commits into from
Oct 4, 2023

Conversation

KolbyML
Copy link
Member

@KolbyML KolbyML commented Oct 3, 2023

What was wrong?

I made a PR sigp/enr#53 and Age Manning gave me the insight that the signature should always be the same in the client if the content is the same.

We had an issue before my increase seq pr and after that even though our enr could be the same, the signature would change which isn't good.

How was it fixed?

It was fixed by restructuring a bit of my code. I also cleaned it up a bit for how to compare them from suggestions from Age and Nick.

I also resolved a param name nitpik nick had in my last PR.

@KolbyML KolbyML requested a review from njgheorghita October 3, 2023 20:14
@KolbyML KolbyML changed the title fix: resolve changing signatures on trin restart fix: resolve changing signatures on trin enr after restart if content didn't change Oct 3, 2023
@KolbyML KolbyML self-assigned this Oct 3, 2023
@KolbyML KolbyML changed the title fix: resolve changing signatures on trin enr after restart if content didn't change fix: changing signatures on trin enr after restart if content didn't change Oct 3, 2023
@KolbyML KolbyML changed the title fix: changing signatures on trin enr after restart if content didn't change fix: enr signature changes on restart even if enr content is the same Oct 3, 2023
@KolbyML KolbyML marked this pull request as ready for review October 3, 2023 20:32
@@ -425,7 +430,7 @@ impl AsyncUdpSocket<UtpEnr> for Discv5UdpSocket {

// todo: remove this once sigp/enr implements this for enr's
// we need this because signatures can be different for the same data but still valid
fn verify_by_signature(enr: &Enr, signature: &[u8]) -> bool {
fn get_enr_rlp_content(enr: &Enr) -> BytesMut {

Choose a reason for hiding this comment

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

@KolbyML I don't think there is any harm in exposing rlp_content from Enr

Copy link
Member Author

@KolbyML KolbyML Oct 3, 2023

Choose a reason for hiding this comment

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

When we get the update Enr version we can just use compare_content. If we want to expose rlp_content() that is fine too. It just looked like rlp_content() was intentionally privated so that is why I tried to get a compare/verify_by_signature* function added. Cause I didn't want to manually calculate rlp_content in multiple codebases.

Anyways up to you. I didn't know making the rlp_content() function public was an option tbh.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do think compare_content is cleaner though
enr1.compare_content(&enr2)
vs
enr1.rlp_content() == enr2.rlp_content()

Choose a reason for hiding this comment

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

Neither is a problem. Nothing wrong with exposing it, this does not change the enr and it's not private info in any way

@@ -182,7 +182,7 @@ impl Default for PortalnetConfig {
data_radius: Distance::MAX,
internal_ip: false,
no_stun: false,
enr_file_location: None,
trin_data_dir: PathBuf::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, sorry to be a stickler, but this still feels off. Essentially we're still doing the same thing I was previously against, except this time with PathBuf::default() instead of an Option

Ultimately, it feels like PortalnetConfig is not an appropriate place for this argument, since there is no reasonable default value.

I think we just remove this from PortalnetConfig and pass node_data_dir into Discovery::new() directly. Thoughts?

// This should only never run in test cases.
if portal_config.trin_data_dir != PathBuf::default() {
// Check if we have an old version of our Enr and if we do, increase our sequence number
let trin_enr_file_location = portal_config.trin_data_dir.join(ENR_FILE_NAME);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would change to trin_enr_path - basically, _path suffix to these types of variable names describing a file path is what we typically do in this codebase, and I think we should continue with that convention to maintain consistency

// Check if we have an old version of our Enr and if we do, increase our sequence number
if let Some(enr_file_location) = portal_config.enr_file_location {
let trin_enr_file_location = enr_file_location.join(ENR_FILE_NAME);
// This should only never run in test cases.
Copy link
Collaborator

Choose a reason for hiding this comment

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

// This should never run in test cases. - much less confusing in my opinion. But also the fact that this check needs to happen feels off. If we go with my suggestion about node_data_dir then we can just get rid of this check completely

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue I have with this is some Discovery tests don't use a path, but I cause I can just generate a tmp path for those

@KolbyML
Copy link
Member Author

KolbyML commented Oct 4, 2023

@njgheorghita I believe I resolved your concerns let me know what you think

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

Nice! Yeah, it's not ideal to create all those temp dirs in the tests but in the long run I think we're left off with better / easier to read production code this way

if trin_enr_path.is_file() {
let data = fs::read_to_string(trin_enr_path.clone())
.expect("Unable to read Trin Enr from file");
let old_enr = Enr::from_str(&data).expect("Expected read trin.enr to be valid");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit "Expected to read valid Trin Enr from file"

@KolbyML KolbyML merged commit 80cf8ca into ethereum:master Oct 4, 2023
@KolbyML KolbyML deleted the improve-increase-enr-seq branch January 22, 2025 07:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants