@@ -73,6 +73,15 @@ pub struct State {
7373 applied_actions_count : u64 ,
7474}
7575
76+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
77+ pub enum BlockPrevalidationError {
78+ GenesisNotReady ,
79+ TooEarly ,
80+ TooLate ,
81+ ConstantsMismatch ,
82+ GenesisMismatch ,
83+ }
84+
7685// Substate accessors that will be used in reducers
7786use openmina_core:: { impl_substate_access, SubstateAccess } ;
7887
@@ -356,15 +365,18 @@ impl State {
356365 } )
357366 }
358367
359- pub fn prevalidate_block ( & self , block : & ArcBlockWithHash ) -> bool {
368+ pub fn prevalidate_block (
369+ & self ,
370+ block : & ArcBlockWithHash ,
371+ ) -> Result < ( ) , BlockPrevalidationError > {
360372 let Some ( ( genesis, cur_global_slot) ) =
361373 None . or_else ( || Some ( ( self . genesis_block ( ) ?, self . cur_global_slot ( ) ?) ) )
362374 else {
363375 // we don't have genesis block. This should be impossible
364376 // because we don't even know chain_id before we have genesis
365377 // block, so we can't be connected to any peers from which
366378 // we would receive a block.
367- return false ;
379+ return Err ( BlockPrevalidationError :: GenesisNotReady ) ;
368380 } ;
369381
370382 // received_at_valid_time
@@ -375,23 +387,23 @@ impl State {
375387 let delta = genesis. constants ( ) . delta . as_u32 ( ) ;
376388 if cur_global_slot < block_global_slot {
377389 // Too_early
378- return false ;
390+ return Err ( BlockPrevalidationError :: TooEarly ) ;
379391 } else if cur_global_slot. saturating_sub ( block_global_slot) > delta {
380392 // Too_late
381- return false ;
393+ return Err ( BlockPrevalidationError :: TooLate ) ;
382394 }
383395 }
384396
385397 if block. constants ( ) != genesis. constants ( ) {
386- return false ;
398+ return Err ( BlockPrevalidationError :: ConstantsMismatch ) ;
387399 }
388400
389401 if block. header ( ) . genesis_state_hash ( ) != genesis. hash ( ) {
390- return false ;
402+ return Err ( BlockPrevalidationError :: GenesisMismatch ) ;
391403 }
392404
393405 // TODO(binier): more checks.
394- true
406+ Ok ( ( ) )
395407 }
396408
397409 pub fn should_log_node_id ( & self ) -> bool {
0 commit comments