Skip to content

Commit 46634ed

Browse files
author
Adrian Nagy
committed
feat(graphql): expand daemonStatus
1 parent 48228e2 commit 46634ed

File tree

6 files changed

+105
-12
lines changed

6 files changed

+105
-12
lines changed

node/native/src/graphql/constants.rs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use juniper::GraphQLObject;
22
use node::{
33
rpc::{
4-
ConsensusTimeQuery, PeerConnectionStatus, RpcConsensusTimeGetResponse, RpcPeerInfo,
5-
RpcRequest,
4+
ConsensusTimeQuery, PeerConnectionStatus, RpcConsensusTimeGetResponse,
5+
RpcNodeStatusNetworkInfo, RpcPeerInfo, RpcRequest,
66
},
77
BuildEnv,
88
};
@@ -156,7 +156,6 @@ impl GraphQLDaemonStatus {
156156
}
157157
}
158158

159-
// highestUnvalidatedBlockLengthReceived
160159
async fn highest_unvalidated_block_length_received(
161160
&self,
162161
context: &Context,
@@ -177,7 +176,6 @@ impl GraphQLDaemonStatus {
177176
}))
178177
}
179178

180-
//highestBlockLengthReceived
181179
async fn highest_block_length_received(
182180
&self,
183181
context: &Context,
@@ -197,6 +195,62 @@ impl GraphQLDaemonStatus {
197195
})
198196
}))
199197
}
198+
199+
async fn addrs_and_ports(
200+
&self,
201+
context: &Context,
202+
) -> juniper::FieldResult<GraphQLAddrsAndPorts> {
203+
let status = context.get_or_fetch_status().await;
204+
205+
match status {
206+
Some(status) => Ok(GraphQLAddrsAndPorts::from(&status.network_info)),
207+
None => Ok(Default::default()),
208+
}
209+
}
210+
211+
async fn block_production_keys(&self, context: &Context) -> juniper::FieldResult<Vec<String>> {
212+
let status = context.get_or_fetch_status().await;
213+
Ok(status.map_or(vec![], |status| {
214+
status
215+
.block_producer
216+
.map_or(vec![], |key| vec![key.to_string()])
217+
}))
218+
}
219+
220+
async fn coinbase_receiver(&self, context: &Context) -> juniper::FieldResult<Option<String>> {
221+
let status = context.get_or_fetch_status().await;
222+
Ok(status.and_then(|status| status.coinbase_receiver.map(|key| key.to_string())))
223+
}
224+
}
225+
226+
#[derive(GraphQLObject, Clone, Debug)]
227+
pub struct GraphQLAddrsAndPorts {
228+
pub bind_ip: String,
229+
pub external_ip: Option<String>,
230+
pub client_port: Option<i32>,
231+
pub libp2p_port: Option<i32>,
232+
}
233+
234+
impl Default for GraphQLAddrsAndPorts {
235+
fn default() -> Self {
236+
Self {
237+
bind_ip: "0.0.0.0".to_string(),
238+
external_ip: None,
239+
client_port: None,
240+
libp2p_port: None,
241+
}
242+
}
243+
}
244+
245+
impl From<&RpcNodeStatusNetworkInfo> for GraphQLAddrsAndPorts {
246+
fn from(network_info: &RpcNodeStatusNetworkInfo) -> Self {
247+
Self {
248+
bind_ip: network_info.bind_ip.clone(),
249+
external_ip: network_info.external_ip.clone(),
250+
client_port: network_info.client_port.map(|port| port.into()),
251+
libp2p_port: network_info.libp2p_port.map(|port| port.into()),
252+
}
253+
}
200254
}
201255

202256
#[derive(GraphQLObject, Clone, Debug)]

node/native/src/node/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl NodeBuilder {
345345
snarker: self.snarker,
346346
consensus_constants: consensus_consts.clone(),
347347
testing_run: false,
348+
client_port: self.http_port,
348349
},
349350
p2p: self.p2p,
350351
ledger: LedgerConfig {},

node/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct GlobalConfig {
3535
pub build: Box<BuildEnv>,
3636
pub snarker: Option<SnarkerConfig>,
3737
pub consensus_constants: ConsensusConstants,
38+
pub client_port: Option<u16>,
3839
pub testing_run: bool,
3940
}
4041

