Skip to content

Commit 59f9299

Browse files
authored
Merge pull request #909 from openmina/feat/next-won-slot-status-rpc
feat(rpc): Add `next_won_slot` info to `/status` response
2 parents 699ccca + 7acbc66 commit 59f9299

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

node/src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub struct RpcNodeStatus {
453453
pub peers: Vec<RpcPeerInfo>,
454454
pub snark_pool: RpcNodeStatusSnarkPool,
455455
pub transaction_pool: RpcNodeStatusTransactionPool,
456+
pub next_won_slot: Option<BlockProductionAttemptWonSlot>,
456457
}
457458

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

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ use crate::{
1717
RpcTransactionInjectResponse, TransactionStatus,
1818
},
1919
snark_pool::SnarkPoolAction,
20+
stats::block_producer::BlockProductionAttemptWonSlot,
2021
transition_frontier::sync::{
2122
ledger::TransitionFrontierSyncLedgerState, TransitionFrontierSyncState,
2223
},
23-
Service, Store,
24+
Service, State, Store,
2425
};
2526
use ledger::{
2627
scan_state::currency::{Balance, Magnitude},
@@ -46,6 +47,15 @@ macro_rules! respond_or_log {
4647
};
4748
}
4849

50+
fn get_next_won_slot(state: &State) -> Option<BlockProductionAttemptWonSlot> {
51+
let best_tip = state.transition_frontier.best_tip()?;
52+
let vrf = state.block_producer.vrf_evaluator()?;
53+
let (_, won_slot) = vrf.won_slots.first_key_value()?;
54+
55+
let won_slot = BlockProducerWonSlot::from_vrf_won_slot(won_slot, best_tip.genesis_timestamp());
56+
Some((&won_slot).into())
57+
}
58+
4959
pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcEffectfulAction>) {
5060
let (action, meta) = action.split();
5161

@@ -64,6 +74,7 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
6474
height: b.height(),
6575
global_slot: b.global_slot(),
6676
};
77+
let next_won_slot = get_next_won_slot(state);
6778
let status = RpcNodeStatus {
6879
chain_id,
6980
transition_frontier: RpcNodeStatusTransitionFrontier {
@@ -89,6 +100,7 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
89100
transaction_pool: RpcNodeStatusTransactionPool {
90101
transactions: state.transaction_pool.size(),
91102
},
103+
next_won_slot,
92104
};
93105
let _ = store.service.respond_status_get(rpc_id, Some(status));
94106
}

0 commit comments

Comments
 (0)