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
This commit is contained in:
Pankaj Garg 2023-09-19 10:46:37 -07:00 committed by GitHub
parent 889d6c655e
commit f50342a790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 371 additions and 79 deletions

84
Cargo.lock generated
View File

@ -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"

View File

@ -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" }

View File

@ -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 }

View File

@ -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::{

View File

@ -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},
};

View File

@ -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,

View File

@ -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,

View File

@ -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},

View File

@ -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 {

View File

@ -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},

View File

@ -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},

View File

@ -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},

View File

@ -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,

View File

@ -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 }

View File

@ -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,

View File

@ -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,

View File

@ -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"] }

View File

@ -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},

View File

@ -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},

View File

@ -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 }

View File

@ -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,

View File

@ -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},

View File

@ -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"

View File

@ -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"] }

View File

@ -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::{

View File

@ -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},

View File

@ -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 }

View File

@ -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,

View File

@ -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")]

View File

@ -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(

View File

@ -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,
};

View File

@ -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;

View File

@ -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},

101
vote/Cargo.toml Normal file
View File

@ -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 = []

27
vote/build.rs Normal file
View File

@ -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");
}
}
}

13
vote/src/lib.rs Normal file
View File

@ -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;

View File

@ -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<HashMap</*node_pubkey:*/ Pubkey, /*stake:*/ u64>> {
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<Item = (&Pubkey, &VoteAccount)> {
pub fn iter(&self) -> impl Iterator<Item = (&Pubkey, &VoteAccount)> {
self.vote_accounts
.iter()
.map(|(vote_pubkey, (_stake, vote_account))| (vote_pubkey, vote_account))
}
pub(crate) fn delegated_stakes(&self) -> impl Iterator<Item = (&Pubkey, u64)> {
pub fn delegated_stakes(&self) -> impl Iterator<Item = (&Pubkey, u64)> {
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