mina_node_testing/scenarios/record_replay/
bootstrap.rs

1use std::time::Duration;
2
3use mina_node_native::replay_state_with_input_actions;
4use node::ActionKind;
5
6use crate::{
7    hosts,
8    node::{Recorder, RustNodeTestingConfig, TestPeerId},
9    scenarios::{ClusterRunner, RunCfg, RunCfgAdvanceTime},
10};
11
12/// Bootstrap a rust node while recorder of state and input actions is
13/// enabled and make sure we can successfully replay it.
14#[derive(documented::Documented, Default, Clone, Copy)]
15pub struct RecordReplayBootstrap;
16
17impl RecordReplayBootstrap {
18    pub async fn run(self, mut runner: ClusterRunner<'_>) {
19        let initial_peers = hosts::devnet();
20
21        let node_id = runner.add_rust_node(RustNodeTestingConfig {
22            initial_time: redux::Timestamp::global_now(),
23            initial_peers,
24            peer_id: TestPeerId::Bytes(rand::random()),
25            recorder: Recorder::StateWithInputActions,
26            ..RustNodeTestingConfig::devnet_default()
27        });
28
29        // bootstrap the node.
30        runner
31            .run(
32                RunCfg::default()
33                    .timeout(Duration::from_secs(40 * 60))
34                    .advance_time(RunCfgAdvanceTime::Real)
35                    .action_handler(|_, state, _, a| {
36                        a.action().kind() == ActionKind::TransitionFrontierSynced
37                            && state
38                                .transition_frontier
39                                .best_tip()
40                                .is_some_and(|tip| !tip.is_genesis())
41                    }),
42            )
43            .await
44            .expect("node failed to bootstrap");
45        // flush the recorded data.
46        node::recorder::Recorder::graceful_shutdown();
47
48        let node = runner.node(node_id).unwrap();
49
50        let recording_dir = node.work_dir().child("recorder");
51        let replayed_node = replay_state_with_input_actions(
52            recording_dir.as_os_str().to_str().unwrap(),
53            None,
54            false,
55            |_, _, _| Ok(()),
56        )
57        .expect("replay failed");
58
59        assert_eq!(
60            node.state().last_action(),
61            replayed_node.store().state().last_action()
62        );
63    }
64}