From fbc15f1130516a8bd69a4da80ad6db68b9a6aec5 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 19 Dec 2024 19:37:38 +0400 Subject: [PATCH] minimize solana-sdk usage in account-decoder --- Cargo.lock | 15 ++++++++ account-decoder/Cargo.toml | 16 ++++++++ account-decoder/src/lib.rs | 6 ++- account-decoder/src/parse_account_data.rs | 38 +++++++++---------- .../src/parse_address_lookup_table.rs | 9 ++--- account-decoder/src/parse_bpf_loader.rs | 5 ++- account-decoder/src/parse_config.rs | 12 +++--- account-decoder/src/parse_nonce.rs | 18 ++++----- account-decoder/src/parse_stake.rs | 12 +++--- account-decoder/src/parse_sysvar.rs | 31 +++++++-------- account-decoder/src/parse_token.rs | 2 +- account-decoder/src/parse_token_extension.rs | 3 +- account-decoder/src/parse_vote.rs | 8 ++-- account-decoder/src/validator_info.rs | 2 +- programs/sbf/Cargo.lock | 14 +++++++ svm/examples/Cargo.lock | 14 +++++++ 16 files changed, 129 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8df165733c5c87..9800090f61ead6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5840,9 +5840,24 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "solana-account", "solana-account-decoder-client-types", + "solana-clock", "solana-config-program", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-instruction", + "solana-nonce", + "solana-program", + "solana-program-pack", + "solana-pubkey", + "solana-rent", "solana-sdk", + "solana-sdk-ids", + "solana-slot-hashes", + "solana-slot-history", + "solana-sysvar", "spl-pod", "spl-token", "spl-token-2022", diff --git a/account-decoder/Cargo.toml b/account-decoder/Cargo.toml index d49d1a69fc3f4f..6e5c9b73b56745 100644 --- a/account-decoder/Cargo.toml +++ b/account-decoder/Cargo.toml @@ -19,9 +19,23 @@ lazy_static = { workspace = true } serde = { workspace = true } serde_derive = { workspace = true } serde_json = { workspace = true } +solana-account = { workspace = true } solana-account-decoder-client-types = { workspace = true, features = ["zstd"] } +solana-clock = { workspace = true } solana-config-program = { workspace = true } +solana-epoch-schedule = { workspace = true } +solana-fee-calculator = { workspace = true } +solana-instruction = { workspace = true } +solana-nonce = { workspace = true } +solana-program = { workspace = true } +solana-program-pack = { workspace = true } +solana-pubkey = { workspace = true } +solana-rent = { workspace = true } solana-sdk = { workspace = true } +solana-sdk-ids = { workspace = true } +solana-slot-hashes = { workspace = true } +solana-slot-history = { workspace = true } +solana-sysvar = { workspace = true } spl-token = { workspace = true, features = ["no-entrypoint"] } spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } spl-token-group-interface = { workspace = true } @@ -31,6 +45,8 @@ zstd = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } +solana-hash = { workspace = true } +solana-program = { workspace = true, default-features = false } spl-pod = { workspace = true } [package.metadata.docs.rs] diff --git a/account-decoder/src/lib.rs b/account-decoder/src/lib.rs index 9dd11fcbada666..b033934bb17b6c 100644 --- a/account-decoder/src/lib.rs +++ b/account-decoder/src/lib.rs @@ -23,7 +23,9 @@ pub use solana_account_decoder_client_types::{ use { crate::parse_account_data::{parse_account_data_v2, AccountAdditionalDataV2}, base64::{prelude::BASE64_STANDARD, Engine}, - solana_sdk::{account::ReadableAccount, fee_calculator::FeeCalculator, pubkey::Pubkey}, + solana_account::ReadableAccount, + solana_fee_calculator::FeeCalculator, + solana_pubkey::Pubkey, std::io::Write, }; @@ -141,7 +143,7 @@ mod test { use { super::*, assert_matches::assert_matches, - solana_sdk::account::{Account, AccountSharedData}, + solana_account::{Account, AccountSharedData}, }; #[test] diff --git a/account-decoder/src/parse_account_data.rs b/account-decoder/src/parse_account_data.rs index cd13a50e94f07f..f290d62b3b82b9 100644 --- a/account-decoder/src/parse_account_data.rs +++ b/account-decoder/src/parse_account_data.rs @@ -7,9 +7,11 @@ use { parse_token::parse_token_v2, parse_vote::parse_vote, }, inflector::Inflector, - solana_sdk::{ - address_lookup_table, clock::UnixTimestamp, instruction::InstructionError, pubkey::Pubkey, - stake, system_program, sysvar, vote, + solana_clock::UnixTimestamp, + solana_instruction::error::InstructionError, + solana_pubkey::Pubkey, + solana_sdk_ids::{ + address_lookup_table, bpf_loader_upgradeable, config, stake, system_program, sysvar, vote, }, spl_token_2022::extension::interest_bearing_mint::InterestBearingConfig, std::collections::HashMap, @@ -17,13 +19,13 @@ use { }; lazy_static! { - static ref ADDRESS_LOOKUP_PROGRAM_ID: Pubkey = address_lookup_table::program::id(); - static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id(); - static ref CONFIG_PROGRAM_ID: Pubkey = solana_config_program::id(); - static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id(); + static ref ADDRESS_LOOKUP_PROGRAM_ID: Pubkey = address_lookup_table::id(); + static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = bpf_loader_upgradeable::id(); + static ref CONFIG_PROGRAM_ID: Pubkey = config::id(); + static ref STAKE_PROGRAM_ID: Pubkey = stake::id(); static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id(); static ref SYSVAR_PROGRAM_ID: Pubkey = sysvar::id(); - static ref VOTE_PROGRAM_ID: Pubkey = vote::program::id(); + static ref VOTE_PROGRAM_ID: Pubkey = vote::id(); pub static ref PARSABLE_PROGRAM_IDS: HashMap = { let mut m = HashMap::new(); m.insert( @@ -160,22 +162,20 @@ pub fn parse_account_data_v2( mod test { use { super::*, - solana_sdk::{ - nonce::{ - state::{Data, Versions}, - State, - }, - vote::{ - program::id as vote_program_id, - state::{VoteState, VoteStateVersions}, - }, + solana_nonce::{ + state::{Data, State}, + versions::Versions, + }, + solana_sdk::vote::{ + program::id as vote_program_id, + state::{VoteState, VoteStateVersions}, }, }; #[test] fn test_parse_account_data() { - let account_pubkey = solana_sdk::pubkey::new_rand(); - let other_program = solana_sdk::pubkey::new_rand(); + let account_pubkey = solana_pubkey::new_rand(); + let other_program = solana_pubkey::new_rand(); let data = vec![0; 4]; assert!(parse_account_data_v2(&account_pubkey, &other_program, &data, None).is_err()); diff --git a/account-decoder/src/parse_address_lookup_table.rs b/account-decoder/src/parse_address_lookup_table.rs index 39c5d44f37b32c..c0e5d0a9420004 100644 --- a/account-decoder/src/parse_address_lookup_table.rs +++ b/account-decoder/src/parse_address_lookup_table.rs @@ -1,6 +1,7 @@ use { crate::parse_account_data::{ParsableAccount, ParseAccountError}, - solana_sdk::{address_lookup_table::state::AddressLookupTable, instruction::InstructionError}, + solana_instruction::error::InstructionError, + solana_program::address_lookup_table::state::AddressLookupTable, }; pub fn parse_address_lookup_table( @@ -61,10 +62,8 @@ impl<'a> From> for UiLookupTable { mod test { use { super::*, - solana_sdk::{ - address_lookup_table::state::{LookupTableMeta, LOOKUP_TABLE_META_SIZE}, - pubkey::Pubkey, - }, + solana_program::address_lookup_table::state::{LookupTableMeta, LOOKUP_TABLE_META_SIZE}, + solana_pubkey::Pubkey, std::borrow::Cow, }; diff --git a/account-decoder/src/parse_bpf_loader.rs b/account-decoder/src/parse_bpf_loader.rs index df9208bc29ebd2..ab795134ee5725 100644 --- a/account-decoder/src/parse_bpf_loader.rs +++ b/account-decoder/src/parse_bpf_loader.rs @@ -5,7 +5,8 @@ use { }, base64::{prelude::BASE64_STANDARD, Engine}, bincode::{deserialize, serialized_size}, - solana_sdk::{bpf_loader_upgradeable::UpgradeableLoaderState, pubkey::Pubkey}, + solana_pubkey::Pubkey, + solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState, }; pub fn parse_bpf_upgradeable_loader( @@ -93,7 +94,7 @@ pub struct UiProgramData { #[cfg(test)] mod test { - use {super::*, bincode::serialize, solana_sdk::pubkey::Pubkey}; + use {super::*, bincode::serialize, solana_pubkey::Pubkey}; #[test] fn test_parse_bpf_upgradeable_loader_accounts() { diff --git a/account-decoder/src/parse_config.rs b/account-decoder/src/parse_config.rs index eadc2675558635..384a9da6e73c48 100644 --- a/account-decoder/src/parse_config.rs +++ b/account-decoder/src/parse_config.rs @@ -6,11 +6,9 @@ use { bincode::deserialize, serde_json::Value, solana_config_program::{get_config_data, ConfigKeys}, - solana_sdk::{ - pubkey::Pubkey, - stake::config::{ - Config as StakeConfig, {self as stake_config}, - }, + solana_pubkey::Pubkey, + solana_sdk::stake::config::{ + Config as StakeConfig, {self as stake_config}, }, }; @@ -99,7 +97,7 @@ pub struct UiConfig { mod test { use { super::*, crate::validator_info::ValidatorInfo, serde_json::json, - solana_config_program::create_config_account, solana_sdk::account::ReadableAccount, + solana_account::ReadableAccount, solana_config_program::create_config_account, }; #[test] @@ -123,7 +121,7 @@ mod test { })) .unwrap(), }; - let info_pubkey = solana_sdk::pubkey::new_rand(); + let info_pubkey = solana_pubkey::new_rand(); let validator_info_config_account = create_config_account( vec![(validator_info::id(), false), (info_pubkey, true)], &validator_info, diff --git a/account-decoder/src/parse_nonce.rs b/account-decoder/src/parse_nonce.rs index 0b589b0cd04cb4..2c6d8f1314423a 100644 --- a/account-decoder/src/parse_nonce.rs +++ b/account-decoder/src/parse_nonce.rs @@ -1,9 +1,7 @@ use { crate::{parse_account_data::ParseAccountError, UiFeeCalculator}, - solana_sdk::{ - instruction::InstructionError, - nonce::{state::Versions, State}, - }, + solana_instruction::error::InstructionError, + solana_nonce::{state::State, versions::Versions}, }; pub fn parse_nonce(data: &[u8]) -> Result { @@ -45,14 +43,12 @@ pub struct UiNonceData { mod test { use { super::*, - solana_sdk::{ - hash::Hash, - nonce::{ - state::{Data, Versions}, - State, - }, - pubkey::Pubkey, + solana_hash::Hash, + solana_nonce::{ + state::{Data, State}, + versions::Versions, }, + solana_pubkey::Pubkey, }; #[test] diff --git a/account-decoder/src/parse_stake.rs b/account-decoder/src/parse_stake.rs index 5654955066f65b..e2636c7471aa3c 100644 --- a/account-decoder/src/parse_stake.rs +++ b/account-decoder/src/parse_stake.rs @@ -4,10 +4,8 @@ use { StringAmount, }, bincode::deserialize, - solana_sdk::{ - clock::{Epoch, UnixTimestamp}, - stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2}, - }, + solana_clock::{Epoch, UnixTimestamp}, + solana_sdk::stake::state::{Authorized, Delegation, Lockup, Meta, Stake, StakeStateV2}, }; pub fn parse_stake(data: &[u8]) -> Result { @@ -153,8 +151,8 @@ mod test { StakeAccountType::Uninitialized ); - let pubkey = solana_sdk::pubkey::new_rand(); - let custodian = solana_sdk::pubkey::new_rand(); + let pubkey = solana_pubkey::new_rand(); + let custodian = solana_pubkey::new_rand(); let authorized = Authorized::auto(&pubkey); let lockup = Lockup { unix_timestamp: 0, @@ -188,7 +186,7 @@ mod test { }) ); - let voter_pubkey = solana_sdk::pubkey::new_rand(); + let voter_pubkey = solana_pubkey::new_rand(); let stake = Stake { delegation: Delegation { voter_pubkey, diff --git a/account-decoder/src/parse_sysvar.rs b/account-decoder/src/parse_sysvar.rs index 7809aa7daa0ee5..c0b260f1542010 100644 --- a/account-decoder/src/parse_sysvar.rs +++ b/account-decoder/src/parse_sysvar.rs @@ -1,5 +1,5 @@ #[allow(deprecated)] -use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes}; +use solana_sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes}; use { crate::{ parse_account_data::{ParsableAccount, ParseAccountError}, @@ -7,17 +7,18 @@ use { }, bincode::deserialize, bv::BitVec, - solana_sdk::{ - clock::{Clock, Epoch, Slot, UnixTimestamp}, - epoch_schedule::EpochSchedule, - pubkey::Pubkey, - rent::Rent, - slot_hashes::SlotHashes, - slot_history::{self, SlotHistory}, + solana_clock::{Clock, Epoch, Slot, UnixTimestamp}, + solana_epoch_schedule::EpochSchedule, + solana_pubkey::Pubkey, + solana_rent::Rent, + solana_sdk_ids::sysvar, + solana_slot_hashes::SlotHashes, + solana_slot_history::{self as slot_history, SlotHistory}, + solana_sysvar::{ + epoch_rewards::EpochRewards, + last_restart_slot::LastRestartSlot, + rewards::Rewards, stake_history::{StakeHistory, StakeHistoryEntry}, - sysvar::{ - self, epoch_rewards::EpochRewards, last_restart_slot::LastRestartSlot, rewards::Rewards, - }, }, }; @@ -268,10 +269,10 @@ impl From for UiEpochRewards { #[cfg(test)] mod test { #[allow(deprecated)] - use solana_sdk::sysvar::recent_blockhashes::IterItem; + use solana_sysvar::recent_blockhashes::IterItem; use { - super::*, - solana_sdk::{account::create_account_for_test, fee_calculator::FeeCalculator, hash::Hash}, + super::*, solana_account::create_account_for_test, solana_fee_calculator::FeeCalculator, + solana_hash::Hash, }; #[test] @@ -376,7 +377,7 @@ mod test { }]), ); - let bad_pubkey = solana_sdk::pubkey::new_rand(); + let bad_pubkey = solana_pubkey::new_rand(); assert!(parse_sysvar(&stake_history_sysvar.data, &bad_pubkey).is_err()); let bad_data = vec![0; 4]; diff --git a/account-decoder/src/parse_token.rs b/account-decoder/src/parse_token.rs index ef08667c40b4fd..65d98c66efa66b 100644 --- a/account-decoder/src/parse_token.rs +++ b/account-decoder/src/parse_token.rs @@ -7,7 +7,7 @@ use { parse_account_data::{ParsableAccount, ParseAccountError, SplTokenAdditionalData}, parse_token_extension::parse_extension, }, - solana_sdk::pubkey::Pubkey, + solana_pubkey::Pubkey, spl_token_2022::{ extension::{BaseStateWithExtensions, StateWithExtensions}, generic_token_account::GenericTokenAccount, diff --git a/account-decoder/src/parse_token_extension.rs b/account-decoder/src/parse_token_extension.rs index 0e63785c367676..e18da6554a06cd 100644 --- a/account-decoder/src/parse_token_extension.rs +++ b/account-decoder/src/parse_token_extension.rs @@ -8,7 +8,8 @@ pub use solana_account_decoder_client_types::token::{ }; use { crate::parse_token::convert_account_state, - solana_sdk::{clock::UnixTimestamp, program_pack::Pack}, + solana_clock::UnixTimestamp, + solana_program_pack::Pack, spl_token_2022::{ extension::{self, BaseState, BaseStateWithExtensions, ExtensionType, StateWithExtensions}, solana_program::pubkey::Pubkey, diff --git a/account-decoder/src/parse_vote.rs b/account-decoder/src/parse_vote.rs index 7f7831f2f3ff48..afe82b6c241908 100644 --- a/account-decoder/src/parse_vote.rs +++ b/account-decoder/src/parse_vote.rs @@ -1,10 +1,8 @@ use { crate::{parse_account_data::ParseAccountError, StringAmount}, - solana_sdk::{ - clock::{Epoch, Slot}, - pubkey::Pubkey, - vote::state::{BlockTimestamp, Lockout, VoteState}, - }, + solana_clock::{Epoch, Slot}, + solana_pubkey::Pubkey, + solana_sdk::vote::state::{BlockTimestamp, Lockout, VoteState}, }; pub fn parse_vote(data: &[u8]) -> Result { diff --git a/account-decoder/src/validator_info.rs b/account-decoder/src/validator_info.rs index 7094fe2fb33033..3b616a060dcdc5 100644 --- a/account-decoder/src/validator_info.rs +++ b/account-decoder/src/validator_info.rs @@ -4,7 +4,7 @@ pub const MAX_SHORT_FIELD_LENGTH: usize = 80; pub const MAX_LONG_FIELD_LENGTH: usize = 300; pub const MAX_VALIDATOR_INFO: u64 = 576; -solana_sdk::declare_id!("Va1idator1nfo111111111111111111111111111111"); +solana_pubkey::declare_id!("Va1idator1nfo111111111111111111111111111111"); #[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Default)] pub struct ValidatorInfo { diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index d30186c24c18d6..5f3deab83b0566 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4915,9 +4915,23 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "solana-account", "solana-account-decoder-client-types", + "solana-clock", "solana-config-program", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-instruction", + "solana-nonce", + "solana-program", + "solana-program-pack", + "solana-pubkey", + "solana-rent", "solana-sdk", + "solana-sdk-ids", + "solana-slot-hashes", + "solana-slot-history", + "solana-sysvar", "spl-token", "spl-token-2022", "spl-token-group-interface", diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 1b7291092c71ac..828275ad04641f 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -4766,9 +4766,23 @@ dependencies = [ "serde", "serde_derive", "serde_json", + "solana-account", "solana-account-decoder-client-types", + "solana-clock", "solana-config-program", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-instruction", + "solana-nonce", + "solana-program", + "solana-program-pack", + "solana-pubkey", + "solana-rent", "solana-sdk", + "solana-sdk-ids", + "solana-slot-hashes", + "solana-slot-history", + "solana-sysvar", "spl-token", "spl-token-2022", "spl-token-group-interface",