Skip to content

Commit

Permalink
use VoteState::deserialize() everywhere except vote program
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Feb 5, 2024
1 parent 7e1464a commit 1474c18
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 23 deletions.
3 changes: 1 addition & 2 deletions account-decoder/src/parse_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use {
};

pub fn parse_vote(data: &[u8]) -> Result<VoteAccountType, ParseAccountError> {
let mut vote_state =
VoteState::deserialize_with_bincode(data).map_err(ParseAccountError::from)?;
let mut vote_state = VoteState::deserialize(data).map_err(ParseAccountError::from)?;
let epoch_credits = vote_state
.epoch_credits()
.iter()
Expand Down
2 changes: 1 addition & 1 deletion programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl From<VoteStateUpdate> for VoteTransaction {

// utility function, used by Stakes, tests
pub fn from<T: ReadableAccount>(account: &T) -> Option<VoteState> {
VoteState::deserialize_with_bincode(account.data()).ok()
VoteState::deserialize(account.data()).ok()
}

// utility function, used by Stakes, tests
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ impl Bank {
// vote_accounts_cache_miss_count is shown to be always zero.
let account = self.get_account_with_fixed_root(vote_pubkey)?;
if account.owner() == &solana_vote_program
&& VoteState::deserialize_with_bincode(account.data()).is_ok()
&& VoteState::deserialize(account.data()).is_ok()
{
vote_accounts_cache_miss_count.fetch_add(1, Relaxed);
}
Expand Down
14 changes: 0 additions & 14 deletions sdk/program/src/vote/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,6 @@ impl VoteState {
Ok(vote_state)
}

// this only exists for the sake of the feature gated upgrade to the new parser; do not use it
#[doc(hidden)]
#[allow(clippy::used_underscore_binding)]
pub fn deserialize_with_bincode(_input: &[u8]) -> Result<Self, InstructionError> {
#[cfg(not(target_os = "solana"))]
{
bincode::deserialize::<VoteStateVersions>(_input)
.map(|versioned| versioned.convert_to_current())
.map_err(|_| InstructionError::InvalidAccountData)
}
#[cfg(target_os = "solana")]
unimplemented!()
}

/// Deserializes the input buffer into the provided `VoteState`
///
/// This function is exposed to allow deserialization in a BPF context directly into boxed memory.
Expand Down
7 changes: 2 additions & 5 deletions vote/src/vote_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,10 @@ impl VoteAccount {
}

pub fn vote_state(&self) -> Result<&VoteState, &Error> {
// VoteState::deserialize_with_bincode deserializes a VoteStateVersions and then
// calls VoteStateVersions::convert_to_current.
// VoteState::deserialize deserializes a VoteStateVersions directly into VoteState
self.0
.vote_state
.get_or_init(|| {
VoteState::deserialize_with_bincode(self.0.account.data()).map_err(Error::from)
})
.get_or_init(|| VoteState::deserialize(self.0.account.data()).map_err(Error::from))
.as_ref()
}

Expand Down

0 comments on commit 1474c18

Please sign in to comment.