Skip to content

Commit 8f50185

Browse files
committed
refactor(external_snark_worker): Combine all action types of the external_snark_worker module into the parent action type
1 parent 2bf5ca3 commit 8f50185

File tree

7 files changed

+198
-317
lines changed

7 files changed

+198
-317
lines changed

node/src/effects.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use redux::ActionMeta;
33
use crate::block_producer::{block_producer_effects, BlockProducerWonSlotProduceInitAction};
44
use crate::consensus::consensus_effects;
55
use crate::event_source::event_source_effects;
6-
use crate::external_snark_worker::{
7-
external_snark_worker_effects, ExternalSnarkWorkerStartAction,
8-
ExternalSnarkWorkerStartTimeoutAction, ExternalSnarkWorkerWorkTimeoutAction,
9-
};
6+
use crate::external_snark_worker::external_snark_worker_effects;
107
use crate::logger::logger_effects;
118
use crate::p2p::channels::rpc::{
129
P2pChannelsRpcRequestSendAction, P2pChannelsRpcTimeoutAction, P2pRpcKind, P2pRpcRequest,
@@ -28,7 +25,7 @@ use crate::snark_pool::{
2825
use crate::transition_frontier::sync::TransitionFrontierSyncBlocksNextApplyInitAction;
2926
use crate::transition_frontier::transition_frontier_effects;
3027
use crate::watched_accounts::watched_accounts_effects;
31-
use crate::{Action, ActionWithMeta, Service, Store};
28+
use crate::{Action, ActionWithMeta, ExternalSnarkWorkerAction, Service, Store};
3229

3330
pub const MAX_PEER_PENDING_SNARKS: usize = 32;
3431

@@ -47,7 +44,7 @@ pub fn effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta) {
4744
// effect execution should be as light as possible.
4845
Action::CheckTimeouts(_) => {
4946
// TODO(binier): create init action and dispatch this there.
50-
store.dispatch(ExternalSnarkWorkerStartAction {});
47+
store.dispatch(ExternalSnarkWorkerAction::Start);
5148

5249
p2p_connection_timeouts(store, &meta);
5350

@@ -78,8 +75,8 @@ pub fn effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta) {
7875
// TODO(binier): remove once ledger communication is async.
7976
store.dispatch(TransitionFrontierSyncBlocksNextApplyInitAction {});
8077

81-
store.dispatch(ExternalSnarkWorkerStartTimeoutAction { now: meta.time() });
82-
store.dispatch(ExternalSnarkWorkerWorkTimeoutAction { now: meta.time() });
78+
store.dispatch(ExternalSnarkWorkerAction::StartTimeout { now: meta.time() });
79+
store.dispatch(ExternalSnarkWorkerAction::WorkTimeout { now: meta.time() });
8380

8481
store.dispatch(BlockProducerWonSlotProduceInitAction {});
8582
}

node/src/event_source/event_source_effects.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ use p2p::P2pListenEvent;
55

66
use crate::action::CheckTimeoutsAction;
77
use crate::block_producer::vrf_evaluator::BlockProducerVrfEvaluatorEvaluationSuccessAction;
8-
use crate::external_snark_worker::{
9-
ExternalSnarkWorkerErrorAction, ExternalSnarkWorkerEvent, ExternalSnarkWorkerKilledAction,
10-
ExternalSnarkWorkerStartedAction, ExternalSnarkWorkerWorkCancelledAction,
11-
ExternalSnarkWorkerWorkErrorAction, ExternalSnarkWorkerWorkResultAction,
12-
};
8+
use crate::external_snark_worker::ExternalSnarkWorkerEvent;
139
use crate::p2p::channels::best_tip::P2pChannelsBestTipReadyAction;
1410
use crate::p2p::channels::rpc::P2pChannelsRpcReadyAction;
1511
use crate::p2p::channels::snark::{
@@ -48,7 +44,7 @@ use crate::rpc::{
4844
use crate::snark::block_verify::SnarkBlockVerifyAction;
4945
use crate::snark::work_verify::SnarkWorkVerifyAction;
5046
use crate::snark::SnarkEvent;
51-
use crate::{Service, Store};
47+
use crate::{ExternalSnarkWorkerAction, Service, Store};
5248

5349
use super::{
5450
Event, EventSourceAction, EventSourceActionWithMeta, EventSourceNewEventAction,
@@ -304,22 +300,22 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
304300
},
305301
Event::ExternalSnarkWorker(e) => match e {
306302
ExternalSnarkWorkerEvent::Started => {
307-
store.dispatch(ExternalSnarkWorkerStartedAction {});
303+
store.dispatch(ExternalSnarkWorkerAction::Started);
308304
}
309305
ExternalSnarkWorkerEvent::Killed => {
310-
store.dispatch(ExternalSnarkWorkerKilledAction {});
306+
store.dispatch(ExternalSnarkWorkerAction::Killed);
311307
}
312308
ExternalSnarkWorkerEvent::WorkResult(result) => {
313-
store.dispatch(ExternalSnarkWorkerWorkResultAction { result });
309+
store.dispatch(ExternalSnarkWorkerAction::WorkResult { result });
314310
}
315311
ExternalSnarkWorkerEvent::WorkError(error) => {
316-
store.dispatch(ExternalSnarkWorkerWorkErrorAction { error });
312+
store.dispatch(ExternalSnarkWorkerAction::WorkError { error });
317313
}
318314
ExternalSnarkWorkerEvent::WorkCancelled => {
319-
store.dispatch(ExternalSnarkWorkerWorkCancelledAction {});
315+
store.dispatch(ExternalSnarkWorkerAction::WorkCancelled);
320316
}
321317
ExternalSnarkWorkerEvent::Error(error) => {
322-
store.dispatch(ExternalSnarkWorkerErrorAction {
318+
store.dispatch(ExternalSnarkWorkerAction::Error {
323319
error,
324320
permanent: false,
325321
});

0 commit comments

Comments
 (0)