Skip to content

Commit 338a744

Browse files
committed
fix(scenario): In solo-node-bootstrap scenario, make the initial time match the first block time
This is required so that the block prevalidation logic doesn't reject the block for being outside of the slot time window.
1 parent dc3f17c commit 338a744

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

node/testing/src/scenarios/solo_node/bootstrap.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use node::transition_frontier::sync::TransitionFrontierSyncState;
4+
use openmina_core::constants::constraint_constants;
45
use redux::Instant;
56

67
use crate::{
@@ -19,6 +20,20 @@ use crate::{
1920
#[derive(documented::Documented, Default, Clone, Copy)]
2021
pub 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+
2237
impl 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

Comments
 (0)