-
Notifications
You must be signed in to change notification settings - Fork 54
refactor(l1): discovery service #1768
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
+1,428
−1,379
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7d023c2
refactor: initial removal of discovery code from net move discovery t…
MarcosNicolau dca6bea
refactor: avoid cloning self and move message handling to new function
MarcosNicolau 7c1bbf7
fix: ping and pong send tcp_ports from node
MarcosNicolau 5038e16
refactor: messages errors type and remove old todos
MarcosNicolau d9fbd93
refactor: lookups
MarcosNicolau 2540d39
refactor: merge with main
MarcosNicolau b2dbfa6
Merge branch 'refactor/discovery-v2' into refactor/discovery
MarcosNicolau e3e68a4
chore: remove old files from merge
MarcosNicolau a98e9f9
Merge branch 'main' into refactor/discovery
MarcosNicolau 4cc7a84
refactor: enr messages
MarcosNicolau 4f4bc6a
refactor: lookups
MarcosNicolau 7c59825
chore: address clippy warnings
MarcosNicolau 381ba16
refactor: remove uwnrap on node record decoding
MarcosNicolau 4c233ed
refactor: proper erro handling in network start
MarcosNicolau bd1330c
refactor: better debug on handle message errors
MarcosNicolau 7f82351
refactor: pass node_id directly instead of msg
MarcosNicolau 9f871bb
refactor: remove usage of discv max packet size in rlpx
MarcosNicolau 6fc235c
test: re-enable discovery tests
MarcosNicolau f1ba350
fix: sanity checks
MarcosNicolau 399ef4c
refactor: use try_add_peer_and_ping in ping msg
MarcosNicolau 522a2f7
refactor: handle messages more rustacean code
MarcosNicolau 02d2b06
Merge branch 'main' into refactor/discovery
MarcosNicolau 2f5a38a
test: fix lookups assertion
MarcosNicolau 7d69b81
refactor: handle messages
MarcosNicolau 4da7c89
refactor: enr_seq calculate it once on startup
MarcosNicolau c01d2fc
fix: enr messages with new calculated seq
MarcosNicolau b6a4ed5
test: enr with new calculated seq
MarcosNicolau a8ea0e6
Merge branch 'main' into refactor/discovery
MarcosNicolau 4ec15ba
refactor: usage of context in discv4 module
MarcosNicolau 2e35002
refactor: use node.addr() instead of creating socket addr
MarcosNicolau 4ecebfc
fix: add anr remove request msgs checks
MarcosNicolau d6532fc
refactor: apply some review suggestions
MarcosNicolau 6487eff
docs: discv4 server
MarcosNicolau 5e76cce
refactor: remove time_now_unix from kademlia table
MarcosNicolau fb16d77
refactor: discv4 helpers
MarcosNicolau 28f97de
refactor: move discv4 server from mod to new file
MarcosNicolau a61ea36
Merge branch 'main' into refactor/discovery
MarcosNicolau 68ada44
chore: address clippy warnings
MarcosNicolau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::time::{Duration, SystemTime, UNIX_EPOCH}; | ||
|
||
pub fn get_msg_expiration_from_seconds(seconds: u64) -> u64 { | ||
(SystemTime::now() + Duration::from_secs(seconds)) | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap_or_default() | ||
.as_secs() | ||
} | ||
|
||
pub fn is_msg_expired(expiration: u64) -> bool { | ||
// this cast to a signed integer is needed as the rlp decoder doesn't take into account the sign | ||
// otherwise if a msg contains a negative expiration, it would pass since as it would wrap around the u64. | ||
(expiration as i64) < (current_unix_time() as i64) | ||
} | ||
|
||
pub fn elapsed_time_since(unix_timestamp: u64) -> u64 { | ||
let time = SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(unix_timestamp); | ||
SystemTime::now() | ||
.duration_since(time) | ||
.unwrap_or_default() | ||
.as_secs() | ||
} | ||
|
||
pub fn current_unix_time() -> u64 { | ||
SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap_or_default() | ||
.as_secs() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note that we don't need to spawn the networking as a task. This allows us to panic if there is an err during the network startup.