Skip to content

Commit 03d1796

Browse files
committed
Port rpc reducer
1 parent 99f3d72 commit 03d1796

File tree

15 files changed

+901
-390
lines changed

15 files changed

+901
-390
lines changed

node/common/src/service/rpc/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ use serde::{Deserialize, Serialize};
2020
use node::core::channels::{mpsc, oneshot};
2121
use node::core::requests::PendingRequests;
2222
use node::p2p::connection::P2pConnectionResponse;
23-
pub use node::rpc::{
24-
ActionStatsResponse, RespondError, RpcActionStatsGetResponse, RpcId, RpcIdType,
25-
RpcP2pConnectionOutgoingResponse, RpcScanStateSummaryGetResponse, RpcSnarkPoolGetResponse,
26-
RpcSnarkerJobCommitResponse, RpcSnarkerJobSpecResponse, RpcStateGetResponse,
27-
RpcSyncStatsGetResponse, RpcTransactionInjectSuccess,
28-
};
2923
use node::State;
3024
use node::{event_source::Event, rpc::RpcSnarkPoolJobGetResponse};
25+
pub use node::{
26+
rpc::{
27+
ActionStatsResponse, RpcActionStatsGetResponse, RpcId, RpcIdType,
28+
RpcP2pConnectionOutgoingResponse, RpcScanStateSummaryGetResponse, RpcSnarkPoolGetResponse,
29+
RpcSnarkerJobCommitResponse, RpcSnarkerJobSpecResponse, RpcStateGetResponse,
30+
RpcSyncStatsGetResponse, RpcTransactionInjectSuccess,
31+
},
32+
rpc_effectful::RespondError,
33+
};
3134

3235
use crate::NodeService;
3336

@@ -176,7 +179,7 @@ fn optimize_filtered_state(
176179
Ok((value, filter))
177180
}
178181

