Skip to content

Commit 74386ab

Browse files
committed
Review fixes
1 parent bbcfc4d commit 74386ab

12 files changed

+96
-97
lines changed

node/src/action_kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub enum ActionKind {
214214
P2pChannelsBestTipRequestSend,
215215
P2pChannelsBestTipResponseSend,
216216
P2pChannelsEffectfulInitChannel,
217-
P2pChannelsEffectfulRequestSend,
217+
P2pChannelsEffectfulMessageSend,
218218
P2pChannelsEffectfulSignalingDiscoveryAnswerDecrypt,
219219
P2pChannelsEffectfulSignalingDiscoveryOfferEncryptAndSend,
220220
P2pChannelsEffectfulSignalingExchangeAnswerEncryptAndSend,
@@ -1255,7 +1255,7 @@ impl ActionKindGet for P2pChannelsEffectfulAction {
12551255
fn kind(&self) -> ActionKind {
12561256
match self {
12571257
Self::InitChannel { .. } => ActionKind::P2pChannelsEffectfulInitChannel,
1258-
Self::RequestSend { .. } => ActionKind::P2pChannelsEffectfulRequestSend,
1258+
Self::MessageSend { .. } => ActionKind::P2pChannelsEffectfulMessageSend,
12591259
Self::SignalingDiscoveryAnswerDecrypt { .. } => {
12601260
ActionKind::P2pChannelsEffectfulSignalingDiscoveryAnswerDecrypt
12611261
}

p2p/src/channels/best_tip/p2p_channels_best_tip_reducer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl P2pChannelsBestTipState {
8181
*local = BestTipPropagationState::Requested { time: meta.time() };
8282

8383
let dispatcher = state_context.into_dispatcher();
84-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
84+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
8585
peer_id,
8686
msg_id: MsgId::first(),
8787
msg: ChannelMsg::BestTipPropagation(BestTipPropagationChannelMsg::GetNext),
@@ -152,7 +152,7 @@ impl P2pChannelsBestTipState {
152152
let dispatcher = state_context.into_dispatcher();
153153

154154
if !is_libp2p {
155-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
155+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
156156
peer_id,
157157
msg_id: MsgId::first(),
158158
msg: ChannelMsg::BestTipPropagation(BestTipPropagationChannelMsg::BestTip(

p2p/src/channels/p2p_channels_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum P2pChannelsEffectfulAction {
4242
id: ChannelId,
4343
on_success: Callback<PeerId>,
4444
},
45-
RequestSend {
45+
MessageSend {
4646
peer_id: PeerId,
4747
msg_id: MsgId,
4848
msg: ChannelMsg,

p2p/src/channels/p2p_channels_effectful_effects.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
};
1313

1414
impl P2pChannelsEffectfulAction {
15-
pub fn effects<Store, S>(self, _meta: &ActionMeta, store: &mut Store)
15+
pub fn effects<Store, S>(self, meta: &ActionMeta, store: &mut Store)
1616
where
1717
Store: crate::P2pStore<S>,
1818
Store::Service: P2pChannelsService,
@@ -26,7 +26,7 @@ impl P2pChannelsEffectfulAction {
2626
store.service().channel_open(peer_id, id);
2727
store.dispatch_callback(on_success, peer_id);
2828
}
29-
P2pChannelsEffectfulAction::RequestSend {
29+
P2pChannelsEffectfulAction::MessageSend {
3030
peer_id,
3131
msg_id,
3232
msg,
@@ -60,21 +60,22 @@ impl P2pChannelsEffectfulAction {
6060
peer_id,
6161
pub_key,
6262
offer,
63-
} => {
64-
match store.service().encrypt(&pub_key, offer.as_ref()) {
65-
Err(_) => {
66-
// todo!("Failed to encrypt webrtc offer. Handle it.")
67-
}
68-
Ok(offer) => {
69-
let message = SignalingDiscoveryChannelMsg::DiscoveredAccept(offer);
70-
store.service().channel_send(
71-
peer_id,
72-
super::MsgId::first(),
73-
message.into(),
74-
);
75-
}
63+
} => match store.service().encrypt(&pub_key, offer.as_ref()) {
64+
Err(_) => {
65+
// TODO: handle
66+
openmina_core::error!(
67+
meta.time();
68+
summary = "Failed to encrypt webrtc offer",
69+
peer_id = peer_id.to_string()
70+
);
7671
}
77-
}
72+
Ok(offer) => {
73+
let message = SignalingDiscoveryChannelMsg::DiscoveredAccept(offer);
74+
store
75+
.service()
76+
.channel_send(peer_id, super::MsgId::first(), message.into());
77+
}
78+
},
7879
P2pChannelsEffectfulAction::SignalingExchangeOfferDecrypt {
7980
peer_id,
8081
pub_key,

p2p/src/channels/rpc/p2p_channels_rpc_reducer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ impl P2pChannelsRpcState {
3838

3939
let dispatcher = state_context.into_dispatcher();
4040

41-
// TODO(akoptelov): open a new stream, if we decide not to forcibly do that on connection established
4241
dispatcher.push(P2pChannelsEffectfulAction::InitChannel {
4342
peer_id,
4443
id: ChannelId::Rpc,
@@ -114,7 +113,7 @@ impl P2pChannelsRpcState {
114113
return Ok(());
115114
}
116115

117-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
116+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
118117
peer_id,
119118
msg_id: MsgId::first(),
120119
msg: ChannelMsg::Rpc(RpcChannelMsg::Request(id, *request.clone())),
@@ -248,7 +247,7 @@ impl P2pChannelsRpcState {
248247
return Ok(());
249248
}
250249

251-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
250+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
252251
peer_id,
253252
msg_id: MsgId::first(),
254253
msg: ChannelMsg::Rpc(RpcChannelMsg::Response(id, response.map(|v| *v))),

p2p/src/channels/signaling/discovery/p2p_channels_signaling_discovery_reducer.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use redux::ActionWithMeta;
33

44
use crate::{
55
channels::{
6-
signaling::exchange::P2pChannelsSignalingExchangeAction, ChannelId, ChannelMsg, MsgId,
6+
signaling::exchange::P2pChannelsSignalingExchangeAction, ChannelId, MsgId,
77
P2pChannelsEffectfulAction,
88
},
99
connection::{
@@ -81,11 +81,12 @@ impl P2pChannelsSignalingDiscoveryState {
8181
*local = SignalingDiscoveryState::Requested { time: meta.time() };
8282

8383
let dispatcher = state_context.into_dispatcher();
84-
let message = SignalingDiscoveryChannelMsg::GetNext;
85-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
84+
85+
let msg = SignalingDiscoveryChannelMsg::GetNext.into();
86+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
8687
peer_id,
8788
msg_id: MsgId::first(),
88-
msg: ChannelMsg::SignalingDiscovery(message),
89+
msg,
8990
});
9091
Ok(())
9192
}
@@ -121,11 +122,12 @@ impl P2pChannelsSignalingDiscoveryState {
121122
};
122123

123124
let dispatcher = state_context.into_dispatcher();
124-
let message = SignalingDiscoveryChannelMsg::Discovered { target_public_key };
125-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
125+
126+
let msg = SignalingDiscoveryChannelMsg::Discovered { target_public_key }.into();
127+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
126128
peer_id,
127129
msg_id: MsgId::first(),
128-
msg: ChannelMsg::SignalingDiscovery(message),
130+
msg,
129131
});
130132
Ok(())
131133
}
@@ -204,11 +206,12 @@ impl P2pChannelsSignalingDiscoveryState {
204206
*local = SignalingDiscoveryState::Answered { time: meta.time() };
205207

206208
let dispatcher = state_context.into_dispatcher();
207-
let message = SignalingDiscoveryChannelMsg::Answer(answer.clone());
208-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
209+
210+
let msg = SignalingDiscoveryChannelMsg::Answer(answer.clone()).into();
211+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
209212
peer_id,
210213
msg_id: MsgId::first(),
211-
msg: ChannelMsg::SignalingDiscovery(message),
214+
msg,
212215
});
213216
Ok(())
214217
}
@@ -233,11 +236,12 @@ impl P2pChannelsSignalingDiscoveryState {
233236

234237
*remote = SignalingDiscoveryState::DiscoveryRequested { time: meta.time() };
235238
let dispatcher = state_context.into_dispatcher();
236-
let message = SignalingDiscoveryChannelMsg::Discover;
237-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
239+
240+
let msg = SignalingDiscoveryChannelMsg::Discover.into();
241+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
238242
peer_id,
239243
msg_id: MsgId::first(),
240-
msg: ChannelMsg::SignalingDiscovery(message),
244+
msg,
241245
});
242246
Ok(())
243247
}
@@ -300,11 +304,12 @@ impl P2pChannelsSignalingDiscoveryState {
300304
target_public_key,
301305
};
302306
let dispatcher = state_context.into_dispatcher();
303-
let message = SignalingDiscoveryChannelMsg::DiscoveredReject;
304-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
307+
308+
let msg = SignalingDiscoveryChannelMsg::DiscoveredReject.into();
309+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
305310
peer_id,
306311
msg_id: MsgId::first(),
307-
msg: ChannelMsg::SignalingDiscovery(message),
312+
msg,
308313
});
309314
Ok(())
310315
}
@@ -342,7 +347,7 @@ impl P2pChannelsSignalingDiscoveryState {
342347
P2pChannelsEffectfulAction::SignalingDiscoveryOfferEncryptAndSend {
343348
peer_id,
344349
pub_key: target_public_key,
345-
offer: offer.clone(),
350+
offer,
346351
},
347352
);
348353
Ok(())

p2p/src/channels/signaling/exchange/p2p_channels_signaling_exchange_reducer.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use redux::ActionWithMeta;
33

44
use crate::{
55
channels::{
6-
signaling::discovery::P2pChannelsSignalingDiscoveryAction, ChannelId, ChannelMsg, MsgId,
6+
signaling::discovery::P2pChannelsSignalingDiscoveryAction, ChannelId, MsgId,
77
P2pChannelsEffectfulAction,
88
},
99
connection::{
@@ -82,11 +82,12 @@ impl P2pChannelsSignalingExchangeState {
8282
*local = SignalingExchangeState::Requested { time: meta.time() };
8383

8484
let dispatcher = state_context.into_dispatcher();
85-
let message = SignalingExchangeChannelMsg::GetNext;
86-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
85+
86+
let msg = SignalingExchangeChannelMsg::GetNext.into();
87+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
8788
peer_id,
8889
msg_id: MsgId::first(),
89-
msg: ChannelMsg::SignalingExchange(message),
90+
msg,
9091
});
9192
Ok(())
9293
}
@@ -214,14 +215,16 @@ impl P2pChannelsSignalingExchangeState {
214215
offerer_pub_key: offerer_pub_key.clone(),
215216
};
216217
let dispatcher = state_context.into_dispatcher();
217-
let message = SignalingExchangeChannelMsg::OfferToYou {
218-
offerer_pub_key: offerer_pub_key.clone(),
219-
offer: offer.clone(),
220-
};
221-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
218+
let msg = SignalingExchangeChannelMsg::OfferToYou {
219+
offerer_pub_key,
220+
offer,
221+
}
222+
.into();
223+
224+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
222225
peer_id,
223226
msg_id: MsgId::first(),
224-
msg: ChannelMsg::SignalingExchange(message),
227+
msg,
225228
});
226229
Ok(())
227230
}

p2p/src/channels/snark/p2p_channels_snark_reducer.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use openmina_core::{bug_condition, Substate};
22
use redux::ActionWithMeta;
33

44
use crate::{
5-
channels::{ChannelId, ChannelMsg, MsgId, P2pChannelsEffectfulAction},
5+
channels::{ChannelId, MsgId, P2pChannelsEffectfulAction},
66
P2pNetworkPubsubAction, P2pState,
77
};
88

@@ -78,12 +78,10 @@ impl P2pChannelsSnarkState {
7878
};
7979

8080
let dispatcher = state_context.into_dispatcher();
81-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
81+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
8282
peer_id,
8383
msg_id: MsgId::first(),
84-
msg: ChannelMsg::SnarkPropagation(SnarkPropagationChannelMsg::GetNext {
85-
limit,
86-
}),
84+
msg: SnarkPropagationChannelMsg::GetNext { limit }.into(),
8785
});
8886
Ok(())
8987
}
@@ -197,19 +195,17 @@ impl P2pChannelsSnarkState {
197195
};
198196

199197
let dispatcher = state_context.into_dispatcher();
200-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
198+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
201199
peer_id,
202200
msg_id: MsgId::first(),
203-
msg: ChannelMsg::SnarkPropagation(SnarkPropagationChannelMsg::WillSend {
204-
count,
205-
}),
201+
msg: SnarkPropagationChannelMsg::WillSend { count }.into(),
206202
});
207203

