Skip to content

Commit

Permalink
Clean up set merkle fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Feb 4, 2025
1 parent ecdbfaf commit 41d6234
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
3 changes: 3 additions & 0 deletions tip-router-operator-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub enum Commands {

#[arg(long, env)]
override_target_slot: Option<u64>,

#[arg(long, env, default_value = "false")]
set_merkle_roots: bool,
},
SnapshotSlot {
#[arg(short, long, env)]
Expand Down
3 changes: 3 additions & 0 deletions tip-router-operator-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn main() -> Result<()> {
num_monitored_epochs,
start_next_epoch,
override_target_slot,
set_merkle_roots,
} => {
info!("Running Tip Router...");
info!("NCN Address: {}", ncn_address);
Expand Down Expand Up @@ -110,6 +111,7 @@ async fn main() -> Result<()> {
&tip_distribution_program_id,
num_monitored_epochs,
&cli_clone,
set_merkle_roots,
)
.await
{
Expand Down Expand Up @@ -240,6 +242,7 @@ async fn main() -> Result<()> {
&tip_router_program_id,
&tip_distribution_program_id,
cli.submit_as_memo,
true,
)
.await?;
}
Expand Down
11 changes: 4 additions & 7 deletions tip-router-operator-cli/src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub async fn submit_recent_epochs_to_ncn(
tip_distribution_program_id: &Pubkey,
num_monitored_epochs: u64,
cli_args: &Cli,
set_merkle_roots: bool,
) -> Result<(), anyhow::Error> {
let epoch = client.get_epoch_info()?;
let operator_address = Pubkey::from_str(&cli_args.operator_address)?;
Expand All @@ -54,6 +55,7 @@ pub async fn submit_recent_epochs_to_ncn(
tip_router_program_id,
tip_distribution_program_id,
cli_args.submit_as_memo,
set_merkle_roots,
)
.await
{
Expand All @@ -75,12 +77,12 @@ pub async fn submit_to_ncn(
tip_router_program_id: &Pubkey,
tip_distribution_program_id: &Pubkey,
submit_as_memo: bool,
set_merkle_roots: bool,
) -> Result<(), anyhow::Error> {
let epoch_info = client.get_epoch_info()?;
let meta_merkle_tree = MetaMerkleTree::new_from_file(meta_merkle_tree_path)?;
let config_pda = Config::find_program_address(tip_router_program_id, ncn_address).0;
let config = get_ncn_config(client, tip_router_program_id, ncn_address).await?;
info!("Fetched NCN config");

// The meta merkle root files are tagged with the epoch they have created the snapshot for
// Tip router accounts for that merkle root are created in the next epoch
Expand All @@ -105,15 +107,12 @@ pub async fn submit_to_ncn(
}
};

info!("Fetched ballot box account");

let ballot_box = BallotBox::try_from_slice_unchecked(&ballot_box_account.data)?;

let is_voting_valid = ballot_box.is_voting_valid(
epoch_info.absolute_slot,
config.valid_slots_after_consensus(),
)?;
info!("Is voting valid: {}", is_voting_valid);

// If exists, look for vote from current operator
let vote = ballot_box
Expand Down Expand Up @@ -187,7 +186,7 @@ pub async fn submit_to_ncn(
}
}

if ballot_box.is_consensus_reached() {
if ballot_box.is_consensus_reached() && set_merkle_roots {
// Fetch TipDistributionAccounts filtered by epoch and upload authority
// Tip distribution accounts are derived from the epoch they are for
let tip_distribution_accounts = get_tip_distribution_accounts_to_upload(
Expand Down Expand Up @@ -255,8 +254,6 @@ async fn get_tip_distribution_accounts_to_upload(
tip_distribution_program_id: &Pubkey,
) -> Result<Vec<(Pubkey, TipDistributionAccount)>, anyhow::Error> {
let rpc_client = AsyncRpcClient::new_with_timeout(client.url(), Duration::from_secs(1800));
let tip_distribution_config_address =
derive_config_account_address(tip_distribution_program_id).0;

// Filters assume merkle root is None
let filters = vec![
Expand Down
9 changes: 2 additions & 7 deletions tip-router-operator-cli/src/tip_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use jito_tip_router_core::{
epoch_snapshot::{EpochSnapshot, OperatorSnapshot},
epoch_state::EpochState,
};
use log::info;
use log::{error, info};
use meta_merkle_tree::meta_merkle_tree::MetaMerkleTree;
use solana_sdk::{
pubkey::Pubkey,
Expand Down Expand Up @@ -114,7 +114,7 @@ pub async fn set_merkle_roots_batched(
let proof = if let Some(proof) = meta_merkle_node.proof {
proof
} else {
// TODO emit big warning NO PROOF
error!("No proof found for tip distribution account {:?}", key);
return None;
};

Expand All @@ -140,11 +140,6 @@ pub async fn set_merkle_roots_batched(
})
.collect::<Vec<_>>();

info!(
"Build instructions for {} tip distribution accounts",
instructions.len()
);

let mut results = vec![];
for _ in 0..instructions.len() {
results.push(Err(EllipsisClientError::Other(anyhow::anyhow!(
Expand Down

0 comments on commit 41d6234

Please sign in to comment.