Skip to content

Commit

Permalink
fix: force peer identity signature (#4387)
Browse files Browse the repository at this point in the history
Description
---
Forces peer identity signature.

Peers will now not be updated unless they supply a valid signature. This was added in during the previous testnet where not all peers had this. 

Fixes: #4383
  • Loading branch information
SWvheerden committed Aug 4, 2022
1 parent ad11ec5 commit c901dbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions comms/core/src/connection_manager/common.rs
Expand Up @@ -116,9 +116,10 @@ pub(super) async fn validate_and_add_peer_from_peer_identity(
peer.features = PeerFeatures::from_bits_truncate(peer_identity.features);
peer.supported_protocols = supported_protocols.clone();
peer.user_agent = peer_identity.user_agent;
if let Some(identity_signature) = peer_identity.identity_signature {
add_valid_identity_signature_to_peer(&mut peer, identity_signature)?;
}
let identity_sig = peer_identity
.identity_signature
.ok_or(ConnectionManagerError::PeerIdentityNoSignature)?;
add_valid_identity_signature_to_peer(&mut peer, identity_sig)?;
peer
},
None => {
Expand All @@ -137,10 +138,10 @@ pub(super) async fn validate_and_add_peer_from_peer_identity(
peer_identity.user_agent,
);
new_peer.connection_stats.set_connection_success();
// TODO(testnetreset): Require an identity signature once majority nodes are upgraded
if let Some(identity_sig) = peer_identity.identity_signature {
add_valid_identity_signature_to_peer(&mut new_peer, identity_sig)?;
}
let identity_sig = peer_identity
.identity_signature
.ok_or(ConnectionManagerError::PeerIdentityNoSignature)?;
add_valid_identity_signature_to_peer(&mut new_peer, identity_sig)?;
if let Some(addr) = dialed_addr {
new_peer.addresses.mark_last_seen_now(addr);
}
Expand Down
2 changes: 2 additions & 0 deletions comms/core/src/connection_manager/error.rs
Expand Up @@ -85,6 +85,8 @@ pub enum ConnectionManagerError {
ListenerOneshotCancelled,
#[error("Peer sent invalid identity signature")]
PeerIdentityInvalidSignature,
#[error("Peer did not provide an identity signature")]
PeerIdentityNoSignature,
#[error("Peer did not provide any public addresses")]
PeerIdentityNoAddresses,
}
Expand Down

0 comments on commit c901dbc

Please sign in to comment.