Skip to content

Commit a96136c

Browse files
committed
fix(node/p2p): connecting 2 rust nodes failing because rpc channel is being dropped midway
Broke with: 09a9b76#diff-11d338081a1445e76741181b44fb934e652e1bb53e7097178b4d400dc21f7420L124
1 parent 1798e44 commit a96136c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

node/native/src/rpc.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,22 @@ impl node::rpc::RpcService for NodeService {
9898
respond_p2p_connection_outgoing,
9999
RpcP2pConnectionOutgoingResponse
100100
);
101-
rpc_service_impl!(
102-
respond_p2p_connection_incoming_answer,
103-
P2pConnectionResponse
104-
);
101+
102+
fn respond_p2p_connection_incoming_answer(
103+
&mut self,
104+
rpc_id: RpcId,
105+
response: P2pConnectionResponse,
106+
) -> Result<(), RespondError> {
107+
let entry = self.rpc.pending.get(rpc_id);
108+
let chan = entry.ok_or(RespondError::UnknownRpcId)?;
109+
let chan = chan
110+
.downcast_ref::<mpsc::Sender<RpcP2pConnectionIncomingResponse>>()
111+
.ok_or(RespondError::UnexpectedResponseType)?
112+
.clone();
113+
chan.try_send(RpcP2pConnectionIncomingResponse::Answer(response))
114+
.or(Err(RespondError::RespondingFailed))?;
115+
Ok(())
116+
}
105117

106118
fn respond_p2p_connection_incoming(
107119
&mut self,

node/src/rpc/rpc_actions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,13 @@ pub struct RpcHealthCheckAction {
262262

263263
impl redux::EnablingCondition<crate::State> for RpcHealthCheckAction {}
264264

265-
266265
#[derive(Serialize, Deserialize, Debug, Clone)]
267266
pub struct RpcReadinessCheckAction {
268267
pub rpc_id: RpcId,
269268
}
270269

271270
impl redux::EnablingCondition<crate::State> for RpcReadinessCheckAction {}
272271

273-
274272
/// Finish/Cleanup rpc request.
275273
#[derive(Serialize, Deserialize, Debug, Clone)]
276274
pub struct RpcFinishAction {

0 commit comments

Comments
 (0)