Skip to content

Commit 4cc0397

Browse files
committed
fix(snark/block_verify): use on_init callback, otherwise verify init action isn't enabled
1 parent 480bac4 commit 4cc0397

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

node/src/consensus/consensus_reducer.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use openmina_core::{
33
bug_condition,
44
consensus::{is_short_range_fork, long_range_fork_take, short_range_fork_take},
55
};
6-
use snark::block_verify::{SnarkBlockVerifyAction, SnarkBlockVerifyError};
6+
use snark::block_verify::{SnarkBlockVerifyAction, SnarkBlockVerifyError, SnarkBlockVerifyId};
77

88
use crate::{
99
transition_frontier::sync::{
@@ -48,11 +48,13 @@ impl ConsensusState {
4848
);
4949

5050
// Dispatch
51-
let (dispatcher, global_state) = state_context.into_dispatcher_and_state();
52-
let req_id = global_state.snark.block_verify.next_req_id();
51+
let dispatcher = state_context.into_dispatcher();
5352
dispatcher.push(SnarkBlockVerifyAction::Init {
54-
req_id,
5553
block: (hash.clone(), block.clone()).into(),
54+
on_init: redux::callback!(
55+
on_received_block_snark_verify_init((hash: BlockHash, req_id: SnarkBlockVerifyId)) -> crate::Action {
56+
ConsensusAction::BlockSnarkVerifyPending { hash, req_id }
57+
}),
5658
on_success: redux::callback!(
5759
on_received_block_snark_verify_success(hash: BlockHash) -> crate::Action {
5860
ConsensusAction::BlockSnarkVerifySuccess { hash }
@@ -62,10 +64,6 @@ impl ConsensusState {
6264
ConsensusAction::BlockSnarkVerifyError { hash, error }
6365
}),
6466
});
65-
dispatcher.push(ConsensusAction::BlockSnarkVerifyPending {
66-
req_id,
67-
hash: hash.clone(),
68-
});
6967
}
7068
ConsensusAction::BlockChainProofUpdate { hash, chain_proof } => {
7169
if state.best_tip.as_ref() == Some(hash) {

snark/src/block_verify/snark_block_verify_actions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ pub type SnarkBlockVerifyActionWithMetaRef<'a> = redux::ActionWithMeta<&'a Snark
99
#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)]
1010
pub enum SnarkBlockVerifyAction {
1111
Init {
12-
req_id: SnarkBlockVerifyId,
1312
block: VerifiableBlockWithHash,
13+
14+
on_init: redux::Callback<(BlockHash, SnarkBlockVerifyId)>,
1415
on_success: redux::Callback<BlockHash>,
1516
on_error: redux::Callback<(BlockHash, SnarkBlockVerifyError)>,
1617
},
@@ -32,9 +33,7 @@ pub enum SnarkBlockVerifyAction {
3233
impl redux::EnablingCondition<crate::SnarkState> for SnarkBlockVerifyAction {
3334
fn is_enabled(&self, state: &crate::SnarkState, _time: redux::Timestamp) -> bool {
3435
match self {
35-
SnarkBlockVerifyAction::Init { req_id, .. } => {
36-
state.block_verify.jobs.next_req_id() == *req_id
37-
}
36+
SnarkBlockVerifyAction::Init { .. } => true,
3837
SnarkBlockVerifyAction::Pending { req_id } => state
3938
.block_verify
4039
.jobs

snark/src/block_verify/snark_block_verify_reducer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ pub fn reducer<State, Action>(
2727
match action {
2828
SnarkBlockVerifyAction::Init {
2929
block,
30-
req_id,
30+
on_init,
3131
on_success,
3232
on_error,
3333
} => {
34-
state.jobs.add(SnarkBlockVerifyStatus::Init {
34+
let req_id = state.jobs.add(SnarkBlockVerifyStatus::Init {
3535
time: meta.time(),
3636
block: block.clone(),
3737
on_success: on_success.clone(),
@@ -42,13 +42,14 @@ pub fn reducer<State, Action>(
4242
let verifier_index = state.verifier_index.clone();
4343
let verifier_srs = state.verifier_srs.clone();
4444
let dispatcher = state_context.into_dispatcher();
45+
dispatcher.push_callback(on_init.clone(), (block.hash_ref().clone(), req_id));
4546
dispatcher.push(SnarkBlockVerifyEffectfulAction::Init {
46-
req_id: *req_id,
47+
req_id,
4748
block: block.clone(),
4849
verifier_index,
4950
verifier_srs,
5051
});
51-
dispatcher.push(SnarkBlockVerifyAction::Pending { req_id: *req_id });
52+
dispatcher.push(SnarkBlockVerifyAction::Pending { req_id });
5253
}
5354
SnarkBlockVerifyAction::Pending { req_id } => {
5455
if let Some(req) = state.jobs.get_mut(*req_id) {

0 commit comments

Comments
 (0)