-
Notifications
You must be signed in to change notification settings - Fork 136
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
Conversation
@@ -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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
portalnet/src/types/messages.rs
Outdated
@@ -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(), |
There was a problem hiding this comment.
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?
portalnet/src/discovery.rs
Outdated
// 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); |
There was a problem hiding this comment.
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
Line 142 in 040ad41
const EXECUTABLE_PATH: &str = "path/to/executable"; trin/portal-bridge/src/bridge.rs
Line 50 in 040ad41
pub epoch_acc_path: PathBuf, Line 74 in 040ad41
.web3_ipc_path
portalnet/src/discovery.rs
Outdated
// 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@njgheorghita I believe I resolved your concerns let me know what you think |
There was a problem hiding this 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
portalnet/src/discovery.rs
Outdated
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"); |
There was a problem hiding this comment.
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"
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.