-
Notifications
You must be signed in to change notification settings - Fork 207
feat: VoteStateV4 goodies
#331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}, | ||
| }; | ||
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| .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 { | ||
|
|
@@ -214,4 +228,13 @@ impl VoteStateV4 { | |
| ..Self::default() | ||
| } | ||
| } | ||
|
|
||
| pub fn commission(&self) -> Result<u8, InstructionError> { | ||
| let commission_bps = self | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?