Skip to content

Commit a257142

Browse files
authored
Merge pull request #1051 from openmina/feat/earlier-produced-block-tracking
feat(heartbeats): Track produced blocks earlier
2 parents 6763f61 + 12596c1 commit a257142

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

node/src/action_kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub enum ActionKind {
126126
BlockProducerWonSlotTransactionsGet,
127127
BlockProducerWonSlotTransactionsSuccess,
128128
BlockProducerWonSlotWait,
129-
BlockProducerEffectfulBlockInjected,
129+
BlockProducerEffectfulBlockProduced,
130130
BlockProducerEffectfulBlockProveInit,
131131
BlockProducerEffectfulBlockProveSuccess,
132132
BlockProducerEffectfulBlockUnprovenBuild,
@@ -1019,7 +1019,7 @@ impl ActionKindGet for BlockProducerEffectfulAction {
10191019
Self::BlockUnprovenBuild => ActionKind::BlockProducerEffectfulBlockUnprovenBuild,
10201020
Self::BlockProveInit => ActionKind::BlockProducerEffectfulBlockProveInit,
10211021
Self::BlockProveSuccess => ActionKind::BlockProducerEffectfulBlockProveSuccess,
1022-
Self::BlockInjected { .. } => ActionKind::BlockProducerEffectfulBlockInjected,
1022+
Self::BlockProduced { .. } => ActionKind::BlockProducerEffectfulBlockProduced,
10231023
}
10241024
}
10251025
}

node/src/block_producer/block_producer_reducer.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,18 @@ impl BlockProducerEnabled {
305305
bug_condition!("Invalid state for `BlockProducerAction::BlockProduced` expected: `BlockProducerCurrentState::BlockProveSuccess`, found: {:?}", current_state);
306306
}
307307

308-
let dispatcher = state_context.into_dispatcher();
308+
let (dispatcher, global_state) = state_context.into_dispatcher_and_state();
309+
310+
// Store the produced block in stats, used by heartbeats
311+
let block = global_state
312+
.block_producer
313+
.as_ref()
314+
.and_then(|bp| bp.current.produced_block())
315+
.cloned();
316+
if let Some(block) = block {
317+
dispatcher.push(BlockProducerEffectfulAction::BlockProduced { block });
318+
}
319+
309320
dispatcher.push(BlockProducerAction::BlockInject);
310321
}
311322
BlockProducerAction::BlockInject => {
@@ -360,16 +371,6 @@ impl BlockProducerEnabled {
360371

361372
let (dispatcher, global_state) = state_context.into_dispatcher_and_state();
362373

363-
// Store the produced block in stats, used by heartbeats
364-
let block = global_state
365-
.block_producer
366-
.as_ref()
367-
.and_then(|bp| bp.current.injected_block())
368-
.cloned();
369-
if let Some(block) = block {
370-
dispatcher.push(BlockProducerEffectfulAction::BlockInjected { block });
371-
}
372-
373374
#[cfg(feature = "p2p-libp2p")]
374375
broadcast_injected_block(global_state, dispatcher);
375376

node/src/block_producer_effectful/block_producer_effectful_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub enum BlockProducerEffectfulAction {
1717
BlockUnprovenBuild,
1818
BlockProveInit,
1919
BlockProveSuccess,
20-
BlockInjected {
20+
BlockProduced {
2121
block: ArcBlockWithHash,
2222
},
2323
}

node/src/block_producer_effectful/block_producer_effectful_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn block_producer_effects<S: crate::Service>(
221221
}
222222
store.dispatch(BlockProducerAction::WonSlotSearch);
223223
}
224-
BlockProducerEffectfulAction::BlockInjected { block } => {
224+
BlockProducerEffectfulAction::BlockProduced { block } => {
225225
if let Some(stats) = store.service.stats() {
226226
stats.block_producer().last_produced_block = Some(block.clone());
227227
}

0 commit comments

Comments
 (0)