Skip to content

Commit 6a609e6

Browse files
committed
Review fixes
1 parent 5dd323d commit 6a609e6

File tree

7 files changed

+280
-203
lines changed

7 files changed

+280
-203
lines changed

p2p/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub mod connection;
44
pub mod disconnection;
55
pub mod discovery;
66
pub mod identity;
7-
pub mod peer;
87
use bootstrap::P2pNetworkKadBootstrapState;
98
use channels::{
10-
rpc::P2pChannelsRpcAction, snark::P2pChannelsSnarkAction,
11-
transaction::P2pChannelsTransactionAction,
9+
best_tip::P2pChannelsBestTipAction, rpc::P2pChannelsRpcAction, snark::P2pChannelsSnarkAction,
10+
snark_job_commitment::P2pChannelsSnarkJobCommitmentAction,
11+
streaming_rpc::P2pChannelsStreamingRpcAction, transaction::P2pChannelsTransactionAction,
1212
};
1313
use connection::incoming::P2pConnectionIncomingAction;
1414
use disconnection::P2pDisconnectionAction;
@@ -27,6 +27,9 @@ pub mod identify;
2727
pub mod network;
2828
pub use self::network::*;
2929

30+
pub mod peer;
31+
pub use peer::*;
32+
3033
mod p2p_config;
3134
pub use p2p_config::*;
3235

@@ -117,5 +120,8 @@ pub trait P2pActionTrait<State>:
117120
+ From<P2pChannelsRpcAction>
118121
+ From<P2pDisconnectionAction>
119122
+ From<P2pNetworkSchedulerEffectfulAction>
123+
+ From<P2pChannelsBestTipAction>
124+
+ From<P2pChannelsSnarkJobCommitmentAction>
125+
+ From<P2pChannelsStreamingRpcAction>
120126
{
121127
}

p2p/src/network/pnet/p2p_network_pnet_actions.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ impl From<P2pNetworkPnetAction> for crate::P2pAction {
4242
}
4343

4444
impl redux::EnablingCondition<P2pState> for P2pNetworkPnetAction {
45-
fn is_enabled(&self, _state: &P2pState, _time: redux::Timestamp) -> bool {
46-
true
45+
fn is_enabled(&self, state: &P2pState, _time: redux::Timestamp) -> bool {
46+
state
47+
.network
48+
.scheduler
49+
.connection_state(self.addr())
50+
.is_some()
4751
}
4852
}

p2p/src/network/pnet/p2p_network_pnet_reducer.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use openmina_core::Substate;
1+
use openmina_core::{bug_condition, Substate};
22
use salsa_simple::XSalsa20;
33

44
use crate::{
@@ -68,6 +68,7 @@ impl P2pNetworkPnetState {
6868
.pnet;
6969

7070
let Half::Done { to_send, .. } = &pnet_state.incoming else {
71+
// this should be only if incoming state didn't receive enough data
7172
return Ok(());
7273
};
7374

@@ -93,6 +94,7 @@ impl P2pNetworkPnetState {
9394
.pnet;
9495

9596
let Half::Done { to_send, .. } = &pnet_state.outgoing else {
97+
// this should be only if we haven't set enough data to change from `Buffering` to `Done`
9698
return Ok(());
9799
};
98100

@@ -111,7 +113,21 @@ impl P2pNetworkPnetState {
111113
} => {
112114
pnet_state.outgoing.reduce(&pnet_state.shared_secret, nonce);
113115

114-
let dispatcher = state_context.into_dispatcher();
116+
let (dispatcher, state) = state_context.into_dispatcher_and_state();
117+
let scheduler_state: &P2pNetworkSchedulerState = state.substate()?;
118+
let pnet_state = &scheduler_state
119+
.connection_state(addr)
120+
.ok_or_else(|| format!("Missing connection for action: {:?}", action))?
121+
.pnet;
122+
123+
if !matches!(&pnet_state.outgoing, Half::Done { .. }) {
124+
bug_condition!(
125+
"Invalid state for `P2pNetworkPnetAction::SetupNonce`, state: {:?}",
126+
pnet_state.outgoing
127+
);
128+
return Ok(());
129+
};
130+
115131
dispatcher.push(P2pNetworkPnetEffectfulAction::SetupNonce {
116132
addr: *addr,
117133
nonce: nonce.clone(),

p2p/src/network/scheduler/p2p_network_scheduler_actions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ impl redux::EnablingCondition<P2pState> for P2pNetworkSchedulerAction {
127127
| P2pNetworkSchedulerAction::ListenerReady { .. }
128128
| P2pNetworkSchedulerAction::ListenerError { .. }
129129
| P2pNetworkSchedulerAction::SelectDone { .. }
130-
| P2pNetworkSchedulerAction::SelectError { .. }
131-
| P2pNetworkSchedulerAction::YamuxDidInit { .. } => true,
130+
| P2pNetworkSchedulerAction::SelectError { .. } => true,
132131
P2pNetworkSchedulerAction::IncomingDidAccept { addr, .. } => {
133132
addr.as_ref().map_or(false, |addr| {
134133
!state.network.scheduler.connections.contains_key(addr)
@@ -149,7 +148,8 @@ impl redux::EnablingCondition<P2pState> for P2pNetworkSchedulerAction {
149148
.get(addr)
150149
.map_or(false, |conn_state| !conn_state.incoming),
151150
P2pNetworkSchedulerAction::IncomingDataDidReceive { addr, .. }
152-
| P2pNetworkSchedulerAction::IncomingDataIsReady { addr } => {
151+
| P2pNetworkSchedulerAction::IncomingDataIsReady { addr }
152+
| P2pNetworkSchedulerAction::YamuxDidInit { addr, .. } => {
153153
state.network.scheduler.connections.contains_key(addr)
154154
}
155155
P2pNetworkSchedulerAction::Disconnect { addr, .. }

0 commit comments

Comments
 (0)