Skip to content

Commit

Permalink
simplify code (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
getong authored Jan 21, 2025
1 parent e3195b5 commit 8bd948f
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/mod_libp2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,20 @@ impl EventLoop {
if let Ok(controller_address) =
Self::libp2p_publickey_to_eth_address(&public_key).await
{
if controller_address == METRICS_ADDRESS {
if controller_address == METRICS_ADDRESS
|| Self::is_controller_valid(&controller_address).await.is_ok()
{
indexer_cache.cache_set(peer_id, ());
drop(indexer_cache);
for addr in listen_addrs {
self.swarm.behaviour_mut().kad.add_address(&peer_id, addr);
}
} else if let Ok(()) = Self::is_controller_valid(&controller_address).await {
indexer_cache.cache_set(peer_id, ());
drop(indexer_cache);
for addr in listen_addrs {
self.swarm.behaviour_mut().kad.add_address(&peer_id, addr);
}
} else {
error!(
"peer_id {:?} not found, controller_address is {:?}",
peer_id, controller_address
);
self.swarm.close_connection(connection_id);
}
} else {
error!("peer_id {:?} not found, controller_address cannot be converted into ethereum address", peer_id);
error!(
"peer_id {:?} is not valid, cannot convert into ethereum address",
peer_id,
);
self.swarm.close_connection(connection_id);
}
}
Expand Down

0 comments on commit 8bd948f

Please sign in to comment.