Skip to content

Commit 1b042e5

Browse files
authored
patch 1.1.1 (#103)
* update version to 1.1.1 * refactor `CLI` * make --save-path and --meta-merkle-tree-dir optional arguments, where one must be present * Brings back ENV var support for META_MERKLE_TREE_DIR * marked --meta-merkle-tree-dir as deprecated
1 parent d27f552 commit 1b042e5

File tree

7 files changed

+51
-29
lines changed

7 files changed

+51
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tip-router-operator-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tip-router-operator-cli"
3-
version = "0.1.0"
3+
version = "1.1.1"
44
edition = "2021"
55
description = "CLI for Jito Tip Router"
66

tip-router-operator-cli/src/claim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub async fn claim_mev_tips_with_emit(
7878
let keypair = read_keypair_file(cli.keypair_path.clone())
7979
.map_err(|e| anyhow::anyhow!("Failed to read keypair file: {:?}", e))?;
8080
let keypair = Arc::new(keypair);
81-
let meta_merkle_tree_dir = cli.save_path.clone();
81+
let meta_merkle_tree_dir = cli.get_save_path().clone();
8282
let rpc_url = cli.rpc_url.clone();
8383
let merkle_tree_coll_path = meta_merkle_tree_dir.join(merkle_tree_collection_file_name(epoch));
8484
let mut merkle_tree_coll = GeneratedMerkleTreeCollection::new_from_file(&merkle_tree_coll_path)

tip-router-operator-cli/src/cli.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,41 @@ pub struct Cli {
3737
#[arg(long, env, default_value_t = 1)]
3838
pub micro_lamports: u64,
3939

40-
#[arg(
41-
long,
42-
env,
43-
alias = "meta-merkle-tree-dir",
44-
help = "Path to save data (formerly meta-merkle-tree-dir)"
45-
)]
46-
pub save_path: PathBuf,
40+
#[arg(long, env, help = "Path to save data (formerly meta-merkle-tree-dir)")]
41+
pub save_path: Option<PathBuf>,
42+
43+
#[arg(short, long, env, help = "Path to save data (deprecated)")]
44+
#[deprecated(since = "1.1.0", note = "use --save-path instead")]
45+
pub meta_merkle_tree_dir: Option<PathBuf>,
4746

4847
#[command(subcommand)]
4948
pub command: Commands,
5049
}
5150

