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
feat(net): add discv4 crate #113
Conversation
currently blocked by pending ethers-corre bump with breaking changes. |
Update: reimplemented the entire protocol TODO
|
Codecov Report
@@ Coverage Diff @@
## main #113 +/- ##
==========================================
- Coverage 72.50% 68.78% -3.73%
==========================================
Files 150 146 -4
Lines 10642 10575 -67
==========================================
- Hits 7716 7274 -442
- Misses 2926 3301 +375
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
the self lookup step is a bit hacky atm, there's a bug in |
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.
love it. a bunch of comments / but you can merge and address separately.
|
||
#[tokio::test(flavor = "multi_thread")] | ||
#[traced_test] | ||
#[ignore] |
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.
is this so we don't get banned? i'd maybe feature gate it
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 is ignored since this connects with live nodes, started writing a mock service that allows us to test messages.
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.
sweet - let's also keep in mind a integration test runner which spawns geth nodes and peers with them (let's just copy-paste geth.rs from ethers-core and add options for p2p config)
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.
will take this on and track
#[test] | ||
fn test_noderecord_codec_ipv4() { | ||
let mut rng = thread_rng(); | ||
for _ in 0..100 { |
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.
wshould be replaced with proptest or test-fuzz, but let's do separately cc @joshieDo , lets track
let signature: RecoverableSignature = SECP256K1.sign_ecdsa_recoverable( | ||
&secp256k1::Message::from_slice(keccak256(&payload).as_ref()) | ||
.expect("is correct MESSAGE_SIZE; qed"), | ||
secret_key, | ||
); |
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.
lets track in an issue about maybe using k256 down the line if performance improves
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.
wanted to do this, but the other p2p stuff also relies on secp256k currently, so we should migrate this in one step. will track
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS; | ||
use bytes::BytesMut; | ||
use rand::{thread_rng, Rng, RngCore}; | ||
|
||
fn rng_endpoint(rng: &mut impl Rng) -> NodeEndpoint { |
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.
should also be done w fuzzer @joshieDo
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.
In essence this is an Arbitrary
impl for NodeEndpoint
since all values are randomly generated.
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.
test-fuzz
does not require Arbitrary
, only requires:
-
the fuzzed (input) type to be
Serialize
andDeserialize
-
a
test
which can be run withcargo test
https://github.com/foundry-rs/reth/blob/main/crates/interfaces/src/db/codecs/fuzz/mod.rs#L47-L50 -
the above
test
should go through a function annotated with#[test_fuzz::test_fuzz]
. Ideally the function should receive the targeted object.
https://github.com/foundry-rs/reth/blob/main/crates/interfaces/src/db/codecs/fuzz/mod.rs#L41-L45
/// # use std::io; | ||
/// use std::net::SocketAddr; | ||
/// use std::str::FromStr; | ||
/// use rand::thread_rng; | ||
/// use secp256k1::SECP256K1; | ||
/// use reth_discv4::{Discv4, Discv4Config, NodeId, NodeRecord}; | ||
/// # async fn t() -> io::Result<()> { | ||
/// // generate a (random) keypair | ||
/// let mut rng = thread_rng(); | ||
/// let (secret_key, pk) = SECP256K1.generate_keypair(&mut rng); | ||
/// let id = NodeId::from_slice(&pk.serialize_uncompressed()[1..]); | ||
/// | ||
/// let socket = SocketAddr::from_str("0.0.0.0:0").unwrap(); | ||
/// let local_enr = NodeRecord { | ||
/// address: socket.ip(), | ||
/// tcp_port: socket.port(), | ||
/// udp_port: socket.port(), | ||
/// id, | ||
/// }; | ||
/// let config = Discv4Config::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.
sick
Add discv4 support.
This merges parts of https://github.com/vorot93/discv4 and parts of https://github.com/sigp/discv5 (kademlia) and also applies reth rlp encoding.
TODO