Skip to content

Commit

Permalink
running test ncn
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Jan 28, 2025
1 parent 3dfcf82 commit 4798d5f
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# placeholders for clippy and other tools
# Program IDs may not be correct
[env]
TIP_ROUTER_PROGRAM_ID = "RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb"
TIP_ROUTER_PROGRAM_ID = "Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf"
RESTAKING_PROGRAM_ID = "RestkWeAVL8fRGgzhfeoqFhsqKRchg6aa1XrcH96z4Q"
VAULT_PROGRAM_ID = "Vau1t6sLNxnzB7ZDsef8TLbPLfyZMYXH8WTNqUdm9g8"
2 changes: 1 addition & 1 deletion .cargo/programs.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TIP_ROUTER_PROGRAM_ID=RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb
TIP_ROUTER_PROGRAM_ID=Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf
RESTAKING_PROGRAM_ID=RestkWeAVL8fRGgzhfeoqFhsqKRchg6aa1XrcH96z4Q
VAULT_PROGRAM_ID=Vau1t6sLNxnzB7ZDsef8TLbPLfyZMYXH8WTNqUdm9g8
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
# - name: Generate code coverage
# run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
# env:
# TIP_ROUTER_PROGRAM_ID: RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb
# TIP_ROUTER_PROGRAM_ID: Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf
# - name: Upload coverage to Codecov
# uses: codecov/[email protected]
# with:
Expand Down
2 changes: 1 addition & 1 deletion cli/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

| Account | Address |
| -------------------------- | -------------------------------------------- |
| Test Tip Router Program ID | RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb |
| Test Tip Router Program ID | Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf |
| Test NCN | rYQFkFYXuDqJPoH2FvFtZTC8oC3CntgRjtNatx6q1z1 |

