Skip to content

Commit

Permalink
remove solana-sdk from solana-system-program (#4037)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey authored Dec 10, 2024
1 parent dd9e1b1 commit 2cea8e6
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 59 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

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

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

15 changes: 14 additions & 1 deletion programs/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@ 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]
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"]
Expand Down
27 changes: 13 additions & 14 deletions programs/system/benches/system.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
18 changes: 9 additions & 9 deletions programs/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,11 +19,11 @@ pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAcco
if system_program::check_id(account.owner()) {
if account.data().is_empty() {
Some(SystemAccountKind::System)
} else if account.data().len() == nonce::State::size() {
let nonce_versions: nonce::state::Versions = account.state().ok()?;
} else if account.data().len() == nonce::state::State::size() {
let nonce_versions: nonce::versions::Versions = account.state().ok()?;
match nonce_versions.state() {
nonce::State::Uninitialized => None,
nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce),
nonce::state::State::Uninitialized => None,
nonce::state::State::Initialized(_) => Some(SystemAccountKind::Nonce),
}
} else {
None
Expand Down
43 changes: 22 additions & 21 deletions programs/system/src/system_instruction.rs
Original file line number Diff line number Diff line change
@@ -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<u64, InstructionError> {
a.checked_add(b).ok_or(InstructionError::InsufficientFunds)
}

pub fn advance_nonce_account(
account: &mut BorrowedAccount,
signers: &HashSet<Pubkey>,
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 13 additions & 12 deletions programs/system/src/system_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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),
Expand Down
11 changes: 10 additions & 1 deletion svm/examples/Cargo.lock

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

0 comments on commit 2cea8e6

Please sign in to comment.