5251
impl Cli {
52+
#[allow(deprecated)]
53+
pub fn get_save_path(&self) -> PathBuf {
54+
self.save_path.to_owned().map_or_else(
55+
|| {
56+
self.meta_merkle_tree_dir.to_owned().map_or_else(
57+
|| {
58+
panic!("--save-path argument must be set");
59+
},
60+
|save_path| save_path,
61+
)
62+
},
63+
|save_path| save_path,
64+
)
65+
}
66+
5367
pub fn create_save_path(&self) {
54-
if !self.save_path.exists() {
68+
let save_path = self.get_save_path();
69+
if !save_path.exists() {
5570
info!(
5671
"Creating Tip Router save directory at {}",
57-
self.save_path.display()
72+
save_path.display()
5873
);
59-
std::fs::create_dir_all(&self.save_path).unwrap();
74+
std::fs::create_dir_all(&save_path).unwrap();
6075
}
6176
}
6277

tip-router-operator-cli/src/main.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ async fn main() -> Result<()> {
4040

4141
set_host_id(cli.operator_address.to_string());
4242

43+
// Will panic if the user did not set --save-path or the deprecated --meta-merkle-tree-dir
44+
let save_path = cli.get_save_path();
45+
4346
info!(
4447
"CLI Arguments:
4548
keypair_path: {}
@@ -48,14 +51,16 @@ async fn main() -> Result<()> {
4851
ledger_path: {}
4952
full_snapshots_path: {:?}
5053
snapshot_output_dir: {}
51-
backup_snapshots_dir: {}",
54+
backup_snapshots_dir: {}
55+
save_path: {}",
5256
cli.keypair_path,
5357
cli.operator_address,
5458
cli.rpc_url,
5559
cli.ledger_path.display(),
5660
cli.full_snapshots_path,
5761
cli.snapshot_output_dir.display(),
58-
cli.backup_snapshots_dir.display()
62+
cli.backup_snapshots_dir.display(),
63+
save_path.display(),
5964
);
6065

6166
cli.create_save_path();
@@ -132,7 +137,7 @@ async fn main() -> Result<()> {
132137
let cli_clone: Cli = cli.clone();
133138
// Track incremental snapshots and backup to `backup_snapshots_dir`
134139
tokio::spawn(async move {
135-
let save_path = cli_clone.save_path;
140+
let save_path = cli_clone.get_save_path();
136141
loop {
137142
if let Err(e) = BackupSnapshotMonitor::new(
138143
&rpc_url,
@@ -206,7 +211,7 @@ async fn main() -> Result<()> {
206211
epoch,
207212
set_merkle_roots,
208213
} => {
209-
let meta_merkle_tree_path = cli.save_path.join(meta_merkle_tree_file_name(epoch));
214+
let meta_merkle_tree_path = cli.get_save_path().join(meta_merkle_tree_file_name(epoch));
210215
info!(
211216
"Submitting epoch {} from {}...",
212217
epoch,
@@ -277,7 +282,7 @@ async fn main() -> Result<()> {
277282
&Arc::new(bank),
278283
&tip_distribution_program_id,
279284
&tip_payment_program_id,
280-
&cli.save_path,
285+
&save_path,
281286
save,
282287
);
283288
}
@@ -289,7 +294,7 @@ async fn main() -> Result<()> {
289294
} => {
290295
// Load the stake_meta_collection from disk
291296
let stake_meta_collection = match StakeMetaCollection::new_from_file(
292-
&cli.save_path.join(stake_meta_file_name(epoch)),
297+
&cli.get_save_path().join(stake_meta_file_name(epoch)),
293298
) {
294299
Ok(stake_meta_collection) => stake_meta_collection,
295300
Err(e) => panic!("{}", e),
@@ -309,14 +314,14 @@ async fn main() -> Result<()> {
309314
epoch,
310315
&ncn_address,
311316
protocol_fee_bps,
312-
&cli.save_path,
317+
&save_path,
313318
save,
314319
);
315320
}
316321
Commands::CreateMetaMerkleTree { epoch, save } => {
317322
// Load the stake_meta_collection from disk
318323
let merkle_tree_collection = match GeneratedMerkleTreeCollection::new_from_file(
319-
&cli.save_path.join(merkle_tree_collection_file_name(epoch)),
324+
&save_path.join(merkle_tree_collection_file_name(epoch)),
320325
) {
321326
Ok(merkle_tree_collection) => merkle_tree_collection,
322327
Err(e) => panic!("{}", e),
@@ -326,7 +331,7 @@ async fn main() -> Result<()> {
326331
cli.operator_address,
327332
merkle_tree_collection,
328333
epoch,
329-
&cli.save_path,
334+
&save_path,
330335
save,
331336
);
332337
}

tip-router-operator-cli/src/process_epoch.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub async fn loop_stages(
185185
bank.as_ref().expect("Bank was not set"),
186186
tip_distribution_program_id,
187187
tip_payment_program_id,
188-
&cli.save_path,
188+
&cli.get_save_path(),
189189
save_stages,
190190
));
191191
// we should be able to safely drop the bank in this loop
@@ -197,7 +197,9 @@ pub async fn loop_stages(
197197
let some_stake_meta_collection = match stake_meta_collection.to_owned() {
198198
Some(collection) => collection,
199199
None => {
200-
let file = cli.save_path.join(stake_meta_file_name(epoch_to_process));
200+
let file = cli
201+
.get_save_path()
202+
.join(stake_meta_file_name(epoch_to_process));
201203
StakeMetaCollection::new_from_file(&file)?
202204
}
203205
};
@@ -217,7 +219,7 @@ pub async fn loop_stages(
217219
epoch_to_process,
218220
ncn_address,
219221
protocol_fee_bps,
220-
&cli.save_path,
222+
&cli.get_save_path(),
221223
save_stages,
222224
));
223225

@@ -230,7 +232,7 @@ pub async fn loop_stages(
230232
Some(collection) => collection,
231233
None => {
232234
let file = cli
233-
.save_path
235+
.get_save_path()
234236
.join(merkle_tree_collection_file_name(epoch_to_process));
235237
GeneratedMerkleTreeCollection::new_from_file(&file)?
236238
}
@@ -240,7 +242,7 @@ pub async fn loop_stages(
240242
cli.operator_address.clone(),
241243
some_merkle_tree_collection,
242244
epoch_to_process,
243-
&cli.save_path,
245+
&cli.get_save_path(),
244246
// This is defaulted to true because the output file is required by the
245247
// task that sets TipDistributionAccounts' merkle roots
246248
true,
@@ -250,7 +252,7 @@ pub async fn loop_stages(
250252
OperatorState::CastVote => {
251253
let meta_merkle_tree_path = PathBuf::from(format!(
252254
"{}/{}",
253-
cli.save_path.display(),
255+
cli.get_save_path().display(),
254256
meta_merkle_tree_file_name(epoch_to_process)
255257
));
256258
let operator_address = Pubkey::from_str(&cli.operator_address)?;

tip-router-operator-cli/src/submit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub async fn submit_recent_epochs_to_ncn(
4141
for i in 0..num_monitored_epochs {
4242
let process_epoch = epoch.epoch.checked_sub(i).unwrap();
4343

44-
let meta_merkle_tree_dir = cli_args.save_path.clone();
44+
let meta_merkle_tree_dir = cli_args.get_save_path();
4545
let target_meta_merkle_tree_file = meta_merkle_tree_file_name(process_epoch);
4646
let target_meta_merkle_tree_path = meta_merkle_tree_dir.join(target_meta_merkle_tree_file);
4747
if !target_meta_merkle_tree_path.exists() {

0 commit comments

Comments
 (0)