Skip to content

Commit 989a6c4

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 989a6c4

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

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

Lines changed: 25 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,24 @@ 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
35+
.checked_add(first_block_global_slot_delta_ms)
36+
.unwrap()
37+
.checked_mul(1_000_000)
38+
.unwrap()
39+
}
40+
2241
impl SoloNodeBootstrap {
2342
pub async fn run(self, mut runner: ClusterRunner<'_>) {
2443
use self::TransitionFrontierSyncState::*;
@@ -27,10 +46,12 @@ impl SoloNodeBootstrap {
2746

2847
let replayer = hosts::replayer();
2948

30-
let node_id = runner.add_rust_node(
31-
RustNodeTestingConfig::devnet_default()
32-
.initial_peers(vec![ListenerNode::Custom(replayer)]),
33-
);
49+
let mut config = RustNodeTestingConfig::devnet_default();
50+
51+
config.initial_time = redux::Timestamp::new(first_block_slot_timestamp_nanos(&config));
52+
53+
let node_id =
54+
runner.add_rust_node(config.initial_peers(vec![ListenerNode::Custom(replayer)]));
3455
eprintln!("launch Openmina node with default configuration, id: {node_id}");
3556

3657
let mut timeout = TIMEOUT;

0 commit comments

Comments
 (0)