node/src/rpc/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,17 @@ pub struct RpcNodeStatus {
516516
pub peers: Vec<RpcPeerInfo>,
517517
pub resources_status: RpcNodeStatusResources,
518518
pub service_queues: Queues,
519+
pub network_info: RpcNodeStatusNetworkInfo,
520+
pub block_producer: Option<AccountPublicKey>,
521+
pub coinbase_receiver: Option<AccountPublicKey>,
522+
}
523+
524+
#[derive(Serialize, Debug, Clone)]
525+
pub struct RpcNodeStatusNetworkInfo {
526+
pub bind_ip: String,
527+
pub external_ip: Option<String>,
528+
pub client_port: Option<u16>,
529+
pub libp2p_port: Option<u16>,
519530
}
520531

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

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use crate::{
1414
AccountQuery, AccountSlim, ActionStatsQuery, ActionStatsResponse, CurrentMessageProgress,
1515
MessagesStats, NodeHeartbeat, ProducedBlockInfo, RootLedgerSyncProgress,
1616
RootStagedLedgerSyncProgress, RpcAction, RpcBlockProducerStats, RpcMessageProgressResponse,
17-
RpcNodeStatus, RpcNodeStatusLedger, RpcNodeStatusResources, RpcNodeStatusTransactionPool,
18-
RpcNodeStatusTransitionFrontier, RpcNodeStatusTransitionFrontierBlockSummary,
19-
RpcNodeStatusTransitionFrontierSync, RpcRequestExtraData, RpcScanStateSummary,
20-
RpcScanStateSummaryBlock, RpcScanStateSummaryBlockTransaction,
21-
RpcScanStateSummaryBlockTransactionKind, RpcScanStateSummaryScanStateJob,
22-
RpcSnarkPoolJobFull, RpcSnarkPoolJobSnarkWork, RpcSnarkPoolJobSummary,
23-
RpcSnarkerJobCommitResponse, RpcSnarkerJobSpecResponse, RpcTransactionInjectResponse,
24-
TransactionStatus,
17+
RpcNodeStatus, RpcNodeStatusLedger, RpcNodeStatusNetworkInfo, RpcNodeStatusResources,
18+
RpcNodeStatusTransactionPool, RpcNodeStatusTransitionFrontier,
19+
RpcNodeStatusTransitionFrontierBlockSummary, RpcNodeStatusTransitionFrontierSync,
20+
RpcRequestExtraData, RpcScanStateSummary, RpcScanStateSummaryBlock,
21+
RpcScanStateSummaryBlockTransaction, RpcScanStateSummaryBlockTransactionKind,
22+
RpcScanStateSummaryScanStateJob, RpcSnarkPoolJobFull, RpcSnarkPoolJobSnarkWork,
23+
RpcSnarkPoolJobSummary, RpcSnarkerJobCommitResponse, RpcSnarkerJobSpecResponse,
24+
RpcTransactionInjectResponse, TransactionStatus,
2525
},
2626
snark_pool::SnarkPoolAction,
2727
transition_frontier::sync::{
@@ -37,6 +37,7 @@ use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
3737
use mina_p2p_messages::{rpc_kernel::QueryHeader, v2};
3838
use mina_signer::CompressedPubKey;
3939
use openmina_core::{block::ArcBlockWithHash, bug_condition};
40+
use openmina_node_account::AccountPublicKey;
4041
use p2p::channels::streaming_rpc::{
4142
staged_ledger_parts::calc_total_pieces_to_transfer, P2pStreamingRpcReceiveProgress,
4243
};
@@ -869,8 +870,31 @@ fn compute_node_status<S: Service>(store: &mut Store<S>) -> RpcNodeStatus {
869870
.and_then(|idx| block_production_attempts.get(idx))
870871
.cloned();
871872

873+
let network_info = RpcNodeStatusNetworkInfo {
874+
bind_ip: "0.0.0.0".to_string(),
875+
external_ip: state
876+
.p2p
877+
.config()
878+
.external_addrs
879+
.first()
880+
.map(|addr| addr.to_string()),
881+
client_port: state.config.client_port,
882+
libp2p_port: state.p2p.config().libp2p_port,
883+
};
884+
885+
let block_producer = state
886+
.block_producer
887+
.config()
888+
.map(|config| AccountPublicKey::from(config.pub_key.clone()));
889+
let coinbase_receiver = state
890+
.block_producer
891+
.config()
892+
.map(|config| AccountPublicKey::from(config.coinbase_receiver().clone()));
893+
872894
let status = RpcNodeStatus {
873895
chain_id,
896+
block_producer,
897+
coinbase_receiver,
874898
transition_frontier: RpcNodeStatusTransitionFrontier {
875899
best_tip: state.transition_frontier.best_tip().map(block_summary),
876900
sync: RpcNodeStatusTransitionFrontierSync {
@@ -924,6 +948,7 @@ fn compute_node_status<S: Service>(store: &mut Store<S>) -> RpcNodeStatus {
924948
snark_pool: state.snark_pool.resources_usage(),
925949
},
926950
service_queues: store.service.queues(),
951+
network_info,
927952
};
928953
status
929954
}

node/testing/src/cluster/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ impl Cluster {
272272
build: BuildEnv::get().into(),
273273
snarker: testing_config.snark_worker,
274274
consensus_constants: consensus_consts.clone(),
275+
client_port: Some(http_port),
275276
testing_run: true,
276277
},
277278
p2p: P2pConfig {

0 commit comments

Comments
 (0)