208204
for snark in snarks {
209-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
205+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
210206
peer_id,
211207
msg_id: MsgId::first(),
212-
msg: ChannelMsg::SnarkPropagation(SnarkPropagationChannelMsg::Snark(snark)),
208+
msg: SnarkPropagationChannelMsg::Snark(snark).into(),
213209
});
214210
}
215211
Ok(())

p2p/src/channels/snark_job_commitment/p2p_channels_snark_job_commitment_reducer.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use openmina_core::{bug_condition, Substate};
22
use redux::ActionWithMeta;
33

44
use crate::{
5-
channels::{ChannelId, ChannelMsg, MsgId, P2pChannelsEffectfulAction},
5+
channels::{ChannelId, MsgId, P2pChannelsEffectfulAction},
66
P2pState,
77
};
88

@@ -205,19 +205,20 @@ impl P2pChannelsSnarkJobCommitmentState {
205205
};
206206

207207
let dispatcher = state_context.into_dispatcher();
208-
let message = SnarkJobCommitmentPropagationChannelMsg::WillSend { count };
209-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
208+
let msg = SnarkJobCommitmentPropagationChannelMsg::WillSend { count }.into();
209+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
210210
peer_id,
211211
msg_id: MsgId::first(),
212-
msg: ChannelMsg::SnarkJobCommitmentPropagation(message),
212+
msg,
213213
});
214214

215215
for commitment in commitments {
216-
let message = SnarkJobCommitmentPropagationChannelMsg::Commitment(commitment);
217-
dispatcher.push(P2pChannelsEffectfulAction::RequestSend {
216+
let msg =
217+
SnarkJobCommitmentPropagationChannelMsg::Commitment(commitment).into();
218+
dispatcher.push(P2pChannelsEffectfulAction::MessageSend {
218219
peer_id,
219220
msg_id: MsgId::first(),
220-
msg: ChannelMsg::SnarkJobCommitmentPropagation(message),
221+
msg,
221222
});
222223
}
223224

0 commit comments

Comments
 (0)