Skip to content

Commit

Permalink
Mismatched handshake (#12690)
Browse files Browse the repository at this point in the history
The detailed description of the problem is available at #12364
  • Loading branch information
mkamonMdt authored Jan 11, 2025
1 parent 22bc169 commit cbef830
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 5 additions & 3 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,12 @@ impl PeerActor {
async fn receive_routed_message(
clock: &time::Clock,
network_state: &Arc<NetworkState>,
peer_id: PeerId,
msg_author: PeerId,
prev_hop: PeerId,
msg_hash: CryptoHash,
body: RoutedMessageBody,
) -> Result<Option<RoutedMessageBody>, ReasonForBan> {
Ok(network_state.receive_routed_message(clock, peer_id, msg_hash, body).await)
Ok(network_state.receive_routed_message(clock, msg_author, prev_hop, msg_hash, body).await)
}

fn receive_message(
Expand Down Expand Up @@ -1029,7 +1030,8 @@ impl PeerActor {
Self::receive_routed_message(
&clock,
&network_state,
peer_id,
msg.msg.author,
peer_id.clone(),
msg_hash,
msg.msg.body,
)
Expand Down
25 changes: 19 additions & 6 deletions chain/network/src/peer_manager/network_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,21 @@ impl NetworkState {
debug_assert!(msg.allow_sending_to_self());
let this = self.clone();
let clock = clock.clone();
let peer_id = self.config.node_id();
let my_peer_id = self.config.node_id();
let msg = self.sign_message(
&clock,
RawRoutedMessage { target: PeerIdOrHash::PeerId(peer_id.clone()), body: msg },
RawRoutedMessage { target: PeerIdOrHash::PeerId(my_peer_id.clone()), body: msg },
);
actix::spawn(async move {
this.receive_routed_message(&clock, peer_id, msg.hash(), msg.msg.body).await;
let hash = msg.hash();
this.receive_routed_message(
&clock,
msg.msg.author.clone(),
my_peer_id,
hash,
msg.msg.body,
)
.await;
});
return true;
}
Expand Down Expand Up @@ -701,7 +709,8 @@ impl NetworkState {
pub async fn receive_routed_message(
self: &Arc<Self>,
clock: &time::Clock,
peer_id: PeerId,
msg_author: PeerId,
prev_hop: PeerId,
msg_hash: CryptoHash,
body: RoutedMessageBody,
) -> Option<RoutedMessageBody> {
Expand All @@ -718,7 +727,7 @@ impl NetworkState {
None
}
RoutedMessageBody::BlockApproval(approval) => {
self.client.send_async(BlockApproval(approval, peer_id)).await.ok();
self.client.send_async(BlockApproval(approval, prev_hop)).await.ok();
None
}
RoutedMessageBody::ForwardTx(transaction) => {
Expand Down Expand Up @@ -779,7 +788,11 @@ impl NetworkState {
}
RoutedMessageBody::StatePartRequest(request) => {
self.peer_manager_adapter.send(Tier3Request {
peer_info: PeerInfo { id: peer_id, addr: Some(request.addr), account_id: None },
peer_info: PeerInfo {
id: msg_author,
addr: Some(request.addr),
account_id: None,
},
body: Tier3RequestBody::StatePart(StatePartRequestBody {
shard_id: request.shard_id,
sync_hash: request.sync_hash,
Expand Down

0 comments on commit cbef830

Please sign in to comment.