Skip to content

Commit

Permalink
addressed everything
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Jan 21, 2025
1 parent ddce590 commit 8c79c39
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
19 changes: 11 additions & 8 deletions core/src/ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ impl std::fmt::Display for Ballot {

impl Ballot {
pub fn new(merkle_root: &[u8; 32]) -> Self {
let is_valid = merkle_root.iter().any(|byte| *byte != 0);

if !is_valid {
return Self::default();
}

Self {
let mut ballot = Self {
meta_merkle_root: *merkle_root,
is_valid: PodBool::from(true),
is_valid: PodBool::from(false),
reserved: [0; 63],
};

for byte in ballot.meta_merkle_root.iter() {
if *byte != 0 {
ballot.is_valid = PodBool::from(true);
break;
}
}

ballot
}

pub const fn root(&self) -> [u8; 32] {
Expand Down
13 changes: 2 additions & 11 deletions program/src/close_epoch_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use solana_program::{
program_error::ProgramError, pubkey::Pubkey, sysvar::Sysvar,
};

/// Reallocates the ballot box account to its full size.
/// This is needed due to Solana's account size limits during initialization.
/// Crank Closes all accounts associated with an epoch
#[allow(clippy::cognitive_complexity)]
pub fn process_close_epoch_account(
program_id: &Pubkey,
Expand Down Expand Up @@ -71,15 +70,7 @@ pub fn process_close_epoch_account(

let epoch_delta = current_epoch.saturating_sub(epoch_consensus_reached);
if epoch_delta < epochs_after_consensus_before_close {
msg!("Not enough epochs have passed since epoch state creation");
return Err(TipRouterError::CannotCloseAccount.into());
}
}

// Progress Check
{
if !epoch_state_account.voting_progress().is_complete() {
msg!("Cannot close account until voting is complete");
msg!("Not enough epochs have passed since consensus reached");
return Err(TipRouterError::CannotCloseAccount.into());
}
}
Expand Down
4 changes: 2 additions & 2 deletions program/src/initialize_ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use jito_jsm_core::loader::{load_system_account, load_system_program};
use jito_restaking_core::ncn::Ncn;
use jito_tip_router_core::{
account_payer::AccountPayer, ballot_box::BallotBox, config::Config as NcnConfig,
epoch_state::EpochState,
constants::MAX_REALLOC_BYTES, epoch_state::EpochState,
};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn process_initialize_ballot_box(
ballot_box,
system_program,
program_id,
BallotBox::SIZE,
MAX_REALLOC_BYTES as usize,
&ballot_box_seeds,
)?;

Expand Down
3 changes: 2 additions & 1 deletion program/src/initialize_base_reward_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use jito_restaking_core::ncn::Ncn;
use jito_tip_router_core::{
account_payer::AccountPayer,
base_reward_router::{BaseRewardReceiver, BaseRewardRouter},
constants::MAX_REALLOC_BYTES,
epoch_state::EpochState,
};
use solana_program::{
Expand Down Expand Up @@ -52,7 +53,7 @@ pub fn process_initialize_base_reward_router(
base_reward_router,
system_program,
program_id,
BaseRewardRouter::SIZE,
MAX_REALLOC_BYTES as usize,
&base_reward_router_seeds,
)?;

Expand Down
7 changes: 5 additions & 2 deletions program/src/initialize_epoch_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use jito_jsm_core::loader::{load_system_account, load_system_program};
use jito_restaking_core::ncn::Ncn;
use jito_tip_router_core::{account_payer::AccountPayer, config::Config, epoch_state::EpochState};
use jito_tip_router_core::{
account_payer::AccountPayer, config::Config, constants::MAX_REALLOC_BYTES,
epoch_state::EpochState,
};
use solana_program::{
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
program_error::ProgramError, pubkey::Pubkey, sysvar::Sysvar,
Expand Down Expand Up @@ -43,7 +46,7 @@ pub fn process_initialize_epoch_state(
epoch_state,
system_program,
program_id,
EpochState::SIZE,
MAX_REALLOC_BYTES as usize,
&epoch_state_seeds,
)?;

Expand Down
3 changes: 2 additions & 1 deletion program/src/initialize_operator_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use jito_restaking_core::{ncn::Ncn, ncn_operator_state::NcnOperatorState, operat
use jito_tip_router_core::{
account_payer::AccountPayer,
config::Config,
constants::MAX_REALLOC_BYTES,
epoch_snapshot::{EpochSnapshot, OperatorSnapshot},
epoch_state::EpochState,
error::TipRouterError,
Expand Down Expand Up @@ -82,7 +83,7 @@ pub fn process_initialize_operator_snapshot(
operator_snapshot,
system_program,
program_id,
OperatorSnapshot::SIZE,
MAX_REALLOC_BYTES as usize,
&operator_snapshot_seeds,
)?;

Expand Down
5 changes: 3 additions & 2 deletions program/src/initialize_vault_registry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use jito_jsm_core::loader::{load_system_account, load_system_program};
use jito_restaking_core::ncn::Ncn;
use jito_tip_router_core::{
account_payer::AccountPayer, config::Config as NcnConfig, vault_registry::VaultRegistry,
account_payer::AccountPayer, config::Config as NcnConfig, constants::MAX_REALLOC_BYTES,
vault_registry::VaultRegistry,
};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
Expand Down Expand Up @@ -39,7 +40,7 @@ pub fn process_initialize_vault_registry(
vault_registry,
system_program,
program_id,
VaultRegistry::SIZE,
MAX_REALLOC_BYTES as usize,
&vault_registry_seeds,
)?;

Expand Down
6 changes: 3 additions & 3 deletions program/src/initialize_weight_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use jito_bytemuck::AccountDeserialize;
use jito_jsm_core::loader::{load_system_account, load_system_program};
use jito_restaking_core::ncn::Ncn;
use jito_tip_router_core::{
account_payer::AccountPayer, epoch_state::EpochState, vault_registry::VaultRegistry,
weight_table::WeightTable,
account_payer::AccountPayer, constants::MAX_REALLOC_BYTES, epoch_state::EpochState,
vault_registry::VaultRegistry, weight_table::WeightTable,
};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError,
Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn process_initialize_weight_table(
weight_table,
system_program,
program_id,
WeightTable::SIZE,
MAX_REALLOC_BYTES as usize,
&weight_table_seeds,
)?;

Expand Down

0 comments on commit 8c79c39

Please sign in to comment.