Skip to content

Commit f3ac44a

Browse files
authored
Merge pull request #1124 from 0xMimir/feat/graphql-genesis-block
Added graphql genesis block endpoint
2 parents c55a74d + f19ef49 commit f3ac44a

File tree

12 files changed

+78
-22
lines changed

12 files changed

+78
-22
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ pub mod transition_frontier;
99

1010
use node::rpc::{
1111
RpcBestChainResponse, RpcBlockProducerStatsGetResponse, RpcConsensusConstantsGetResponse,
12-
RpcDiscoveryBoostrapStatsResponse, RpcDiscoveryRoutingTableResponse, RpcGetBlockResponse,
13-
RpcHealthCheckResponse, RpcHeartbeatGetResponse, RpcLedgerAccountsResponse,
14-
RpcLedgerSlimAccountsResponse, RpcMessageProgressResponse, RpcPeersGetResponse,
15-
RpcPooledUserCommandsResponse, RpcPooledZkappCommandsResponse, RpcReadinessCheckResponse,
16-
RpcRequest, RpcStateGetError, RpcStatusGetResponse, RpcTransactionInjectResponse,
17-
RpcTransactionPoolResponse, RpcTransactionStatusGetResponse,
12+
RpcDiscoveryBoostrapStatsResponse, RpcDiscoveryRoutingTableResponse, RpcGenesisBlockResponse,
13+
RpcGetBlockResponse, RpcHealthCheckResponse, RpcHeartbeatGetResponse,
14+
RpcLedgerAccountsResponse, RpcLedgerSlimAccountsResponse, RpcMessageProgressResponse,
15+
RpcPeersGetResponse, RpcPooledUserCommandsResponse, RpcPooledZkappCommandsResponse,
16+
RpcReadinessCheckResponse, RpcRequest, RpcStateGetError, RpcStatusGetResponse,
17+
RpcTransactionInjectResponse, RpcTransactionPoolResponse, RpcTransactionStatusGetResponse,
1818
RpcTransitionFrontierUserCommandsResponse,
1919
};
2020
use serde::{Deserialize, Serialize};
@@ -315,6 +315,7 @@ impl node::rpc_effectful::RpcService for NodeService {
315315
respond_pooled_zkapp_commands,
316316
RpcPooledZkappCommandsResponse
317317
);
318+
rpc_service_impl!(respond_genesis_block, RpcGenesisBlockResponse);
318319
}
319320

320321
#[cfg(test)]

node/native/src/graphql/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use mina_p2p_messages::v2::{
88
use node::{
99
account::AccountPublicKey,
1010
rpc::{
11-
AccountQuery, GetBlockQuery, PooledCommandsQuery, RpcGetBlockResponse,
12-
RpcPooledUserCommandsResponse, RpcPooledZkappCommandsResponse, RpcRequest,
13-
RpcSyncStatsGetResponse, RpcTransactionInjectResponse, RpcTransactionStatusGetResponse,
14-
SyncStatsQuery,
11+
AccountQuery, GetBlockQuery, PooledCommandsQuery, RpcGenesisBlockResponse,
12+
RpcGetBlockResponse, RpcPooledUserCommandsResponse, RpcPooledZkappCommandsResponse,
13+
RpcRequest, RpcSyncStatsGetResponse, RpcTransactionInjectResponse,
14+
RpcTransactionStatusGetResponse, SyncStatsQuery,
1515
},
1616
stats::sync::SyncKind,
1717
};
@@ -391,6 +391,20 @@ impl Query {
391391
.map(GraphQLZkapp::try_from)
392392
.collect::<Result<Vec<_>, _>>()?)
393393
}
394+
395+
async fn genesis_block(context: &Context) -> juniper::FieldResult<GraphQLBlock> {
396+
let block = context
397+
.0
398+
.oneshot_request::<RpcGenesisBlockResponse>(RpcRequest::GenesisBlockGet)
399+
.await
400+
.ok_or(Error::StateMachineEmptyResponse)?
401+
.ok_or(Error::StateMachineEmptyResponse)?;
402+
403+
Ok(GraphQLBlock::try_from(AppliedBlock {
404+
block,
405+
just_emitted_a_proof: false,
406+
})?)
407+
}
394408
}
395409

