Skip to content

Commit 0a63a16

Browse files
committed
Added snark pool endpoint
1 parent f3ac44a commit 0a63a16

File tree

13 files changed

+85
-7
lines changed

13 files changed

+85
-7
lines changed

core/src/snark/snark.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ impl From<TransactionSnarkWorkTStableV2> for Snark {
7777
}
7878
}
7979

80+
impl From<Snark> for TransactionSnarkWorkTStableV2 {
81+
fn from(value: Snark) -> Self {
82+
Self {
83+
fee: value.fee,
84+
proofs: value.proofs.as_ref().clone(),
85+
prover: value.snarker,
86+
}
87+
}
88+
}
89+
8090
impl From<NetworkPoolSnarkPoolDiffVersionedStableV2AddSolvedWork1> for Snark {
8191
fn from(value: NetworkPoolSnarkPoolDiffVersionedStableV2AddSolvedWork1) -> Self {
8292
Self {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl node::rpc_effectful::RpcService for NodeService {
272272
);
273273
rpc_service_impl!(respond_snark_pool_get, RpcSnarkPoolGetResponse);
274274
rpc_service_impl!(respond_snark_pool_job_get, RpcSnarkPoolJobGetResponse);
275+
rpc_service_impl!(
276+
respond_snark_pool_completed_jobs_get,
277+
RpcSnarkPoolCompletedJobsResponse
278+
);
275279
rpc_service_impl!(respond_snarker_job_commit, RpcSnarkerJobCommitResponse);
276280
rpc_service_impl!(
277281
respond_snarker_job_spec,

node/native/src/graphql/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use block::{GraphQLBlock, GraphQLUserCommands};
1+
use block::{GraphQLBlock, GraphQLSnarkJob, GraphQLUserCommands};
22
use juniper::{graphql_value, EmptySubscription, FieldError, GraphQLEnum, RootNode};
33
use ledger::Account;
44
use mina_p2p_messages::v2::{
@@ -405,6 +405,19 @@ impl Query {
405405
just_emitted_a_proof: false,
406406
})?)
407407
}
408+
409+
async fn snark_pool(context: &Context) -> juniper::FieldResult<Vec<GraphQLSnarkJob>> {
410+
let jobs: RpcSnarkPoolCompletedJobsResponse = context
411+
.0
412+
.oneshot_request(RpcRequest::SnarkPoolCompletedJobsGet)
413+
.await
414+
.ok_or(Error::StateMachineEmptyResponse)?;
415+
416+
Ok(jobs
417+
.iter()
418+
.map(GraphQLSnarkJob::from)
419+
.collect())
420+
}
408421
}
409422

410423
async fn inject_tx<R>(

node/src/action_kind.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ pub enum ActionKind {
503503
RpcScanStateSummaryGetSuccess,
504504
RpcScanStateSummaryLedgerGetInit,
505505
RpcSnarkPoolAvailableJobsGet,
506+
RpcSnarkPoolCompletedJobsGet,
506507
RpcSnarkPoolJobGet,
507508
RpcSnarkerConfigGet,
508509
RpcSnarkerJobCommit,
@@ -542,6 +543,7 @@ pub enum ActionKind {
542543
RpcEffectfulReadinessCheck,
543544
RpcEffectfulScanStateSummaryGetSuccess,
544545
RpcEffectfulSnarkPoolAvailableJobsGet,
546+
RpcEffectfulSnarkPoolCompletedJobsGet,
545547
RpcEffectfulSnarkPoolJobGet,
546548
RpcEffectfulSnarkerConfigGet,
547549
RpcEffectfulSnarkerJobCommit,
@@ -724,7 +726,7 @@ pub enum ActionKind {
724726
}
725727

726728
impl ActionKind {
727-
pub const COUNT: u16 = 614;
729+
pub const COUNT: u16 = 616;
728730
}
729731

730732
impl std::fmt::Display for ActionKind {
@@ -1070,6 +1072,7 @@ impl ActionKindGet for RpcAction {
10701072
Self::ScanStateSummaryGetSuccess { .. } => ActionKind::RpcScanStateSummaryGetSuccess,
10711073
Self::SnarkPoolAvailableJobsGet { .. } => ActionKind::RpcSnarkPoolAvailableJobsGet,
10721074
Self::SnarkPoolJobGet { .. } => ActionKind::RpcSnarkPoolJobGet,
1075+
Self::SnarkPoolCompletedJobsGet { .. } => ActionKind::RpcSnarkPoolCompletedJobsGet,
10731076
Self::SnarkerConfigGet { .. } => ActionKind::RpcSnarkerConfigGet,
10741077
Self::SnarkerJobCommit { .. } => ActionKind::RpcSnarkerJobCommit,
10751078
Self::SnarkerJobSpec { .. } => ActionKind::RpcSnarkerJobSpec,
@@ -1135,6 +1138,9 @@ impl ActionKindGet for RpcEffectfulAction {
11351138
ActionKind::RpcEffectfulSnarkPoolAvailableJobsGet
11361139
}
11371140
Self::SnarkPoolJobGet { .. } => ActionKind::RpcEffectfulSnarkPoolJobGet,
1141+
Self::SnarkPoolCompletedJobsGet { .. } => {
1142+
ActionKind::RpcEffectfulSnarkPoolCompletedJobsGet
1143+
}
11381144
Self::SnarkerConfigGet { .. } => ActionKind::RpcEffectfulSnarkerConfigGet,
11391145
Self::SnarkerJobCommit { .. } => ActionKind::RpcEffectfulSnarkerJobCommit,
11401146
Self::SnarkerJobSpec { .. } => ActionKind::RpcEffectfulSnarkerJobSpec,

node/src/event_source/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl std::fmt::Display for Event {
5151
RpcRequest::SnarkPoolJobGet { job_id } => {
5252
write!(f, "SnarkPoolJobGet, {job_id}")
5353
}
54+
RpcRequest::SnarkPoolCompletedJobsGet => write!(f, "SnarkPoolCompletedJobsGet"),
5455
RpcRequest::SnarkerConfig => write!(f, "SnarkerConfig"),
5556
RpcRequest::SnarkerJobCommit { job_id } => {
5657
write!(f, "SnarkerJobCommit, {job_id}")

node/src/event_source/event_source_effects.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
340340
RpcRequest::SnarkPoolJobGet { job_id } => {
341341
store.dispatch(RpcAction::SnarkPoolJobGet { rpc_id, job_id });
342342
}
343+
RpcRequest::SnarkPoolCompletedJobsGet => {
344+
store.dispatch(RpcAction::SnarkPoolCompletedJobsGet { rpc_id });
345+
}
343346
RpcRequest::SnarkerConfig => {
344347
store.dispatch(RpcAction::SnarkerConfigGet { rpc_id });
345348
}

node/src/rpc/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use mina_p2p_messages::v2::{
1414
MinaBaseTransactionStatusStableV2, MinaBaseUserCommandStableV2,
1515
MinaBaseZkappCommandTStableV1WireStableV1, MinaTransactionTransactionStableV2,
1616
SnarkWorkerWorkerRpcsVersionedGetWorkV2TResponse, StateHash, TransactionHash,
17+
TransactionSnarkWorkTStableV2,
1718
};
1819
use openmina_core::block::{AppliedBlock, ArcBlockWithHash};
1920
use openmina_core::consensus::ConsensusConstants;
@@ -72,6 +73,7 @@ pub enum RpcRequest {
7273
ScanStateSummaryGet(RpcScanStateSummaryGetQuery),
7374
SnarkPoolGet,
7475
SnarkPoolJobGet { job_id: SnarkJobId },
76+
SnarkPoolCompletedJobsGet,
7577
SnarkerConfig,
7678
SnarkerJobCommit { job_id: SnarkJobId },
7779
SnarkerJobSpec { job_id: SnarkJobId },
@@ -362,6 +364,7 @@ pub type RpcPeersGetResponse = Vec<RpcPeerInfo>;
362364
pub type RpcP2pConnectionOutgoingResponse = Result<(), String>;
363365
pub type RpcScanStateSummaryGetResponse = Result<RpcScanStateSummary, String>;
364366
pub type RpcSnarkPoolGetResponse = Vec<RpcSnarkPoolJobSummary>;
367+
pub type RpcSnarkPoolCompletedJobsResponse = Vec<TransactionSnarkWorkTStableV2>;
365368
pub type RpcSnarkPoolJobGetResponse = Option<RpcSnarkPoolJobFull>;
366369
pub type RpcSnarkerConfigGetResponse = Option<RpcSnarkerConfig>;
367370
pub type RpcTransactionPoolResponse = Vec<ValidCommandWithHash>;

node/src/rpc/rpc_actions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ pub enum RpcAction {
115115
job_id: SnarkWorkId,
116116
rpc_id: RpcId,
117117
},
118-
118+
SnarkPoolCompletedJobsGet {
119+
rpc_id: RpcId,
120+
},
119121
SnarkerConfigGet {
120122
rpc_id: RpcId,
121123
},
@@ -306,6 +308,7 @@ impl redux::EnablingCondition<crate::State> for RpcAction {
306308
.is_some_and(|v| v.status.is_pending()),
307309
RpcAction::SnarkPoolAvailableJobsGet { .. } => true,
308310
RpcAction::SnarkPoolJobGet { .. } => true,
311+
RpcAction::SnarkPoolCompletedJobsGet { .. } => true,
309312
RpcAction::SnarkerConfigGet { .. } => true,
310313
RpcAction::SnarkerJobCommit { .. } => true,
311314
RpcAction::SnarkerJobSpec { .. } => true,

node/src/rpc/rpc_reducer.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ledger::scan_state::transaction_logic::valid;
22
use mina_p2p_messages::v2::{
3-
MinaBaseSignedCommandStableV2, MinaBaseZkappCommandTStableV1WireStableV1, NonZeroCurvePoint,
3+
MinaBaseSignedCommandStableV2, MinaBaseZkappCommandTStableV1WireStableV1, NonZeroCurvePoint, TransactionSnarkWorkTStableV2,
44
};
55
use openmina_core::{
66
block::AppliedBlock,
@@ -331,6 +331,20 @@ impl RpcState {
331331
job_id: job_id.clone(),
332332
});
333333
}
334+
RpcAction::SnarkPoolCompletedJobsGet { rpc_id } => {
335+
let (dispatcher, state) = state_context.into_dispatcher_and_state();
336+
337+
let jobs = state
338+
.snark_pool
339+
.completed_snarks_iter()
340+
.map(|s| TransactionSnarkWorkTStableV2::from(s.clone()))
341+
.collect::<Vec<_>>();
342+
343+
dispatcher.push(RpcEffectfulAction::SnarkPoolCompletedJobsGet {
344+
rpc_id: *rpc_id,
345+
jobs,
346+
});
347+
}
334348
RpcAction::SnarkerConfigGet { rpc_id } => {
335349
let (dispatcher, state) = state_context.into_dispatcher_and_state();
336350

node/src/rpc_effectful/rpc_effectful_action.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::{
44
rpc::{
55
discovery::RpcDiscoveryRoutingTable, AccountQuery, ActionStatsQuery, RpcBestChainResponse,
66
RpcGenesisBlockResponse, RpcGetBlockResponse, RpcPeerInfo, RpcPooledUserCommandsResponse,
7-
RpcPooledZkappCommandsResponse, RpcScanStateSummaryScanStateJob, RpcSnarkerConfig,
8-
RpcTransactionInjectFailure, RpcTransactionInjectRejected, RpcTransactionInjectSuccess,
9-
SyncStatsQuery,
7+
RpcPooledZkappCommandsResponse, RpcScanStateSummaryScanStateJob,
8+
RpcSnarkPoolCompletedJobsResponse, RpcSnarkerConfig, RpcTransactionInjectFailure,
9+
RpcTransactionInjectRejected, RpcTransactionInjectSuccess, SyncStatsQuery,
1010
},
1111
};
1212
use ledger::{
@@ -80,6 +80,10 @@ pub enum RpcEffectfulAction {
8080
job_id: SnarkWorkId,
8181
rpc_id: RpcId,
8282
},
83+
SnarkPoolCompletedJobsGet {
84+
rpc_id: RpcId,
85+
jobs: RpcSnarkPoolCompletedJobsResponse,
86+
},
8387
SnarkerConfigGet {
8488
rpc_id: RpcId,
8589
config: Option<RpcSnarkerConfig>,

0 commit comments

Comments
 (0)