Upgrade to discv5 0.7.0 (#6385)

* Upgrade to discv5 v0.7.0
This commit is contained in:
Age Manning
2024-09-12 10:26:20 +10:00
committed by GitHub
parent a94b12b4d5
commit e5a40fb73b
7 changed files with 84 additions and 235 deletions

View File

@@ -45,22 +45,24 @@ pub trait Eth2Enr {
impl Eth2Enr for Enr {
fn attestation_bitfield<E: EthSpec>(&self) -> Result<EnrAttestationBitfield<E>, &'static str> {
let bitfield_bytes = self
.get(ATTESTATION_BITFIELD_ENR_KEY)
.ok_or("ENR attestation bitfield non-existent")?;
let bitfield_bytes: Vec<u8> = self
.get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
.ok_or("ENR attestation bitfield non-existent")?
.map_err(|_| "Invalid RLP Encoding")?;
BitVector::<E::SubnetBitfieldLength>::from_ssz_bytes(bitfield_bytes)
BitVector::<E::SubnetBitfieldLength>::from_ssz_bytes(&bitfield_bytes)
.map_err(|_| "Could not decode the ENR attnets bitfield")
}
fn sync_committee_bitfield<E: EthSpec>(
&self,
) -> Result<EnrSyncCommitteeBitfield<E>, &'static str> {
let bitfield_bytes = self
.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
.ok_or("ENR sync committee bitfield non-existent")?;
let bitfield_bytes: Vec<u8> = self
.get_decodable(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
.ok_or("ENR sync committee bitfield non-existent")?
.map_err(|_| "Invalid RLP Encoding")?;
BitVector::<E::SyncCommitteeSubnetCount>::from_ssz_bytes(bitfield_bytes)
BitVector::<E::SyncCommitteeSubnetCount>::from_ssz_bytes(&bitfield_bytes)
.map_err(|_| "Could not decode the ENR syncnets bitfield")
}
@@ -78,9 +80,12 @@ impl Eth2Enr for Enr {
}
fn eth2(&self) -> Result<EnrForkId, &'static str> {
let eth2_bytes = self.get(ETH2_ENR_KEY).ok_or("ENR has no eth2 field")?;
let eth2_bytes: Vec<u8> = self
.get_decodable(ETH2_ENR_KEY)
.ok_or("ENR has no eth2 field")?
.map_err(|_| "Invalid RLP Encoding")?;
EnrForkId::from_ssz_bytes(eth2_bytes).map_err(|_| "Could not decode EnrForkId")
EnrForkId::from_ssz_bytes(&eth2_bytes).map_err(|_| "Could not decode EnrForkId")
}
}
@@ -270,16 +275,16 @@ fn compare_enr(local_enr: &Enr, disk_enr: &Enr) -> bool {
&& local_enr.quic4() == disk_enr.quic4()
&& local_enr.quic6() == disk_enr.quic6()
// must match on the same fork
&& local_enr.get(ETH2_ENR_KEY) == disk_enr.get(ETH2_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(ETH2_ENR_KEY) == disk_enr.get_decodable(ETH2_ENR_KEY)
// take preference over disk udp port if one is not specified
&& (local_enr.udp4().is_none() || local_enr.udp4() == disk_enr.udp4())
&& (local_enr.udp6().is_none() || local_enr.udp6() == disk_enr.udp6())
// we need the ATTESTATION_BITFIELD_ENR_KEY and SYNC_COMMITTEE_BITFIELD_ENR_KEY and
// PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY key to match, otherwise we use a new ENR. This will
// likely only be true for non-validating nodes.
&& local_enr.get(ATTESTATION_BITFIELD_ENR_KEY) == disk_enr.get(ATTESTATION_BITFIELD_ENR_KEY)
&& local_enr.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY) == disk_enr.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
&& local_enr.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY) == disk_enr.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(ATTESTATION_BITFIELD_ENR_KEY) == disk_enr.get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(SYNC_COMMITTEE_BITFIELD_ENR_KEY) == disk_enr.get_decodable(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY) == disk_enr.get_decodable(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
}
/// Loads enr from the given directory

View File

@@ -1072,10 +1072,7 @@ impl<E: EthSpec> NetworkBehaviour for Discovery<E> {
// NOTE: We assume libp2p itself can keep track of IP changes and we do
// not inform it about IP changes found via discovery.
}
discv5::Event::EnrAdded { .. }
| discv5::Event::TalkRequest(_)
| discv5::Event::NodeInserted { .. }
| discv5::Event::SessionEstablished { .. } => {} // Ignore all other discv5 server events
_ => {} // Ignore all other discv5 server events
}
}
}