179-
impl node::rpc::RpcService for NodeService {
182+
impl node::rpc_effectful::RpcService for NodeService {
180183
fn respond_state_get(
181184
&mut self,
182185
rpc_id: RpcId,

node/src/action.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use crate::ledger::LedgerAction;
1212
use crate::p2p::callbacks::P2pCallbacksAction;
1313
pub use crate::p2p::P2pAction;
1414
pub use crate::rpc::RpcAction;
15+
use crate::rpc_effectful::RpcEffectfulAction;
1516
pub use crate::snark::SnarkAction;
1617
pub use crate::snark_pool::SnarkPoolAction;
1718
pub use crate::snark_pool::SnarkPoolEffectfulAction;
@@ -48,6 +49,7 @@ pub enum Action {
4849
ExternalSnarkWorker(ExternalSnarkWorkerAction),
4950
BlockProducer(BlockProducerAction),
5051
Rpc(RpcAction),
52+
RpcEffectful(RpcEffectfulAction),
5153

5254
WatchedAccounts(WatchedAccountsAction),
5355
}
@@ -95,6 +97,7 @@ impl redux::EnablingCondition<crate::State> for Action {
9597
Action::TransactionPool(a) => a.is_enabled(state, time),
9698
Action::TransactionPoolEffect(a) => a.is_enabled(state, time),
9799
Action::P2pCallbacks(a) => a.is_enabled(state, time),
100+
Action::RpcEffectful(a) => a.is_enabled(state, time),
98101
}
99102
}
100103
}

node/src/action_kind.rs

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use crate::p2p::network::{P2pNetworkAction, P2pNetworkEffectfulAction};
7373
use crate::p2p::peer::P2pPeerAction;
7474
use crate::p2p::{P2pAction, P2pEffectfulAction, P2pInitializeAction};
7575
use crate::rpc::RpcAction;
76+
use crate::rpc_effectful::RpcEffectfulAction;
7677
use crate::snark::block_verify::SnarkBlockVerifyAction;
7778
use crate::snark::block_verify_effectful::SnarkBlockVerifyEffectfulAction;
7879
use crate::snark::user_command_verify::SnarkUserCommandVerifyAction;
@@ -520,6 +521,38 @@ pub enum ActionKind {
520521
RpcTransactionPool,
521522
RpcTransactionStatusGet,
522523
RpcTransitionFrontierUserCommandsGet,
524+
RpcEffectfulActionStatsGet,
525+
RpcEffectfulBestChain,
526+
RpcEffectfulBlockProducerStatsGet,
527+
RpcEffectfulConsensusConstantsGet,
528+
RpcEffectfulDiscoveryBoostrapStats,
529+
RpcEffectfulDiscoveryRoutingTable,
530+
RpcEffectfulGlobalStateGet,
531+
RpcEffectfulHealthCheck,
532+
RpcEffectfulLedgerAccountsGetSuccess,
533+
RpcEffectfulMessageProgressGet,
534+
RpcEffectfulP2pConnectionIncomingError,
535+
RpcEffectfulP2pConnectionIncomingRespond,
536+
RpcEffectfulP2pConnectionIncomingSuccess,
537+
RpcEffectfulP2pConnectionOutgoingError,
538+
RpcEffectfulP2pConnectionOutgoingSuccess,
539+
RpcEffectfulPeersGet,
540+
RpcEffectfulReadinessCheck,
541+
RpcEffectfulScanStateSummaryGetSuccess,
542+
RpcEffectfulSnarkPoolAvailableJobsGet,
543+
RpcEffectfulSnarkPoolJobGet,
544+
RpcEffectfulSnarkerConfigGet,
545+
RpcEffectfulSnarkerJobCommit,
546+
RpcEffectfulSnarkerJobSpec,
547+
RpcEffectfulSnarkerWorkersGet,
548+
RpcEffectfulStatusGet,
549+
RpcEffectfulSyncStatsGet,
550+
RpcEffectfulTransactionInjectFailure,
551+
RpcEffectfulTransactionInjectRejected,
552+
RpcEffectfulTransactionInjectSuccess,
553+
RpcEffectfulTransactionPool,
554+
RpcEffectfulTransactionStatusGet,
555+
RpcEffectfulTransitionFrontierUserCommandsGet,
523556
SnarkBlockVerifyError,
524557
SnarkBlockVerifyFinish,
525558
SnarkBlockVerifyInit,
@@ -661,7 +694,7 @@ pub enum ActionKind {
661694
}
662695

663696
impl ActionKind {
664-
pub const COUNT: u16 = 549;
697+
pub const COUNT: u16 = 581;
665698
}
666699

667700
impl std::fmt::Display for ActionKind {
@@ -689,6 +722,7 @@ impl ActionKindGet for Action {
689722
Self::ExternalSnarkWorker(a) => a.kind(),
690723
Self::BlockProducer(a) => a.kind(),
691724
Self::Rpc(a) => a.kind(),
725+
Self::RpcEffectful(a) => a.kind(),
692726
Self::WatchedAccounts(a) => a.kind(),
693727
}
694728
}
@@ -1003,6 +1037,69 @@ impl ActionKindGet for RpcAction {
10031037
}
10041038
}
10051039

1040+
impl ActionKindGet for RpcEffectfulAction {
1041+
fn kind(&self) -> ActionKind {
1042+
match self {
1043+
Self::GlobalStateGet { .. } => ActionKind::RpcEffectfulGlobalStateGet,
1044+
Self::StatusGet { .. } => ActionKind::RpcEffectfulStatusGet,
1045+
Self::ActionStatsGet { .. } => ActionKind::RpcEffectfulActionStatsGet,
1046+
Self::SyncStatsGet { .. } => ActionKind::RpcEffectfulSyncStatsGet,
1047+
Self::BlockProducerStatsGet { .. } => ActionKind::RpcEffectfulBlockProducerStatsGet,
1048+
Self::MessageProgressGet { .. } => ActionKind::RpcEffectfulMessageProgressGet,
1049+
Self::PeersGet { .. } => ActionKind::RpcEffectfulPeersGet,
1050+
Self::P2pConnectionOutgoingError { .. } => {
1051+
ActionKind::RpcEffectfulP2pConnectionOutgoingError
1052+
}
1053+
Self::P2pConnectionOutgoingSuccess { .. } => {
1054+
ActionKind::RpcEffectfulP2pConnectionOutgoingSuccess
1055+
}
1056+
Self::P2pConnectionIncomingRespond { .. } => {
1057+
ActionKind::RpcEffectfulP2pConnectionIncomingRespond
1058+
}
1059+
Self::P2pConnectionIncomingError { .. } => {
1060+
ActionKind::RpcEffectfulP2pConnectionIncomingError
1061+
}
1062+
Self::P2pConnectionIncomingSuccess { .. } => {
1063+
ActionKind::RpcEffectfulP2pConnectionIncomingSuccess
1064+
}
1065+
Self::ScanStateSummaryGetSuccess { .. } => {
1066+
ActionKind::RpcEffectfulScanStateSummaryGetSuccess
1067+
}
1068+
Self::SnarkPoolAvailableJobsGet { .. } => {
1069+
ActionKind::RpcEffectfulSnarkPoolAvailableJobsGet
1070+
}
1071+
Self::SnarkPoolJobGet { .. } => ActionKind::RpcEffectfulSnarkPoolJobGet,
1072+
Self::SnarkerConfigGet { .. } => ActionKind::RpcEffectfulSnarkerConfigGet,
1073+
Self::SnarkerJobCommit { .. } => ActionKind::RpcEffectfulSnarkerJobCommit,
1074+
Self::SnarkerJobSpec { .. } => ActionKind::RpcEffectfulSnarkerJobSpec,
1075+
Self::SnarkerWorkersGet { .. } => ActionKind::RpcEffectfulSnarkerWorkersGet,
1076+
Self::HealthCheck { .. } => ActionKind::RpcEffectfulHealthCheck,
1077+
Self::ReadinessCheck { .. } => ActionKind::RpcEffectfulReadinessCheck,
1078+
Self::DiscoveryRoutingTable { .. } => ActionKind::RpcEffectfulDiscoveryRoutingTable,
1079+
Self::DiscoveryBoostrapStats { .. } => ActionKind::RpcEffectfulDiscoveryBoostrapStats,
1080+
Self::TransactionPool { .. } => ActionKind::RpcEffectfulTransactionPool,
1081+
Self::LedgerAccountsGetSuccess { .. } => {
1082+
ActionKind::RpcEffectfulLedgerAccountsGetSuccess
1083+
}
1084+
Self::TransactionInjectSuccess { .. } => {
1085+
ActionKind::RpcEffectfulTransactionInjectSuccess
1086+
}
1087+
Self::TransactionInjectRejected { .. } => {
1088+
ActionKind::RpcEffectfulTransactionInjectRejected
1089+
}
1090+
Self::TransactionInjectFailure { .. } => {
1091+
ActionKind::RpcEffectfulTransactionInjectFailure
1092+
}
1093+
Self::TransitionFrontierUserCommandsGet { .. } => {
1094+
ActionKind::RpcEffectfulTransitionFrontierUserCommandsGet
1095+
}
1096+
Self::BestChain { .. } => ActionKind::RpcEffectfulBestChain,
1097+
Self::ConsensusConstantsGet { .. } => ActionKind::RpcEffectfulConsensusConstantsGet,
1098+
Self::TransactionStatusGet { .. } => ActionKind::RpcEffectfulTransactionStatusGet,
1099+
}
1100+
}
1101+
}
1102+
10061103
impl ActionKindGet for WatchedAccountsAction {
10071104
fn kind(&self) -> ActionKind {
10081105
match self {

node/src/effects.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ledger::ledger_effects;
88
use crate::ledger::read::LedgerReadAction;
99
use crate::logger::logger_effects;
1010
use crate::p2p::node_p2p_effects;
11-
use crate::rpc::rpc_effects;
11+
use crate::rpc_effectful::rpc_effects;
1212
use crate::snark::snark_effects;
1313
use crate::snark_pool::candidate::SnarkPoolCandidateAction;
1414
use crate::snark_pool::{snark_pool_effects, SnarkPoolAction};
@@ -87,7 +87,10 @@ pub fn effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta) {
8787
Action::ExternalSnarkWorker(action) => {
8888
external_snark_worker_effects(store, meta.with_action(action));
8989
}
90-
Action::Rpc(action) => {
90+
Action::Rpc(_) => {
91+
// Handled by reducer
92+
}
93+
Action::RpcEffectful(action) => {
9194
rpc_effects(store, meta.with_action(action));
9295
}
9396
Action::WatchedAccounts(_) => {

node/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub mod ledger;
3838
pub mod logger;
3939
pub mod p2p;
4040
pub mod rpc;
41+
pub mod rpc_effectful;
4142
pub mod snark;
4243
pub mod snark_pool;
4344
pub mod transaction_pool;

node/src/reducer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use openmina_core::{bug_condition, error, Substate};
22
use p2p::{P2pAction, P2pEffectfulAction, P2pInitializeAction, P2pState};
33

4-
use crate::{Action, ActionWithMeta, ConsensusAction, EventSourceAction, P2p, State};
4+
use crate::{rpc::RpcState, Action, ActionWithMeta, ConsensusAction, EventSourceAction, P2p, State};
55

66
pub fn reducer(
77
state: &mut State,
@@ -87,9 +87,10 @@ pub fn reducer(
8787
Action::ExternalSnarkWorker(a) => {
8888
state.external_snark_worker.reducer(meta.with_action(a));
8989
}
90-
Action::Rpc(a) => {
91-
state.rpc.reducer(meta.with_action(a));
90+
Action::Rpc(action) => {
91+
RpcState::reducer(Substate::new(state, dispatcher), meta.with_action(action));
9292
}
93+
Action::RpcEffectful(_) => {}
9394
Action::WatchedAccounts(a) => {
9495
crate::watched_accounts::WatchedAccountsState::reducer(
9596
Substate::new(state, dispatcher),

node/src/rpc/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ pub use rpc_actions::*;
2525

2626
mod rpc_reducer;
2727

28-
mod rpc_effects;
29-
pub use rpc_effects::*;
30-
31-
mod rpc_service;
32-
pub use rpc_service::*;
33-
3428
mod rpc_impls;
3529

3630
pub use openmina_core::requests::{RpcId, RpcIdType};
@@ -128,14 +122,14 @@ impl TryFrom<RpcInjectPayment> for MinaBaseUserCommandStableV2 {
128122
}
129123
}
130124

131-
#[derive(Serialize, Deserialize, Debug, Clone)]
125+
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
132126
pub enum ActionStatsQuery {
133127
SinceStart,
134128
ForLatestBlock,
135129
ForBlockWithId(u64),
136130
}
137131

138-
#[derive(Serialize, Deserialize, Debug, Clone)]
132+
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
139133
pub struct SyncStatsQuery {
140134
pub limit: Option<usize>,
141135
}
@@ -490,8 +484,8 @@ pub struct RpcBlockProducerStats {
490484

491485
#[derive(Serialize, Deserialize, Debug, Clone)]
492486
pub struct RpcSnarkerConfig {
493-
public_key: NonZeroCurvePoint,
494-
fee: CurrencyFeeStableV1,
487+
pub public_key: NonZeroCurvePoint,
488+
pub fee: CurrencyFeeStableV1,
495489
}
496490

497491
#[derive(Serialize, Debug, Clone)]

node/src/rpc/rpc_actions.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ use super::{
1919
SyncStatsQuery,
2020
};
2121

22-
pub type RpcActionWithMeta = redux::ActionWithMeta<RpcAction>;
23-
pub type RpcActionWithMetaRef<'a> = redux::ActionWithMeta<&'a RpcAction>;
24-
2522
#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)]
2623
pub enum RpcAction {
2724
GlobalStateGet {

0 commit comments

Comments
 (0)