Skip to content

Commit ccb0f4a

Browse files
authored
Merge pull request #1620 from o1-labs/dw/multiaddress-fix
Replayer node - add documentation
2 parents 9710d1a + 106380e commit ccb0f4a

File tree

19 files changed

+453
-46
lines changed

19 files changed

+453
-46
lines changed

cli/src/commands/node/mod.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
use std::{fs::File, path::PathBuf, sync::Arc};
2-
31
use anyhow::Context;
42
use ledger::proofs::provers::BlockProver;
5-
use node::{
6-
account::AccountSecretKey,
7-
snark::{BlockVerifier, TransactionVerifier},
8-
transition_frontier::genesis::GenesisConfig,
9-
};
10-
113
use mina_node_account::AccountPublicKey;
12-
use reqwest::Url;
13-
4+
use mina_node_native::{archive::config::ArchiveStorageOptions, tracing, NodeBuilder};
145
use node::{
6+
account::AccountSecretKey,
157
core::log::inner::Level,
168
p2p::{connection::outgoing::P2pConnectionOutgoingInitOpts, identity::SecretKey},
179
service::Recorder,
10+
snark::{BlockVerifier, TransactionVerifier},
11+
transition_frontier::genesis::GenesisConfig,
1812
SnarkerStrategy,
1913
};
20-
21-
use mina_node_native::{archive::config::ArchiveStorageOptions, tracing, NodeBuilder};
14+
use reqwest::Url;
15+
use std::{fs::File, path::PathBuf, sync::Arc};
2216

