Skip to content

Commit 23382ea

Browse files
committed
Review fixes
1 parent 8631a4a commit 23382ea

File tree

4 files changed

+43
-51
lines changed

4 files changed

+43
-51
lines changed

node/src/block_producer/block_producer_reducer.rs

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl BlockProducerState {
4343
}
4444

4545
impl BlockProducerEnabled {
46+
/// Substate is accesses from global state, because applied blocks from transition frontier are required
4647
pub fn reducer(mut state_context: Substate<State>, action: BlockProducerActionWithMetaRef<'_>) {
4748
let (action, meta) = action.split();
4849
let Ok(global_state) = state_context.get_substate_mut() else {
@@ -88,11 +89,10 @@ impl BlockProducerEnabled {
8889
won_slot: won_slot.clone(),
8990
};
9091

91-
state_context
92-
.into_dispatcher()
93-
.push(BlockProducerEffectfulAction::WonSlot {
94-
won_slot: won_slot.clone(),
95-
});
92+
let dispatcher = state_context.into_dispatcher();
93+
dispatcher.push(BlockProducerEffectfulAction::WonSlot {
94+
won_slot: won_slot.clone(),
95+
});
9696
}
9797
BlockProducerAction::WonSlotDiscard { reason } => {
9898
if let Some(won_slot) = state.current.won_slot() {
@@ -103,9 +103,8 @@ impl BlockProducerEnabled {
103103
};
104104
}
105105

106-
state_context
107-
.into_dispatcher()
108-
.push(BlockProducerEffectfulAction::WonSlotDiscard { reason: *reason });
106+
let dispatcher = state_context.into_dispatcher();
107+
dispatcher.push(BlockProducerEffectfulAction::WonSlotDiscard { reason: *reason });
109108
}
110109
BlockProducerAction::WonSlotWait => {
111110
if let Some(won_slot) = state.current.won_slot() {
@@ -129,9 +128,8 @@ impl BlockProducerEnabled {
129128
chain: chain.clone(),
130129
};
131130

132-
state_context
133-
.into_dispatcher()
134-
.push(TransactionPoolAction::CollectTransactionsByFee);
131+
let dispatcher = state_context.into_dispatcher();
132+
dispatcher.push(TransactionPoolAction::CollectTransactionsByFee);
135133
}
136134
BlockProducerAction::WonSlotTransactionsSuccess {
137135
transactions_by_fee,
@@ -150,9 +148,8 @@ impl BlockProducerEnabled {
150148
transactions_by_fee: transactions_by_fee.clone(),
151149
};
152150

153-
state_context
154-
.into_dispatcher()
155-
.push(BlockProducerAction::StagedLedgerDiffCreateInit);
151+
let dispatcher = state_context.into_dispatcher();
152+
dispatcher.push(BlockProducerAction::StagedLedgerDiffCreateInit);
156153
}
157154
BlockProducerAction::WonSlotProduceInit => {
158155
if let Some(won_slot) = state.current.won_slot() {
@@ -173,14 +170,12 @@ impl BlockProducerEnabled {
173170
};
174171
}
175172

176-
state_context
177-
.into_dispatcher()
178-
.push(BlockProducerAction::WonSlotTransactionsGet);
173+
let dispatcher = state_context.into_dispatcher();
174+
dispatcher.push(BlockProducerAction::WonSlotTransactionsGet);
179175
}
180176
BlockProducerAction::StagedLedgerDiffCreateInit => {
181-
state_context
182-
.into_dispatcher()
183-
.push(BlockProducerEffectfulAction::StagedLedgerDiffCreateInit);
177+
let dispatcher = state_context.into_dispatcher();
178+
dispatcher.push(BlockProducerEffectfulAction::StagedLedgerDiffCreateInit);
184179
}
185180
BlockProducerAction::StagedLedgerDiffCreatePending => {
186181
let BlockProducerCurrentState::WonSlotTransactionsSuccess {
@@ -221,21 +216,18 @@ impl BlockProducerEnabled {
221216
stake_proof_sparse_ledger: output.stake_proof_sparse_ledger.clone(),
222217
};
223218

224-
state_context
225-
.into_dispatcher()
226-
.push(BlockProducerEffectfulAction::StagedLedgerDiffCreateSuccess);
219+
let dispatcher = state_context.into_dispatcher();
220+
dispatcher.push(BlockProducerEffectfulAction::StagedLedgerDiffCreateSuccess);
227221
}
228222
BlockProducerAction::BlockUnprovenBuild => {
229223
state.reduce_block_unproved_build(meta.time());
230224

231-
state_context
232-
.into_dispatcher()
233-
.push(BlockProducerEffectfulAction::BlockUnprovenBuild);
225+
let dispatcher = state_context.into_dispatcher();
226+
dispatcher.push(BlockProducerEffectfulAction::BlockUnprovenBuild);
234227
}
235228
BlockProducerAction::BlockProveInit => {
236-
state_context
237-
.into_dispatcher()
238-
.push(BlockProducerEffectfulAction::BlockProveInit);
229+
let dispatcher = state_context.into_dispatcher();
230+
dispatcher.push(BlockProducerEffectfulAction::BlockProveInit);
239231
}
240232
BlockProducerAction::BlockProvePending => {
241233
if let BlockProducerCurrentState::BlockUnprovenBuilt {
@@ -282,9 +274,8 @@ impl BlockProducerEnabled {
282274
};
283275
}
284276

285-
state_context
286-
.into_dispatcher()
287-
.push(BlockProducerEffectfulAction::BlockProveSuccess);
277+
let dispatcher = state_context.into_dispatcher();
278+
dispatcher.push(BlockProducerEffectfulAction::BlockProveSuccess);
288279
}
289280
BlockProducerAction::BlockProduced => {
290281
if let BlockProducerCurrentState::BlockProveSuccess {
@@ -304,9 +295,8 @@ impl BlockProducerEnabled {
304295
};
305296
}
306297

307-
state_context
308-
.into_dispatcher()
309-
.push(BlockProducerAction::BlockInject);
298+
let dispatcher = state_context.into_dispatcher();
299+
dispatcher.push(BlockProducerAction::BlockInject);
310300
}
311301
BlockProducerAction::BlockInject => {
312302
let (dispatcher, state) = state_context.into_dispatcher_and_state();
@@ -355,9 +345,8 @@ impl BlockProducerEnabled {
355345
};
356346
}
357347

358-
state_context
359-
.into_dispatcher()
360-
.push(BlockProducerAction::WonSlotSearch);
348+
let dispatcher = state_context.into_dispatcher();
349+
dispatcher.push(BlockProducerAction::WonSlotSearch);
361350
}
362351
}
363352
}

node/src/block_producer/vrf_evaluator/block_producer_vrf_evaluator_reducer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use openmina_core::bug_condition;
12
use vrf::VrfEvaluationOutput;
23

34
use crate::{
@@ -30,11 +31,10 @@ impl BlockProducerVrfEvaluatorState {
3031
global_slot: vrf_input.global_slot,
3132
};
3233

33-
state_context.into_dispatcher().push(
34-
BlockProducerVrfEvaluatorEffectfulAction::EvaluateSlot {
35-
vrf_input: vrf_input.clone(),
36-
},
37-
);
34+
let dispatcher = state_context.into_dispatcher();
35+
dispatcher.push(BlockProducerVrfEvaluatorEffectfulAction::EvaluateSlot {
36+
vrf_input: vrf_input.clone(),
37+
});
3838
}
3939
BlockProducerVrfEvaluatorAction::ProcessSlotEvaluationSuccess {
4040
vrf_output,
@@ -243,9 +243,8 @@ impl BlockProducerVrfEvaluatorState {
243243
producer: producer.clone(),
244244
};
245245

246-
state_context
247-
.into_dispatcher()
248-
.push(BlockProducerVrfEvaluatorAction::BeginDelegatorTableConstruction);
246+
let dispatcher = state_context.into_dispatcher();
247+
dispatcher.push(BlockProducerVrfEvaluatorAction::BeginDelegatorTableConstruction);
249248
}
250249
BlockProducerVrfEvaluatorAction::BeginDelegatorTableConstruction => {
251250
let BlockProducerVrfEvaluatorStatus::ReadyToEvaluate {
@@ -299,6 +298,7 @@ impl BlockProducerVrfEvaluatorState {
299298
staking_epoch_ledger_hash: _,
300299
} = &state.status
301300
else {
301+
bug_condition!("Invalid state for `BlockProducerVrfEvaluatorAction::FinalizeDelegatorTableConstruction` expected: `BlockProducerVrfEvaluatorStatus::EpochDelegatorTablePending`, found: {:?}", state.status);
302302
return;
303303
};
304304

@@ -336,7 +336,7 @@ impl BlockProducerVrfEvaluatorState {
336336
},
337337
)) = get_slot_and_status()
338338
else {
339-
// error here!
339+
bug_condition!("Invalid state for `BlockProducerVrfEvaluatorAction::FinalizeDelegatorTableConstruction`");
340340
return;
341341
};
342342

p2p/src/connection/incoming/p2p_connection_incoming_reducer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl P2pConnectionIncomingState {
252252
rpc_id: rpc_id.take(),
253253
};
254254

255-
state_context.into_dispatcher().push(P2pConnectionIncomingEffectfulAction::ConnectionAuthorizationEncryptAndSend { peer_id, other_pub_key, auth });
255+
let dispatcher = state_context.into_dispatcher();
256+
dispatcher.push(P2pConnectionIncomingEffectfulAction::ConnectionAuthorizationEncryptAndSend { peer_id, other_pub_key, auth });
256257
} else {
257258
bug_condition!(
258259
"Invalid state for `P2pConnectionIncomingAction::FinalizePending`: {:?}",

p2p/src/connection/outgoing/p2p_connection_outgoing_reducer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ impl P2pConnectionOutgoingState {
315315
state
316316
);
317317
}
318-
state_context
319-
.into_dispatcher()
318+
319+
let dispatcher = state_context.into_dispatcher();
320+
dispatcher
320321
.push(P2pConnectionOutgoingEffectfulAction::AnswerSet { peer_id, answer });
321322
Ok(())
322323
}
@@ -362,7 +363,8 @@ impl P2pConnectionOutgoingState {
362363
}
363364
};
364365

365-
state_context.into_dispatcher().push(
366+
let dispatcher = state_context.into_dispatcher();
367+
dispatcher.push(
366368
P2pConnectionOutgoingEffectfulAction::ConnectionAuthorizationEncryptAndSend {
367369
peer_id,
368370
other_pub_key,

0 commit comments

Comments
 (0)