Discovery v5.1 (#1786)

## Overview 

This updates lighthouse to discovery v5.1

Note: This makes lighthouse's discovery not compatible with any previous version. Lighthouse cannot discover peers or send/receive ENR's from any previous version. This is a breaking change. 

This resolves #1605
This commit is contained in:
Age Manning 2020-10-23 04:16:33 +00:00
parent ae96dab5d2
commit 2c7f362908
6 changed files with 456 additions and 230 deletions

671
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
discv5 = { version = "0.1.0-alpha.13", features = ["libp2p"] } discv5 = { git = "https://github.com/sigp/discv5", rev = "3ab46fbec53a0bb9da53340e10b9daa1a3effc9f", features = ["libp2p"] }
types = { path = "../../consensus/types" } types = { path = "../../consensus/types" }
hashset_delay = { path = "../../common/hashset_delay" } hashset_delay = { path = "../../common/hashset_delay" }
eth2_ssz_types = { path = "../../consensus/ssz_types" } eth2_ssz_types = { path = "../../consensus/ssz_types" }

View File

@ -198,7 +198,7 @@ impl CombinedKeyPublicExt for CombinedPublicKey {
fn into_peer_id(&self) -> PeerId { fn into_peer_id(&self) -> PeerId {
match self { match self {
Self::Secp256k1(pk) => { Self::Secp256k1(pk) => {
let pk_bytes = pk.serialize_compressed(); let pk_bytes = pk.to_bytes();
let libp2p_pk = libp2p::core::PublicKey::Secp256k1( let libp2p_pk = libp2p::core::PublicKey::Secp256k1(
libp2p::core::identity::secp256k1::PublicKey::decode(&pk_bytes) libp2p::core::identity::secp256k1::PublicKey::decode(&pk_bytes)
.expect("valid public key"), .expect("valid public key"),
@ -221,7 +221,7 @@ impl CombinedKeyExt for CombinedKey {
fn from_libp2p(key: &libp2p::core::identity::Keypair) -> Result<CombinedKey, &'static str> { fn from_libp2p(key: &libp2p::core::identity::Keypair) -> Result<CombinedKey, &'static str> {
match key { match key {
Keypair::Secp256k1(key) => { Keypair::Secp256k1(key) => {
let secret = discv5::enr::secp256k1::SecretKey::parse(&key.secret().to_bytes()) let secret = discv5::enr::k256::ecdsa::SigningKey::new(&key.secret().to_bytes())
.expect("libp2p key must be valid"); .expect("libp2p key must be valid");
Ok(CombinedKey::Secp256k1(secret)) Ok(CombinedKey::Secp256k1(secret))
} }
@ -277,7 +277,7 @@ mod tests {
fn test_secp256k1_peer_id_conversion() { fn test_secp256k1_peer_id_conversion() {
let sk_hex = "df94a73d528434ce2309abb19c16aedb535322797dbd59c157b1e04095900f48"; let sk_hex = "df94a73d528434ce2309abb19c16aedb535322797dbd59c157b1e04095900f48";
let sk_bytes = hex::decode(sk_hex).unwrap(); let sk_bytes = hex::decode(sk_hex).unwrap();
let secret_key = discv5::enr::secp256k1::SecretKey::parse_slice(&sk_bytes).unwrap(); let secret_key = discv5::enr::k256::ecdsa::SigningKey::new(&sk_bytes).unwrap();
let libp2p_sk = libp2p::identity::secp256k1::SecretKey::from_bytes(sk_bytes).unwrap(); let libp2p_sk = libp2p::identity::secp256k1::SecretKey::from_bytes(sk_bytes).unwrap();
let secp256k1_kp: libp2p::identity::secp256k1::Keypair = libp2p_sk.into(); let secp256k1_kp: libp2p::identity::secp256k1::Keypair = libp2p_sk.into();

View File

@ -240,7 +240,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
while let Some((result, original_addr)) = fut_coll.next().await { while let Some((result, original_addr)) = fut_coll.next().await {
match result { match result {
Ok(Some(enr)) => { Ok(enr) => {
debug!( debug!(
log, log,
"Adding node to routing table"; "Adding node to routing table";
@ -259,9 +259,6 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
) )
}); });
} }
Ok(None) => {
error!(log, "No ENR found for MultiAddr"; "addr" => original_addr.to_string())
}
Err(e) => { Err(e) => {
error!(log, "Error getting mapping to ENR"; "multiaddr" => original_addr.to_string(), "error" => e.to_string()) error!(log, "Error getting mapping to ENR"; "multiaddr" => original_addr.to_string(), "error" => e.to_string())
} }

View File

@ -19,4 +19,4 @@ serde_yaml = "0.8.13"
types = { path = "../../consensus/types"} types = { path = "../../consensus/types"}
eth2_ssz = "0.1.2" eth2_ssz = "0.1.2"
eth2_config = { path = "../eth2_config"} eth2_config = { path = "../eth2_config"}
enr = { version = "0.3.0", features = ["ed25519"] } enr = { version = "0.4.0", features = ["ed25519", "k256"] }