Skip to content

Commit 97e7eed

Browse files
authored
Merge pull request #944 from 0xMimir/feat/add-remaining-callbacks
Ported remaining callbacks in p2p layer and snark layer
2 parents f04d63e + fde0905 commit 97e7eed

File tree

36 files changed

+609
-443
lines changed

36 files changed

+609
-443
lines changed

node/src/action_kind.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ pub enum ActionKind {
351351
P2pNetworkIdentifyStreamNew,
352352
P2pNetworkIdentifyStreamPrune,
353353
P2pNetworkIdentifyStreamRemoteClose,
354-
P2pNetworkIdentifyStreamEffectfulSendIdentify,
354+
P2pNetworkIdentifyStreamSendIdentify,
355+
P2pNetworkIdentifyStreamEffectfulGetListenAddresses,
355356
P2pNetworkKadBootstrapAppendRequest,
356357
P2pNetworkKadBootstrapCreateRequests,
357358
P2pNetworkKadBootstrapFinalizeRequests,
@@ -435,20 +436,17 @@ pub enum ActionKind {
435436
P2pNetworkSchedulerOutgoingDidConnect,
436437
P2pNetworkSchedulerPrune,
437438
P2pNetworkSchedulerPruneStream,
438-
P2pNetworkSchedulerPruneStreams,
439439
P2pNetworkSchedulerSelectDone,
440440
P2pNetworkSchedulerSelectError,
441441
P2pNetworkSchedulerYamuxDidInit,
442442
P2pNetworkSchedulerEffectfulDisconnect,
443-
P2pNetworkSchedulerEffectfulError,
444443
P2pNetworkSchedulerEffectfulIncomingConnectionIsReady,
445444
P2pNetworkSchedulerEffectfulIncomingDataIsReady,
446445
P2pNetworkSchedulerEffectfulIncomingDidAccept,
447446
P2pNetworkSchedulerEffectfulInterfaceDetected,
448447
P2pNetworkSchedulerEffectfulNoiseSelectDone,
449448
P2pNetworkSchedulerEffectfulOutgoingConnect,
450449
P2pNetworkSchedulerEffectfulOutgoingDidConnect,
451-
P2pNetworkSchedulerEffectfulSelectError,
452450
P2pNetworkSelectIncomingData,
453451
P2pNetworkSelectIncomingDataAuth,
454452
P2pNetworkSelectIncomingDataMux,
@@ -688,7 +686,7 @@ pub enum ActionKind {
688686
}
689687

690688
impl ActionKind {
691-
pub const COUNT: u16 = 579;
689+
pub const COUNT: u16 = 577;
692690
}
693691

694692
impl std::fmt::Display for ActionKind {
@@ -1804,7 +1802,6 @@ impl ActionKindGet for P2pNetworkSchedulerAction {
18041802
Self::Error { .. } => ActionKind::P2pNetworkSchedulerError,
18051803
Self::Disconnected { .. } => ActionKind::P2pNetworkSchedulerDisconnected,
18061804
Self::Prune { .. } => ActionKind::P2pNetworkSchedulerPrune,
1807-
Self::PruneStreams { .. } => ActionKind::P2pNetworkSchedulerPruneStreams,
18081805
Self::PruneStream { .. } => ActionKind::P2pNetworkSchedulerPruneStream,
18091806
}
18101807
}
@@ -1925,7 +1922,7 @@ impl ActionKindGet for P2pNetworkRpcAction {
19251922
impl ActionKindGet for P2pConnectionOutgoingEffectfulAction {
19261923
fn kind(&self) -> ActionKind {
19271924
match self {
1928-
Self::RandomInit => ActionKind::P2pConnectionOutgoingEffectfulRandomInit,
1925+
Self::RandomInit { .. } => ActionKind::P2pConnectionOutgoingEffectfulRandomInit,
19291926
Self::Init { .. } => ActionKind::P2pConnectionOutgoingEffectfulInit,
19301927
Self::OfferSend { .. } => ActionKind::P2pConnectionOutgoingEffectfulOfferSend,
19311928
Self::AnswerSet { .. } => ActionKind::P2pConnectionOutgoingEffectfulAnswerSet,
@@ -1973,9 +1970,7 @@ impl ActionKindGet for P2pNetworkSchedulerEffectfulAction {
19731970
ActionKind::P2pNetworkSchedulerEffectfulIncomingDataIsReady
19741971
}
19751972
Self::NoiseSelectDone { .. } => ActionKind::P2pNetworkSchedulerEffectfulNoiseSelectDone,
1976-
Self::SelectError { .. } => ActionKind::P2pNetworkSchedulerEffectfulSelectError,
19771973
Self::Disconnect { .. } => ActionKind::P2pNetworkSchedulerEffectfulDisconnect,
1978-
Self::Error { .. } => ActionKind::P2pNetworkSchedulerEffectfulError,
19791974
}
19801975
}
19811976
}
@@ -2034,6 +2029,7 @@ impl ActionKindGet for P2pNetworkIdentifyStreamAction {
20342029
Self::Close { .. } => ActionKind::P2pNetworkIdentifyStreamClose,
20352030
Self::RemoteClose { .. } => ActionKind::P2pNetworkIdentifyStreamRemoteClose,
20362031
Self::Prune { .. } => ActionKind::P2pNetworkIdentifyStreamPrune,
2032+
Self::SendIdentify { .. } => ActionKind::P2pNetworkIdentifyStreamSendIdentify,
20372033
}
20382034
}
20392035
}
@@ -2102,7 +2098,9 @@ impl ActionKindGet for P2pNetworkKademliaStreamAction {
21022098
impl ActionKindGet for P2pNetworkIdentifyStreamEffectfulAction {
21032099
fn kind(&self) -> ActionKind {
21042100
match self {
2105-
Self::SendIdentify { .. } => ActionKind::P2pNetworkIdentifyStreamEffectfulSendIdentify,
2101+
Self::GetListenAddresses { .. } => {
2102+
ActionKind::P2pNetworkIdentifyStreamEffectfulGetListenAddresses
2103+
}
21062104
}
21072105
}
21082106
}

node/src/rpc/rpc_reducer.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use openmina_core::{
22
block::AppliedBlock,
33
bug_condition,
4-
requests::{RequestId, RpcIdType},
4+
requests::{RequestId, RpcId, RpcIdType},
55
};
66
use p2p::{
77
connection::{incoming::P2pConnectionIncomingAction, outgoing::P2pConnectionOutgoingAction},
88
webrtc::P2pConnectionResponse,
9+
PeerId,
910
};
1011
use redux::ActionWithMeta;
1112

@@ -79,11 +80,20 @@ impl RpcState {
7980
state.requests.insert(*rpc_id, rpc_state);
8081

8182
let dispatcher = state_context.into_dispatcher();
83+
8284
dispatcher.push(P2pConnectionOutgoingAction::Init {
8385
opts: opts.clone(),
8486
rpc_id: Some(*rpc_id),
87+
on_success: Some(redux::callback!(
88+
on_p2p_connection_outgoing_rpc_connection_success((peer_id: PeerId, rpc_id: Option<RpcId>)) -> crate::Action {
89+
let Some(rpc_id) = rpc_id else {
90+
unreachable!("RPC ID not provided");
91+
};
92+
93+
RpcAction::P2pConnectionOutgoingPending{ rpc_id }
94+
}
95+
)),
8596
});
86-
dispatcher.push(RpcAction::P2pConnectionOutgoingPending { rpc_id: *rpc_id });
8797
}
8898
RpcAction::P2pConnectionOutgoingPending { rpc_id } => {
8999
let Some(rpc) = state.requests.get_mut(rpc_id) else {

node/src/snark/snark_effects.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use snark::work_verify::SnarkWorkVerifyAction;
2-
3-
use crate::{snark_pool::candidate::SnarkPoolCandidateAction, Service, Store};
1+
use crate::{Service, Store};
42

53
use super::{SnarkAction, SnarkActionWithMeta};
64

@@ -12,35 +10,7 @@ pub fn snark_effects<S: Service>(store: &mut Store<S>, action: SnarkActionWithMe
1210
SnarkAction::BlockVerifyEffect(a) => {
1311
a.effects(&meta, store);
1412
}
15-
SnarkAction::WorkVerify(a) => match a {
16-
// TODO(tizoc): handle this logic with the on_error callback passed on the Init action
17-
SnarkWorkVerifyAction::Error { req_id, .. } => {
18-
let req = store.state().snark.work_verify.jobs.get(req_id);
19-
let Some(req) = req else { return };
20-
let sender = req.sender().parse().unwrap();
21-
22-
store.dispatch(SnarkPoolCandidateAction::WorkVerifyError {
23-
peer_id: sender,
24-
verify_id: req_id,
25-
});
26-
}
27-
// TODO(tizoc): handle this logic with the on_success callback passed on the Init action
28-
SnarkWorkVerifyAction::Success { req_id } => {
29-
let req = store.state().snark.work_verify.jobs.get(req_id);
30-
let Some(req) = req else { return };
31-
let sender = req.sender().parse().unwrap();
32-
let batch = req.batch().to_vec();
33-
34-
store.dispatch(SnarkPoolCandidateAction::WorkVerifySuccess {
35-
peer_id: sender,
36-
verify_id: req_id,
37-
batch,
38-
});
39-
}
40-
SnarkWorkVerifyAction::Init { .. } => {}
41-
SnarkWorkVerifyAction::Pending { .. } => {}
42-
SnarkWorkVerifyAction::Finish { .. } => {}
43-
},
13+
SnarkAction::WorkVerify(_) => {}
4414
SnarkAction::WorkVerifyEffect(a) => {
4515
a.effects(&meta, store);
4616
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ impl P2pChannelsSignalingDiscoveryState {
269269
},
270270
},
271271
rpc_id: None,
272+
on_success: None,
272273
};
273274
let accepted = redux::EnablingCondition::is_enabled(&action, state, meta.time());
274275
if accepted {

p2p/src/connection/outgoing/p2p_connection_outgoing_actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use openmina_core::ActionEvent;
2+
use redux::Callback;
23
use serde::{Deserialize, Serialize};
34

45
use openmina_core::requests::RpcId;
@@ -18,6 +19,7 @@ pub enum P2pConnectionOutgoingAction {
1819
Init {
1920
opts: P2pConnectionOutgoingInitOpts,
2021
rpc_id: Option<RpcId>,
22+
on_success: Option<Callback<(PeerId, Option<RpcId>)>>,
2123
},
2224
/// Reconnect to an existing peer.
2325
// TODO: rename `Init` and `Reconnect` to `New` and `Connect` or something

0 commit comments

Comments
 (0)