-
Notifications
You must be signed in to change notification settings - Fork 803
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
Add client support for the lighthouse/peers
route
#4937
Open
jmcph4
wants to merge
8
commits into
sigp:unstable
Choose a base branch
from
jmcph4:implement-lighthouse-route
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a879c01
Add serde_utils crate
jmcph4 184fe2b
Implement client call for lighthouse/peers route
jmcph4 47b7cdb
Remove now-redundant comment
jmcph4 149b28e
Remove unused dependencies from serde_utils
jmcph4 422d5dd
Merge branch 'unstable' into implement-lighthouse-route
jmcph4 6f1a94d
Update lockfile
jmcph4 fc1ae5f
Fix return type on route
jmcph4 57d5e53
Remove custom serialisation for PeerConnectionStatus
jmcph4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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,10 @@ | ||
[package] | ||
name = "serde_utils" | ||
version = "0.1.0" | ||
authors = ["Jack McPherson <jack@sigmaprime.io>"] | ||
edition = { workspace = true } | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
serde = { workspace = true } |
This file contains 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,27 @@ | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; | ||
/// Serialise and deserialise `std::time::Instant`s | ||
/// | ||
/// Due to David Tolnay via: https://github.com/serde-rs/serde/issues/1375#issuecomment-419688068 | ||
use std::time::{Instant, SystemTime}; | ||
|
||
pub fn serialize<S>(instant: &Instant, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let system_now = SystemTime::now(); | ||
let instant_now = Instant::now(); | ||
let approx = system_now - (instant_now - *instant); | ||
approx.serialize(serializer) | ||
} | ||
|
||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Instant, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let de = SystemTime::deserialize(deserializer)?; | ||
let system_now = SystemTime::now(); | ||
let instant_now = Instant::now(); | ||
let duration = system_now.duration_since(de).map_err(Error::custom)?; | ||
let approx = instant_now - duration; | ||
Ok(approx) | ||
} |
This file contains 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 @@ | ||
pub mod approx_instant; |
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.
We have an external package (
ethereum_serde_utils
) which defines a crate calledserde_utils
. I think we could either put this code there, give it a different crate name to avoid confusion, or put theInstant
serialisation as a module in thelighthouse_network
crate.I think my preference is for the latter, as the
Instant
stuff is not really Ethereum-specific, and seems a bit too hacky (usingSystemTime::now
) to put inethereum_serde_utils
. Similarly, for future serde utils, if we deem them Ethereum-relevant we can put them in the extern crate, whereas if they're Lighthouse-specific we can keep them in-tree. Wdyt?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.
My preference is the former, although I understand your point about lack of Ethereum specificity (and concur). My issue with moving it to
lighthouse_network
is that, in my opinion, that crate is already too busy and this busyness complicates downstream use of the crate outside of Lighthouse. I already have some changes that I need to open a (separate) PR for that address some of this.I also agree here, but my desire for full client-side implementation of the HTTP API overrides this. This certainly isn't a nice solution but my feeling at the moment is that having missing routes is less nice than even this.
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.
Ok cool. I'm happy with putting it in
ethereum_serde_utils
. I thought it might break WASM compatibility (which seems to be something people want from our crates) but it seems it will compile fine and just panic on WASM, which is fine as it's completely optional (rust-lang/rust#48564).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.
Oh wow, hadn't considered that WASM quirk before!