11use std:: time:: Duration ;
22
33use node:: transition_frontier:: sync:: TransitionFrontierSyncState ;
4+ use openmina_core:: constants:: constraint_constants;
45use redux:: Instant ;
56
67use crate :: {
@@ -19,6 +20,20 @@ use crate::{
1920#[ derive( documented:: Documented , Default , Clone , Copy ) ]
2021pub struct SoloNodeBootstrap ;
2122
23+ // TODO(tizoc): this is ugly, do a cleaner conversion or figure out a better way.
24+ // This test will fail if we don't start with this as the initial time because
25+ // the time validation for the first block will reject it.
26+ fn first_block_slot_timestamp_nanos ( config : & RustNodeTestingConfig ) -> u64 {
27+ let first_block_global_slot = 46891 ; // Update if replay changes
28+ let protocol_constants = config. genesis . protocol_constants ( ) . unwrap ( ) ;
29+ let genesis_timestamp_ms = protocol_constants. genesis_state_timestamp . 0 . as_u64 ( ) ;
30+ let milliseconds_per_slot = constraint_constants ( ) . block_window_duration_ms ;
31+ let first_block_global_slot_delta_ms = first_block_global_slot * milliseconds_per_slot;
32+
33+ // Convert to nanos
34+ ( genesis_timestamp_ms + first_block_global_slot_delta_ms) * 1000_000
35+ }
36+
2237impl SoloNodeBootstrap {
2338 pub async fn run ( self , mut runner : ClusterRunner < ' _ > ) {
2439 use self :: TransitionFrontierSyncState :: * ;
@@ -27,10 +42,12 @@ impl SoloNodeBootstrap {
2742
2843 let replayer = hosts:: replayer ( ) ;
2944
30- let node_id = runner. add_rust_node (
31- RustNodeTestingConfig :: devnet_default ( )
32- . initial_peers ( vec ! [ ListenerNode :: Custom ( replayer) ] ) ,
33- ) ;
45+ let mut config = RustNodeTestingConfig :: devnet_default ( ) ;
46+
47+ config. initial_time = redux:: Timestamp :: new ( first_block_slot_timestamp_nanos ( & config) ) ;
48+
49+ let node_id =
50+ runner. add_rust_node ( config. initial_peers ( vec ! [ ListenerNode :: Custom ( replayer) ] ) ) ;
3451 eprintln ! ( "launch Openmina node with default configuration, id: {node_id}" ) ;
3552
3653 let mut timeout = TIMEOUT ;
0 commit comments