From 2cea8e6e9315bc775aa27145f1a486cd5ae5ed84 Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Tue, 10 Dec 2024 21:38:36 +0400 Subject: [PATCH] remove solana-sdk from solana-system-program (#4037) --- Cargo.lock | 13 +++++++ programs/sbf/Cargo.lock | 11 +++++- programs/system/Cargo.toml | 15 +++++++- programs/system/benches/system.rs | 27 +++++++------- programs/system/src/lib.rs | 18 +++++----- programs/system/src/system_instruction.rs | 43 ++++++++++++----------- programs/system/src/system_processor.rs | 25 ++++++------- svm/examples/Cargo.lock | 11 +++++- 8 files changed, 104 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37a3faf1621377..d29e987acdb3dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9254,12 +9254,25 @@ dependencies = [ "log", "serde", "serde_derive", + "solana-account", + "solana-bincode", "solana-compute-budget", "solana-feature-set", + "solana-hash", + "solana-instruction", "solana-log-collector", "solana-logger", + "solana-nonce", + "solana-packet", "solana-program-runtime", + "solana-pubkey", + "solana-rent", "solana-sdk", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-system-interface", + "solana-sysvar", + "solana-transaction-context", "solana-type-overrides", ] diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index f5dcedd46f85ba..61a54fb50e9b85 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -7793,9 +7793,18 @@ dependencies = [ "log", "serde", "serde_derive", + "solana-account", + "solana-bincode", + "solana-instruction", "solana-log-collector", + "solana-nonce", + "solana-packet", "solana-program-runtime", - "solana-sdk", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-transaction-context", "solana-type-overrides", ] diff --git a/programs/system/Cargo.toml b/programs/system/Cargo.toml index aafec6fbc31539..ff371e5ac1eccb 100644 --- a/programs/system/Cargo.toml +++ b/programs/system/Cargo.toml @@ -14,9 +14,18 @@ bincode = { workspace = true } log = { workspace = true } serde = { workspace = true } serde_derive = { workspace = true } +solana-account = { workspace = true } +solana-bincode = { workspace = true } +solana-instruction = { workspace = true } solana-log-collector = { workspace = true } +solana-nonce = { workspace = true, features = ["serde"] } +solana-packet = { workspace = true } solana-program-runtime = { workspace = true } -solana-sdk = { workspace = true } +solana-pubkey = { workspace = true, features = ["sha2"] } +solana-sdk-ids = { workspace = true } +solana-system-interface = { workspace = true, features = ["serde"] } +solana-sysvar = { workspace = true } +solana-transaction-context = { workspace = true, features = ["bincode"] } solana-type-overrides = { workspace = true } [dev-dependencies] @@ -24,7 +33,11 @@ assert_matches = { workspace = true } criterion = { workspace = true } solana-compute-budget = { workspace = true } solana-feature-set = { workspace = true } +solana-hash = { workspace = true } solana-logger = { workspace = true } +solana-rent = { workspace = true } +solana-sdk = { workspace = true } +solana-sha256-hasher = { workspace = true } [lib] crate-type = ["lib"] diff --git a/programs/system/benches/system.rs b/programs/system/benches/system.rs index 37ce86ca1f4430..3d952f069f8d90 100644 --- a/programs/system/benches/system.rs +++ b/programs/system/benches/system.rs @@ -1,23 +1,22 @@ #[allow(deprecated)] use { criterion::{criterion_group, criterion_main, Criterion}, + solana_account::{self as account, AccountSharedData, WritableAccount}, + solana_hash::Hash, + solana_instruction::AccountMeta, + solana_nonce::{ + state::{DurableNonce, State}, + versions::Versions, + }, solana_program_runtime::invoke_context::mock_process_instruction, - solana_sdk::{ - account::{self, AccountSharedData, WritableAccount}, - hash::Hash, - instruction::AccountMeta, - nonce::{ - state::{DurableNonce, Versions}, - State, - }, - pubkey::Pubkey, - system_instruction::SystemInstruction, + solana_pubkey::Pubkey, + solana_rent::Rent, + solana_sdk_ids::{ system_program, - sysvar::{ - recent_blockhashes::{self, IterItem, RecentBlockhashes, MAX_ENTRIES}, - rent::{self, Rent}, - }, + sysvar::{recent_blockhashes, rent}, }, + solana_system_interface::instruction::SystemInstruction, + solana_sysvar::recent_blockhashes::{IterItem, RecentBlockhashes, MAX_ENTRIES}, }; const SEED: &str = "bench test"; diff --git a/programs/system/src/lib.rs b/programs/system/src/lib.rs index 140127c213923a..b0dbfd1844e3ca 100644 --- a/programs/system/src/lib.rs +++ b/programs/system/src/lib.rs @@ -2,12 +2,12 @@ pub mod system_instruction; pub mod system_processor; -use solana_sdk::{ - account::{AccountSharedData, ReadableAccount}, - account_utils::StateMut, - nonce, system_program, -}; pub use system_program::id; +use { + solana_account::{state_traits::StateMut, AccountSharedData, ReadableAccount}, + solana_nonce as nonce, + solana_sdk_ids::system_program, +}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum SystemAccountKind { @@ -19,11 +19,11 @@ pub fn get_system_account_kind(account: &AccountSharedData) -> Option None, - nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce), + nonce::state::State::Uninitialized => None, + nonce::state::State::Initialized(_) => Some(SystemAccountKind::Nonce), } } else { None diff --git a/programs/system/src/system_instruction.rs b/programs/system/src/system_instruction.rs index 18e27c0a71ba74..8d575b25d78d1e 100644 --- a/programs/system/src/system_instruction.rs +++ b/programs/system/src/system_instruction.rs @@ -1,23 +1,26 @@ use { + solana_instruction::error::InstructionError, solana_log_collector::ic_msg, + solana_nonce::{ + self as nonce, + state::{DurableNonce, State}, + versions::{AuthorizeNonceError, Versions}, + }, solana_program_runtime::invoke_context::InvokeContext, - solana_sdk::{ - instruction::{checked_add, InstructionError}, - nonce::{ - self, - state::{AuthorizeNonceError, DurableNonce, Versions}, - State, - }, - pubkey::Pubkey, - system_instruction::SystemError, - sysvar::rent::Rent, - transaction_context::{ - BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext, - }, + solana_pubkey::Pubkey, + solana_system_interface::error::SystemError, + solana_sysvar::rent::Rent, + solana_transaction_context::{ + BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext, }, std::collections::HashSet, }; +/// Addition that returns [`InstructionError::InsufficientFunds`] on overflow. +fn checked_add(a: u64, b: u64) -> Result { + a.checked_add(b).ok_or(InstructionError::InsufficientFunds) +} + pub fn advance_nonce_account( account: &mut BorrowedAccount, signers: &HashSet, @@ -248,15 +251,13 @@ mod test { use { super::*, assert_matches::assert_matches, + solana_account::AccountSharedData, + solana_nonce::{self as nonce, state::State}, solana_program_runtime::with_mock_invoke_context, - solana_sdk::{ - account::AccountSharedData, - hash::hash, - nonce::{self, State}, - nonce_account::{create_account, verify_nonce_account}, - system_program, - transaction_context::InstructionAccount, - }, + solana_sdk::nonce_account::{create_account, verify_nonce_account}, + solana_sdk_ids::system_program, + solana_sha256_hasher::hash, + solana_transaction_context::InstructionAccount, }; pub const NONCE_ACCOUNT_INDEX: IndexOfAccount = 0; diff --git a/programs/system/src/system_processor.rs b/programs/system/src/system_processor.rs index 528f4dc222674a..f05e8c8f37b210 100644 --- a/programs/system/src/system_processor.rs +++ b/programs/system/src/system_processor.rs @@ -4,21 +4,21 @@ use { withdraw_nonce_account, }, log::*, + solana_bincode::limited_deserialize, + solana_instruction::error::InstructionError, solana_log_collector::ic_msg, + solana_nonce as nonce, solana_program_runtime::{ declare_process_instruction, invoke_context::InvokeContext, sysvar_cache::get_sysvar_with_account_check, }, - solana_sdk::{ - instruction::InstructionError, - nonce, - program_utils::limited_deserialize, - pubkey::Pubkey, - system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH}, - system_program, - transaction_context::{ - BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext, - }, + solana_pubkey::Pubkey, + solana_sdk_ids::system_program, + solana_system_interface::{ + error::SystemError, instruction::SystemInstruction, MAX_PERMITTED_DATA_LENGTH, + }, + solana_transaction_context::{ + BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext, }, std::collections::HashSet, }; @@ -302,7 +302,8 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context| let transaction_context = &invoke_context.transaction_context; let instruction_context = transaction_context.get_current_instruction_context()?; let instruction_data = instruction_context.get_instruction_data(); - let instruction = limited_deserialize(instruction_data)?; + let instruction = + limited_deserialize(instruction_data, solana_packet::PACKET_DATA_SIZE as u64)?; trace!("process_instruction: {:?}", instruction); @@ -479,7 +480,7 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context| if !nonce_account.is_writable() { return Err(InstructionError::InvalidArgument); } - let nonce_versions: nonce::state::Versions = nonce_account.get_state()?; + let nonce_versions: nonce::versions::Versions = nonce_account.get_state()?; match nonce_versions.upgrade() { None => Err(InstructionError::InvalidArgument), Some(nonce_versions) => nonce_account.set_state(&nonce_versions), diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 9f9fbb6c105260..12dfa64ee7a2ae 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -7129,9 +7129,18 @@ dependencies = [ "log", "serde", "serde_derive", + "solana-account", + "solana-bincode", + "solana-instruction", "solana-log-collector", + "solana-nonce", + "solana-packet", "solana-program-runtime", - "solana-sdk", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-transaction-context", "solana-type-overrides", ]