Skip to content

Commit d27f552

Browse files
feat: TipRouter CLI separate stages (#87)
### Change notes * New top-level environment variable/CLI arg * SAVE_PATH: renaming of `META_MERKLE_TREE_DIR`. Path where all generated operator files are stored * Separates each stage of the process into more coherent functions. * `run` CLI command loops through each stage, saving the outputs to _save-path_ CLI argument. The output from each stage is held in memory to reduce the processing. * New Environment Variables/CLI Args for `run` * STARTING_STAGE: Ability to start the operator from a specific stage before it continues * one of: `load-bank-from-snapshot, create-stake-meta, create-merkle-tree-collection, create-meta-merkle-tree, cast-vote, wait-for-next-epoch` * SAVE_STAGES: true/false - whether to save the state of intermediate stages in files. Needed for CLAIM_TIPS and SET_MERKLE_ROOT * SAVE_SNAPSHOTS: true/false - whether to save the bank loaded in the target as a full snapshot (~100GB). * Create CLI commands for each stage * _snapshot-slot_ - Create and store a full snapshot for a given slot * _create-stake-meta_ - For a given epoch and slot, load the bank and create the `StakeMetaCollection` file which contains validator vote accounts and their staking delegations. * _create-merkle-tree-collection_ - For a given epoch, load the `StakeMetaCollection` from disk at _save-path_, generate and save the `GeneratedMerkleTreeCollection`. * _create-meta-merkle-tree_ - For a given epoch, load the `GeneratedMerkleTreeCollection` from disk at _save-path_, generate and save the`MetaMerkleTree`. * _submit-epoch_ - For a given epoch, load the MetaMerkle file and cast a vote to the NCN's ballot box. Optionally set the merkle root on the Tip Distribution account if the NCN has consensus for the epoch. * _claim-tips_ - For a given epoch, generate and execute Tip Distribution Claim instructions for any unclaimed tips. * TipRouter saved files * generated files are now saved under _save-path_ * Files _<= current_epoch - num_monitored_epochs_ are purged for anything * NOTE: file names have change to a _{epoch}_file_name.json_ format. All previous files will not be removed. Operators should manually delete old files. --------- Co-authored-by: Evan Batsell <[email protected]>
1 parent 7bf9c11 commit d27f552

File tree

17 files changed

+1153
-695
lines changed

17 files changed

+1153
-695
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
name: jito_tip_router_program.so
201201
path: integration_tests/tests/fixtures/
202202
- uses: taiki-e/install-action@nextest
203-
- run: cargo nextest run --all-features -E 'not test(ledger_utils::tests::test_get_bank_from_ledger_success) and not test(test_meta_merkle_creation_from_ledger)'
203+
- run: cargo nextest run --all-features -E 'not test(ledger_utils::tests)'
204204
env:
205205
SBF_OUT_DIR: ${{ github.workspace }}/integration_tests/tests/fixtures
206206

Cargo.lock

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

format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cargo fmt --all
1414

1515
print_executing "cargo nextest run --all-features"
1616
cargo build-sbf --sbf-out-dir integration_tests/tests/fixtures
17-
SBF_OUT_DIR=integration_tests/tests/fixtures cargo nextest run --all-features -E 'not test(ledger_utils::tests::test_get_bank_from_ledger_success) and not test(test_meta_merkle_creation_from_ledger)'
17+
SBF_OUT_DIR=integration_tests/tests/fixtures cargo nextest run --all-features -E 'not test(ledger_utils::tests::test_get_bank_from_ledger_success)'
1818

1919
# Code coverage only runs with flag
2020
if [[ "$*" == *"--code-coverage"* ]]; then

meta_merkle_tree/src/generated_merkle_tree.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{fs::File, io::BufReader, path::PathBuf};
1+
use std::{
2+
fs::File,
3+
io::{BufReader, Write},
4+
path::PathBuf,
5+
};
26

37
use jito_tip_distribution_sdk::{
48
jito_tip_distribution::ID as TIP_DISTRIBUTION_ID, CLAIM_STATUS_SEED,
@@ -119,6 +123,14 @@ impl GeneratedMerkleTreeCollection {
119123

120124
Ok(tree)
121125
}
126+
127+
/// Write a GeneratedMerkleTreeCollection to a filepath
128+
pub fn write_to_file(&self, path: &PathBuf) -> Result<(), MerkleRootGeneratorError> {
129+
let serialized = serde_json::to_string_pretty(&self)?;
130+
let mut file = File::create(path)?;
131+
file.write_all(serialized.as_bytes())?;
132+
Ok(())
133+
}
122134
}
123135

124136
#[derive(Clone, Eq, Debug, Hash, PartialEq, Deserialize, Serialize)]
@@ -339,6 +351,24 @@ pub struct StakeMetaCollection {
339351
pub slot: Slot,
340352
}
341353

354+
impl StakeMetaCollection {
355+
/// Load a serialized merkle tree from file path
356+
pub fn new_from_file(path: &PathBuf) -> Result<Self, MerkleRootGeneratorError> {
357+
let file = File::open(path)?;
358+
let reader = BufReader::new(file);
359+
let tree: Self = serde_json::from_reader(reader)?;
360+
361+
Ok(tree)
362+
}
363+
364+
/// Write a merkle tree to a filepath
365+
pub fn write_to_file(&self, path: &PathBuf) {
366+
let serialized = serde_json::to_string_pretty(&self).unwrap();
367+
let mut file = File::create(path).unwrap();
368+
file.write_all(serialized.as_bytes()).unwrap();
369+
}
370+
}
371+
342372
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
343373
pub struct StakeMeta {
344374
#[serde(with = "pubkey_string_conversion")]

meta_merkle_tree/src/meta_merkle_tree.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ impl MetaMerkleTree {
9090
}
9191

9292
/// Write a merkle tree to a filepath
93-
pub fn write_to_file(&self, path: &PathBuf) {
94-
let serialized = serde_json::to_string_pretty(&self).unwrap();
95-
let mut file = File::create(path).unwrap();
96-
file.write_all(serialized.as_bytes()).unwrap();
93+
pub fn write_to_file(&self, path: &PathBuf) -> Result<()> {
94+
let serialized = serde_json::to_string_pretty(&self)?;
95+
let mut file = File::create(path)?;
96+
file.write_all(serialized.as_bytes())?;
97+
Ok(())
9798
}
9899

99100
pub fn get_node(&self, tip_distribution_account: &Pubkey) -> TreeNode {
@@ -241,7 +242,7 @@ mod tests {
241242
let path = PathBuf::from("merkle_tree.json");
242243

243244
// serialize merkle distributor to file
244-
merkle_distributor_info.write_to_file(&path);
245+
merkle_distributor_info.write_to_file(&path).unwrap();
245246
// now test we can successfully read from file
246247
let merkle_distributor_read: MetaMerkleTree = MetaMerkleTree::new_from_file(&path).unwrap();
247248

tip-router-operator-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ hex = "0.4"
1717
im = "15.1"
1818
itertools = "0.11"
1919
jito-bytemuck = { workspace = true }
20-
jito-restaking-program = { workspace = true }
2120
jito-tip-distribution-sdk = { workspace = true }
2221
jito-tip-payment-sdk = { workspace = true }
2322
jito-tip-router-client = { workspace = true }

0 commit comments

Comments
 (0)