11use openmina_core:: {
2- block:: BlockHash ,
2+ block:: { ArcBlockWithHash , BlockHash } ,
33 bug_condition,
44 consensus:: { is_short_range_fork, long_range_fork_take, short_range_fork_take} ,
55} ;
@@ -48,9 +48,31 @@ impl ConsensusState {
4848 ) ;
4949
5050 // Dispatch
51+ let ( dispatcher, state) = state_context. into_dispatcher_and_state ( ) ;
52+
53+ let hash = hash. clone ( ) ;
54+ let block = ArcBlockWithHash {
55+ hash : hash. clone ( ) ,
56+ block : block. clone ( ) ,
57+ } ;
58+ if state. prevalidate_block ( & block) {
59+ dispatcher. push ( ConsensusAction :: BlockValidateSuccess { hash } ) ;
60+ } else {
61+ let error = "Failed" . into ( ) ;
62+ dispatcher. push ( ConsensusAction :: BlockValidateError { hash, error } ) ;
63+ }
64+ }
65+ ConsensusAction :: BlockValidateSuccess { hash } => {
66+ let Some ( block) = state. blocks . get_mut ( hash) else {
67+ return ;
68+ } ;
69+ block. status = ConsensusBlockStatus :: Validated ;
70+
71+ // Dispatch
72+ let block = ( hash. clone ( ) , block. block . clone ( ) ) . into ( ) ;
5173 let dispatcher = state_context. into_dispatcher ( ) ;
5274 dispatcher. push ( SnarkBlockVerifyAction :: Init {
53- block : ( hash . clone ( ) , block . clone ( ) ) . into ( ) ,
75+ block,
5476 on_init : redux:: callback!(
5577 on_received_block_snark_verify_init( ( hash: BlockHash , req_id: SnarkBlockVerifyId ) ) -> crate :: Action {
5678 ConsensusAction :: BlockSnarkVerifyPending { hash, req_id }
@@ -65,6 +87,9 @@ impl ConsensusState {
6587 } ) ,
6688 } ) ;
6789 }
90+ ConsensusAction :: BlockValidateError { hash, .. } => {
91+ state. blocks . remove ( hash) ;
92+ }
6893 ConsensusAction :: BlockChainProofUpdate { hash, chain_proof } => {
6994 if state. best_tip . as_ref ( ) == Some ( hash) {
7095 state. best_tip_chain_proof = Some ( chain_proof. clone ( ) ) ;
0 commit comments