Skip to content

feat(l1): properly calculate enr sequence field #2679

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

Merged
merged 42 commits into from
May 19, 2025

Conversation

mechanix97
Copy link
Contributor

@mechanix97 mechanix97 commented May 6, 2025

Motivation

The seq field in the node record was hardcoded with the unix time.

Description

The enr_seq field is updated by one when the node_record is changed. The ping/pong messages are sent with the enr_seq in it, so the peer knows when an update is made in the node_record. Since we don't modify the node_record yet, the enr_seq is not being updated. There is a new PR incoming (#2654) which is using this funtionality to inform the peers about changes in the node_record.

A reference was added to the p2pcontext in order to be able to access the current NodeRecord seq in several parts of the code.

Some functions firms were changed to accept this improvement.

A new config struct has been built to persist the enr seq field and also store the known peers in the same file.

The test discv4::server::tests::discovery_enr_message checks this feature

enr

Closes #1756

Copy link

github-actions bot commented May 6, 2025

Lines of code report

Total lines added: 77
Total lines removed: 0
Total lines changed: 77

Detailed view
+-----------------------------------------------+-------+------+
| File                                          | Lines | Diff |
+-----------------------------------------------+-------+------+
| ethrex/cmd/ethrex/ethrex.rs                   | 96    | +8   |
+-----------------------------------------------+-------+------+
| ethrex/cmd/ethrex/initializers.rs             | 388   | +18  |
+-----------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2/command.rs               | 207   | +8   |
+-----------------------------------------------+-------+------+
| ethrex/cmd/ethrex/utils.rs                    | 148   | +20  |
+-----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/discv4/server.rs | 683   | +8   |
+-----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/network.rs       | 177   | +1   |
+-----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/types.rs         | 420   | +14  |
+-----------------------------------------------+-------+------+

@mechanix97 mechanix97 marked this pull request as ready for review May 7, 2025 14:54
@mechanix97 mechanix97 requested a review from a team as a code owner May 7, 2025 14:54
@mechanix97 mechanix97 marked this pull request as draft May 7, 2025 14:57
@mechanix97 mechanix97 marked this pull request as ready for review May 7, 2025 15:20
@mechanix97 mechanix97 marked this pull request as draft May 7, 2025 15:24
@mechanix97 mechanix97 marked this pull request as ready for review May 7, 2025 15:46
cmd/ethrex/l2.rs Outdated
peer_table.clone(),
local_p2p_node,
local_node_record.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we have to pass a node record through rpc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The admin_nodeInfo msg requires the node record
See crates/networking/rpc/rpc.rs:446

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about this, and for the moment a copy of the node record is enough

@@ -552,8 +554,9 @@ impl Discv4Server {
tcp_port: node.tcp_port,
};

let ping =
Message::Ping(PingMessage::new(from, to, expiration).with_enr_seq(self.ctx.enr_seq));
let enr_seq = self.ctx.local_node_record.lock().await.seq;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is enr ever updated? seems like a constant to me here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the enr is not being change anywhere in the code, so the sequence is also not updated. The important part is to have a reference to the node_record in every part of the code to get the seq number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The enr seq is updated in the test discv4::server::tests::discovery_enr_message where a field is changed and after the seq is updated, both servers have the info

Copy link
Collaborator

@mpaulucci mpaulucci May 9, 2025

Choose a reason for hiding this comment

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

The whole point of the ticket is to implement the logic to how and where to update the enr...

Copy link
Collaborator

@mpaulucci mpaulucci left a comment

Choose a reason for hiding this comment

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

This Pr as is doesn't make much sense to me. I don't understand if the enr is ever updated and what is the criteria for it

@mechanix97 mechanix97 added p2p Issues related to p2p network L1 Ethereum client labels May 9, 2025
@mechanix97 mechanix97 self-assigned this May 9, 2025
@mechanix97 mechanix97 requested review from mpaulucci May 13, 2025 13:17
Copy link
Contributor

@fedacking fedacking left a comment

Choose a reason for hiding this comment

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

Small change

Copy link
Contributor

@fedacking fedacking left a comment

Choose a reason for hiding this comment

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

LGTM

serde_json::from_reader(file)
pub fn read_node_config_file(file_path: PathBuf) -> Result<NodeConfigFile, String> {
match std::fs::File::open(file_path) {
Ok(file) => serde_json::from_reader(file).map_err(|e| format!("Invlid config file {}", e)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Invalid

Copy link
Collaborator

@mpaulucci mpaulucci left a comment

Choose a reason for hiding this comment

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

LGTM

@mechanix97 mechanix97 added this pull request to the merge queue May 19, 2025
Merged via the queue into main with commit 2fcf668 May 19, 2025
19 checks passed
@mechanix97 mechanix97 deleted the feat/properly-calculate-enr-seq branch May 19, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L1 Ethereum client p2p Issues related to p2p network
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly calculate ENR seq number
3 participants