From f50342a790cd0870159aa5b061ceada89f6a58b4 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 19 Sep 2023 10:46:37 -0700 Subject: [PATCH] Split vote related code from runtime to its own crate (#32882) * Move vote related code to its own crate * Update imports in code and tests * update programs/sbf/Cargo.lock * fix check errors * update abi_digest * rebase fixes * fixes after rebase --- Cargo.lock | 84 +++++++++++++++++ Cargo.toml | 2 + core/Cargo.toml | 1 + core/src/banking_stage.rs | 6 +- core/src/banking_stage/committer.rs | 2 +- core/src/banking_stage/consume_worker.rs | 6 +- core/src/cluster_info_vote_listener.rs | 14 +-- core/src/consensus.rs | 9 +- core/src/consensus/progress_map.rs | 5 +- core/src/replay_stage.rs | 2 +- core/src/tpu.rs | 7 +- core/src/tvu.rs | 2 +- core/src/verified_vote_packets.rs | 6 +- gossip/Cargo.toml | 1 + gossip/src/cluster_info.rs | 3 +- gossip/src/crds_value.rs | 2 +- ledger/Cargo.toml | 1 + ledger/src/blockstore_processor.rs | 11 +-- ledger/src/staking_utils.rs | 6 +- local-cluster/Cargo.toml | 1 + local-cluster/src/cluster_tests.rs | 2 +- local-cluster/tests/local_cluster.rs | 2 +- programs/sbf/Cargo.lock | 75 +++++++++++++++ rpc/Cargo.toml | 1 + rpc/src/rpc_pubsub.rs | 2 +- rpc/src/rpc_subscriptions.rs | 2 +- runtime/Cargo.toml | 1 + runtime/src/bank.rs | 2 +- runtime/src/bank/serde_snapshot.rs | 2 +- runtime/src/bank_utils.rs | 3 +- runtime/src/epoch_stakes.rs | 5 +- runtime/src/lib.rs | 4 - runtime/src/stakes.rs | 7 +- vote/Cargo.toml | 101 +++++++++++++++++++++ vote/build.rs | 27 ++++++ vote/src/lib.rs | 13 +++ {runtime => vote}/src/vote_account.rs | 30 +++--- {runtime => vote}/src/vote_parser.rs | 0 {runtime => vote}/src/vote_sender_types.rs | 0 {runtime => vote}/src/vote_transaction.rs | 0 40 files changed, 371 insertions(+), 79 deletions(-) create mode 100644 vote/Cargo.toml create mode 100644 vote/build.rs create mode 100644 vote/src/lib.rs rename {runtime => vote}/src/vote_account.rs (95%) rename {runtime => vote}/src/vote_parser.rs (100%) rename {runtime => vote}/src/vote_sender_types.rs (100%) rename {runtime => vote}/src/vote_transaction.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 7ce6d9a51f..30729d6ab7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5784,6 +5784,7 @@ dependencies = [ "solana-transaction-status", "solana-turbine", "solana-version", + "solana-vote", "solana-vote-program", "static_assertions", "strum", @@ -6074,6 +6075,7 @@ dependencies = [ "solana-thin-client", "solana-tpu-client", "solana-version", + "solana-vote", "solana-vote-program", "static_assertions", "test-case", @@ -6184,6 +6186,7 @@ dependencies = [ "solana-storage-bigtable", "solana-storage-proto", "solana-transaction-status", + "solana-vote", "solana-vote-program", "spl-token", "spl-token-2022", @@ -6291,6 +6294,7 @@ dependencies = [ "solana-thin-client", "solana-tpu-client", "solana-turbine", + "solana-vote", "solana-vote-program", "static_assertions", "tempfile", @@ -6712,6 +6716,7 @@ dependencies = [ "solana-tpu-client", "solana-transaction-status", "solana-version", + "solana-vote", "solana-vote-program", "spl-token", "spl-token-2022", @@ -6883,6 +6888,7 @@ dependencies = [ "solana-stake-program", "solana-system-program", "solana-version", + "solana-vote", "solana-vote-program", "solana-zk-token-proof-program", "solana-zk-token-sdk", @@ -7405,6 +7411,84 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-vote" +version = "1.17.0" +dependencies = [ + "arrayref", + "assert_matches", + "bincode", + "blake3", + "bv", + "bytemuck", + "byteorder", + "bzip2", + "crossbeam-channel", + "dashmap 4.0.2", + "dir-diff", + "ed25519-dalek", + "flate2", + "fnv", + "fs-err", + "im", + "index_list", + "itertools", + "lazy_static", + "libsecp256k1", + "log", + "lru", + "lz4", + "memmap2", + "memoffset 0.9.0", + "modular-bitfield", + "num-derive", + "num-traits", + "num_cpus", + "num_enum 0.6.1", + "ouroboros", + "percentage", + "qualifier_attr", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rayon", + "regex", + "rustc_version 0.4.0", + "serde", + "serde_derive", + "siphasher", + "solana-address-lookup-table-program", + "solana-bpf-loader-program", + "solana-bucket-map", + "solana-compute-budget-program", + "solana-config-program", + "solana-cost-model", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-loader-v4-program", + "solana-logger", + "solana-measure", + "solana-metrics", + "solana-perf", + "solana-program-runtime", + "solana-rayon-threadlimit", + "solana-sdk", + "solana-stake-program", + "solana-system-program", + "solana-vote", + "solana-vote-program", + "solana-zk-token-proof-program", + "solana-zk-token-sdk", + "static_assertions", + "strum", + "strum_macros", + "symlink", + "tar", + "tempfile", + "test-case", + "thiserror", + "zstd", +] + [[package]] name = "solana-vote-program" version = "1.17.0" diff --git a/Cargo.toml b/Cargo.toml index 3653d88c15..58cb4f8305 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,7 @@ members = [ "upload-perf", "validator", "version", + "vote", "watchtower", "zk-keygen", "zk-token-sdk", @@ -367,6 +368,7 @@ solana-transaction-status = { path = "transaction-status", version = "=1.17.0" } solana-turbine = { path = "turbine", version = "=1.17.0" } solana-udp-client = { path = "udp-client", version = "=1.17.0" } solana-version = { path = "version", version = "=1.17.0" } +solana-vote = { path = "vote", version = "=1.17.0" } solana-vote-program = { path = "programs/vote", version = "=1.17.0" } solana-zk-keygen = { path = "zk-keygen", version = "=1.17.0" } solana-zk-token-proof-program = { path = "programs/zk-token-proof", version = "=1.17.0" } diff --git a/core/Cargo.toml b/core/Cargo.toml index f29ed64031..fcab8ff877 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -69,6 +69,7 @@ solana-tpu-client = { workspace = true } solana-transaction-status = { workspace = true } solana-turbine = { workspace = true } solana-version = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } strum = { workspace = true, features = ["derive"] } strum_macros = { workspace = true } diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 7e9138048c..2dfb1e32b1 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -27,11 +27,9 @@ use { solana_measure::{measure, measure_us}, solana_perf::{data_budget::DataBudget, packet::PACKETS_PER_BATCH}, solana_poh::poh_recorder::PohRecorder, - solana_runtime::{ - bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache, - vote_sender_types::ReplayVoteSender, - }, + solana_runtime::{bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache}, solana_sdk::timing::AtomicInterval, + solana_vote::vote_sender_types::ReplayVoteSender, std::{ cmp, env, sync::{ diff --git a/core/src/banking_stage/committer.rs b/core/src/banking_stage/committer.rs index 26f5e56054..a5e42cbc75 100644 --- a/core/src/banking_stage/committer.rs +++ b/core/src/banking_stage/committer.rs @@ -14,12 +14,12 @@ use { bank_utils, prioritization_fee_cache::PrioritizationFeeCache, transaction_batch::TransactionBatch, - vote_sender_types::ReplayVoteSender, }, solana_sdk::{pubkey::Pubkey, saturating_add_assign}, solana_transaction_status::{ token_balances::TransactionTokenBalancesSet, TransactionTokenBalance, }, + solana_vote::vote_sender_types::ReplayVoteSender, std::{collections::HashMap, sync::Arc}, }; diff --git a/core/src/banking_stage/consume_worker.rs b/core/src/banking_stage/consume_worker.rs index 3c4d275bdd..1795db9743 100644 --- a/core/src/banking_stage/consume_worker.rs +++ b/core/src/banking_stage/consume_worker.rs @@ -138,14 +138,12 @@ mod tests { get_tmp_ledger_path_auto_delete, leader_schedule_cache::LeaderScheduleCache, }, solana_poh::poh_recorder::{PohRecorder, WorkingBankEntry}, - solana_runtime::{ - bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache, - vote_sender_types::ReplayVoteReceiver, - }, + solana_runtime::{bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache}, solana_sdk::{ genesis_config::GenesisConfig, poh_config::PohConfig, pubkey::Pubkey, signature::Keypair, system_transaction, }, + solana_vote::vote_sender_types::ReplayVoteReceiver, std::{ sync::{atomic::AtomicBool, RwLock}, thread::JoinHandle, diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index 4a851946fa..183cabcf04 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -26,13 +26,8 @@ use { rpc_subscriptions::RpcSubscriptions, }, solana_runtime::{ - bank::Bank, - bank_forks::BankForks, - commitment::VOTE_THRESHOLD_SIZE, + bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE, epoch_stakes::EpochStakes, - vote_parser::{self, ParsedVote}, - vote_sender_types::ReplayVoteReceiver, - vote_transaction::VoteTransaction, }, solana_sdk::{ clock::{Slot, DEFAULT_MS_PER_SLOT, DEFAULT_TICKS_PER_SLOT}, @@ -43,6 +38,11 @@ use { timing::AtomicInterval, transaction::Transaction, }, + solana_vote::{ + vote_parser::{self, ParsedVote}, + vote_sender_types::ReplayVoteReceiver, + vote_transaction::VoteTransaction, + }, std::{ collections::{HashMap, HashSet}, iter::repeat, @@ -883,13 +883,13 @@ mod tests { genesis_utils::{ self, create_genesis_config, GenesisConfigInfo, ValidatorVoteKeypairs, }, - vote_sender_types::ReplayVoteSender, }, solana_sdk::{ hash::Hash, pubkey::Pubkey, signature::{Keypair, Signature, Signer}, }, + solana_vote::vote_sender_types::ReplayVoteSender, solana_vote_program::{vote_state::Vote, vote_transaction}, std::{ collections::BTreeSet, diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 0e204dbe56..50c04dbbf4 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -19,10 +19,7 @@ use { }, chrono::prelude::*, solana_ledger::{ancestor_iterator::AncestorIterator, blockstore::Blockstore, blockstore_db}, - solana_runtime::{ - bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE, - vote_account::VoteAccountsHashMap, - }, + solana_runtime::{bank::Bank, bank_forks::BankForks, commitment::VOTE_THRESHOLD_SIZE}, solana_sdk::{ clock::{Slot, UnixTimestamp}, hash::Hash, @@ -31,6 +28,7 @@ use { signature::Keypair, slot_history::{Check, SlotHistory}, }, + solana_vote::vote_account::VoteAccountsHashMap, solana_vote_program::{ vote_instruction, vote_state::{ @@ -1521,7 +1519,7 @@ pub mod test { }, itertools::Itertools, solana_ledger::{blockstore::make_slot_entries, get_tmp_ledger_path}, - solana_runtime::{bank::Bank, vote_account::VoteAccount}, + solana_runtime::bank::Bank, solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, clock::Slot, @@ -1530,6 +1528,7 @@ pub mod test { signature::Signer, slot_history::SlotHistory, }, + solana_vote::vote_account::VoteAccount, solana_vote_program::vote_state::{Vote, VoteStateVersions, MAX_LOCKOUT_HISTORY}, std::{ collections::{HashMap, VecDeque}, diff --git a/core/src/consensus/progress_map.rs b/core/src/consensus/progress_map.rs index 870449e80e..a34509ef81 100644 --- a/core/src/consensus/progress_map.rs +++ b/core/src/consensus/progress_map.rs @@ -7,8 +7,9 @@ use { }, solana_ledger::blockstore_processor::{ConfirmationProgress, ConfirmationTiming}, solana_program_runtime::{report_execute_timings, timings::ExecuteTimingType}, - solana_runtime::{bank::Bank, bank_forks::BankForks, vote_account::VoteAccountsHashMap}, + solana_runtime::{bank::Bank, bank_forks::BankForks}, solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey}, + solana_vote::vote_account::VoteAccountsHashMap, std::{ collections::{BTreeMap, HashMap, HashSet}, ops::Index, @@ -531,8 +532,8 @@ impl ProgressMap { mod test { use { super::*, - solana_runtime::vote_account::VoteAccount, solana_sdk::account::{Account, AccountSharedData}, + solana_vote::vote_account::VoteAccount, }; fn new_test_vote_account() -> VoteAccount { diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 55e9b7ad21..0fec5020d6 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -63,7 +63,6 @@ use { bank_forks::{BankForks, MAX_ROOT_DISTANCE_FOR_VOTE_ONLY}, commitment::BlockCommitmentCache, prioritization_fee_cache::PrioritizationFeeCache, - vote_sender_types::ReplayVoteSender, }, solana_sdk::{ clock::{BankId, Slot, MAX_PROCESSING_AGE, NUM_CONSECUTIVE_LEADER_SLOTS}, @@ -75,6 +74,7 @@ use { timing::timestamp, transaction::Transaction, }, + solana_vote::vote_sender_types::ReplayVoteSender, solana_vote_program::vote_state::VoteTransaction, std::{ collections::{HashMap, HashSet}, diff --git a/core/src/tpu.rs b/core/src/tpu.rs index 884153d3d6..028a88f416 100644 --- a/core/src/tpu.rs +++ b/core/src/tpu.rs @@ -30,11 +30,7 @@ use { optimistically_confirmed_bank_tracker::BankNotificationSender, rpc_subscriptions::RpcSubscriptions, }, - solana_runtime::{ - bank_forks::BankForks, - prioritization_fee_cache::PrioritizationFeeCache, - vote_sender_types::{ReplayVoteReceiver, ReplayVoteSender}, - }, + solana_runtime::{bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache}, solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Keypair}, solana_streamer::{ nonblocking::quic::DEFAULT_WAIT_FOR_CHUNK_TIMEOUT, @@ -42,6 +38,7 @@ use { streamer::StakedNodes, }, solana_turbine::broadcast_stage::{BroadcastStage, BroadcastStageType}, + solana_vote::vote_sender_types::{ReplayVoteReceiver, ReplayVoteSender}, std::{ collections::HashMap, net::{SocketAddr, UdpSocket}, diff --git a/core/src/tvu.rs b/core/src/tvu.rs index d3d57c1314..0b8358863f 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -44,10 +44,10 @@ use { solana_runtime::{ accounts_background_service::AbsRequestSender, bank_forks::BankForks, commitment::BlockCommitmentCache, prioritization_fee_cache::PrioritizationFeeCache, - vote_sender_types::ReplayVoteSender, }, solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Keypair}, solana_turbine::retransmit_stage::RetransmitStage, + solana_vote::vote_sender_types::ReplayVoteSender, std::{ collections::HashSet, net::{SocketAddr, UdpSocket}, diff --git a/core/src/verified_vote_packets.rs b/core/src/verified_vote_packets.rs index fa486062cf..3edee355b8 100644 --- a/core/src/verified_vote_packets.rs +++ b/core/src/verified_vote_packets.rs @@ -2,10 +2,7 @@ use { crate::{cluster_info_vote_listener::VerifiedLabelVotePacketsReceiver, result::Result}, itertools::Itertools, solana_perf::packet::PacketBatch, - solana_runtime::{ - bank::Bank, - vote_transaction::{VoteTransaction, VoteTransaction::VoteStateUpdate}, - }, + solana_runtime::bank::Bank, solana_sdk::{ account::from_account, clock::{Slot, UnixTimestamp}, @@ -15,6 +12,7 @@ use { slot_hashes::SlotHashes, sysvar, }, + solana_vote::vote_transaction::{VoteTransaction, VoteTransaction::VoteStateUpdate}, std::{ collections::{BTreeMap, HashMap, HashSet}, sync::Arc, diff --git a/gossip/Cargo.toml b/gossip/Cargo.toml index fcbcf9c9a9..3696342ae8 100644 --- a/gossip/Cargo.toml +++ b/gossip/Cargo.toml @@ -47,6 +47,7 @@ solana-streamer = { workspace = true } solana-thin-client = { workspace = true } solana-tpu-client = { workspace = true } solana-version = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } static_assertions = { workspace = true } thiserror = { workspace = true } diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index d5b2b447ea..b0b99b1c02 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -60,7 +60,7 @@ use { packet::{Packet, PacketBatch, PacketBatchRecycler, PACKET_DATA_SIZE}, }, solana_rayon_threadlimit::get_thread_count, - solana_runtime::{bank_forks::BankForks, vote_parser}, + solana_runtime::bank_forks::BankForks, solana_sdk::{ clock::{Slot, DEFAULT_MS_PER_SLOT, DEFAULT_SLOTS_PER_EPOCH}, feature_set::FeatureSet, @@ -77,6 +77,7 @@ use { socket::SocketAddrSpace, streamer::{PacketBatchReceiver, PacketBatchSender}, }, + solana_vote::vote_parser, solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY, std::{ borrow::Cow, diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index 24d66e3c52..87ba34604e 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -10,7 +10,6 @@ use { bincode::{serialize, serialized_size}, rand::{CryptoRng, Rng}, serde::de::{Deserialize, Deserializer}, - solana_runtime::vote_parser, solana_sdk::{ clock::Slot, hash::Hash, @@ -20,6 +19,7 @@ use { timing::timestamp, transaction::Transaction, }, + solana_vote::vote_parser, std::{ borrow::{Borrow, Cow}, cmp::Ordering, diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index fa77b944d3..f6fbb140e5 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -54,6 +54,7 @@ solana-stake-program = { workspace = true } solana-storage-bigtable = { workspace = true } solana-storage-proto = { workspace = true } solana-transaction-status = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"] } spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 9c988f1fcb..488ada1466 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -43,8 +43,6 @@ use { prioritization_fee_cache::PrioritizationFeeCache, runtime_config::RuntimeConfig, transaction_batch::TransactionBatch, - vote_account::VoteAccountsHashMap, - vote_sender_types::ReplayVoteSender, }, solana_sdk::{ clock::{Slot, MAX_PROCESSING_AGE}, @@ -61,6 +59,7 @@ use { }, }, solana_transaction_status::token_balances::TransactionTokenBalancesSet, + solana_vote::{vote_account::VoteAccountsHashMap, vote_sender_types::ReplayVoteSender}, std::{ borrow::Cow, collections::{HashMap, HashSet}, @@ -1863,11 +1862,8 @@ pub mod tests { rand::{thread_rng, Rng}, solana_entry::entry::{create_ticks, next_entry, next_entry_mut}, solana_program_runtime::declare_process_instruction, - solana_runtime::{ - genesis_utils::{ - self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs, - }, - vote_account::VoteAccount, + solana_runtime::genesis_utils::{ + self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs, }, solana_sdk::{ account::{AccountSharedData, WritableAccount}, @@ -1881,6 +1877,7 @@ pub mod tests { system_transaction, transaction::{Transaction, TransactionError}, }, + solana_vote::vote_account::VoteAccount, solana_vote_program::{ self, vote_state::{VoteState, VoteStateVersions, MAX_LOCKOUT_HISTORY}, diff --git a/ledger/src/staking_utils.rs b/ledger/src/staking_utils.rs index dda6229844..75d1352792 100644 --- a/ledger/src/staking_utils.rs +++ b/ledger/src/staking_utils.rs @@ -2,10 +2,7 @@ pub(crate) mod tests { use { rand::Rng, - solana_runtime::{ - bank::Bank, - vote_account::{VoteAccount, VoteAccounts}, - }, + solana_runtime::bank::Bank, solana_sdk::{ account::AccountSharedData, clock::Clock, @@ -19,6 +16,7 @@ pub(crate) mod tests { }, transaction::Transaction, }, + solana_vote::vote_account::{VoteAccount, VoteAccounts}, solana_vote_program::{ vote_instruction, vote_state::{VoteInit, VoteState, VoteStateVersions}, diff --git a/local-cluster/Cargo.toml b/local-cluster/Cargo.toml index 5f0a3eeae5..4248fc0294 100644 --- a/local-cluster/Cargo.toml +++ b/local-cluster/Cargo.toml @@ -33,6 +33,7 @@ solana-streamer = { workspace = true } solana-thin-client = { workspace = true } solana-tpu-client = { workspace = true } solana-turbine = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } static_assertions = { workspace = true } tempfile = { workspace = true } diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index dc44a307c4..b410585396 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -21,7 +21,6 @@ use { gossip_service::{self, discover_cluster, GossipService}, }, solana_ledger::blockstore::Blockstore, - solana_runtime::vote_transaction::VoteTransaction, solana_sdk::{ client::SyncClient, clock::{self, Slot, NUM_CONSECUTIVE_LEADER_SLOTS}, @@ -38,6 +37,7 @@ use { transport::TransportError, }, solana_streamer::socket::SocketAddrSpace, + solana_vote::vote_transaction::VoteTransaction, solana_vote_program::vote_transaction, std::{ borrow::Borrow, diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 2280bd98f4..137477be1c 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -61,7 +61,6 @@ use { snapshot_config::SnapshotConfig, snapshot_package::SnapshotKind, snapshot_utils::{self}, - vote_parser, }, solana_sdk::{ account::AccountSharedData, @@ -83,6 +82,7 @@ use { broadcast_duplicates_run::{BroadcastDuplicatesConfig, ClusterPartition}, BroadcastStageType, }, + solana_vote::vote_parser, solana_vote_program::{vote_state::MAX_LOCKOUT_HISTORY, vote_transaction}, std::{ collections::{BTreeSet, HashMap, HashSet}, diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 8d34c0206a..f0d50d5391 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4837,6 +4837,7 @@ dependencies = [ "solana-transaction-status", "solana-turbine", "solana-version", + "solana-vote", "solana-vote-program", "strum", "strum_macros", @@ -5050,6 +5051,7 @@ dependencies = [ "solana-thin-client", "solana-tpu-client", "solana-version", + "solana-vote", "solana-vote-program", "static_assertions", "thiserror", @@ -5105,6 +5107,7 @@ dependencies = [ "solana-storage-bigtable", "solana-storage-proto", "solana-transaction-status", + "solana-vote", "solana-vote-program", "spl-token", "spl-token-2022", @@ -5449,6 +5452,7 @@ dependencies = [ "solana-tpu-client", "solana-transaction-status", "solana-version", + "solana-vote", "solana-vote-program", "spl-token", "spl-token-2022", @@ -5574,6 +5578,7 @@ dependencies = [ "solana-stake-program", "solana-system-program", "solana-version", + "solana-vote", "solana-vote-program", "solana-zk-token-proof-program", "solana-zk-token-sdk", @@ -6392,6 +6397,76 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-vote" +version = "1.17.0" +dependencies = [ + "arrayref", + "bincode", + "blake3", + "bv", + "bytemuck", + "byteorder 1.4.3", + "bzip2", + "crossbeam-channel", + "dashmap", + "dir-diff", + "flate2", + "fnv", + "fs-err", + "im", + "index_list", + "itertools", + "lazy_static", + "log", + "lru", + "lz4", + "memmap2", + "modular-bitfield", + "num-derive", + "num-traits", + "num_cpus", + "num_enum 0.6.1", + "ouroboros", + "percentage", + "qualifier_attr", + "rand 0.8.5", + "rayon", + "regex", + "rustc_version", + "serde", + "serde_derive", + "siphasher", + "solana-address-lookup-table-program", + "solana-bpf-loader-program", + "solana-bucket-map", + "solana-compute-budget-program", + "solana-config-program", + "solana-cost-model", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-loader-v4-program", + "solana-measure", + "solana-metrics", + "solana-perf", + "solana-program-runtime", + "solana-rayon-threadlimit", + "solana-sdk", + "solana-stake-program", + "solana-system-program", + "solana-vote-program", + "solana-zk-token-proof-program", + "solana-zk-token-sdk", + "static_assertions", + "strum", + "strum_macros", + "symlink", + "tar", + "tempfile", + "thiserror", + "zstd", +] + [[package]] name = "solana-vote-program" version = "1.17.0" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 62ae098cb6..f6fa5160f9 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -51,6 +51,7 @@ solana-streamer = { workspace = true } solana-tpu-client = { workspace = true } solana-transaction-status = { workspace = true } solana-version = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"] } spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } diff --git a/rpc/src/rpc_pubsub.rs b/rpc/src/rpc_pubsub.rs index e318940b1c..e45a5f8af6 100644 --- a/rpc/src/rpc_pubsub.rs +++ b/rpc/src/rpc_pubsub.rs @@ -622,7 +622,6 @@ mod tests { activate_all_features, create_genesis_config, create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs, }, - vote_transaction::VoteTransaction, }, solana_sdk::{ account::ReadableAccount, @@ -641,6 +640,7 @@ mod tests { transaction::{self, Transaction}, }, solana_stake_program::stake_state, + solana_vote::vote_transaction::VoteTransaction, solana_vote_program::vote_state::Vote, std::{ sync::{ diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index ad9de1664c..6fca7d4503 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -29,7 +29,6 @@ use { bank::{Bank, TransactionLogInfo}, bank_forks::BankForks, commitment::{BlockCommitmentCache, CommitmentSlots}, - vote_transaction::VoteTransaction, }, solana_sdk::{ account::{AccountSharedData, ReadableAccount}, @@ -42,6 +41,7 @@ use { solana_transaction_status::{ BlockEncodingOptions, ConfirmedBlock, EncodeError, VersionedConfirmedBlock, }, + solana_vote::vote_transaction::VoteTransaction, std::{ cell::RefCell, collections::{HashMap, VecDeque}, diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 319e6f4d7f..2d15c7acba 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -66,6 +66,7 @@ solana-sdk = { workspace = true } solana-stake-program = { workspace = true } solana-system-program = { workspace = true } solana-version = { workspace = true } +solana-vote = { workspace = true } solana-vote-program = { workspace = true } solana-zk-token-proof-program = { workspace = true } solana-zk-token-sdk = { workspace = true } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 543c903506..5963503095 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -54,7 +54,6 @@ use { stakes::{InvalidCacheEntryReason, Stakes, StakesCache, StakesEnum}, status_cache::{SlotDelta, StatusCache}, transaction_batch::TransactionBatch, - vote_account::{VoteAccount, VoteAccounts, VoteAccountsHashMap}, }, byteorder::{ByteOrder, LittleEndian}, dashmap::{DashMap, DashSet}, @@ -178,6 +177,7 @@ use { self, InflationPointCalculationEvent, PointValue, StakeStateV2, }, solana_system_program::{get_system_account_kind, SystemAccountKind}, + solana_vote::vote_account::{VoteAccount, VoteAccounts, VoteAccountsHashMap}, solana_vote_program::vote_state::VoteState, std::{ borrow::Cow, diff --git a/runtime/src/bank/serde_snapshot.rs b/runtime/src/bank/serde_snapshot.rs index 338698407b..2e0bdd3ecc 100644 --- a/runtime/src/bank/serde_snapshot.rs +++ b/runtime/src/bank/serde_snapshot.rs @@ -612,7 +612,7 @@ mod tests { // This some what long test harness is required to freeze the ABI of // Bank's serialization due to versioned nature - #[frozen_abi(digest = "5G71eC1ofQ6pqgeQLb8zaK4EQCncs5Rs51rfmMAvtF8U")] + #[frozen_abi(digest = "12WNiuA7qeLU8JFweQszX5sCnCj1fYnYV4i9DeACqhQD")] #[derive(Serialize, AbiExample)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper_newer")] diff --git a/runtime/src/bank_utils.rs b/runtime/src/bank_utils.rs index 0eeb750bf4..96844da635 100644 --- a/runtime/src/bank_utils.rs +++ b/runtime/src/bank_utils.rs @@ -2,11 +2,10 @@ use { crate::{ bank::Bank, genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs}, - vote_parser, - vote_sender_types::ReplayVoteSender, }, solana_accounts_db::transaction_results::TransactionResults, solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::SanitizedTransaction}, + solana_vote::{vote_parser, vote_sender_types::ReplayVoteSender}, }; pub fn setup_bank_and_vote_pubkeys_for_tests( diff --git a/runtime/src/epoch_stakes.rs b/runtime/src/epoch_stakes.rs index 89707e1a5e..1124906e2e 100644 --- a/runtime/src/epoch_stakes.rs +++ b/runtime/src/epoch_stakes.rs @@ -1,7 +1,8 @@ use { - crate::{stakes::StakesEnum, vote_account::VoteAccountsHashMap}, + crate::stakes::StakesEnum, serde::{Deserialize, Serialize}, solana_sdk::{clock::Epoch, pubkey::Pubkey}, + solana_vote::vote_account::VoteAccountsHashMap, std::{collections::HashMap, sync::Arc}, }; @@ -123,7 +124,7 @@ impl EpochStakes { #[cfg(test)] pub(crate) mod tests { use { - super::*, crate::vote_account::VoteAccount, solana_sdk::account::AccountSharedData, + super::*, solana_sdk::account::AccountSharedData, solana_vote::vote_account::VoteAccount, solana_vote_program::vote_state::create_account_with_authorized, std::iter, }; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index fb22c1f96c..ff94a68c69 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -37,10 +37,6 @@ pub mod static_ids; pub mod status_cache; pub mod transaction_batch; pub mod transaction_priority_details; -pub mod vote_account; -pub mod vote_parser; -pub mod vote_sender_types; -pub mod vote_transaction; #[macro_use] extern crate solana_metrics; diff --git a/runtime/src/stakes.rs b/runtime/src/stakes.rs index 8d8f72d2ab..977c25b180 100644 --- a/runtime/src/stakes.rs +++ b/runtime/src/stakes.rs @@ -1,11 +1,7 @@ //! Stakes serve as a cache of stake and vote accounts to derive //! node stakes use { - crate::{ - stake_account, - stake_history::StakeHistory, - vote_account::{VoteAccount, VoteAccounts}, - }, + crate::{stake_account, stake_history::StakeHistory}, dashmap::DashMap, im::HashMap as ImHashMap, log::error, @@ -20,6 +16,7 @@ use { stake::state::{Delegation, StakeActivationStatus}, vote::state::VoteStateVersions, }, + solana_vote::vote_account::{VoteAccount, VoteAccounts}, std::{ collections::{HashMap, HashSet}, ops::{Add, Deref}, diff --git a/vote/Cargo.toml b/vote/Cargo.toml new file mode 100644 index 0000000000..13adc56ba4 --- /dev/null +++ b/vote/Cargo.toml @@ -0,0 +1,101 @@ +[package] +name = "solana-vote" +description = "Solana vote" +documentation = "https://docs.rs/solana-vote" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +arrayref = { workspace = true } +bincode = { workspace = true } +blake3 = { workspace = true } +bv = { workspace = true, features = ["serde"] } +bytemuck = { workspace = true } +byteorder = { workspace = true } +bzip2 = { workspace = true } +crossbeam-channel = { workspace = true } +dashmap = { workspace = true, features = ["rayon", "raw-api"] } +dir-diff = { workspace = true } +flate2 = { workspace = true } +fnv = { workspace = true } +fs-err = { workspace = true } +im = { workspace = true, features = ["rayon", "serde"] } +index_list = { workspace = true } +itertools = { workspace = true } +lazy_static = { workspace = true } +log = { workspace = true } +lru = { workspace = true } +lz4 = { workspace = true } +memmap2 = { workspace = true } +modular-bitfield = { workspace = true } +num-derive = { workspace = true } +num-traits = { workspace = true } +num_cpus = { workspace = true } +num_enum = { workspace = true } +ouroboros = { workspace = true } +percentage = { workspace = true } +qualifier_attr = { workspace = true } +rand = { workspace = true } +rayon = { workspace = true } +regex = { workspace = true } +serde = { workspace = true, features = ["rc"] } +serde_derive = { workspace = true } +siphasher = { workspace = true } +solana-address-lookup-table-program = { workspace = true } +solana-bpf-loader-program = { workspace = true } +solana-bucket-map = { workspace = true } +solana-compute-budget-program = { workspace = true } +solana-config-program = { workspace = true } +solana-cost-model = { workspace = true } +solana-frozen-abi = { workspace = true } +solana-frozen-abi-macro = { workspace = true } +solana-loader-v4-program = { workspace = true } +solana-measure = { workspace = true } +solana-metrics = { workspace = true } +solana-perf = { workspace = true } +solana-program-runtime = { workspace = true } +solana-rayon-threadlimit = { workspace = true } +solana-sdk = { workspace = true } +solana-stake-program = { workspace = true } +solana-system-program = { workspace = true } +solana-vote-program = { workspace = true } +solana-zk-token-proof-program = { workspace = true } +solana-zk-token-sdk = { workspace = true } +static_assertions = { workspace = true } +strum = { workspace = true, features = ["derive"] } +strum_macros = { workspace = true } +symlink = { workspace = true } +tar = { workspace = true } +tempfile = { workspace = true } +thiserror = { workspace = true } +zstd = { workspace = true } + +[lib] +crate-type = ["lib"] +name = "solana_vote" + +[dev-dependencies] +assert_matches = { workspace = true } +ed25519-dalek = { workspace = true } +libsecp256k1 = { workspace = true } +memoffset = { workspace = true } +rand_chacha = { workspace = true } +solana-logger = { workspace = true } +solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } +# See order-crates-for-publishing.py for using this unusual `path = "."` +solana-vote = { path = ".", features = ["dev-context-only-utils"] } +static_assertions = { workspace = true } +test-case = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[build-dependencies] +rustc_version = { workspace = true } + +[features] +dev-context-only-utils = [] diff --git a/vote/build.rs b/vote/build.rs new file mode 100644 index 0000000000..c9550c1c5c --- /dev/null +++ b/vote/build.rs @@ -0,0 +1,27 @@ +extern crate rustc_version; +use rustc_version::{version_meta, Channel}; + +fn main() { + // Copied and adapted from + // https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example + // Licensed under Apache-2.0 + MIT + match version_meta().unwrap().channel { + Channel::Stable => { + println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); + } + Channel::Beta => { + println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION"); + } + Channel::Nightly => { + println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); + } + Channel::Dev => { + println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION"); + // See https://github.com/solana-labs/solana/issues/11055 + // We may be running the custom `rust-bpf-builder` toolchain, + // which currently needs `#![feature(proc_macro_hygiene)]` to + // be applied. + println!("cargo:rustc-cfg=RUSTC_NEEDS_PROC_MACRO_HYGIENE"); + } + } +} diff --git a/vote/src/lib.rs b/vote/src/lib.rs new file mode 100644 index 0000000000..bfff15ff92 --- /dev/null +++ b/vote/src/lib.rs @@ -0,0 +1,13 @@ +#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] +#![allow(clippy::integer_arithmetic)] + +pub mod vote_account; +pub mod vote_parser; +pub mod vote_sender_types; +pub mod vote_transaction; + +#[macro_use] +extern crate serde_derive; + +#[macro_use] +extern crate solana_frozen_abi_macro; diff --git a/runtime/src/vote_account.rs b/vote/src/vote_account.rs similarity index 95% rename from runtime/src/vote_account.rs rename to vote/src/vote_account.rs index 93789e3eed..cd4d538b2c 100644 --- a/runtime/src/vote_account.rs +++ b/vote/src/vote_account.rs @@ -54,15 +54,15 @@ pub struct VoteAccounts { } impl VoteAccount { - pub(crate) fn account(&self) -> &AccountSharedData { + pub fn account(&self) -> &AccountSharedData { &self.0.account } - pub(crate) fn lamports(&self) -> u64 { + pub fn lamports(&self) -> u64 { self.0.account.lamports() } - pub(crate) fn owner(&self) -> &Pubkey { + pub fn owner(&self) -> &Pubkey { self.0.account.owner() } @@ -75,7 +75,7 @@ impl VoteAccount { .as_ref() } - pub(crate) fn is_deserialized(&self) -> bool { + pub fn is_deserialized(&self) -> bool { self.0.vote_state.get().is_some() } @@ -86,10 +86,14 @@ impl VoteAccount { } impl VoteAccounts { - pub(crate) fn len(&self) -> usize { + pub fn len(&self) -> usize { self.vote_accounts.len() } + pub fn is_empty(&self) -> bool { + self.vote_accounts.is_empty() + } + pub fn staked_nodes(&self) -> Arc> { self.staked_nodes .get_or_init(|| { @@ -109,7 +113,7 @@ impl VoteAccounts { .clone() } - pub(crate) fn get(&self, pubkey: &Pubkey) -> Option<&VoteAccount> { + pub fn get(&self, pubkey: &Pubkey) -> Option<&VoteAccount> { let (_stake, vote_account) = self.vote_accounts.get(pubkey)?; Some(vote_account) } @@ -121,25 +125,25 @@ impl VoteAccounts { .unwrap_or_default() } - pub(crate) fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { self.vote_accounts .iter() .map(|(vote_pubkey, (_stake, vote_account))| (vote_pubkey, vote_account)) } - pub(crate) fn delegated_stakes(&self) -> impl Iterator { + pub fn delegated_stakes(&self) -> impl Iterator { self.vote_accounts .iter() .map(|(vote_pubkey, (stake, _vote_account))| (vote_pubkey, *stake)) } - pub(crate) fn find_max_by_delegated_stake(&self) -> Option<&VoteAccount> { + pub fn find_max_by_delegated_stake(&self) -> Option<&VoteAccount> { let key = |(_pubkey, (stake, _vote_account)): &(_, &(u64, _))| *stake; let (_pubkey, (_stake, vote_account)) = self.vote_accounts.iter().max_by_key(key)?; Some(vote_account) } - pub(crate) fn insert(&mut self, pubkey: Pubkey, (stake, vote_account): (u64, VoteAccount)) { + pub fn insert(&mut self, pubkey: Pubkey, (stake, vote_account): (u64, VoteAccount)) { self.add_node_stake(stake, &vote_account); let vote_accounts = Arc::make_mut(&mut self.vote_accounts); if let Some((stake, vote_account)) = vote_accounts.insert(pubkey, (stake, vote_account)) { @@ -147,7 +151,7 @@ impl VoteAccounts { } } - pub(crate) fn remove(&mut self, pubkey: &Pubkey) -> Option<(u64, VoteAccount)> { + pub fn remove(&mut self, pubkey: &Pubkey) -> Option<(u64, VoteAccount)> { let vote_accounts = Arc::make_mut(&mut self.vote_accounts); let entry = vote_accounts.remove(pubkey); if let Some((stake, ref vote_account)) = entry { @@ -156,7 +160,7 @@ impl VoteAccounts { entry } - pub(crate) fn add_stake(&mut self, pubkey: &Pubkey, delta: u64) { + pub fn add_stake(&mut self, pubkey: &Pubkey, delta: u64) { let vote_accounts = Arc::make_mut(&mut self.vote_accounts); if let Some((stake, vote_account)) = vote_accounts.get_mut(pubkey) { *stake += delta; @@ -165,7 +169,7 @@ impl VoteAccounts { } } - pub(crate) fn sub_stake(&mut self, pubkey: &Pubkey, delta: u64) { + pub fn sub_stake(&mut self, pubkey: &Pubkey, delta: u64) { let vote_accounts = Arc::make_mut(&mut self.vote_accounts); if let Some((stake, vote_account)) = vote_accounts.get_mut(pubkey) { *stake = stake diff --git a/runtime/src/vote_parser.rs b/vote/src/vote_parser.rs similarity index 100% rename from runtime/src/vote_parser.rs rename to vote/src/vote_parser.rs diff --git a/runtime/src/vote_sender_types.rs b/vote/src/vote_sender_types.rs similarity index 100% rename from runtime/src/vote_sender_types.rs rename to vote/src/vote_sender_types.rs diff --git a/runtime/src/vote_transaction.rs b/vote/src/vote_transaction.rs similarity index 100% rename from runtime/src/vote_transaction.rs rename to vote/src/vote_transaction.rs