Move vote program state and instructions to solana-program

This commit is contained in:
Michael Vines 2022-08-03 23:12:59 -07:00
parent b9a5af0a41
commit ccfbc54195
28 changed files with 2090 additions and 2037 deletions

1
Cargo.lock generated
View File

@ -6565,6 +6565,7 @@ dependencies = [
"solana-frozen-abi-macro 1.12.0", "solana-frozen-abi-macro 1.12.0",
"solana-logger 1.12.0", "solana-logger 1.12.0",
"solana-metrics", "solana-metrics",
"solana-program 1.12.0",
"solana-program-runtime", "solana-program-runtime",
"solana-sdk 1.12.0", "solana-sdk 1.12.0",
"thiserror", "thiserror",

View File

@ -259,7 +259,7 @@ mod tests {
solana_sdk::{account::Account, pubkey::Pubkey, signature::Signer}, solana_sdk::{account::Account, pubkey::Pubkey, signature::Signer},
solana_stake_program::stake_state, solana_stake_program::stake_state,
solana_vote_program::{ solana_vote_program::{
vote_state::{self, VoteStateVersions}, vote_state::{self, process_slot_vote_unchecked, VoteStateVersions},
vote_transaction, vote_transaction,
}, },
}; };
@ -309,7 +309,7 @@ mod tests {
let root = ancestors[2]; let root = ancestors[2];
vote_state.root_slot = Some(root); vote_state.root_slot = Some(root);
vote_state.process_slot_vote_unchecked(*ancestors.last().unwrap()); process_slot_vote_unchecked(&mut vote_state, *ancestors.last().unwrap());
AggregateCommitmentService::aggregate_commitment_for_vote_account( AggregateCommitmentService::aggregate_commitment_for_vote_account(
&mut commitment, &mut commitment,
&mut rooted_stake, &mut rooted_stake,
@ -341,8 +341,8 @@ mod tests {
let root = ancestors[2]; let root = ancestors[2];
vote_state.root_slot = Some(root); vote_state.root_slot = Some(root);
assert!(ancestors[4] + 2 >= ancestors[6]); assert!(ancestors[4] + 2 >= ancestors[6]);
vote_state.process_slot_vote_unchecked(ancestors[4]); process_slot_vote_unchecked(&mut vote_state, ancestors[4]);
vote_state.process_slot_vote_unchecked(ancestors[6]); process_slot_vote_unchecked(&mut vote_state, ancestors[6]);
AggregateCommitmentService::aggregate_commitment_for_vote_account( AggregateCommitmentService::aggregate_commitment_for_vote_account(
&mut commitment, &mut commitment,
&mut rooted_stake, &mut rooted_stake,
@ -431,30 +431,30 @@ mod tests {
// Create bank // Create bank
let bank = Arc::new(Bank::new_for_tests(&genesis_config)); let bank = Arc::new(Bank::new_for_tests(&genesis_config));
let mut vote_state1 = VoteState::from(&vote_account1).unwrap(); let mut vote_state1 = vote_state::from(&vote_account1).unwrap();
vote_state1.process_slot_vote_unchecked(3); process_slot_vote_unchecked(&mut vote_state1, 3);
vote_state1.process_slot_vote_unchecked(5); process_slot_vote_unchecked(&mut vote_state1, 5);
let versioned = VoteStateVersions::new_current(vote_state1); let versioned = VoteStateVersions::new_current(vote_state1);
VoteState::to(&versioned, &mut vote_account1).unwrap(); vote_state::to(&versioned, &mut vote_account1).unwrap();
bank.store_account(&pk1, &vote_account1); bank.store_account(&pk1, &vote_account1);
let mut vote_state2 = VoteState::from(&vote_account2).unwrap(); let mut vote_state2 = vote_state::from(&vote_account2).unwrap();
vote_state2.process_slot_vote_unchecked(9); process_slot_vote_unchecked(&mut vote_state2, 9);
vote_state2.process_slot_vote_unchecked(10); process_slot_vote_unchecked(&mut vote_state2, 10);
let versioned = VoteStateVersions::new_current(vote_state2); let versioned = VoteStateVersions::new_current(vote_state2);
VoteState::to(&versioned, &mut vote_account2).unwrap(); vote_state::to(&versioned, &mut vote_account2).unwrap();
bank.store_account(&pk2, &vote_account2); bank.store_account(&pk2, &vote_account2);
let mut vote_state3 = VoteState::from(&vote_account3).unwrap(); let mut vote_state3 = vote_state::from(&vote_account3).unwrap();
vote_state3.root_slot = Some(1); vote_state3.root_slot = Some(1);
let versioned = VoteStateVersions::new_current(vote_state3); let versioned = VoteStateVersions::new_current(vote_state3);
VoteState::to(&versioned, &mut vote_account3).unwrap(); vote_state::to(&versioned, &mut vote_account3).unwrap();
bank.store_account(&pk3, &vote_account3); bank.store_account(&pk3, &vote_account3);
let mut vote_state4 = VoteState::from(&vote_account4).unwrap(); let mut vote_state4 = vote_state::from(&vote_account4).unwrap();
vote_state4.root_slot = Some(2); vote_state4.root_slot = Some(2);
let versioned = VoteStateVersions::new_current(vote_state4); let versioned = VoteStateVersions::new_current(vote_state4);
VoteState::to(&versioned, &mut vote_account4).unwrap(); vote_state::to(&versioned, &mut vote_account4).unwrap();
bank.store_account(&pk4, &vote_account4); bank.store_account(&pk4, &vote_account4);
let (commitment, rooted_stake) = let (commitment, rooted_stake) =

View File

@ -24,8 +24,8 @@ use {
solana_vote_program::{ solana_vote_program::{
vote_instruction, vote_instruction,
vote_state::{ vote_state::{
BlockTimestamp, Lockout, Vote, VoteState, VoteStateUpdate, VoteTransaction, process_slot_vote_unchecked, process_vote_unchecked, BlockTimestamp, Lockout, Vote,
MAX_LOCKOUT_HISTORY, VoteState, VoteStateUpdate, VoteTransaction, MAX_LOCKOUT_HISTORY,
}, },
}, },
std::{ std::{
@ -169,7 +169,7 @@ impl TowerVersions {
} }
} }
#[frozen_abi(digest = "8Y9r3XAwXwmrVGMCyTuy4Kbdotnt1V6N8J6NEniBFD9x")] #[frozen_abi(digest = "GrkFcKqGEkJNUYoK1M8rorehi2yyLF4N3Gsj6j8f47Jn")]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)]
pub struct Tower { pub struct Tower {
pub node_pubkey: Pubkey, pub node_pubkey: Pubkey,
@ -337,7 +337,7 @@ impl Tower {
); );
} }
vote_state.process_slot_vote_unchecked(bank_slot); process_slot_vote_unchecked(&mut vote_state, bank_slot);
for vote in &vote_state.votes { for vote in &vote_state.votes {
bank_weight += vote.lockout() as u128 * voted_stake as u128; bank_weight += vote.lockout() as u128 * voted_stake as u128;
@ -438,7 +438,7 @@ impl Tower {
last_voted_slot_in_bank: Option<Slot>, last_voted_slot_in_bank: Option<Slot>,
) -> VoteTransaction { ) -> VoteTransaction {
let vote = Vote::new(vec![slot], hash); let vote = Vote::new(vec![slot], hash);
local_vote_state.process_vote_unchecked(vote); process_vote_unchecked(local_vote_state, vote);
let slots = if let Some(last_voted_slot) = last_voted_slot_in_bank { let slots = if let Some(last_voted_slot) = last_voted_slot_in_bank {
local_vote_state local_vote_state
.votes .votes
@ -483,7 +483,7 @@ impl Tower {
let mut new_vote = if is_direct_vote_state_update_enabled { let mut new_vote = if is_direct_vote_state_update_enabled {
let vote = Vote::new(vec![vote_slot], vote_hash); let vote = Vote::new(vec![vote_slot], vote_hash);
self.vote_state.process_vote_unchecked(vote); process_vote_unchecked(&mut self.vote_state, vote);
VoteTransaction::from(VoteStateUpdate::new( VoteTransaction::from(VoteStateUpdate::new(
self.vote_state.votes.clone(), self.vote_state.votes.clone(),
self.vote_state.root_slot, self.vote_state.root_slot,
@ -608,7 +608,7 @@ impl Tower {
// remaining voted slots are on a different fork from the checked slot, // remaining voted slots are on a different fork from the checked slot,
// it's still locked out. // it's still locked out.
let mut vote_state = self.vote_state.clone(); let mut vote_state = self.vote_state.clone();
vote_state.process_slot_vote_unchecked(slot); process_slot_vote_unchecked(&mut vote_state, slot);
for vote in &vote_state.votes { for vote in &vote_state.votes {
if slot != vote.slot && !ancestors.contains(&vote.slot) { if slot != vote.slot && !ancestors.contains(&vote.slot) {
return true; return true;
@ -980,7 +980,7 @@ impl Tower {
total_stake: Stake, total_stake: Stake,
) -> bool { ) -> bool {
let mut vote_state = self.vote_state.clone(); let mut vote_state = self.vote_state.clone();
vote_state.process_slot_vote_unchecked(slot); process_slot_vote_unchecked(&mut vote_state, slot);
let vote = vote_state.nth_recent_vote(self.threshold_depth); let vote = vote_state.nth_recent_vote(self.threshold_depth);
if let Some(vote) = vote { if let Some(vote) = vote {
if let Some(fork_stake) = voted_stakes.get(&vote.slot) { if let Some(fork_stake) = voted_stakes.get(&vote.slot) {
@ -1432,7 +1432,7 @@ pub mod test {
signature::Signer, signature::Signer,
slot_history::SlotHistory, slot_history::SlotHistory,
}, },
solana_vote_program::vote_state::{Vote, VoteStateVersions, MAX_LOCKOUT_HISTORY}, solana_vote_program::vote_state::{self, Vote, VoteStateVersions, MAX_LOCKOUT_HISTORY},
std::{ std::{
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},
fs::{remove_file, OpenOptions}, fs::{remove_file, OpenOptions},
@ -1456,7 +1456,7 @@ pub mod test {
}); });
let mut vote_state = VoteState::default(); let mut vote_state = VoteState::default();
for slot in *votes { for slot in *votes {
vote_state.process_slot_vote_unchecked(*slot); process_slot_vote_unchecked(&mut vote_state, *slot);
} }
VoteState::serialize( VoteState::serialize(
&VoteStateVersions::new_current(vote_state), &VoteStateVersions::new_current(vote_state),
@ -2409,7 +2409,7 @@ pub mod test {
hash: Hash::default(), hash: Hash::default(),
timestamp: None, timestamp: None,
}; };
local.process_vote_unchecked(vote); vote_state::process_vote_unchecked(&mut local, vote);
assert_eq!(local.votes.len(), 1); assert_eq!(local.votes.len(), 1);
let vote = let vote =
Tower::apply_vote_and_generate_vote_diff(&mut local, 1, Hash::default(), Some(0)); Tower::apply_vote_and_generate_vote_diff(&mut local, 1, Hash::default(), Some(0));
@ -2425,7 +2425,7 @@ pub mod test {
hash: Hash::default(), hash: Hash::default(),
timestamp: None, timestamp: None,
}; };
local.process_vote_unchecked(vote); vote_state::process_vote_unchecked(&mut local, vote);
assert_eq!(local.votes.len(), 1); assert_eq!(local.votes.len(), 1);
// First vote expired, so should be evicted from tower. Thus even with // First vote expired, so should be evicted from tower. Thus even with

View File

@ -3529,7 +3529,7 @@ pub(crate) mod tests {
solana_streamer::socket::SocketAddrSpace, solana_streamer::socket::SocketAddrSpace,
solana_transaction_status::VersionedTransactionWithStatusMeta, solana_transaction_status::VersionedTransactionWithStatusMeta,
solana_vote_program::{ solana_vote_program::{
vote_state::{VoteState, VoteStateVersions}, vote_state::{self, VoteStateVersions},
vote_transaction, vote_transaction,
}, },
std::{ std::{
@ -4220,10 +4220,10 @@ pub(crate) mod tests {
fn test_replay_commitment_cache() { fn test_replay_commitment_cache() {
fn leader_vote(vote_slot: Slot, bank: &Arc<Bank>, pubkey: &Pubkey) { fn leader_vote(vote_slot: Slot, bank: &Arc<Bank>, pubkey: &Pubkey) {
let mut leader_vote_account = bank.get_account(pubkey).unwrap(); let mut leader_vote_account = bank.get_account(pubkey).unwrap();
let mut vote_state = VoteState::from(&leader_vote_account).unwrap(); let mut vote_state = vote_state::from(&leader_vote_account).unwrap();
vote_state.process_slot_vote_unchecked(vote_slot); vote_state::process_slot_vote_unchecked(&mut vote_state, vote_slot);
let versioned = VoteStateVersions::new_current(vote_state); let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut leader_vote_account).unwrap(); vote_state::to(&versioned, &mut leader_vote_account).unwrap();
bank.store_account(pubkey, &leader_vote_account); bank.store_account(pubkey, &leader_vote_account);
} }

View File

@ -9,7 +9,7 @@ use {
solana_vote_program::vote_state::{BlockTimestamp, Vote, VoteState}, solana_vote_program::vote_state::{BlockTimestamp, Vote, VoteState},
}; };
#[frozen_abi(digest = "7phMrqmBo2D3rXPdhBj8CpjRvvmx9qgpcU4cDGkL3W9q")] #[frozen_abi(digest = "8EBpwHf9gys2irNgyRCEe6A5KSh4RK875Fa46yA2NSoN")]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)]
pub struct Tower1_7_14 { pub struct Tower1_7_14 {
pub(crate) node_pubkey: Pubkey, pub(crate) node_pubkey: Pubkey,

View File

@ -99,7 +99,7 @@ use {
}, },
solana_send_transaction_service::send_transaction_service, solana_send_transaction_service::send_transaction_service,
solana_streamer::{socket::SocketAddrSpace, streamer::StakedNodes}, solana_streamer::{socket::SocketAddrSpace, streamer::StakedNodes},
solana_vote_program::vote_state::VoteState, solana_vote_program::vote_state,
std::{ std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
net::SocketAddr, net::SocketAddr,
@ -1206,7 +1206,7 @@ impl Validator {
fn active_vote_account_exists_in_bank(bank: &Arc<Bank>, vote_account: &Pubkey) -> bool { fn active_vote_account_exists_in_bank(bank: &Arc<Bank>, vote_account: &Pubkey) -> bool {
if let Some(account) = &bank.get_account(vote_account) { if let Some(account) = &bank.get_account(vote_account) {
if let Some(vote_state) = VoteState::from(account) { if let Some(vote_state) = vote_state::from(account) {
return !vote_state.votes.is_empty(); return !vote_state.votes.is_empty();
} }
} }

View File

@ -49,7 +49,7 @@ use {
solana_streamer::socket::SocketAddrSpace, solana_streamer::socket::SocketAddrSpace,
solana_vote_program::{ solana_vote_program::{
vote_instruction, vote_instruction,
vote_state::{VoteInit, VoteState}, vote_state::{self, VoteInit},
}, },
std::{ std::{
collections::HashMap, collections::HashMap,
@ -706,7 +706,7 @@ impl LocalCluster {
(Ok(Some(stake_account)), Ok(Some(vote_account))) => { (Ok(Some(stake_account)), Ok(Some(vote_account))) => {
match ( match (
stake_state::stake_from(&stake_account), stake_state::stake_from(&stake_account),
VoteState::from(&vote_account), vote_state::from(&vote_account),
) { ) {
(Some(stake_state), Some(vote_state)) => { (Some(stake_state), Some(vote_state)) => {
if stake_state.delegation.voter_pubkey != vote_account_pubkey if stake_state.delegation.voter_pubkey != vote_account_pubkey

View File

@ -40,7 +40,7 @@ use {
signature::{Keypair, Signer}, signature::{Keypair, Signer},
sysvar::{Sysvar, SysvarId}, sysvar::{Sysvar, SysvarId},
}, },
solana_vote_program::vote_state::{VoteState, VoteStateVersions}, solana_vote_program::vote_state::{self, VoteState, VoteStateVersions},
std::{ std::{
cell::RefCell, cell::RefCell,
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
@ -1054,14 +1054,14 @@ impl ProgramTestContext {
// generate some vote activity for rewards // generate some vote activity for rewards
let mut vote_account = bank.get_account(vote_account_address).unwrap(); let mut vote_account = bank.get_account(vote_account_address).unwrap();
let mut vote_state = VoteState::from(&vote_account).unwrap(); let mut vote_state = vote_state::from(&vote_account).unwrap();
let epoch = bank.epoch(); let epoch = bank.epoch();
for _ in 0..number_of_credits { for _ in 0..number_of_credits {
vote_state.increment_credits(epoch, 1); vote_state.increment_credits(epoch, 1);
} }
let versioned = VoteStateVersions::new_current(vote_state); let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
bank.store_account(vote_account_address, &vote_account); bank.store_account(vote_account_address, &vote_account);
} }

View File

@ -5837,6 +5837,7 @@ dependencies = [
"solana-frozen-abi 1.12.0", "solana-frozen-abi 1.12.0",
"solana-frozen-abi-macro 1.12.0", "solana-frozen-abi-macro 1.12.0",
"solana-metrics", "solana-metrics",
"solana-program 1.12.0",
"solana-program-runtime", "solana-program-runtime",
"solana-sdk 1.12.0", "solana-sdk 1.12.0",
"thiserror", "thiserror",

View File

@ -2267,7 +2267,7 @@ mod tests {
fn test_stake_delegate(feature_set: FeatureSet) { fn test_stake_delegate(feature_set: FeatureSet) {
let mut vote_state = VoteState::default(); let mut vote_state = VoteState::default();
for i in 0..1000 { for i in 0..1000 {
vote_state.process_slot_vote_unchecked(i); vote_state::process_slot_vote_unchecked(&mut vote_state, i);
} }
let vote_state_credits = vote_state.credits(); let vote_state_credits = vote_state.credits();
let vote_address = solana_sdk::pubkey::new_rand(); let vote_address = solana_sdk::pubkey::new_rand();

View File

@ -30,7 +30,7 @@ use {
stake_history::{StakeHistory, StakeHistoryEntry}, stake_history::{StakeHistory, StakeHistoryEntry},
transaction_context::{BorrowedAccount, InstructionContext, TransactionContext}, transaction_context::{BorrowedAccount, InstructionContext, TransactionContext},
}, },
solana_vote_program::vote_state::{VoteState, VoteStateVersions}, solana_vote_program::vote_state::{self, VoteState, VoteStateVersions},
std::{collections::HashSet, convert::TryFrom}, std::{collections::HashSet, convert::TryFrom},
}; };
@ -1750,7 +1750,7 @@ fn do_create_account(
) -> AccountSharedData { ) -> AccountSharedData {
let mut stake_account = AccountSharedData::new(lamports, StakeState::size_of(), &id()); let mut stake_account = AccountSharedData::new(lamports, StakeState::size_of(), &id());
let vote_state = VoteState::from(vote_account).expect("vote_state"); let vote_state = vote_state::from(vote_account).expect("vote_state");
let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len()); let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());

View File

@ -19,6 +19,7 @@ serde_derive = "1.0.103"
solana-frozen-abi = { path = "../../frozen-abi", version = "=1.12.0" } solana-frozen-abi = { path = "../../frozen-abi", version = "=1.12.0" }
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.12.0" } solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.12.0" }
solana-metrics = { path = "../../metrics", version = "=1.12.0" } solana-metrics = { path = "../../metrics", version = "=1.12.0" }
solana-program = { path = "../../sdk/program", version = "=1.12.0" }
solana-program-runtime = { path = "../../program-runtime", version = "=1.12.0" } solana-program-runtime = { path = "../../program-runtime", version = "=1.12.0" }
solana-sdk = { path = "../../sdk", version = "=1.12.0" } solana-sdk = { path = "../../sdk", version = "=1.12.0" }
thiserror = "1.0" thiserror = "1.0"

View File

@ -1,9 +1,6 @@
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] #![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))]
#![allow(clippy::integer_arithmetic)] #![allow(clippy::integer_arithmetic)]
pub mod authorized_voters;
pub mod vote_error;
pub mod vote_instruction;
pub mod vote_processor; pub mod vote_processor;
pub mod vote_state; pub mod vote_state;
pub mod vote_transaction; pub mod vote_transaction;
@ -14,4 +11,7 @@ extern crate solana_metrics;
#[macro_use] #[macro_use]
extern crate solana_frozen_abi_macro; extern crate solana_frozen_abi_macro;
pub use solana_sdk::vote::program::{check_id, id}; pub use solana_sdk::vote::{
authorized_voters, error as vote_error, instruction as vote_instruction,
program::{check_id, id},
};

View File

@ -1,12 +1,13 @@
//! Vote program processor //! Vote program processor
use { use {
crate::{ crate::vote_state,
id,
vote_instruction::VoteInstruction,
vote_state::{self, VoteAuthorize, VoteStateUpdate},
},
log::*, log::*,
solana_program::vote::{
instruction::VoteInstruction,
program::id,
state::{VoteAuthorize, VoteStateUpdate},
},
solana_program_runtime::{ solana_program_runtime::{
invoke_context::InvokeContext, sysvar_cache::get_sysvar_with_account_check, invoke_context::InvokeContext, sysvar_cache::get_sysvar_with_account_check,
}, },
@ -143,7 +144,7 @@ pub fn process_instruction(
get_sysvar_with_account_check::slot_hashes(invoke_context, instruction_context, 1)?; get_sysvar_with_account_check::slot_hashes(invoke_context, instruction_context, 1)?;
let clock = let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
vote_state::process_vote( vote_state::process_vote_with_account(
&mut me, &mut me,
&slot_hashes, &slot_hashes,
&clock, &clock,
@ -264,7 +265,7 @@ mod tests {
vote_switch, withdraw, VoteInstruction, vote_switch, withdraw, VoteInstruction,
}, },
vote_state::{ vote_state::{
Lockout, Vote, VoteAuthorize, VoteAuthorizeCheckedWithSeedArgs, self, Lockout, Vote, VoteAuthorize, VoteAuthorizeCheckedWithSeedArgs,
VoteAuthorizeWithSeedArgs, VoteInit, VoteState, VoteStateUpdate, VoteStateVersions, VoteAuthorizeWithSeedArgs, VoteInit, VoteState, VoteStateUpdate, VoteStateVersions,
}, },
}, },
@ -462,7 +463,7 @@ mod tests {
let (vote_pubkey, vote_account) = create_test_account(); let (vote_pubkey, vote_account) = create_test_account();
let vote_account_space = vote_account.data().len(); let vote_account_space = vote_account.data().len();
let mut vote_state = VoteState::from(&vote_account).unwrap(); let mut vote_state = vote_state::from(&vote_account).unwrap();
vote_state.authorized_withdrawer = vote_pubkey; vote_state.authorized_withdrawer = vote_pubkey;
vote_state.epoch_credits = Vec::new(); vote_state.epoch_credits = Vec::new();
@ -482,7 +483,7 @@ mod tests {
let mut vote_account_with_epoch_credits = let mut vote_account_with_epoch_credits =
AccountSharedData::new(lamports, vote_account_space, &id()); AccountSharedData::new(lamports, vote_account_space, &id());
let versioned = VoteStateVersions::new_current(vote_state); let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut vote_account_with_epoch_credits); vote_state::to(&versioned, &mut vote_account_with_epoch_credits);
(vote_pubkey, vote_account_with_epoch_credits) (vote_pubkey, vote_account_with_epoch_credits)
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
use { use {
crate::{vote_instruction, vote_state::Vote}, solana_program::vote::{self, state::Vote},
solana_sdk::{ solana_sdk::{
clock::Slot, clock::Slot,
hash::Hash, hash::Hash,
@ -19,14 +19,14 @@ pub fn new_vote_transaction(
) -> Transaction { ) -> Transaction {
let votes = Vote::new(slots, bank_hash); let votes = Vote::new(slots, bank_hash);
let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash {
vote_instruction::vote_switch( vote::instruction::vote_switch(
&vote_keypair.pubkey(), &vote_keypair.pubkey(),
&authorized_voter_keypair.pubkey(), &authorized_voter_keypair.pubkey(),
votes, votes,
switch_proof_hash, switch_proof_hash,
) )
} else { } else {
vote_instruction::vote( vote::instruction::vote(
&vote_keypair.pubkey(), &vote_keypair.pubkey(),
&authorized_voter_keypair.pubkey(), &authorized_voter_keypair.pubkey(),
votes, votes,

View File

@ -4617,7 +4617,7 @@ pub mod tests {
}, },
solana_vote_program::{ solana_vote_program::{
vote_instruction, vote_instruction,
vote_state::{Vote, VoteInit, VoteStateVersions, MAX_LOCKOUT_HISTORY}, vote_state::{self, Vote, VoteInit, VoteStateVersions, MAX_LOCKOUT_HISTORY},
}, },
spl_token_2022::{ spl_token_2022::{
extension::{ extension::{
@ -4937,7 +4937,7 @@ pub mod tests {
let balance = bank.get_minimum_balance_for_rent_exemption(space); let balance = bank.get_minimum_balance_for_rent_exemption(space);
let mut vote_account = let mut vote_account =
AccountSharedData::new(balance, space, &solana_vote_program::id()); AccountSharedData::new(balance, space, &solana_vote_program::id());
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
bank.store_account(vote_pubkey, &vote_account); bank.store_account(vote_pubkey, &vote_account);
} }

View File

@ -10186,13 +10186,13 @@ pub(crate) mod tests {
bank0.store_account_and_update_capitalization(&stake_id, &stake_account); bank0.store_account_and_update_capitalization(&stake_id, &stake_account);
// generate some rewards // generate some rewards
let mut vote_state = Some(VoteState::from(&vote_account).unwrap()); let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
for i in 0..MAX_LOCKOUT_HISTORY + 42 { for i in 0..MAX_LOCKOUT_HISTORY + 42 {
if let Some(v) = vote_state.as_mut() { if let Some(v) = vote_state.as_mut() {
v.process_slot_vote_unchecked(i as u64) vote_state::process_slot_vote_unchecked(v, i as u64)
} }
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap())); let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
bank0.store_account_and_update_capitalization(&vote_id, &vote_account); bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
match versioned { match versioned {
VoteStateVersions::Current(v) => { VoteStateVersions::Current(v) => {
@ -10307,13 +10307,13 @@ pub(crate) mod tests {
bank.store_account_and_update_capitalization(&stake_id2, &stake_account2); bank.store_account_and_update_capitalization(&stake_id2, &stake_account2);
// generate some rewards // generate some rewards
let mut vote_state = Some(VoteState::from(&vote_account).unwrap()); let mut vote_state = Some(vote_state::from(&vote_account).unwrap());
for i in 0..MAX_LOCKOUT_HISTORY + 42 { for i in 0..MAX_LOCKOUT_HISTORY + 42 {
if let Some(v) = vote_state.as_mut() { if let Some(v) = vote_state.as_mut() {
v.process_slot_vote_unchecked(i as u64) vote_state::process_slot_vote_unchecked(v, i as u64)
} }
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap())); let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
bank.store_account_and_update_capitalization(&vote_id, &vote_account); bank.store_account_and_update_capitalization(&vote_id, &vote_account);
match versioned { match versioned {
VoteStateVersions::Current(v) => { VoteStateVersions::Current(v) => {
@ -15726,10 +15726,10 @@ pub(crate) mod tests {
vote_pubkey: &Pubkey, vote_pubkey: &Pubkey,
) { ) {
let mut vote_account = bank.get_account(vote_pubkey).unwrap_or_default(); let mut vote_account = bank.get_account(vote_pubkey).unwrap_or_default();
let mut vote_state = VoteState::from(&vote_account).unwrap_or_default(); let mut vote_state = vote_state::from(&vote_account).unwrap_or_default();
vote_state.last_timestamp = timestamp; vote_state.last_timestamp = timestamp;
let versioned = VoteStateVersions::new_current(vote_state); let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
bank.store_account(vote_pubkey, &vote_account); bank.store_account(vote_pubkey, &vote_account);
} }

View File

@ -618,7 +618,7 @@ pub(crate) mod tests {
stakes_cache.check_and_store(&vote11_pubkey, &vote11_account); stakes_cache.check_and_store(&vote11_pubkey, &vote11_account);
stakes_cache.check_and_store(&stake11_pubkey, &stake11_account); stakes_cache.check_and_store(&stake11_pubkey, &stake11_account);
let vote11_node_pubkey = VoteState::from(&vote11_account).unwrap().node_pubkey; let vote11_node_pubkey = vote_state::from(&vote11_account).unwrap().node_pubkey;
let highest_staked_node = stakes_cache.stakes().highest_staked_node(); let highest_staked_node = stakes_cache.stakes().highest_staked_node();
assert_eq!(highest_staked_node, Some(vote11_node_pubkey)); assert_eq!(highest_staked_node, Some(vote11_node_pubkey));
@ -681,7 +681,7 @@ pub(crate) mod tests {
// Vote account uninitialized // Vote account uninitialized
let default_vote_state = VoteState::default(); let default_vote_state = VoteState::default();
let versioned = VoteStateVersions::new_current(default_vote_state); let versioned = VoteStateVersions::new_current(default_vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap(); vote_state::to(&versioned, &mut vote_account).unwrap();
stakes_cache.check_and_store(&vote_pubkey, &vote_account); stakes_cache.check_and_store(&vote_pubkey, &vote_account);
{ {

View File

@ -607,6 +607,7 @@ pub mod syscalls;
pub mod system_instruction; pub mod system_instruction;
pub mod system_program; pub mod system_program;
pub mod sysvar; pub mod sysvar;
pub mod vote;
pub mod wasm; pub mod wasm;
#[cfg(target_os = "solana")] #[cfg(target_os = "solana")]
@ -626,15 +627,6 @@ pub mod config {
} }
} }
/// The [vote native program][np].
///
/// [np]: https://docs.solana.com/developing/runtime-facilities/programs#vote-program
pub mod vote {
pub mod program {
crate::declare_id!("Vote111111111111111111111111111111111111111");
}
}
/// A vector of Solana SDK IDs /// A vector of Solana SDK IDs
pub mod sdk_ids { pub mod sdk_ids {
use { use {

View File

@ -1,7 +1,6 @@
use { use {
log::*, crate::{clock::Epoch, pubkey::Pubkey},
serde_derive::{Deserialize, Serialize}, serde_derive::{Deserialize, Serialize},
solana_sdk::{clock::Epoch, pubkey::Pubkey},
std::collections::BTreeMap, std::collections::BTreeMap,
}; };
@ -93,12 +92,14 @@ impl AuthorizedVoters {
// from the latest epoch before this one // from the latest epoch before this one
let res = self.authorized_voters.range(0..epoch).next_back(); let res = self.authorized_voters.range(0..epoch).next_back();
/*
if res.is_none() { if res.is_none() {
warn!( warn!(
"Tried to query for the authorized voter of an epoch earlier "Tried to query for the authorized voter of an epoch earlier
than the current epoch. Earlier epochs have been purged" than the current epoch. Earlier epochs have been purged"
); );
} }
*/
res.map(|(_, pubkey)| (*pubkey, false)) res.map(|(_, pubkey)| (*pubkey, false))
} else { } else {

View File

@ -1,9 +1,8 @@
//! Vote program errors //! Vote program errors
use { use {
log::*, crate::decode_error::DecodeError,
num_derive::{FromPrimitive, ToPrimitive}, num_derive::{FromPrimitive, ToPrimitive},
solana_sdk::decode_error::DecodeError,
thiserror::Error, thiserror::Error,
}; };
@ -77,7 +76,7 @@ impl<E> DecodeError<E> for VoteError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use {super::*, solana_sdk::instruction::InstructionError}; use {super::*, crate::instruction::InstructionError};
#[test] #[test]
fn test_custom_error_decode() { fn test_custom_error_decode() {

View File

@ -2,19 +2,19 @@
use { use {
crate::{ crate::{
id,
vote_state::{
CompactVoteStateUpdate, Vote, VoteAuthorize, VoteAuthorizeCheckedWithSeedArgs,
VoteAuthorizeWithSeedArgs, VoteInit, VoteState, VoteStateUpdate,
},
},
serde_derive::{Deserialize, Serialize},
solana_sdk::{
hash::Hash, hash::Hash,
instruction::{AccountMeta, Instruction}, instruction::{AccountMeta, Instruction},
pubkey::Pubkey, pubkey::Pubkey,
system_instruction, sysvar, system_instruction, sysvar,
vote::{
program::id,
state::{
CompactVoteStateUpdate, Vote, VoteAuthorize, VoteAuthorizeCheckedWithSeedArgs,
VoteAuthorizeWithSeedArgs, VoteInit, VoteState, VoteStateUpdate,
}, },
},
},
serde_derive::{Deserialize, Serialize},
}; };
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]

View File

@ -0,0 +1,11 @@
/// The [vote native program][np].
///
/// [np]: https://docs.solana.com/developing/runtime-facilities/programs#vote-program
pub mod authorized_voters;
pub mod error;
pub mod instruction;
pub mod state;
pub mod program {
crate::declare_id!("Vote111111111111111111111111111111111111111");
}

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
#![allow(clippy::integer_arithmetic)]
use super::*; use super::*;
const MAX_ITEMS: usize = 32; const MAX_ITEMS: usize = 32;

View File

@ -1,4 +1,4 @@
use {super::*, crate::vote_state::vote_state_0_23_5::VoteState0_23_5}; use super::{vote_state_0_23_5::VoteState0_23_5, *};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub enum VoteStateVersions { pub enum VoteStateVersions {

View File

@ -264,7 +264,7 @@ fn check_vote_account(
.value .value
.ok_or_else(|| format!("identity account does not exist: {}", identity_pubkey))?; .ok_or_else(|| format!("identity account does not exist: {}", identity_pubkey))?;
let vote_state = solana_vote_program::vote_state::VoteState::from(&vote_account); let vote_state = solana_vote_program::vote_state::from(&vote_account);
if let Some(vote_state) = vote_state { if let Some(vote_state) = vote_state {
if vote_state.authorized_voters().is_empty() { if vote_state.authorized_voters().is_empty() {
return Err("Vote account not yet initialized".to_string()); return Err("Vote account not yet initialized".to_string());