Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vote-interface/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ mod tests {
authorized_voter: original_voter,
authorized_withdrawer: original_voter,
commission: 0,
bls_pubkey_compressed: None,
},
&Clock::default(),
);
Expand Down Expand Up @@ -1002,6 +1003,7 @@ mod tests {
authorized_voter: original_voter,
authorized_withdrawer: original_voter,
commission: 0,
bls_pubkey_compressed: None,
},
&Clock::default(),
);
Expand Down Expand Up @@ -1100,6 +1102,7 @@ mod tests {
authorized_voter: original_voter,
authorized_withdrawer: original_voter,
commission: 0,
bls_pubkey_compressed: None,
},
&Clock::default(),
);
Expand Down Expand Up @@ -1217,6 +1220,7 @@ mod tests {
authorized_voter: Pubkey::new_unique(),
authorized_withdrawer: Pubkey::new_unique(),
commission: 0,
bls_pubkey_compressed: None,
},
&Clock::default(),
);
Expand Down
12 changes: 11 additions & 1 deletion vote-interface/src/state/vote_instruction_data.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "serde")]
use serde_with::serde_as;
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
use {
crate::state::{Lockout, MAX_LOCKOUT_HISTORY},
crate::state::{Lockout, BLS_PUBLIC_KEY_COMPRESSED_SIZE, MAX_LOCKOUT_HISTORY},
solana_clock::{Slot, UnixTimestamp},
solana_hash::Hash,
solana_pubkey::Pubkey,
Expand Down Expand Up @@ -192,13 +194,21 @@ impl TowerSync {
}
}

#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_as)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
pub struct VoteInit {
pub node_pubkey: Pubkey,
pub authorized_voter: Pubkey,
pub authorized_withdrawer: Pubkey,
pub commission: u8,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstarry @buffalojoec - should we add in fields for the inflation bps and block rewards bps commissions?

/// Compressed BLS pubkey for Alpenglow.
#[cfg_attr(
feature = "serde",
serde_as(as = "Option<[_; BLS_PUBLIC_KEY_COMPRESSED_SIZE]>")
)]
pub bls_pubkey_compressed: Option<[u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE]>,
}

#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
Expand Down
27 changes: 26 additions & 1 deletion vote-interface/src/state/vote_state_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use {
MAX_LOCKOUT_HISTORY, VOTE_CREDITS_GRACE_SLOTS, VOTE_CREDITS_MAXIMUM_PER_SLOT,
},
crate::{
authorized_voters::AuthorizedVoters, error::VoteError, state::DEFAULT_PRIOR_VOTERS_OFFSET,
authorized_voters::AuthorizedVoters,
error::VoteError,
state::{VoteStateV4, DEFAULT_PRIOR_VOTERS_OFFSET},
},
solana_clock::{Clock, Epoch, Slot, UnixTimestamp},
solana_instruction_error::InstructionError,
Expand Down Expand Up @@ -513,3 +515,26 @@ impl VoteStateV3 {
&& data[VERSION_OFFSET..DEFAULT_PRIOR_VOTERS_END] != [0; DEFAULT_PRIOR_VOTERS_OFFSET]
}
}

impl From<VoteStateV4> for VoteStateV3 {
fn from(vote_state: VoteStateV4) -> Self {
let commission_bps = vote_state
.inflation_rewards_commission_bps
.checked_add(vote_state.block_revenue_commission_bps)
.expect("Inflation rewards commission and block revenue commission bps overflow.");

let commission = commission_bps.div_ceil(10_000) as u8;

Self {
node_pubkey: vote_state.node_pubkey,
authorized_withdrawer: vote_state.authorized_withdrawer,
commission,
votes: vote_state.votes,
root_slot: vote_state.root_slot,
authorized_voters: vote_state.authorized_voters,
prior_voters: CircBuf::default(),
epoch_credits: vote_state.epoch_credits,
last_timestamp: vote_state.last_timestamp,
}
}
}
31 changes: 27 additions & 4 deletions vote-interface/src/state/vote_state_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use serde_derive::{Deserialize, Serialize};
use serde_with::serde_as;
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
#[cfg(any(target_os = "solana", feature = "bincode"))]
use solana_instruction::error::InstructionError;
use {
super::{BlockTimestamp, LandedVote, BLS_PUBLIC_KEY_COMPRESSED_SIZE},
crate::authorized_voters::AuthorizedVoters,
solana_clock::{Epoch, Slot},
crate::{authorized_voters::AuthorizedVoters, state::VoteInit},
solana_clock::{Clock, Epoch, Slot},
solana_instruction_error::InstructionError,
solana_pubkey::Pubkey,
std::{collections::VecDeque, fmt::Debug},
};
Expand Down Expand Up @@ -71,6 +70,21 @@ pub struct VoteStateV4 {
}

impl VoteStateV4 {
pub fn new(vote_init: &VoteInit, clock: &Clock) -> Self {
let inflation_rewards_commission_bps = (vote_init.commission as u16)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstarry @buffalojoec - leaving this as a placeholder, though we probably don't want to do this. My guess is that we want VoteInit to have both commission bps fields.

.checked_mul(10_000)
.expect("Turning commission into basis points results in an overflow.");

Self {
node_pubkey: vote_init.node_pubkey,
authorized_voters: AuthorizedVoters::new(clock.epoch, vote_init.authorized_voter),
authorized_withdrawer: vote_init.authorized_withdrawer,
inflation_rewards_commission_bps,
bls_pubkey_compressed: vote_init.bls_pubkey_compressed,
..VoteStateV4::default()
}
}

/// Upper limit on the size of the Vote State
/// when votes.len() is MAX_LOCKOUT_HISTORY.
pub const fn size_of() -> usize {
Expand Down Expand Up @@ -214,4 +228,13 @@ impl VoteStateV4 {
..Self::default()
}
}

pub fn commission(&self) -> Result<u8, InstructionError> {
let commission_bps = self
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same here)

.inflation_rewards_commission_bps
.checked_add(self.block_revenue_commission_bps)
.ok_or(InstructionError::ArithmeticOverflow)?;

Ok(commission_bps.div_ceil(10_000) as u8)
}
}
Loading