## Setup CLIs
Expand Down
2 changes: 1 addition & 1 deletion cli/src/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub async fn get_vault_registry(handler: &CliHandler) -> Result<VaultRegistry> {
let account = get_account(handler, &address).await?;

if account.is_none() {
return Err(anyhow::anyhow!("Account not found"));
return Err(anyhow::anyhow!("VR Account not found"));
}
let account = account.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub async fn admin_set_config_fees(
}

if let Some(wallet) = &new_base_fee_wallet {
let wallet = Pubkey::from_str(&wallet).map_err(|_| anyhow!("Invalid wallet address"))?;
let wallet = Pubkey::from_str(wallet).map_err(|_| anyhow!("Invalid wallet address"))?;
ix.new_base_fee_wallet(wallet);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/src/keeper/keeper_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
crank_snapshot, crank_vote, create_epoch_state,
},
keeper::{
keeper_metrics::{emit_epoch_metrics, emit_error},
keeper_metrics::{emit_epoch_metrics, emit_error, emit_ncn_metrics},
keeper_state::KeeperState,
},
log::{boring_progress_bar, progress_bar},
Expand Down Expand Up @@ -101,7 +101,7 @@ pub async fn run_keeper(
loop {
{
info!("A. Emit NCN Metrics");
let result = emit_epoch_metrics(handler, state.epoch).await;
let result = emit_ncn_metrics(handler).await;

check_and_timeout_error(
"Emit NCN Metrics".to_string(),
Expand Down
79 changes: 77 additions & 2 deletions cli/src/keeper/keeper_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use jito_tip_router_core::{
account_payer::AccountPayer, base_fee_group::BaseFeeGroup, constants::MAX_OPERATORS,
epoch_state::AccountStatus, ncn_fee_group::NcnFeeGroup,
};
use log::info;
use solana_metrics::datapoint_info;
use solana_sdk::native_token::lamports_to_sol;

Expand All @@ -11,8 +12,9 @@ use crate::{
get_account_payer, get_all_operators_in_ncn, get_all_tickets, get_all_vaults_in_ncn,
get_ballot_box, get_base_reward_receiver, get_base_reward_router,
get_current_epoch_and_slot, get_epoch_snapshot, get_epoch_state, get_is_epoch_completed,
get_ncn_reward_receiver, get_ncn_reward_router, get_operator, get_tip_router_config,
get_vault, get_vault_operator_delegation, get_vault_registry, get_weight_table,
get_ncn_reward_receiver, get_ncn_reward_router, get_operator, get_operator_snapshot,
get_tip_router_config, get_vault, get_vault_operator_delegation, get_vault_registry,
get_weight_table,
},
handler::CliHandler,
};
Expand Down Expand Up @@ -40,6 +42,8 @@ pub async fn emit_ncn_metrics(handler: &CliHandler) -> Result<()> {

pub async fn emit_ncn_metrics_account_payer(handler: &CliHandler) -> Result<()> {
let (current_epoch, current_slot) = get_current_epoch_and_slot(handler).await?;
info!("\n\nACCOUNT PAYER\n\n");

let (account_payer_address, _, _) =
AccountPayer::find_program_address(&handler.tip_router_program_id, handler.ncn()?);
let account_payer = get_account_payer(handler).await?;
Expand Down Expand Up @@ -115,6 +119,8 @@ pub async fn emit_ncn_metrics_operators(handler: &CliHandler) -> Result<()> {
let all_operators = get_all_operators_in_ncn(handler).await?;

for operator in all_operators {
info!("\n\nOPERATOR {}\n\n", operator);

let operator_account = get_operator(handler, &operator).await?;

datapoint_info!(
Expand Down Expand Up @@ -148,6 +154,10 @@ pub async fn emit_ncn_metrics_vault_registry(handler: &CliHandler) -> Result<()>
);

for vault in vault_registry.vault_list {
if vault.is_empty() {
continue;
}

let vault_account = get_vault(handler, vault.vault()).await?;

datapoint_info!(
Expand Down Expand Up @@ -194,6 +204,8 @@ pub async fn emit_ncn_metrics_vault_registry(handler: &CliHandler) -> Result<()>

pub async fn emit_ncn_metrics_config(handler: &CliHandler) -> Result<()> {
let (current_epoch, current_slot) = get_current_epoch_and_slot(handler).await?;
info!("\n\nTIP ROUTER CONFIG\n\n");

let config = get_tip_router_config(handler).await?;
let fee_config = config.fee_config;
let current_fees = fee_config.current_fees(current_epoch);
Expand Down Expand Up @@ -258,6 +270,7 @@ pub async fn emit_epoch_metrics(handler: &CliHandler, epoch: u64) -> Result<()>
emit_epoch_metrics_state(handler, epoch).await?;
emit_epoch_metrics_weight_table(handler, epoch).await?;
emit_epoch_metrics_epoch_snapshot(handler, epoch).await?;
emit_epoch_metrics_operator_snapshot(handler, epoch).await?;
emit_epoch_metrics_ballot_box(handler, epoch).await?;
emit_epoch_metrics_base_rewards(handler, epoch).await?;
emit_epoch_metrics_ncn_rewards(handler, epoch).await?;
Expand Down Expand Up @@ -399,6 +412,7 @@ pub async fn emit_epoch_metrics_base_rewards(handler: &CliHandler, epoch: u64) -
Ok(())
}

#[allow(clippy::large_stack_frames)]
pub async fn emit_epoch_metrics_ballot_box(handler: &CliHandler, epoch: u64) -> Result<()> {
let (current_epoch, current_slot) = get_current_epoch_and_slot(handler).await?;
let valid_slots_after_consensus = {
Expand All @@ -411,6 +425,10 @@ pub async fn emit_epoch_metrics_ballot_box(handler: &CliHandler, epoch: u64) ->

if let Ok(ballot_box) = result {
for operator_vote in ballot_box.operator_votes() {
if operator_vote.is_empty() {
continue;
}

let ballot_index = operator_vote.ballot_index();
let ballot_tally = ballot_box.ballot_tallies()[ballot_index as usize];
let vote = format!("{:?}", ballot_tally.ballot().root());
Expand Down Expand Up @@ -456,6 +474,61 @@ pub async fn emit_epoch_metrics_ballot_box(handler: &CliHandler, epoch: u64) ->
Ok(())
}

pub async fn emit_epoch_metrics_operator_snapshot(handler: &CliHandler, epoch: u64) -> Result<()> {
let (current_epoch, current_slot) = get_current_epoch_and_slot(handler).await?;

let all_operators = get_all_operators_in_ncn(handler).await?;

for operator in all_operators.iter() {
let result = get_operator_snapshot(handler, operator, epoch).await;

if let Ok(operator_snapshot) = result {
datapoint_info!(
"beta-trk-ee-operator-snapshot",
("current-epoch", current_epoch, i64),
("current-slot", current_slot, i64),
("keeper-epoch", epoch, i64),
("operator", operator.to_string(), String),
("is-finalized", operator_snapshot.finalized(), bool),
("is-active", operator_snapshot.is_active(), bool),
(
"ncn-operator-index",
operator_snapshot.ncn_operator_index(),
i64
),
(
"operator-fee-bps",
operator_snapshot.operator_fee_bps(),
i64
),
(
"valid-operator-vault-delegations",
operator_snapshot.valid_operator_vault_delegations(),
i64
),
(
"vault-operator-delegation-count",
operator_snapshot.vault_operator_delegation_count(),
i64
),
(
"vault-operator-delegations-registered",
operator_snapshot.vault_operator_delegations_registered(),
i64
),
(
"stake-weight",
operator_snapshot.stake_weights().stake_weight(),
i64
),
("slot-finalized", operator_snapshot.slot_finalized(), i64),
);
}
}

Ok(())
}

pub async fn emit_epoch_metrics_epoch_snapshot(handler: &CliHandler, epoch: u64) -> Result<()> {
let (current_epoch, current_slot) = get_current_epoch_and_slot(handler).await?;

Expand Down Expand Up @@ -549,6 +622,8 @@ pub async fn emit_epoch_metrics_state(handler: &CliHandler, epoch: u64) -> Resul
("keeper-epoch", epoch, i64),
("is-complete", true, bool),
);

return Ok(());
}

let state = get_epoch_state(handler, epoch).await?;
Expand Down
4 changes: 2 additions & 2 deletions clients/js/jito_tip_router/programs/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
} from '../instructions';

export const JITO_TIP_ROUTER_PROGRAM_ADDRESS =
'RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb' as Address<'RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb'>;
'Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf' as Address<'Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf'>;

export enum JitoTipRouterAccount {
BallotBox,
Expand Down Expand Up @@ -219,7 +219,7 @@ export function identifyJitoTipRouterInstruction(
}

export type ParsedJitoTipRouterInstruction<
TProgram extends string = 'RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb',
TProgram extends string = 'Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf',
> =
| ({
instructionType: JitoTipRouterInstruction.InitializeConfig;
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/jito_tip_router/src/generated/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
use solana_program::{pubkey, pubkey::Pubkey};

/// `jito_tip_router` program ID.
pub const JITO_TIP_ROUTER_ID: Pubkey = pubkey!("RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb");
pub const JITO_TIP_ROUTER_ID: Pubkey = pubkey!("Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf");
37 changes: 37 additions & 0 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::mem::size_of;

use borsh::{BorshDeserialize, BorshSerialize};
Expand Down Expand Up @@ -128,6 +129,42 @@ impl Config {
}
}

impl fmt::Display for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "\nConfig:")?;
writeln!(f, " NCN: {}", self.ncn)?;
writeln!(
f,
" Tie Breaker: {}",
self.tie_breaker_admin
)?;
writeln!(f, " Fee Admin: {}", self.fee_admin)?;
writeln!(
f,
" Valid Slots After Consensus: {}",
self.valid_slots_after_consensus()
)?;
writeln!(
f,
" Epochs Before Stall: {}",
self.epochs_before_stall()
)?;
writeln!(
f,
" Starting Valid Epochs: {}",
self.starting_valid_epoch()
)?;
writeln!(
f,
" Close Epoch: {}",
self.epochs_after_consensus_before_close()
)?;
// writeln!(f, " Fees: {}", self.fee_config)?;
writeln!(f, " Bump: {}", self.bump)?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion idl/jito_tip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,6 @@
],
"metadata": {
"origin": "shank",
"address": "RouterBmuRBkPUbgEDMtdvTZ75GBdSREZR5uGUxxxpb"
"address": "Ap2AH3VcZGuuauEDq87uhgjNoUKcCAafc4DTyTByLMFf"
}
}

0 comments on commit 4798d5f

Please sign in to comment.