Skip to content

Commit

Permalink
Moves the system program into its own crate in "programs/system".
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Apr 18, 2023
1 parent f5fe260 commit 4aceea0
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 38 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ members = [
"programs/ed25519-tests",
"programs/loader-v3",
"programs/stake",
"programs/system",
"programs/vote",
"programs/zk-token-proof",
"programs/zk-token-proof-tests",
Expand Down Expand Up @@ -348,6 +349,7 @@ solana-storage-bigtable = { path = "storage-bigtable", version = "=1.16.0" }
solana-storage-proto = { path = "storage-proto", version = "=1.16.0" }
solana-streamer = { path = "streamer", version = "=1.16.0" }
solana-sys-tuner = { path = "sys-tuner", version = "=1.16.0" }
solana-system-program = { path = "programs/system", version = "=1.16.0" }
solana-test-validator = { path = "test-validator", version = "=1.16.0" }
solana-thin-client = { path = "thin-client", version = "=1.16.0" }
solana-tpu-client = { path = "tpu-client", version = "=1.16.0", default-features = false }
Expand Down
13 changes: 13 additions & 0 deletions programs/sbf/Cargo.lock

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

30 changes: 30 additions & 0 deletions programs/system/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "solana-system-program"
description = "Solana System program"
documentation = "https://docs.rs/solana-system-program"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
bincode = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
solana-program-runtime = { workspace = true }
solana-sdk = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
solana-logger = { workspace = true }
solana-runtime = { workspace = true }

[lib]
crate-type = ["lib"]
name = "solana_system_program"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
35 changes: 35 additions & 0 deletions programs/system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![allow(clippy::integer_arithmetic)]
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;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SystemAccountKind {
System,
Nonce,
}

pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAccountKind> {
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()?;
match nonce_versions.state() {
nonce::State::Uninitialized => None,
nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce),
}
} else {
None
}
} else {
None
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
crate::nonce_keyed_account::{
crate::system_instruction::{
advance_nonce_account, authorize_nonce_account, initialize_nonce_account,
withdraw_nonce_account,
},
Expand All @@ -9,8 +9,6 @@ use {
sysvar_cache::get_sysvar_with_account_check,
},
solana_sdk::{
account::AccountSharedData,
account_utils::StateMut,
feature_set,
instruction::InstructionError,
nonce,
Expand Down Expand Up @@ -557,31 +555,6 @@ declare_process_instruction!(process_instruction, 150, |invoke_context| {
}
});

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SystemAccountKind {
System,
Nonce,
}

pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAccountKind> {
use solana_sdk::account::ReadableAccount;
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()?;
match nonce_versions.state() {
nonce::State::Uninitialized => None,
nonce::State::Initialized(_) => Some(SystemAccountKind::Nonce),
}
} else {
None
}
} else {
None
}
}

#[cfg(test)]
mod tests {
#[allow(deprecated)]
Expand All @@ -608,11 +581,12 @@ mod tests {
};
use {
super::*,
crate::{bank::Bank, bank_client::BankClient},
crate::{get_system_account_kind, SystemAccountKind},
bincode::serialize,
solana_program_runtime::{
invoke_context::mock_process_instruction, with_mock_invoke_context,
},
solana_runtime::{bank::Bank, bank_client::BankClient},
std::sync::Arc,
};

Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ 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 }
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use {
rent_collector::RentCollector,
rent_debits::RentDebits,
storable_accounts::StorableAccounts,
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
transaction_error_metrics::TransactionErrorMetrics,
},
dashmap::DashMap,
Expand All @@ -29,6 +28,7 @@ use {
compute_budget::{self, ComputeBudget},
loaded_programs::{LoadedProgram, LoadedProgramType},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ use {
stakes::{InvalidCacheEntryReason, Stakes, StakesCache, StakesEnum},
status_cache::{SlotDelta, StatusCache},
storable_accounts::StorableAccounts,
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
transaction_batch::TransactionBatch,
transaction_error_metrics::TransactionErrorMetrics,
vote_account::{VoteAccount, VoteAccountsHashMap},
Expand All @@ -103,6 +102,7 @@ use {
sysvar_cache::SysvarCache,
timings::{ExecuteTimingType, ExecuteTimings},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
solana_sdk::{
account::{
create_account_shared_data_with_fields as create_account, from_account, Account,
Expand Down Expand Up @@ -7726,7 +7726,7 @@ impl Bank {
//
// This fn is meant to be called by the snapshot handler in Accounts Background Service. If
// calling from elsewhere, ensure the same invariants hold/expectations are met.
pub(crate) fn clean_accounts(&self, last_full_snapshot_slot: Option<Slot>) {
pub fn clean_accounts(&self, last_full_snapshot_slot: Option<Slot>) {
// Don't clean the slot we're snapshotting because it may have zero-lamport
// accounts that were included in the bank delta hash when the bank was frozen,
// and if we clean them here, any newly created snapshot's hash for this bank
Expand Down
7 changes: 3 additions & 4 deletions runtime/src/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;
use {
crate::system_instruction_processor,
solana_program_runtime::invoke_context::ProcessInstructionWithContext,
solana_sdk::{feature_set, pubkey::Pubkey, stake, system_program},
solana_sdk::{feature_set, pubkey::Pubkey, stake},
std::fmt,
};

Expand Down Expand Up @@ -118,8 +117,8 @@ fn genesis_builtins() -> Vec<Builtin> {
vec![
Builtin::new(
"system_program",
system_program::id(),
system_instruction_processor::process_instruction,
solana_system_program::id(),
solana_system_program::system_processor::process_instruction,
),
Builtin::new(
"vote_program",
Expand Down
2 changes: 0 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub mod inline_spl_token_2022;
pub mod loader_utils;
pub mod message_processor;
pub mod non_circulating_supply;
mod nonce_keyed_account;
pub mod prioritization_fee;
pub mod prioritization_fee_cache;
mod pubkey_bins;
Expand Down Expand Up @@ -76,7 +75,6 @@ pub mod stakes;
pub mod static_ids;
pub mod status_cache;
mod storable_accounts;
mod system_instruction_processor;
pub mod transaction_batch;
pub mod transaction_error_metrics;
pub mod transaction_priority_details;
Expand Down

0 comments on commit 4aceea0

Please sign in to comment.