From fc171c8f246a0d68c2a5b795e808ae8e6a3aa541 Mon Sep 17 00:00:00 2001 From: Carl Lin Date: Fri, 7 Feb 2025 01:09:55 -0500 Subject: [PATCH] Move VoteTransaction to vote crate --- Cargo.lock | 3 + core/benches/banking_stage.rs | 3 +- core/src/banking_stage.rs | 5 +- .../banking_stage/latest_unprocessed_votes.rs | 5 +- core/src/banking_stage/qos_service.rs | 3 +- .../unprocessed_packet_batches.rs | 3 +- .../unprocessed_transaction_storage.rs | 5 +- core/src/cluster_info_vote_listener.rs | 6 +- core/src/commitment_service.rs | 9 +- core/src/consensus.rs | 4 +- core/src/consensus/tower1_14_11.rs | 7 +- core/src/consensus/tower_storage.rs | 4 +- core/src/replay_stage.rs | 8 +- core/src/vote_simulator.rs | 6 +- cost-model/Cargo.toml | 1 + cost-model/src/transaction_cost.rs | 3 +- gossip/src/crds_value.rs | 3 +- ledger/src/blockstore_processor.rs | 3 +- local-cluster/src/cluster_tests.rs | 4 +- local-cluster/tests/local_cluster.rs | 4 +- perf/Cargo.toml | 2 + perf/src/test_tx.rs | 3 +- programs/sbf/Cargo.lock | 4 + programs/vote/src/lib.rs | 2 - programs/vote/src/vote_state/mod.rs | 127 +----------- programs/vote/src/vote_transaction.rs | 134 ------------ .../src/bank/partitioned_epoch_rewards/mod.rs | 6 +- svm/examples/Cargo.lock | 4 + vote/Cargo.toml | 5 +- vote/src/lib.rs | 6 +- vote/src/vote_transaction.rs | 195 ++++++++++++++++-- wen-restart/Cargo.toml | 2 +- wen-restart/src/wen_restart.rs | 2 +- 33 files changed, 249 insertions(+), 332 deletions(-) delete mode 100644 programs/vote/src/vote_transaction.rs diff --git a/Cargo.lock b/Cargo.lock index a0189812ff6123..ddda6499566961 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7330,6 +7330,7 @@ dependencies = [ "solana-system-transaction", "solana-transaction", "solana-transaction-error", + "solana-vote", "solana-vote-program", "static_assertions", "test-case", @@ -8516,6 +8517,7 @@ dependencies = [ "solana-system-transaction", "solana-time-utils", "solana-transaction", + "solana-vote", "solana-vote-program", "test-case", ] @@ -10728,6 +10730,7 @@ dependencies = [ "solana-hash", "solana-instruction", "solana-keypair", + "solana-logger", "solana-packet", "solana-pubkey", "solana-sdk-ids", diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 10e121db4210b9..b3d34f8cb7aee0 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -7,7 +7,8 @@ use { banking_trace::Channels, validator::{BlockProductionMethod, TransactionStructure}, }, - solana_vote_program::{vote_state::TowerSync, vote_transaction::new_tower_sync_transaction}, + solana_vote::vote_transaction::new_tower_sync_transaction, + solana_vote_program::vote_state::TowerSync, }; extern crate test; diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index eb2597a308cdd3..b6c365c8ade0c5 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -888,9 +888,8 @@ mod tests { transaction::{SanitizedTransaction, Transaction}, }, solana_streamer::socket::SocketAddrSpace, - solana_vote_program::{ - vote_state::TowerSync, vote_transaction::new_tower_sync_transaction, - }, + solana_vote::vote_transaction::new_tower_sync_transaction, + solana_vote_program::vote_state::TowerSync, std::{ sync::atomic::{AtomicBool, Ordering}, thread::sleep, diff --git a/core/src/banking_stage/latest_unprocessed_votes.rs b/core/src/banking_stage/latest_unprocessed_votes.rs index ae13c37caa5a0e..93cf3e15222e17 100644 --- a/core/src/banking_stage/latest_unprocessed_votes.rs +++ b/core/src/banking_stage/latest_unprocessed_votes.rs @@ -532,9 +532,8 @@ mod tests { epoch_schedule::MINIMUM_SLOTS_PER_EPOCH, genesis_config::GenesisConfig, hash::Hash, signature::Signer, system_transaction::transfer, }, - solana_vote_program::{ - vote_state::TowerSync, vote_transaction::new_tower_sync_transaction, - }, + solana_vote::vote_transaction::new_tower_sync_transaction, + solana_vote_program::vote_state::TowerSync, std::{sync::Arc, thread::Builder}, }; diff --git a/core/src/banking_stage/qos_service.rs b/core/src/banking_stage/qos_service.rs index b694b3f731a61e..61cb6cfc8fb8a7 100644 --- a/core/src/banking_stage/qos_service.rs +++ b/core/src/banking_stage/qos_service.rs @@ -618,7 +618,8 @@ mod tests { signature::{Keypair, Signer}, system_transaction, }, - solana_vote_program::{vote_state::TowerSync, vote_transaction}, + solana_vote::vote_transaction, + solana_vote_program::vote_state::TowerSync, std::sync::Arc, }; diff --git a/core/src/banking_stage/unprocessed_packet_batches.rs b/core/src/banking_stage/unprocessed_packet_batches.rs index 4c32a311875630..bd154108f17198 100644 --- a/core/src/banking_stage/unprocessed_packet_batches.rs +++ b/core/src/banking_stage/unprocessed_packet_batches.rs @@ -305,7 +305,8 @@ mod tests { system_instruction, system_transaction, transaction::Transaction, }, - solana_vote_program::{vote_state::TowerSync, vote_transaction}, + solana_vote::vote_transaction, + solana_vote_program::vote_state::TowerSync, }; fn simple_deserialized_packet() -> DeserializedPacket { diff --git a/core/src/banking_stage/unprocessed_transaction_storage.rs b/core/src/banking_stage/unprocessed_transaction_storage.rs index db94cc0a558663..46af035f555b5d 100644 --- a/core/src/banking_stage/unprocessed_transaction_storage.rs +++ b/core/src/banking_stage/unprocessed_transaction_storage.rs @@ -1005,9 +1005,8 @@ mod tests { system_transaction, transaction::Transaction, }, - solana_vote_program::{ - vote_state::TowerSync, vote_transaction::new_tower_sync_transaction, - }, + solana_vote::vote_transaction::new_tower_sync_transaction, + solana_vote_program::vote_state::TowerSync, std::error::Error, }; diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index 1f82c765741cb7..500e7416794d57 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -749,10 +749,8 @@ mod tests { pubkey::Pubkey, signature::{Keypair, Signature, Signer}, }, - solana_vote_program::{ - vote_state::{TowerSync, Vote, MAX_LOCKOUT_HISTORY}, - vote_transaction, - }, + solana_vote::vote_transaction, + solana_vote_program::vote_state::{TowerSync, Vote, MAX_LOCKOUT_HISTORY}, std::{ collections::BTreeSet, iter::repeat_with, diff --git a/core/src/commitment_service.rs b/core/src/commitment_service.rs index b25875b80f2055..c9fd2dca454511 100644 --- a/core/src/commitment_service.rs +++ b/core/src/commitment_service.rs @@ -273,12 +273,9 @@ mod tests { }, solana_sdk::{account::Account, pubkey::Pubkey, signature::Signer}, solana_stake_program::stake_state, - solana_vote_program::{ - vote_state::{ - self, process_slot_vote_unchecked, TowerSync, VoteStateVersions, - MAX_LOCKOUT_HISTORY, - }, - vote_transaction, + solana_vote::vote_transaction, + solana_vote_program::vote_state::{ + self, process_slot_vote_unchecked, TowerSync, VoteStateVersions, MAX_LOCKOUT_HISTORY, }, }; diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 8f262de42204da..0a381e90b694f8 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -34,13 +34,13 @@ use { signature::Keypair, slot_history::{Check, SlotHistory}, }, - solana_vote::vote_account::VoteAccountsHashMap, + solana_vote::{vote_account::VoteAccountsHashMap, vote_transaction::VoteTransaction}, solana_vote_program::{ vote_error::VoteError, vote_instruction, vote_state::{ process_slot_vote_unchecked, BlockTimestamp, Lockout, TowerSync, Vote, - VoteState1_14_11, VoteStateUpdate, VoteTransaction, MAX_LOCKOUT_HISTORY, + VoteState1_14_11, VoteStateUpdate, MAX_LOCKOUT_HISTORY, }, }, std::{ diff --git a/core/src/consensus/tower1_14_11.rs b/core/src/consensus/tower1_14_11.rs index 2b3a9ccd9eb4e0..6d7310775cf20c 100644 --- a/core/src/consensus/tower1_14_11.rs +++ b/core/src/consensus/tower1_14_11.rs @@ -1,15 +1,14 @@ use { crate::consensus::{BlockhashStatus, SwitchForkDecision}, solana_sdk::{clock::Slot, pubkey::Pubkey}, - solana_vote_program::vote_state::{ - vote_state_1_14_11::VoteState1_14_11, BlockTimestamp, VoteTransaction, - }, + solana_vote::vote_transaction::VoteTransaction, + solana_vote_program::vote_state::{vote_state_1_14_11::VoteState1_14_11, BlockTimestamp}, }; #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "6Z9SDTJAihx2mVbdcifTvNN96keT4DyJ9BKGazgVUkzD") + frozen_abi(digest = "CV9vH427g44yTRqdcCMB8ZToWbm19enEd87x7Fif9JNf") )] #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] pub struct Tower1_14_11 { diff --git a/core/src/consensus/tower_storage.rs b/core/src/consensus/tower_storage.rs index f8b171f9354b85..75f7f6739ee158 100644 --- a/core/src/consensus/tower_storage.rs +++ b/core/src/consensus/tower_storage.rs @@ -381,9 +381,9 @@ pub mod test { BlockhashStatus, Tower, }, solana_sdk::{hash::Hash, signature::Keypair}, + solana_vote::vote_transaction::VoteTransaction, solana_vote_program::vote_state::{ - BlockTimestamp, LandedVote, Vote, VoteState, VoteState1_14_11, VoteTransaction, - MAX_LOCKOUT_HISTORY, + BlockTimestamp, LandedVote, Vote, VoteState, VoteState1_14_11, MAX_LOCKOUT_HISTORY, }, tempfile::TempDir, }; diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 43f0233a69ff24..7a6eda12d39c34 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -77,7 +77,7 @@ use { transaction::Transaction, }, solana_timings::ExecuteTimings, - solana_vote_program::vote_state::VoteTransaction, + solana_vote::vote_transaction::VoteTransaction, std::{ collections::{HashMap, HashSet}, num::NonZeroUsize, @@ -4331,10 +4331,8 @@ pub(crate) mod tests { solana_streamer::socket::SocketAddrSpace, solana_tpu_client::tpu_client::{DEFAULT_TPU_CONNECTION_POOL_SIZE, DEFAULT_VOTE_USE_QUIC}, solana_transaction_status::VersionedTransactionWithStatusMeta, - solana_vote_program::{ - vote_state::{self, TowerSync, VoteStateVersions}, - vote_transaction, - }, + solana_vote::vote_transaction, + solana_vote_program::vote_state::{self, TowerSync, VoteStateVersions}, std::{ fs::remove_dir_all, iter, diff --git a/core/src/vote_simulator.rs b/core/src/vote_simulator.rs index 3d93548cc0a6ef..375e669b5a4e0c 100644 --- a/core/src/vote_simulator.rs +++ b/core/src/vote_simulator.rs @@ -26,10 +26,8 @@ use { }, }, solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer}, - solana_vote_program::{ - vote_state::{process_vote_unchecked, Lockout, TowerSync}, - vote_transaction, - }, + solana_vote::vote_transaction, + solana_vote_program::vote_state::{process_vote_unchecked, Lockout, TowerSync}, std::{ collections::{HashMap, HashSet, VecDeque}, sync::{Arc, RwLock}, diff --git a/cost-model/Cargo.toml b/cost-model/Cargo.toml index 821160d610af00..8ee33b590f664d 100644 --- a/cost-model/Cargo.toml +++ b/cost-model/Cargo.toml @@ -40,6 +40,7 @@ solana-svm-transaction = { workspace = true } solana-system-interface = { workspace = true } solana-transaction = { workspace = true, optional = true } solana-transaction-error = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } [lib] diff --git a/cost-model/src/transaction_cost.rs b/cost-model/src/transaction_cost.rs index 824f447392f594..f9f1d89dccab9b 100644 --- a/cost-model/src/transaction_cost.rs +++ b/cost-model/src/transaction_cost.rs @@ -298,7 +298,8 @@ mod tests { solana_reserved_account_keys::ReservedAccountKeys, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, solana_transaction::{sanitized::MessageHash, versioned::VersionedTransaction}, - solana_vote_program::{vote_state::TowerSync, vote_transaction}, + solana_vote::vote_transaction, + solana_vote_program::vote_state::TowerSync, }; #[test] diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index b40d7e6f6221c0..7785ad081f8a68 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -251,7 +251,8 @@ mod test { timing::timestamp, vote::state::TowerSync, }, - solana_vote_program::{vote_state::Lockout, vote_transaction::new_tower_sync_transaction}, + solana_vote::vote_transaction::new_tower_sync_transaction, + solana_vote_program::vote_state::Lockout, std::str::FromStr, }; diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index b3c2c56c223276..0f13e76f99c7dc 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -2411,11 +2411,10 @@ pub mod tests { transaction_processing_result::ProcessedTransaction, transaction_processor::ExecutionRecordingConfig, }, - solana_vote::vote_account::VoteAccount, + solana_vote::{vote_account::VoteAccount, vote_transaction}, solana_vote_program::{ self, vote_state::{TowerSync, VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY}, - vote_transaction, }, std::{collections::BTreeSet, slice, sync::RwLock}, test_case::{test_case, test_matrix}, diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index 277165f681d869..2b05ad35b174c3 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -37,8 +37,8 @@ use { }, solana_streamer::socket::SocketAddrSpace, solana_tpu_client::tpu_client::{TpuClient, TpuClientConfig, TpuSenderError}, - solana_vote::vote_transaction::VoteTransaction, - solana_vote_program::{vote_state::TowerSync, vote_transaction}, + solana_vote::vote_transaction::{self, VoteTransaction}, + solana_vote_program::vote_state::TowerSync, std::{ collections::{HashMap, HashSet, VecDeque}, net::{SocketAddr, TcpListener}, diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index e3010cd9eb7ced..e06f541d4b3ae1 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -83,8 +83,8 @@ use { broadcast_duplicates_run::{BroadcastDuplicatesConfig, ClusterPartition}, BroadcastStageType, }, - solana_vote::vote_parser, - solana_vote_program::{vote_state::MAX_LOCKOUT_HISTORY, vote_transaction}, + solana_vote::{vote_parser, vote_transaction}, + solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY, std::{ collections::{BTreeSet, HashMap, HashSet}, fs, diff --git a/perf/Cargo.toml b/perf/Cargo.toml index 73d2ca0e23842d..45c508ee762409 100644 --- a/perf/Cargo.toml +++ b/perf/Cargo.toml @@ -43,6 +43,7 @@ solana-system-interface = { workspace = true, optional = true } solana-system-transaction = { workspace = true, optional = true } solana-time-utils = { workspace = true } solana-transaction = { workspace = true, optional = true } +solana-vote = { workspace = true, optional = true } solana-vote-program = { workspace = true, optional = true } [target."cfg(target_os = \"linux\")".dependencies] @@ -69,6 +70,7 @@ dev-context-only-utils = [ "dep:solana-system-transaction", "dep:solana-transaction", "dep:solana-vote-program", + "dep:solana-vote", ] frozen-abi = [ "dep:solana-frozen-abi", diff --git a/perf/src/test_tx.rs b/perf/src/test_tx.rs index e6979fee8263b1..0ec18a070e1889 100644 --- a/perf/src/test_tx.rs +++ b/perf/src/test_tx.rs @@ -8,7 +8,8 @@ use { solana_signer::Signer, solana_system_interface::instruction::SystemInstruction, solana_transaction::Transaction, - solana_vote_program::{vote_state::TowerSync, vote_transaction}, + solana_vote::vote_transaction, + solana_vote_program::vote_state::TowerSync, }; pub fn test_tx() -> Transaction { diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 703715a06bcc3f..3f331fe6bd7b1a 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5829,6 +5829,7 @@ dependencies = [ "solana-svm-transaction", "solana-system-interface", "solana-transaction-error", + "solana-vote", "solana-vote-program", ] @@ -8944,10 +8945,12 @@ dependencies = [ "solana-clock", "solana-hash", "solana-instruction", + "solana-keypair", "solana-packet", "solana-pubkey", "solana-sdk-ids", "solana-signature", + "solana-signer", "solana-svm-transaction", "solana-transaction", "solana-vote-interface", @@ -9032,6 +9035,7 @@ dependencies = [ "solana-shred-version", "solana-time-utils", "solana-timings", + "solana-vote", "solana-vote-program", ] diff --git a/programs/vote/src/lib.rs b/programs/vote/src/lib.rs index ad5180e12598e4..280949b282d4fe 100644 --- a/programs/vote/src/lib.rs +++ b/programs/vote/src/lib.rs @@ -2,13 +2,11 @@ pub mod vote_processor; pub mod vote_state; -pub mod vote_transaction; #[cfg_attr(feature = "metrics", macro_use)] #[cfg(feature = "metrics")] extern crate solana_metrics; -#[cfg_attr(feature = "frozen-abi", macro_use)] #[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/programs/vote/src/vote_state/mod.rs b/programs/vote/src/vote_state/mod.rs index 2bdef98a22b5ab..990618e61875f8 100644 --- a/programs/vote/src/vote_state/mod.rs +++ b/programs/vote/src/vote_state/mod.rs @@ -3,9 +3,8 @@ pub use solana_vote_interface::state::{vote_state_versions::*, *}; use { log::*, - serde_derive::{Deserialize, Serialize}, solana_account::{AccountSharedData, ReadableAccount, WritableAccount}, - solana_clock::{Clock, Epoch, Slot, UnixTimestamp}, + solana_clock::{Clock, Epoch, Slot}, solana_epoch_schedule::EpochSchedule, solana_feature_set::{self as feature_set, FeatureSet}, solana_hash::Hash, @@ -20,133 +19,9 @@ use { std::{ cmp::Ordering, collections::{HashSet, VecDeque}, - fmt::Debug, }, }; -#[cfg_attr( - feature = "frozen-abi", - derive(AbiExample, AbiEnumVisitor), - frozen_abi(digest = "4BdRo6We16yDbjz69H1oFq6C4nXUZKDchZR76TvvGmBi") -)] -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -pub enum VoteTransaction { - Vote(Vote), - VoteStateUpdate(VoteStateUpdate), - #[serde(with = "serde_compact_vote_state_update")] - CompactVoteStateUpdate(VoteStateUpdate), - #[serde(with = "serde_tower_sync")] - TowerSync(TowerSync), -} - -impl VoteTransaction { - pub fn slots(&self) -> Vec { - match self { - VoteTransaction::Vote(vote) => vote.slots.clone(), - VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.slots(), - VoteTransaction::CompactVoteStateUpdate(vote_state_update) => vote_state_update.slots(), - VoteTransaction::TowerSync(tower_sync) => tower_sync.slots(), - } - } - - pub fn slot(&self, i: usize) -> Slot { - match self { - VoteTransaction::Vote(vote) => vote.slots[i], - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.lockouts[i].slot() - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts[i].slot(), - } - } - - pub fn len(&self) -> usize { - match self { - VoteTransaction::Vote(vote) => vote.slots.len(), - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.lockouts.len() - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts.len(), - } - } - - pub fn is_empty(&self) -> bool { - match self { - VoteTransaction::Vote(vote) => vote.slots.is_empty(), - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.lockouts.is_empty() - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts.is_empty(), - } - } - - pub fn hash(&self) -> Hash { - match self { - VoteTransaction::Vote(vote) => vote.hash, - VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.hash, - VoteTransaction::CompactVoteStateUpdate(vote_state_update) => vote_state_update.hash, - VoteTransaction::TowerSync(tower_sync) => tower_sync.hash, - } - } - - pub fn timestamp(&self) -> Option { - match self { - VoteTransaction::Vote(vote) => vote.timestamp, - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.timestamp - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.timestamp, - } - } - - pub fn set_timestamp(&mut self, ts: Option) { - match self { - VoteTransaction::Vote(vote) => vote.timestamp = ts, - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.timestamp = ts - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.timestamp = ts, - } - } - - pub fn last_voted_slot(&self) -> Option { - match self { - VoteTransaction::Vote(vote) => vote.last_voted_slot(), - VoteTransaction::VoteStateUpdate(vote_state_update) - | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { - vote_state_update.last_voted_slot() - } - VoteTransaction::TowerSync(tower_sync) => tower_sync.last_voted_slot(), - } - } - - pub fn last_voted_slot_hash(&self) -> Option<(Slot, Hash)> { - Some((self.last_voted_slot()?, self.hash())) - } -} - -impl From for VoteTransaction { - fn from(vote: Vote) -> Self { - VoteTransaction::Vote(vote) - } -} - -impl From for VoteTransaction { - fn from(vote_state_update: VoteStateUpdate) -> Self { - VoteTransaction::VoteStateUpdate(vote_state_update) - } -} - -impl From for VoteTransaction { - fn from(tower_sync: TowerSync) -> Self { - VoteTransaction::TowerSync(tower_sync) - } -} - // utility function, used by Stakes, tests pub fn from(account: &T) -> Option { VoteState::deserialize(account.data()).ok() diff --git a/programs/vote/src/vote_transaction.rs b/programs/vote/src/vote_transaction.rs deleted file mode 100644 index c551427522af1a..00000000000000 --- a/programs/vote/src/vote_transaction.rs +++ /dev/null @@ -1,134 +0,0 @@ -use { - solana_clock::Slot, - solana_hash::Hash, - solana_keypair::Keypair, - solana_signer::Signer, - solana_transaction::Transaction, - solana_vote_interface::{ - self as vote, - state::{TowerSync, Vote, VoteStateUpdate}, - }, -}; - -pub fn new_vote_transaction( - slots: Vec, - bank_hash: Hash, - blockhash: Hash, - node_keypair: &Keypair, - vote_keypair: &Keypair, - authorized_voter_keypair: &Keypair, - switch_proof_hash: Option, -) -> Transaction { - let votes = Vote::new(slots, bank_hash); - let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { - vote::instruction::vote_switch( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - votes, - switch_proof_hash, - ) - } else { - vote::instruction::vote( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - votes, - ) - }; - - let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); - - vote_tx.partial_sign(&[node_keypair], blockhash); - vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); - vote_tx -} - -pub fn new_vote_state_update_transaction( - vote_state_update: VoteStateUpdate, - blockhash: Hash, - node_keypair: &Keypair, - vote_keypair: &Keypair, - authorized_voter_keypair: &Keypair, - switch_proof_hash: Option, -) -> Transaction { - let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { - vote::instruction::update_vote_state_switch( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - vote_state_update, - switch_proof_hash, - ) - } else { - vote::instruction::update_vote_state( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - vote_state_update, - ) - }; - - let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); - - vote_tx.partial_sign(&[node_keypair], blockhash); - vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); - vote_tx -} - -pub fn new_compact_vote_state_update_transaction( - vote_state_update: VoteStateUpdate, - blockhash: Hash, - node_keypair: &Keypair, - vote_keypair: &Keypair, - authorized_voter_keypair: &Keypair, - switch_proof_hash: Option, -) -> Transaction { - let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { - vote::instruction::compact_update_vote_state_switch( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - vote_state_update, - switch_proof_hash, - ) - } else { - vote::instruction::compact_update_vote_state( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - vote_state_update, - ) - }; - - let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); - - vote_tx.partial_sign(&[node_keypair], blockhash); - vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); - vote_tx -} - -#[must_use] -pub fn new_tower_sync_transaction( - tower_sync: TowerSync, - blockhash: Hash, - node_keypair: &Keypair, - vote_keypair: &Keypair, - authorized_voter_keypair: &Keypair, - switch_proof_hash: Option, -) -> Transaction { - let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { - vote::instruction::tower_sync_switch( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - tower_sync, - switch_proof_hash, - ) - } else { - vote::instruction::tower_sync( - &vote_keypair.pubkey(), - &authorized_voter_keypair.pubkey(), - tower_sync, - ) - }; - - let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); - - vote_tx.partial_sign(&[node_keypair], blockhash); - vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); - vote_tx -} diff --git a/runtime/src/bank/partitioned_epoch_rewards/mod.rs b/runtime/src/bank/partitioned_epoch_rewards/mod.rs index 2d2e21aace90e3..e53415418a1b26 100644 --- a/runtime/src/bank/partitioned_epoch_rewards/mod.rs +++ b/runtime/src/bank/partitioned_epoch_rewards/mod.rs @@ -252,10 +252,8 @@ mod tests { transaction::Transaction, vote::state::{VoteStateVersions, MAX_LOCKOUT_HISTORY}, }, - solana_vote_program::{ - vote_state::{self, TowerSync}, - vote_transaction, - }, + solana_vote::vote_transaction, + solana_vote_program::vote_state::{self, TowerSync}, }; impl PartitionedStakeReward { diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 06ba2c38ab355c..b1cfe92b734d1e 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5683,6 +5683,7 @@ dependencies = [ "solana-svm-transaction", "solana-system-interface", "solana-transaction-error", + "solana-vote", "solana-vote-program", ] @@ -8281,10 +8282,12 @@ dependencies = [ "solana-clock", "solana-hash", "solana-instruction", + "solana-keypair", "solana-packet", "solana-pubkey", "solana-sdk-ids", "solana-signature", + "solana-signer", "solana-svm-transaction", "solana-transaction", "solana-vote-interface", @@ -8368,6 +8371,7 @@ dependencies = [ "solana-shred-version", "solana-time-utils", "solana-timings", + "solana-vote", "solana-vote-program", ] diff --git a/vote/Cargo.toml b/vote/Cargo.toml index 05c6e40cf387b3..bd29d3080bf469 100644 --- a/vote/Cargo.toml +++ b/vote/Cargo.toml @@ -26,12 +26,14 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-hash = { workspace = true } solana-instruction = { workspace = true } +solana-keypair = { workspace = true } solana-packet = { workspace = true } solana-pubkey = { workspace = true } solana-sdk-ids = { workspace = true } solana-signature = { workspace = true } +solana-signer = { workspace = true } solana-svm-transaction = { workspace = true } -solana-transaction = { workspace = true } +solana-transaction = { workspace = true, features = ["bincode"] } solana-vote-interface = { workspace = true, features = ["bincode"] } thiserror = { workspace = true } @@ -43,6 +45,7 @@ name = "solana_vote" bincode = { workspace = true } rand = { workspace = true } solana-keypair = { workspace = true } +solana-logger = { workspace = true } solana-sha256-hasher = { workspace = true } solana-signer = { workspace = true } solana-transaction = { workspace = true, features = ["bincode"] } diff --git a/vote/src/lib.rs b/vote/src/lib.rs index 53d8fdc37e06a7..b496dde973e15a 100644 --- a/vote/src/lib.rs +++ b/vote/src/lib.rs @@ -5,9 +5,9 @@ pub mod vote_account; pub mod vote_parser; pub mod vote_transaction; -#[macro_use] -extern crate serde_derive; - #[cfg_attr(feature = "frozen-abi", macro_use)] #[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; + +#[macro_use] +extern crate serde_derive; diff --git a/vote/src/vote_transaction.rs b/vote/src/vote_transaction.rs index 8c6346ec371b65..9d20585144d9da 100644 --- a/vote/src/vote_transaction.rs +++ b/vote/src/vote_transaction.rs @@ -1,13 +1,25 @@ use { + serde_derive::{Deserialize, Serialize}, solana_clock::{Slot, UnixTimestamp}, solana_hash::Hash, - solana_vote_interface::state::{TowerSync, Vote, VoteStateUpdate}, + solana_keypair::Keypair, + solana_signer::Signer, + solana_transaction::Transaction, + solana_vote_interface::{self as vote, state::*}, }; -#[derive(Debug, PartialEq, Eq, Clone)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample, AbiEnumVisitor), + frozen_abi(digest = "5tNdc77vxH68VdiV2CNwXRhcJzDMk2ncYXYw3JQdMYhd") +)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub enum VoteTransaction { Vote(Vote), VoteStateUpdate(VoteStateUpdate), + #[serde(with = "serde_compact_vote_state_update")] + CompactVoteStateUpdate(VoteStateUpdate), + #[serde(with = "serde_tower_sync")] TowerSync(TowerSync), } @@ -15,19 +27,39 @@ impl VoteTransaction { pub fn slots(&self) -> Vec { match self { VoteTransaction::Vote(vote) => vote.slots.clone(), - VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update - .lockouts - .iter() - .map(|lockout| lockout.slot()) - .collect(), + VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.slots(), + VoteTransaction::CompactVoteStateUpdate(vote_state_update) => vote_state_update.slots(), VoteTransaction::TowerSync(tower_sync) => tower_sync.slots(), } } + pub fn slot(&self, i: usize) -> Slot { + match self { + VoteTransaction::Vote(vote) => vote.slots[i], + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { + vote_state_update.lockouts[i].slot() + } + VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts[i].slot(), + } + } + + pub fn len(&self) -> usize { + match self { + VoteTransaction::Vote(vote) => vote.slots.len(), + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { + vote_state_update.lockouts.len() + } + VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts.len(), + } + } + pub fn is_empty(&self) -> bool { match self { VoteTransaction::Vote(vote) => vote.slots.is_empty(), - VoteTransaction::VoteStateUpdate(vote_state_update) => { + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { vote_state_update.lockouts.is_empty() } VoteTransaction::TowerSync(tower_sync) => tower_sync.lockouts.is_empty(), @@ -38,6 +70,7 @@ impl VoteTransaction { match self { VoteTransaction::Vote(vote) => vote.hash, VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.hash, + VoteTransaction::CompactVoteStateUpdate(vote_state_update) => vote_state_update.hash, VoteTransaction::TowerSync(tower_sync) => tower_sync.hash, } } @@ -45,16 +78,31 @@ impl VoteTransaction { pub fn timestamp(&self) -> Option { match self { VoteTransaction::Vote(vote) => vote.timestamp, - VoteTransaction::VoteStateUpdate(vote_state_update) => vote_state_update.timestamp, + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { + vote_state_update.timestamp + } VoteTransaction::TowerSync(tower_sync) => tower_sync.timestamp, } } + pub fn set_timestamp(&mut self, ts: Option) { + match self { + VoteTransaction::Vote(vote) => vote.timestamp = ts, + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { + vote_state_update.timestamp = ts + } + VoteTransaction::TowerSync(tower_sync) => tower_sync.timestamp = ts, + } + } + pub fn last_voted_slot(&self) -> Option { match self { - VoteTransaction::Vote(vote) => vote.slots.last().copied(), - VoteTransaction::VoteStateUpdate(vote_state_update) => { - Some(vote_state_update.lockouts.back()?.slot()) + VoteTransaction::Vote(vote) => vote.last_voted_slot(), + VoteTransaction::VoteStateUpdate(vote_state_update) + | VoteTransaction::CompactVoteStateUpdate(vote_state_update) => { + vote_state_update.last_voted_slot() } VoteTransaction::TowerSync(tower_sync) => tower_sync.last_voted_slot(), } @@ -89,3 +137,126 @@ impl From for VoteTransaction { VoteTransaction::TowerSync(tower_sync) } } + +pub fn new_vote_transaction( + slots: Vec, + bank_hash: Hash, + blockhash: Hash, + node_keypair: &Keypair, + vote_keypair: &Keypair, + authorized_voter_keypair: &Keypair, + switch_proof_hash: Option, +) -> Transaction { + let votes = Vote::new(slots, bank_hash); + let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { + vote::instruction::vote_switch( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + votes, + switch_proof_hash, + ) + } else { + vote::instruction::vote( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + votes, + ) + }; + + let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); + + vote_tx.partial_sign(&[node_keypair], blockhash); + vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); + vote_tx +} + +pub fn new_vote_state_update_transaction( + vote_state_update: VoteStateUpdate, + blockhash: Hash, + node_keypair: &Keypair, + vote_keypair: &Keypair, + authorized_voter_keypair: &Keypair, + switch_proof_hash: Option, +) -> Transaction { + let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { + vote::instruction::update_vote_state_switch( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + vote_state_update, + switch_proof_hash, + ) + } else { + vote::instruction::update_vote_state( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + vote_state_update, + ) + }; + + let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); + + vote_tx.partial_sign(&[node_keypair], blockhash); + vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); + vote_tx +} + +pub fn new_compact_vote_state_update_transaction( + vote_state_update: VoteStateUpdate, + blockhash: Hash, + node_keypair: &Keypair, + vote_keypair: &Keypair, + authorized_voter_keypair: &Keypair, + switch_proof_hash: Option, +) -> Transaction { + let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { + vote::instruction::compact_update_vote_state_switch( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + vote_state_update, + switch_proof_hash, + ) + } else { + vote::instruction::compact_update_vote_state( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + vote_state_update, + ) + }; + + let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); + + vote_tx.partial_sign(&[node_keypair], blockhash); + vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); + vote_tx +} + +#[must_use] +pub fn new_tower_sync_transaction( + tower_sync: TowerSync, + blockhash: Hash, + node_keypair: &Keypair, + vote_keypair: &Keypair, + authorized_voter_keypair: &Keypair, + switch_proof_hash: Option, +) -> Transaction { + let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash { + vote::instruction::tower_sync_switch( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + tower_sync, + switch_proof_hash, + ) + } else { + vote::instruction::tower_sync( + &vote_keypair.pubkey(), + &authorized_voter_keypair.pubkey(), + tower_sync, + ) + }; + + let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey())); + + vote_tx.partial_sign(&[node_keypair], blockhash); + vote_tx.partial_sign(&[authorized_voter_keypair], blockhash); + vote_tx +} diff --git a/wen-restart/Cargo.toml b/wen-restart/Cargo.toml index b31731978bc0a2..b8ccda62b8afdf 100644 --- a/wen-restart/Cargo.toml +++ b/wen-restart/Cargo.toml @@ -27,6 +27,7 @@ solana-runtime = { workspace = true } solana-shred-version = { workspace = true } solana-time-utils = { workspace = true } solana-timings = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } [dev-dependencies] @@ -40,7 +41,6 @@ solana-logger = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-signer = { workspace = true } solana-streamer = { workspace = true } -solana-vote = { workspace = true } tempfile = { workspace = true } [build-dependencies] diff --git a/wen-restart/src/wen_restart.rs b/wen-restart/src/wen_restart.rs index 0c901e65fffc2f..76295a43a190ba 100644 --- a/wen-restart/src/wen_restart.rs +++ b/wen-restart/src/wen_restart.rs @@ -50,7 +50,7 @@ use { solana_shred_version::compute_shred_version, solana_time_utils::timestamp, solana_timings::ExecuteTimings, - solana_vote_program::vote_state::VoteTransaction, + solana_vote::vote_transaction::VoteTransaction, std::{ collections::{HashMap, HashSet}, fs::{read, File},