396410
async fn inject_tx<R>(

node/src/action_kind.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ pub enum ActionKind {
476476
RpcDiscoveryBoostrapStats,
477477
RpcDiscoveryRoutingTable,
478478
RpcFinish,
479+
RpcGenesisBlock,
479480
RpcGlobalStateGet,
480481
RpcHealthCheck,
481482
RpcHeartbeatGet,
@@ -524,6 +525,7 @@ pub enum ActionKind {
524525
RpcEffectfulConsensusConstantsGet,
525526
RpcEffectfulDiscoveryBoostrapStats,
526527
RpcEffectfulDiscoveryRoutingTable,
528+
RpcEffectfulGenesisBlock,
527529
RpcEffectfulGlobalStateGet,
528530
RpcEffectfulHealthCheck,
529531
RpcEffectfulHeartbeatGet,
@@ -722,7 +724,7 @@ pub enum ActionKind {
722724
}
723725

724726
impl ActionKind {
725-
pub const COUNT: u16 = 612;
727+
pub const COUNT: u16 = 614;
726728
}
727729

728730
impl std::fmt::Display for ActionKind {
@@ -1094,6 +1096,7 @@ impl ActionKindGet for RpcAction {
10941096
Self::BlockGet { .. } => ActionKind::RpcBlockGet,
10951097
Self::PooledUserCommands { .. } => ActionKind::RpcPooledUserCommands,
10961098
Self::PooledZkappCommands { .. } => ActionKind::RpcPooledZkappCommands,
1099+
Self::GenesisBlock { .. } => ActionKind::RpcGenesisBlock,
10971100
Self::Finish { .. } => ActionKind::RpcFinish,
10981101
}
10991102
}
@@ -1162,6 +1165,7 @@ impl ActionKindGet for RpcEffectfulAction {
11621165
Self::BlockGet { .. } => ActionKind::RpcEffectfulBlockGet,
11631166
Self::PooledUserCommands { .. } => ActionKind::RpcEffectfulPooledUserCommands,
11641167
Self::PooledZkappCommands { .. } => ActionKind::RpcEffectfulPooledZkappCommands,
1168+
Self::GenesisBlock { .. } => ActionKind::RpcEffectfulGenesisBlock,
11651169
}
11661170
}
11671171
}

node/src/event_source/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl std::fmt::Display for Event {
7575
RpcRequest::GetBlock(..) => write!(f, "GetBlock"),
7676
RpcRequest::PooledUserCommands(..) => write!(f, "PooledUserCommands"),
7777
RpcRequest::PooledZkappCommands(..) => write!(f, "PooledZkappCommands"),
78+
RpcRequest::GenesisBlockGet => write!(f, "GenesisBlock"),
7879
}
7980
}
8081
Self::ExternalSnarkWorker(event) => {

node/src/event_source/event_source_effects.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ pub fn event_source_effects<S: Service>(store: &mut Store<S>, action: EventSourc
397397
RpcRequest::PooledZkappCommands(query) => {
398398
store.dispatch(RpcAction::PooledZkappCommands { rpc_id, query });
399399
}
400+
RpcRequest::GenesisBlockGet => {
401+
store.dispatch(RpcAction::GenesisBlock { rpc_id });
402+
}
400403
},
401404
Event::ExternalSnarkWorker(e) => match e {
402405
ExternalSnarkWorkerEvent::Started => {

node/src/rpc/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use mina_p2p_messages::v2::{
1515
MinaBaseZkappCommandTStableV1WireStableV1, MinaTransactionTransactionStableV2,
1616
SnarkWorkerWorkerRpcsVersionedGetWorkV2TResponse, StateHash, TransactionHash,
1717
};
18-
use openmina_core::block::AppliedBlock;
18+
use openmina_core::block::{AppliedBlock, ArcBlockWithHash};
1919
use openmina_core::consensus::ConsensusConstants;
2020
use openmina_node_account::AccountPublicKey;
2121
use p2p::bootstrap::P2pNetworkKadBootstrapStats;
@@ -90,6 +90,7 @@ pub enum RpcRequest {
9090
GetBlock(GetBlockQuery),
9191
PooledUserCommands(PooledUserCommandsQuery),
9292
PooledZkappCommands(PooledZkappsCommandsQuery),
93+
GenesisBlockGet,
9394
}
9495

9596
pub type MaxLength = u32;
@@ -372,6 +373,7 @@ pub type RpcConsensusConstantsGetResponse = ConsensusConstants;
372373
pub type RpcTransactionStatusGetResponse = TransactionStatus;
373374
pub type RpcPooledUserCommandsResponse = Vec<MinaBaseSignedCommandStableV2>;
374375
pub type RpcPooledZkappCommandsResponse = Vec<MinaBaseZkappCommandTStableV1WireStableV1>;
376+
pub type RpcGenesisBlockResponse = Option<ArcBlockWithHash>;
375377

376378
#[derive(Serialize, Deserialize, Debug, Clone, strum_macros::Display)]
377379
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]

node/src/rpc/rpc_actions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ pub enum RpcAction {
219219
rpc_id: RpcId,
220220
query: PooledZkappsCommandsQuery,
221221
},
222+
GenesisBlock {
223+
rpc_id: RpcId,
224+
},
222225

223226
Finish {
224227
rpc_id: RpcId,
@@ -317,6 +320,7 @@ impl redux::EnablingCondition<crate::State> for RpcAction {
317320
RpcAction::TransactionStatusGet { .. } => true,
318321
RpcAction::PooledUserCommands { .. } => true,
319322
RpcAction::PooledZkappCommands { .. } => true,
323+
RpcAction::GenesisBlock { .. } => true,
320324
RpcAction::LedgerAccountsGetInit { .. } => {
321325
state.transition_frontier.best_tip().is_some()
322326
}

node/src/rpc/rpc_reducer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,14 @@ impl RpcState {
696696
user_commands: user_commands.into_iter().map(|(_, tx)| tx).collect(),
697697
});
698698
}
699+
RpcAction::GenesisBlock { rpc_id } => {
700+
let (dispatcher, state) = state_context.into_dispatcher_and_state();
701+
let genesis_block = state.genesis_block();
702+
dispatcher.push(RpcEffectfulAction::GenesisBlock {
703+
rpc_id: *rpc_id,
704+
genesis_block,
705+
});
706+
}
699707
RpcAction::PooledZkappCommands { rpc_id, query } => {
700708
let (dispatcher, state) = state_context.into_dispatcher_and_state();
701709

node/src/rpc_effectful/rpc_effectful_action.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
p2p::connection::P2pConnectionResponse,
44
rpc::{
55
discovery::RpcDiscoveryRoutingTable, AccountQuery, ActionStatsQuery, RpcBestChainResponse,
6-
RpcGetBlockResponse, RpcPeerInfo, RpcPooledUserCommandsResponse,
6+
RpcGenesisBlockResponse, RpcGetBlockResponse, RpcPeerInfo, RpcPooledUserCommandsResponse,
77
RpcPooledZkappCommandsResponse, RpcScanStateSummaryScanStateJob, RpcSnarkerConfig,
88
RpcTransactionInjectFailure, RpcTransactionInjectRejected, RpcTransactionInjectSuccess,
99
SyncStatsQuery,
@@ -160,6 +160,10 @@ pub enum RpcEffectfulAction {
160160
rpc_id: RpcId,
161161
zkapp_commands: RpcPooledZkappCommandsResponse,
162162
},
163+
GenesisBlock {
164+
rpc_id: RpcId,
165+
genesis_block: RpcGenesisBlockResponse,
166+
},
163167
}
164168

165169
impl redux::EnablingCondition<crate::State> for RpcEffectfulAction {

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,15 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
799799
meta.time()
800800
)
801801
}
802+
RpcEffectfulAction::GenesisBlock {
803+
rpc_id,
804+
genesis_block,
805+
} => {
806+
respond_or_log!(
807+
store.service().respond_genesis_block(rpc_id, genesis_block),
808+
meta.time()
809+
)
810+
}
802811
}
803812
}
804813

0 commit comments

Comments
 (0)