Skip to content

Commit

Permalink
remove solana-sdk from solana-vote (#4358)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey authored Jan 9, 2025
1 parent b970a69 commit b2ba133
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 57 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions vote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ log = { workspace = true }
rand = { workspace = true, optional = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
solana-account = { workspace = true, features = ["bincode"] }
solana-bincode = { workspace = true }
solana-clock = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-frozen-abi-macro = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-sdk = { workspace = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true }
solana-packet = { workspace = true }
solana-program = { workspace = true }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-signature = { workspace = true }
solana-svm-transaction = { workspace = true }
solana-transaction = { workspace = true }
thiserror = { workspace = true }

[lib]
Expand All @@ -32,17 +42,17 @@ name = "solana_vote"
[dev-dependencies]
bincode = { workspace = true }
rand = { workspace = true }
solana-keypair = { workspace = true }
solana-sha256-hasher = { workspace = true }
solana-signer = { workspace = true }
solana-transaction = { workspace = true, features = ["bincode"] }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[features]
dev-context-only-utils = ["dep:rand"]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"solana-sdk/frozen-abi",
]
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]

[lints]
workspace = true
12 changes: 5 additions & 7 deletions vote/benches/vote_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ extern crate test;

use {
rand::Rng,
solana_sdk::{
account::AccountSharedData,
pubkey::Pubkey,
vote::state::{VoteInit, VoteState, VoteStateVersions},
},
solana_account::AccountSharedData,
solana_program::vote::state::{VoteInit, VoteState, VoteStateVersions},
solana_pubkey::Pubkey,
solana_vote::vote_account::VoteAccount,
test::Bencher,
};
Expand All @@ -22,7 +20,7 @@ fn new_rand_vote_account<R: Rng>(
authorized_withdrawer: Pubkey::new_unique(),
commission: rng.gen(),
};
let clock = solana_sdk::sysvar::clock::Clock {
let clock = solana_clock::Clock {
slot: rng.gen(),
epoch_start_timestamp: rng.gen(),
epoch: rng.gen(),
Expand All @@ -33,7 +31,7 @@ fn new_rand_vote_account<R: Rng>(
let account = AccountSharedData::new_data(
rng.gen(), // lamports
&VoteStateVersions::new_current(vote_state.clone()),
&solana_sdk::vote::program::id(), // owner
&solana_sdk_ids::vote::id(), // owner
)
.unwrap();
(account, vote_state)
Expand Down
37 changes: 15 additions & 22 deletions vote/src/vote_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use {
de::{MapAccess, Visitor},
ser::{Serialize, Serializer},
},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
instruction::InstructionError,
pubkey::Pubkey,
vote::state::VoteState,
},
solana_account::{AccountSharedData, ReadableAccount},
solana_instruction::error::InstructionError,
solana_program::vote::state::VoteState,
solana_pubkey::Pubkey,
std::{
cmp::Ordering,
collections::{hash_map::Entry, HashMap},
Expand Down Expand Up @@ -98,10 +96,8 @@ impl VoteAccount {
pub fn new_random() -> VoteAccount {
use {
rand::Rng as _,
solana_sdk::{
clock::Clock,
vote::state::{VoteInit, VoteStateVersions},
},
solana_clock::Clock,
solana_program::vote::state::{VoteInit, VoteStateVersions},
};

let mut rng = rand::thread_rng();
Expand All @@ -123,7 +119,7 @@ impl VoteAccount {
let account = AccountSharedData::new_data(
rng.gen(), // lamports
&VoteStateVersions::new_current(vote_state.clone()),
&solana_sdk::vote::program::id(), // owner
&solana_sdk_ids::vote::id(), // owner
)
.unwrap();

Expand Down Expand Up @@ -325,7 +321,7 @@ impl From<VoteAccount> for AccountSharedData {
impl TryFrom<AccountSharedData> for VoteAccount {
type Error = Error;
fn try_from(account: AccountSharedData) -> Result<Self, Self::Error> {
if !solana_sdk::vote::program::check_id(account.owner()) {
if !solana_sdk_ids::vote::check_id(account.owner()) {
return Err(Error::InvalidOwner(*account.owner()));
}

Expand Down Expand Up @@ -485,12 +481,10 @@ mod tests {
super::*,
bincode::Options,
rand::Rng,
solana_sdk::{
account::WritableAccount,
pubkey::Pubkey,
sysvar::clock::Clock,
vote::state::{VoteInit, VoteStateVersions},
},
solana_account::WritableAccount,
solana_clock::Clock,
solana_program::vote::state::{VoteInit, VoteStateVersions},
solana_pubkey::Pubkey,
std::iter::repeat_with,
};

Expand All @@ -515,7 +509,7 @@ mod tests {
let account = AccountSharedData::new_data(
rng.gen(), // lamports
&VoteStateVersions::new_current(vote_state.clone()),
&solana_sdk::vote::program::id(), // owner
&solana_sdk_ids::vote::id(), // owner
)
.unwrap();
(account, vote_state)
Expand Down Expand Up @@ -576,7 +570,7 @@ mod tests {
#[should_panic(expected = "InvalidAccountData")]
fn test_vote_account_try_from_invalid_account() {
let mut account = AccountSharedData::default();
account.set_owner(solana_sdk::vote::program::id());
account.set_owner(solana_sdk_ids::vote::id());
VoteAccount::try_from(account).unwrap();
}

Expand Down Expand Up @@ -640,8 +634,7 @@ mod tests {

// bad data
let invalid_account_data =
AccountSharedData::new_data(42, &vec![0xFF; 42], &solana_sdk::vote::program::id())
.unwrap();
AccountSharedData::new_data(42, &vec![0xFF; 42], &solana_sdk_ids::vote::id()).unwrap();
vote_accounts_hash_map.insert(Pubkey::new_unique(), (0xBB, invalid_account_data));

// wrong owner
Expand Down
32 changes: 17 additions & 15 deletions vote/src/vote_parser.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {
crate::vote_transaction::VoteTransaction,
solana_sdk::{
hash::Hash, program_utils::limited_deserialize, pubkey::Pubkey, signature::Signature,
transaction::Transaction, vote::instruction::VoteInstruction,
},
solana_svm_transaction::svm_transaction::SVMTransaction,
crate::vote_transaction::VoteTransaction, solana_bincode::limited_deserialize,
solana_hash::Hash, solana_program::vote::instruction::VoteInstruction, solana_pubkey::Pubkey,
solana_signature::Signature, solana_svm_transaction::svm_transaction::SVMTransaction,
solana_transaction::Transaction,
};

pub type ParsedVote = (Pubkey, VoteTransaction, Option<Hash>, Signature);
Expand All @@ -13,7 +11,7 @@ pub type ParsedVote = (Pubkey, VoteTransaction, Option<Hash>, Signature);
pub fn parse_sanitized_vote_transaction(tx: &impl SVMTransaction) -> Option<ParsedVote> {
// Check first instruction for a vote
let (program_id, first_instruction) = tx.program_instructions_iter().next()?;
if !solana_sdk::vote::program::check_id(program_id) {
if !solana_sdk_ids::vote::check_id(program_id) {
return None;
}
let first_account = usize::from(*first_instruction.accounts.first()?);
Expand All @@ -30,7 +28,7 @@ pub fn parse_vote_transaction(tx: &Transaction) -> Option<ParsedVote> {
let first_instruction = message.instructions.first()?;
let program_id_index = usize::from(first_instruction.program_id_index);
let program_id = message.account_keys.get(program_id_index)?;
if !solana_sdk::vote::program::check_id(program_id) {
if !solana_sdk_ids::vote::check_id(program_id) {
return None;
}
let first_account = usize::from(*first_instruction.accounts.first()?);
Expand All @@ -43,7 +41,12 @@ pub fn parse_vote_transaction(tx: &Transaction) -> Option<ParsedVote> {
fn parse_vote_instruction_data(
vote_instruction_data: &[u8],
) -> Option<(VoteTransaction, Option<Hash>)> {
match limited_deserialize(vote_instruction_data).ok()? {
match limited_deserialize(
vote_instruction_data,
solana_packet::PACKET_DATA_SIZE as u64,
)
.ok()?
{
VoteInstruction::Vote(vote) => Some((VoteTransaction::from(vote), None)),
VoteInstruction::VoteSwitch(vote, hash) => Some((VoteTransaction::from(vote), Some(hash))),
VoteInstruction::UpdateVoteState(vote_state_update) => {
Expand Down Expand Up @@ -77,12 +80,11 @@ fn parse_vote_instruction_data(
mod test {
use {
super::*,
solana_sdk::{
clock::Slot,
hash::hash,
signature::{Keypair, Signer},
vote::{instruction as vote_instruction, state::Vote},
},
solana_clock::Slot,
solana_keypair::Keypair,
solana_program::vote::{instruction as vote_instruction, state::Vote},
solana_sha256_hasher::hash,
solana_signer::Signer,
};

// Reimplemented locally from Vote program.
Expand Down
8 changes: 4 additions & 4 deletions vote/src/vote_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use solana_sdk::{
clock::{Slot, UnixTimestamp},
hash::Hash,
vote::state::{TowerSync, Vote, VoteStateUpdate},
use {
solana_clock::{Slot, UnixTimestamp},
solana_hash::Hash,
solana_program::vote::state::{TowerSync, Vote, VoteStateUpdate},
};

#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down

0 comments on commit b2ba133

Please sign in to comment.