Skip to content

Commit 0678569

Browse files
committed
Add ledger-tail cli configuration options
Also set default validators.toml path properly
1 parent dc6fd16 commit 0678569

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

monad-node/examples/ledger-tail.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::{
2020
path::{Path, PathBuf},
2121
};
2222

23+
use clap::{CommandFactory, FromArgMatches, Parser};
2324
use futures_util::{Stream, StreamExt};
2425
use inotify::{Inotify, WatchMask};
2526
use lru::LruCache;
@@ -99,14 +100,19 @@ async fn main() {
99100
);
100101
tracing::subscriber::set_global_default(subscriber).expect("unable to set default subscriber");
101102

103+
let mut cmd = Cli::command();
104+
let Cli {
105+
forkpoint_path,
106+
ledger_path,
107+
node_config_path,
108+
validators_path,
109+
} = Cli::from_arg_matches_mut(&mut cmd.get_matches_mut()).expect("unable to parse CLI");
110+
102111
let mut visited_blocks: CachedBlocks = LruCache::new(NonZero::new(100).unwrap());
103112

104-
let forkpoint_path: PathBuf = PathBuf::from("/monad/config/forkpoint");
105-
let ledger_path: PathBuf = PathBuf::from("/monad/ledger");
106-
let node_config: MonadNodeConfig = toml::from_str(
107-
&std::fs::read_to_string("/monad/config/node.toml").expect("node.toml not found"),
108-
)
109-
.unwrap();
113+
let node_config: MonadNodeConfig =
114+
toml::from_str(&std::fs::read_to_string(&node_config_path).expect("node.toml not found"))
115+
.unwrap();
110116
let addresses: HashMap<_, _> = node_config
111117
.bootstrap
112118
.peers
@@ -137,7 +143,7 @@ async fn main() {
137143
.entry(tc.epoch)
138144
.or_insert_with(|| {
139145
let validators: ValidatorsConfig<SignatureCollectionType> =
140-
ValidatorsConfig::read_from_path("/monad/config/validators.toml")
146+
ValidatorsConfig::read_from_path(&validators_path)
141147
.unwrap_or_else(|err| panic!("failed to read validators.toml, or validators.toml corrupt. was this edited manually? err={:?}", err));
142148
validators
143149
.get_validator_set(&tc.epoch)
@@ -261,7 +267,14 @@ pub fn latest_tip_stream(
261267
.expect("failed to watch ledger path");
262268
inotify
263269
.watches()
264-
.add(forkpoint_path, WatchMask::CLOSE_WRITE | WatchMask::MOVE)
270+
.add(
271+
{
272+
let mut forkpoint_dir = PathBuf::from(forkpoint_path);
273+
forkpoint_dir.pop();
274+
forkpoint_dir
275+
},
276+
WatchMask::CLOSE_WRITE | WatchMask::MOVE,
277+
)
265278
.expect("failed to watch forkpoint path");
266279

267280
let inotify_buffer = [0; 1024];
@@ -275,8 +288,7 @@ pub fn latest_tip_stream(
275288
ExecutionProtocolType,
276289
> = FileBlockPersist::new(ledger_path.to_owned());
277290

278-
let mut forkpoint_path = forkpoint_path.to_owned();
279-
forkpoint_path.push("forkpoint.toml");
291+
let forkpoint_path = forkpoint_path.to_owned();
280292

281293
inotify_events.filter_map(move |maybe_event| {
282294
let result = (|| match maybe_event {
@@ -301,3 +313,19 @@ pub fn latest_tip_stream(
301313
async move { result }
302314
})
303315
}
316+
317+
#[derive(Debug, Parser)]
318+
#[command(about, long_about = None)]
319+
pub struct Cli {
320+
#[arg(long, default_value = "/monad/ledger")]
321+
pub ledger_path: PathBuf,
322+
323+
#[arg(long, default_value = "/monad/config/forkpoint/forkpoint.toml")]
324+
pub forkpoint_path: PathBuf,
325+
326+
#[arg(long, default_value = "/monad/config/node.toml")]
327+
pub node_config_path: PathBuf,
328+
329+
#[arg(long, default_value = "/monad/config/validators/validators.toml")]
330+
pub validators_path: PathBuf,
331+
}

0 commit comments

Comments
 (0)