fix: prevent panic during enr conversion (#10824)

This commit is contained in:
Matthias Seitz
2024-09-11 09:58:12 +02:00
committed by GitHub
parent d11bbe686b
commit b3f87ec20a
4 changed files with 17 additions and 5 deletions

View File

@ -148,9 +148,11 @@ impl Discv5 {
/// Returns the [`NodeRecord`] of the local node.
///
/// This includes the currently tracked external IP address of the node.
pub fn node_record(&self) -> NodeRecord {
///
/// Returns `None` if the local ENR does not contain the required fields.
pub fn node_record(&self) -> Option<NodeRecord> {
let enr: Enr<_> = EnrCombinedKeyWrapper(self.discv5.local_enr()).into();
(&enr).try_into().unwrap()
enr.try_into().ok()
}
/// Spawns [`discv5::Discv5`]. Returns [`discv5::Discv5`] handle in reth compatible wrapper type