@@ -3,7 +3,7 @@ use std::time::Duration;
33
44use malloc_size_of_derive:: MallocSizeOf ;
55use mina_p2p_messages:: v2;
6- use openmina_core:: constants :: PROTOCOL_VERSION ;
6+ use openmina_core:: block :: prevalidate :: { prevalidate_block , BlockPrevalidationError } ;
77use openmina_core:: transaction:: { TransactionInfo , TransactionWithHash } ;
88use p2p:: P2pNetworkPubsubMessageCacheId ;
99use rand:: prelude:: * ;
@@ -80,25 +80,6 @@ pub struct State {
8080 applied_actions_count : u64 ,
8181}
8282
83- #[ derive( Serialize , Deserialize , Debug , Clone ) ]
84- pub enum BlockPrevalidationError {
85- GenesisNotReady ,
86- ReceivedTooEarly {
87- current_global_slot : u32 ,
88- block_global_slot : u32 ,
89- } ,
90- ReceivedTooLate {
91- current_global_slot : u32 ,
92- block_global_slot : u32 ,
93- delta : u32 ,
94- } ,
95- InvalidGenesisProtocolState ,
96- InvalidProtocolVersion ,
97- MismatchedProtocolVersion ,
98- ConsantsMismatch ,
99- InvalidDeltaBlockChainProof ,
100- }
101-
10283// Substate accessors that will be used in reducers
10384use openmina_core:: { bug_condition, impl_substate_access, SubstateAccess } ;
10485
@@ -408,70 +389,7 @@ impl State {
408389 return Err ( BlockPrevalidationError :: GenesisNotReady ) ;
409390 } ;
410391
411- // received_at_valid_time
412- // https://github.com/minaprotocol/mina/blob/6af211ad58e9356f00ea4a636cea70aa8267c072/src/lib/consensus/proof_of_stake.ml#L2746
413- {
414- let block_global_slot = block. global_slot ( ) ;
415-
416- let delta = genesis. constants ( ) . delta . as_u32 ( ) ;
417- if cur_global_slot < block_global_slot {
418- // Too_early
419- return Err ( BlockPrevalidationError :: ReceivedTooEarly {
420- current_global_slot : cur_global_slot,
421- block_global_slot,
422- } ) ;
423- } else if !allow_block_too_late
424- && cur_global_slot. saturating_sub ( block_global_slot) > delta
425- {
426- // Too_late
427- return Err ( BlockPrevalidationError :: ReceivedTooLate {
428- current_global_slot : cur_global_slot,
429- block_global_slot,
430- delta,
431- } ) ;
432- }
433- }
434-
435- if block. header ( ) . genesis_state_hash ( ) != genesis. hash ( ) {
436- return Err ( BlockPrevalidationError :: InvalidGenesisProtocolState ) ;
437- }
438-
439- let ( protocol_versions_are_valid, protocol_version_matches_daemon) = {
440- let min_transaction_version = 1 . into ( ) ;
441- let v = & block. header ( ) . current_protocol_version ;
442- let nv = block
443- . header ( )
444- . proposed_protocol_version_opt
445- . as_ref ( )
446- . unwrap_or ( v) ;
447-
448- // Our version values are unsigned, so there is no need to check that the
449- // other parts are not negative.
450- let valid = v. transaction >= min_transaction_version
451- && nv. transaction >= min_transaction_version;
452- let compatible = v. transaction == PROTOCOL_VERSION . transaction
453- && v. network == PROTOCOL_VERSION . network ;
454-
455- ( valid, compatible)
456- } ;
457-
458- if !protocol_versions_are_valid {
459- return Err ( BlockPrevalidationError :: InvalidProtocolVersion ) ;
460- } else if !protocol_version_matches_daemon {
461- return Err ( BlockPrevalidationError :: MismatchedProtocolVersion ) ;
462- }
463-
464- // NOTE: currently these cannot change between blocks, but that
465- // may not always be true?
466- if block. constants ( ) != genesis. constants ( ) {
467- return Err ( BlockPrevalidationError :: ConsantsMismatch ) ;
468- }
469-
470- // TODO(tizoc): check for InvalidDeltaBlockChainProof
471- // https://github.com/MinaProtocol/mina/blob/d800da86a764d8d37ffb8964dd8d54d9f522b358/src/lib/mina_block/validation.ml#L369
472- // https://github.com/MinaProtocol/mina/blob/d800da86a764d8d37ffb8964dd8d54d9f522b358/src/lib/transition_chain_verifier/transition_chain_verifier.ml
473-
474- Ok ( ( ) )
392+ prevalidate_block ( block, & genesis, cur_global_slot, allow_block_too_late)
475393 }
476394
477395 pub fn should_log_node_id ( & self ) -> bool {
0 commit comments