@@ -73,6 +73,15 @@ pub struct State {
7373 applied_actions_count : u64 ,
7474}
7575
76+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
77+ pub enum BlockValidationError {
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,15 @@ impl State {
356365 } )
357366 }
358367
359- pub fn prevalidate_block ( & self , block : & ArcBlockWithHash ) -> bool {
368+ pub fn prevalidate_block ( & self , block : & ArcBlockWithHash ) -> Result < ( ) , BlockValidationError > {
360369 let Some ( ( genesis, cur_global_slot) ) =
361370 None . or_else ( || Some ( ( self . genesis_block ( ) ?, self . cur_global_slot ( ) ?) ) )
362371 else {
363372 // we don't have genesis block. This should be impossible
364373 // because we don't even know chain_id before we have genesis
365374 // block, so we can't be connected to any peers from which
366375 // we would receive a block.
367- return false ;
376+ return Err ( BlockValidationError :: GenesisNotReady ) ;
368377 } ;
369378
370379 // received_at_valid_time
@@ -375,23 +384,23 @@ impl State {
375384 let delta = genesis. constants ( ) . delta . as_u32 ( ) ;
376385 if cur_global_slot < block_global_slot {
377386 // Too_early
378- return false ;
387+ return Err ( BlockValidationError :: TooEarly ) ;
379388 } else if cur_global_slot. saturating_sub ( block_global_slot) > delta {
380389 // Too_late
381- return false ;
390+ return Err ( BlockValidationError :: TooLate ) ;
382391 }
383392 }
384393
385394 if block. constants ( ) != genesis. constants ( ) {
386- return false ;
395+ return Err ( BlockValidationError :: ConstantsMismatch ) ;
387396 }
388397
389398 if block. header ( ) . genesis_state_hash ( ) != genesis. hash ( ) {
390- return false ;
399+ return Err ( BlockValidationError :: GenesisMismatch ) ;
391400 }
392401
393402 // TODO(binier): more checks.
394- true
403+ Ok ( ( ) )
395404 }
396405
397406 pub fn should_log_node_id ( & self ) -> bool {
0 commit comments