2317
/// Mina node configuration and runtime options
2418
///
@@ -216,6 +210,28 @@ pub struct Node {
216210
#[arg(long, requires = "producer")]
217211
pub coinbase_receiver: Option<AccountPublicKey>,
218212

213+
/// Enable recording of node state and actions for debugging and replay
214+
///
215+
/// Recording captures the node's state transitions and input actions,
216+
/// enabling deterministic replay for debugging and testing purposes.
217+
///
218+
/// Available modes:
219+
/// - `none`: No recording (default)
220+
/// - `state-with-input-actions`: Records initial state and all input
221+
/// actions to the `recorder/` directory within the working directory
222+
///
223+
/// Recorded data can be replayed using the `mina replay` command to
224+
/// reproduce the exact sequence of state transitions for debugging.
225+
///
226+
/// # Example
227+
///
228+
/// ```bash
229+
/// # Record node execution
230+
/// mina node --network devnet --record state-with-input-actions
231+
///
232+
/// # Replay recorded execution
233+
/// mina replay state-with-input-actions ~/.mina/recorder
234+
/// ```
219235
#[arg(long, default_value = "none", env)]
220236
pub record: String,
221237

node/common/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
pub mod tracing;
2-
31
mod service;
2+
pub mod tracing;
43
pub use service::*;
5-
64
mod node;
75
pub use node::*;

node/common/src/service/service.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
use std::sync::Arc;
2-
1+
use super::{
2+
archive::ArchiveService,
3+
block_producer::BlockProducerService,
4+
p2p::webrtc_with_libp2p::P2pServiceCtx,
5+
replay::ReplayerState,
6+
rpc::{RpcSender, RpcService},
7+
snark_worker::SnarkWorker,
8+
snarks::SnarkBlockVerifyArgs,
9+
EventReceiver, EventSender,
10+
};
11+
use crate::rpc::RpcReceiver;
312
use node::{
413
core::{channels::mpsc, invariants::InvariantsState},
514
event_source::Event,
@@ -14,43 +23,51 @@ use sha3::{
1423
digest::{core_api::XofReaderCoreWrapper, ExtendableOutput, Update},
1524
Shake256, Shake256ReaderCore,
1625
};
17-
18-
use crate::rpc::RpcReceiver;
19-
20-
use super::{
21-
archive::ArchiveService,
22-
block_producer::BlockProducerService,
23-
p2p::webrtc_with_libp2p::P2pServiceCtx,
24-
replay::ReplayerState,
25-
rpc::{RpcSender, RpcService},
26-
snark_worker::SnarkWorker,
27-
snarks::SnarkBlockVerifyArgs,
28-
EventReceiver, EventSender,
29-
};
26+
use std::sync::Arc;
3027

3128
pub struct NodeService {
29+
/// Master seed for deterministic random number generation.
3230
pub rng_seed: [u8; 32],
31+
/// XOF-based RNG for ephemeral keys (derived from seed + "ephemeral").
3332
pub rng_ephemeral: XofReaderCoreWrapper<Shake256ReaderCore>,
33+
/// XOF-based RNG for static operations (derived from seed + "static").
3434
pub rng_static: XofReaderCoreWrapper<Shake256ReaderCore>,
35+
/// Standard RNG for general-purpose randomness.
3536
pub rng: StdRng,
3637

3738
/// Events sent on this channel are retrieved and processed in the
3839
/// `event_source` state machine defined in the `mina-node` crate.
3940
pub event_sender: EventSender,
41+
/// Channel for consuming events in the event source state machine.
4042
pub event_receiver: EventReceiver,
4143

44+
/// Channel for asynchronous block proof verification requests.
4245
pub snark_block_proof_verify: mpsc::TrackedUnboundedSender<SnarkBlockVerifyArgs>,
4346

47+
/// Manages ledger operations, database access, and staged ledger state.
4448
pub ledger_manager: LedgerManager,
49+
/// SNARK proof worker for generating transaction proofs (enabled when node
50+
/// acts as SNARK worker).
4551
pub snark_worker: Option<SnarkWorker>,
52+
/// Block production service including VRF evaluation and block proving
53+
/// (enabled when node acts as block producer).
4654
pub block_producer: Option<BlockProducerService>,
55+
/// Archive service for storing full blockchain history (enabled when node
56+
/// acts as archive node).
4757
pub archive: Option<ArchiveService>,
58+
/// P2P networking context (WebRTC and optionally libp2p transports).
4859
pub p2p: P2pServiceCtx,
4960

61+
/// Runtime statistics and metrics collection.
5062
pub stats: Option<Stats>,
63+
/// RPC service for external API queries.
5164
pub rpc: RpcService,
65+
/// Records node state and actions for debugging and replay.
5266
pub recorder: Recorder,
67+
/// Replayer state for deterministic action replay (only set in replay
68+
/// mode).
5369
pub replayer: Option<ReplayerState>,
70+
/// State for runtime invariant checking and validation.
5471
pub invariants_state: InvariantsState,
5572
}
5673

node/native/src/replay.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::cell::RefCell;
2-
1+
use crate::NodeService;
32
use node::{
43
core::thread,
54
recorder::StateWithInputActionsReader,
65
snark::{BlockVerifier, TransactionVerifier},
76
ActionWithMeta, BuildEnv, Store,
87
};
9-
10-
use crate::NodeService;
8+
use std::cell::RefCell;
119

1210
pub fn replay_state_with_input_actions(
1311
dir: &str,

node/testing/src/hosts.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1+
use crate::scenario::ListenerNode;
2+
use node::p2p::connection::outgoing::P2pConnectionOutgoingInitOpts;
13
/// This should be the only place where environment variables are converted to addresses.
24
///
35
use std::{env, str::FromStr};
46

5-
use node::p2p::connection::outgoing::P2pConnectionOutgoingInitOpts;
6-
7-
use crate::scenario::ListenerNode;
8-
97
pub fn replayer() -> P2pConnectionOutgoingInitOpts {
10-
// "/dns4/1.k8.openmina.com/tcp/31968/p2p/12D3KooWPayQEdprqY2m3biReUUybA5LoULpJE7YWu6wetEKKELv",
11-
128
let multiaddr = env::var("REPLAYER_MULTIADDR")
139
.expect("must set variable `REPLAYER_MULTIADDR`")
1410
.parse::<libp2p::Multiaddr>()

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
use std::time::Duration;
2-
3-
use mina_core::constants::constraint_constants;
4-
use node::transition_frontier::sync::TransitionFrontierSyncState;
5-
use redux::Instant;
6-
71
use crate::{
82
hosts,
93
node::RustNodeTestingConfig,
104
scenario::{ListenerNode, ScenarioStep},
115
scenarios::ClusterRunner,
126
};
7+
use mina_core::constants::constraint_constants;
8+
use node::transition_frontier::sync::TransitionFrontierSyncState;
9+
use redux::Instant;
10+
use std::time::Duration;
1311

1412
/// Set up single Rust node and bootstrap snarked ledger, bootstrap ledger and blocks.
1513
///
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Record node execution using Docker
3+
4+
# Create directory for recording
5+
mkdir -p mina-replay-test
6+
7+
# Run node with recording enabled using Docker
8+
docker run --rm \
9+
-v "$(pwd)/mina-replay-test:/root/.mina" \
10+
o1labs/mina-rust:latest \
11+
node \
12+
--network devnet \
13+
--record state-with-input-actions \
14+
--work-dir /root/.mina
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# Record node execution for debugging and replay
3+
4+
# Run node with recording enabled
5+
mina node \
6+
--network devnet \
7+
--record state-with-input-actions \
8+
--work-dir ~/.mina-replay-test
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Record with custom directory using Docker
3+
4+
# Create custom directory for recording
5+
mkdir -p my-custom-replay-dir
6+
7+
# Run node with custom recording directory
8+
docker run --rm \
9+
-v "$(pwd)/my-custom-replay-dir:/root/.mina" \
10+
o1labs/mina-rust:latest \
11+
node \
12+
--network devnet \
13+
--record state-with-input-actions \
14+
--work-dir /root/.mina
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Record node execution with custom working directory
3+
4+
WORK_DIR="$1"
5+
if [ -z "$WORK_DIR" ]; then
6+
echo "Usage: $0 <work-directory>"
7+
exit 1
8+
fi
9+
10+
# Run node with recording enabled using custom directory
11+
mina node \
12+
--network devnet \
13+
--record state-with-input-actions \
14+
--work-dir "$WORK_DIR"

0 commit comments

Comments
 (0)