Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 20, 2024
1 parent 42510f2 commit ed4ad08
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
4 changes: 4 additions & 0 deletions clients/js/jito_tip_router/accounts/operatorSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type OperatorSnapshot = {
slotCreated: bigint;
slotFinalized: bigint;
isActive: number;
ncnOperatorIndex: bigint;
operatorIndex: bigint;
operatorFeeBps: number;
vaultOperatorDelegationCount: bigint;
Expand All @@ -75,6 +76,7 @@ export type OperatorSnapshotArgs = {
slotCreated: number | bigint;
slotFinalized: number | bigint;
isActive: number;
ncnOperatorIndex: number | bigint;
operatorIndex: number | bigint;
operatorFeeBps: number;
vaultOperatorDelegationCount: number | bigint;
Expand All @@ -95,6 +97,7 @@ export function getOperatorSnapshotEncoder(): Encoder<OperatorSnapshotArgs> {
['slotCreated', getU64Encoder()],
['slotFinalized', getU64Encoder()],
['isActive', getBoolEncoder()],
['ncnOperatorIndex', getU64Encoder()],
['operatorIndex', getU64Encoder()],
['operatorFeeBps', getU16Encoder()],
['vaultOperatorDelegationCount', getU64Encoder()],
Expand All @@ -119,6 +122,7 @@ export function getOperatorSnapshotDecoder(): Decoder<OperatorSnapshot> {
['slotCreated', getU64Decoder()],
['slotFinalized', getU64Decoder()],
['isActive', getBoolDecoder()],
['ncnOperatorIndex', getU64Decoder()],
['operatorIndex', getU64Decoder()],
['operatorFeeBps', getU16Decoder()],
['vaultOperatorDelegationCount', getU64Decoder()],
Expand Down
5 changes: 0 additions & 5 deletions clients/js/jito_tip_router/types/ballot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
combineCodec,
fixDecoderSize,
fixEncoderSize,
getBoolDecoder,
getBoolEncoder,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
Expand All @@ -24,7 +22,6 @@ import {

export type Ballot = {
merkleRoot: ReadonlyUint8Array;
isCast: number;
reserved: ReadonlyUint8Array;
};

Expand All @@ -33,15 +30,13 @@ export type BallotArgs = Ballot;
export function getBallotEncoder(): Encoder<BallotArgs> {
return getStructEncoder([
['merkleRoot', fixEncoderSize(getBytesEncoder(), 32)],
['isCast', getBoolEncoder()],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
}

export function getBallotDecoder(): Decoder<Ballot> {
return getStructDecoder([
['merkleRoot', fixDecoderSize(getBytesDecoder(), 32)],
['isCast', getBoolDecoder()],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct OperatorSnapshot {
pub slot_created: u64,
pub slot_finalized: u64,
pub is_active: bool,
pub ncn_operator_index: u64,
pub operator_index: u64,
pub operator_fee_bps: u16,
pub vault_operator_delegation_count: u64,
Expand Down
1 change: 0 additions & 1 deletion clients/rust/jito_tip_router/src/generated/types/ballot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use borsh::{BorshDeserialize, BorshSerialize};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ballot {
pub merkle_root: [u8; 32],
pub is_cast: bool,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 64],
}
15 changes: 6 additions & 9 deletions core/src/ballot_box.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use jito_bytemuck::{
types::{PodBool, PodU128, PodU16, PodU64},
types::{PodU128, PodU16, PodU64},
AccountDeserialize, Discriminator,
};
use shank::{ShankAccount, ShankType};
Expand All @@ -13,25 +13,22 @@ use crate::{constants::PRECISE_CONSENSUS, discriminators::Discriminators, error:
#[repr(C)]
pub struct Ballot {
merkle_root: [u8; 32],
is_cast: PodBool,
reserved: [u8; 64],
}

impl Default for Ballot {
fn default() -> Self {
Self {
merkle_root: [0; 32],
is_cast: PodBool::from(false),
reserved: [0; 64],
}
}
}

impl Ballot {
pub fn new(root: [u8; 32]) -> Self {
pub const fn new(root: [u8; 32]) -> Self {
Self {
merkle_root: root,
is_cast: PodBool::from(true),
reserved: [0; 64],
}
}
Expand All @@ -40,8 +37,8 @@ impl Ballot {
self.merkle_root
}

pub fn is_cast(&self) -> bool {
self.is_cast.into()
pub fn is_valid(&self) -> bool {
self.merkle_root.iter().any(|&b| b != 0)
}
}

Expand Down Expand Up @@ -282,11 +279,11 @@ impl BallotBox {
}

pub fn is_consensus_reached(&self) -> bool {
self.slot_consensus_reached() == 0
self.slot_consensus_reached() > 0
}

pub fn get_winning_ballot(&self) -> Result<Ballot, TipRouterError> {
if self.winning_ballot.is_cast() {
if self.winning_ballot.is_valid() {
Ok(self.winning_ballot)
} else {
Err(TipRouterError::ConsensusNotReached)
Expand Down
7 changes: 7 additions & 0 deletions core/src/epoch_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub struct OperatorSnapshot {

is_active: PodBool,

ncn_operator_index: PodU64,
operator_index: PodU64,
operator_fee_bps: PodU16,

Expand Down Expand Up @@ -277,6 +278,7 @@ impl OperatorSnapshot {
bump: u8,
current_slot: u64,
is_active: bool,
ncn_operator_index: u64,
operator_index: u64,
operator_fee_bps: u16,
vault_operator_delegation_count: u64,
Expand All @@ -293,6 +295,7 @@ impl OperatorSnapshot {
slot_created: PodU64::from(current_slot),
slot_finalized: PodU64::from(0),
is_active: PodBool::from(is_active),
ncn_operator_index: PodU64::from(ncn_operator_index),
operator_index: PodU64::from(operator_index),
operator_fee_bps: PodU16::from(operator_fee_bps),
vault_operator_delegation_count: PodU64::from(vault_operator_delegation_count),
Expand All @@ -311,6 +314,7 @@ impl OperatorSnapshot {
ncn_epoch: u64,
bump: u8,
current_slot: u64,
ncn_operator_index: u64,
operator_index: u64,
operator_fee_bps: u16,
vault_count: u64,
Expand All @@ -322,6 +326,7 @@ impl OperatorSnapshot {
bump,
current_slot,
true,
ncn_operator_index,
operator_index,
operator_fee_bps,
vault_count,
Expand All @@ -334,6 +339,7 @@ impl OperatorSnapshot {
ncn_epoch: u64,
bump: u8,
current_slot: u64,
ncn_operator_index: u64,
operator_index: u64,
) -> Result<Self, TipRouterError> {
let mut snapshot = Self::new(
Expand All @@ -343,6 +349,7 @@ impl OperatorSnapshot {
bump,
current_slot,
false,
ncn_operator_index,
operator_index,
0,
0,
Expand Down
12 changes: 6 additions & 6 deletions idl/jito_tip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@
"defined": "PodBool"
}
},
{
"name": "ncnOperatorIndex",
"type": {
"defined": "PodU64"
}
},
{
"name": "operatorIndex",
"type": {
Expand Down Expand Up @@ -967,12 +973,6 @@
]
}
},
{
"name": "isCast",
"type": {
"defined": "PodBool"
}
},
{
"name": "reserved",
"type": {
Expand Down
8 changes: 6 additions & 2 deletions program/src/initialize_operator_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn process_initialize_operator_snapshot(
)?;

//TODO move to helper function
let is_active: bool = {
let (is_active, ncn_operator_index): (bool, u64) = {
let ncn_operator_state_data = ncn_operator_state.data.borrow();
let ncn_operator_state_account =
NcnOperatorState::try_from_slice_unchecked(&ncn_operator_state_data)?;
Expand All @@ -97,7 +97,9 @@ pub fn process_initialize_operator_snapshot(
.operator_opt_in_state
.is_active(current_slot, ncn_epoch_length);

ncn_operator_okay && operator_ncn_okay
let ncn_operator_index = ncn_operator_state_account.index();

(ncn_operator_okay && operator_ncn_okay, ncn_operator_index)
};

let vault_count = {
Expand Down Expand Up @@ -128,6 +130,7 @@ pub fn process_initialize_operator_snapshot(
ncn_epoch,
operator_snapshot_bump,
current_slot,
ncn_operator_index,
operator_index,
operator_fee_bps,
vault_count,
Expand All @@ -139,6 +142,7 @@ pub fn process_initialize_operator_snapshot(
ncn_epoch,
operator_snapshot_bump,
current_slot,
ncn_operator_index,
operator_index,
)?
};
Expand Down

0 comments on commit ed4ad08

Please sign in to comment.