diff --git a/Cargo.lock b/Cargo.lock index 23c429edd446de..c3646244e73fb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7250,6 +7250,37 @@ dependencies = [ "tempfile", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-genesis-utils" version = "2.2.0" @@ -8382,6 +8413,25 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "solana-rent-collector" +version = "2.2.0" +dependencies = [ + "assert_matches", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-epoch-schedule", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-genesis-config", + "solana-logger", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", +] + [[package]] name = "solana-rent-debits" version = "2.2.0" @@ -8802,6 +8852,7 @@ dependencies = [ "solana-fee-structure", "solana-frozen-abi", "solana-frozen-abi-macro", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", @@ -8820,6 +8871,7 @@ dependencies = [ "solana-program-memory", "solana-pubkey", "solana-quic-definitions", + "solana-rent-collector", "solana-rent-debits", "solana-reserved-account-keys", "solana-reward-info", diff --git a/Cargo.toml b/Cargo.toml index ac186c11930cf3..8acf5885f3277e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,6 +135,7 @@ members = [ "sdk/frozen-abi", "sdk/frozen-abi/macro", "sdk/gen-headers", + "sdk/genesis-config", "sdk/hard-forks", "sdk/hash", "sdk/inflation", @@ -166,6 +167,7 @@ members = [ "sdk/pubkey", "sdk/quic-definitions", "sdk/rent", + "sdk/rent-collector", "sdk/rent-debits", "sdk/reserved-account-keys", "sdk/reward-info", @@ -496,6 +498,7 @@ solana-frozen-abi-macro = { path = "sdk/frozen-abi/macro", version = "=2.2.0" } solana-tps-client = { path = "tps-client", version = "=2.2.0" } solana-file-download = { path = "sdk/file-download", version = "=2.2.0" } solana-genesis = { path = "genesis", version = "=2.2.0" } +solana-genesis-config = { path = "sdk/genesis-config", version = "=2.2.0" } solana-genesis-utils = { path = "genesis-utils", version = "=2.2.0" } agave-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=2.2.0" } solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.2.0" } @@ -551,6 +554,7 @@ solana-quic-definitions = { path = "sdk/quic-definitions", version = "=2.2.0" } solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.2.0" } solana-remote-wallet = { path = "remote-wallet", version = "=2.2.0", default-features = false } solana-rent = { path = "sdk/rent", version = "=2.2.0", default-features = false } +solana-rent-collector = { path = "sdk/rent-collector", version = "=2.2.0" } solana-rent-debits = { path = "sdk/rent-debits", version = "=2.2.0" } solana-reserved-account-keys = { path = "sdk/reserved-account-keys", version = "=2.2.0", default-features = false } solana-reward-info = { path = "sdk/reward-info", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index b5ae6a5cfd16b9..d2295ed5ae566c 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5757,6 +5757,35 @@ dependencies = [ "reqwest", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-genesis-utils" version = "2.2.0" @@ -6609,6 +6638,21 @@ dependencies = [ "solana-sysvar-id", ] +[[package]] +name = "solana-rent-collector" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-epoch-schedule", + "solana-genesis-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", +] + [[package]] name = "solana-rent-debits" version = "2.2.0" @@ -7437,6 +7481,7 @@ dependencies = [ "solana-epoch-rewards-hasher", "solana-feature-set", "solana-fee-structure", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", @@ -7453,6 +7498,7 @@ dependencies = [ "solana-program-memory", "solana-pubkey", "solana-quic-definitions", + "solana-rent-collector", "solana-rent-debits", "solana-reserved-account-keys", "solana-reward-info", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 84d662e1422fde..3a11ee006eb49b 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -39,6 +39,7 @@ full = [ "dep:solana-cluster-type", "dep:solana-ed25519-program", "dep:solana-compute-budget-interface", + "dep:solana-genesis-config", "dep:solana-hard-forks", "dep:solana-keypair", "dep:solana-offchain-message", @@ -46,6 +47,7 @@ full = [ "dep:solana-precompiles", "dep:solana-presigner", "dep:solana-quic-definitions", + "dep:solana-rent-collector", "dep:solana-secp256k1-program", "dep:solana-seed-derivable", "dep:solana-seed-phrase", @@ -76,11 +78,13 @@ frozen-abi = [ "solana-fee-structure/frozen-abi", "solana-account/frozen-abi", "solana-cluster-type/frozen-abi", + "solana-genesis-config/frozen-abi", "solana-hard-forks/frozen-abi", "solana-inflation/frozen-abi", "solana-poh-config/frozen-abi", "solana-program/frozen-abi", "solana-reward-info/frozen-abi", + "solana-rent-collector/frozen-abi", "solana-short-vec/frozen-abi", "solana-signature/frozen-abi", "solana-transaction/frozen-abi", @@ -143,6 +147,9 @@ solana-frozen-abi = { workspace = true, optional = true, features = [ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ "frozen-abi", ] } +solana-genesis-config = { workspace = true, features = [ + "serde", +], optional = true } solana-hard-forks = { workspace = true, features = [ "serde", ], optional = true } @@ -165,6 +172,9 @@ solana-pubkey = { workspace = true, default-features = false, features = [ "std", ] } solana-quic-definitions = { workspace = true, optional = true } +solana-rent-collector = { workspace = true, features = [ + "serde", +], optional = true } solana-rent-debits = { workspace = true } solana-reserved-account-keys = { workspace = true } solana-reward-info = { workspace = true, features = ["serde"] } diff --git a/sdk/genesis-config/Cargo.toml b/sdk/genesis-config/Cargo.toml new file mode 100644 index 00000000000000..dd3aef928cc7b7 --- /dev/null +++ b/sdk/genesis-config/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "solana-genesis-config" +description = "The chain's genesis config." +documentation = "https://docs.rs/solana-genesis-config" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bincode = { workspace = true } +chrono = { workspace = true } +memmap2 = { workspace = true } +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account = { workspace = true } +solana-clock = { workspace = true } +solana-cluster-type = { workspace = true } +solana-epoch-schedule = { workspace = true } +solana-fee-calculator = { workspace = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } +solana-hash = { workspace = true } +solana-inflation = { workspace = true } +solana-keypair = { workspace = true } +solana-logger = { workspace = true } +solana-native-token = { workspace = true } +solana-poh-config = { workspace = true } +solana-pubkey = { workspace = true } +solana-rent = { workspace = true } +solana-sdk-ids = { workspace = true } +solana-sha256-hasher = { workspace = true } +solana-shred-version = { workspace = true } +solana-signer = { workspace = true } +solana-time-utils = { workspace = true } + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/src/genesis_config.rs b/sdk/genesis-config/src/lib.rs similarity index 91% rename from sdk/src/genesis_config.rs rename to sdk/genesis-config/src/lib.rs index af86e8e3005659..ad87b154d96c1b 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/genesis-config/src/lib.rs @@ -1,32 +1,34 @@ //! The chain's genesis config. -#![cfg(feature = "full")] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #[deprecated( since = "2.2.0", note = "Use `solana_cluster_type::ClusterType` instead." )] pub use solana_cluster_type::ClusterType; +#[cfg(feature = "frozen-abi")] +use solana_frozen_abi_macro::{frozen_abi, AbiExample}; use { - crate::{ - clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, - epoch_schedule::EpochSchedule, - fee_calculator::FeeRateGovernor, - hash::{hash, Hash}, - inflation::Inflation, - poh_config::PohConfig, - pubkey::Pubkey, - rent::Rent, - shred_version::compute_shred_version, - signature::{Keypair, Signer}, - system_program, - timing::years_as_slots, - }, bincode::{deserialize, serialize}, chrono::{TimeZone, Utc}, memmap2::Mmap, solana_account::{Account, AccountSharedData}, + solana_clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT}, + solana_epoch_schedule::EpochSchedule, + solana_fee_calculator::FeeRateGovernor, + solana_hash::Hash, + solana_inflation::Inflation, + solana_keypair::Keypair, solana_native_token::lamports_to_sol, + solana_poh_config::PohConfig, + solana_pubkey::Pubkey, + solana_rent::Rent, + solana_sdk_ids::system_program, + solana_sha256_hasher::hash, + solana_shred_version::compute_shred_version, + solana_signer::Signer, + solana_time_utils::years_as_slots, std::{ collections::BTreeMap, fmt, @@ -49,7 +51,11 @@ pub const UNUSED_DEFAULT: u64 = 1024; derive(AbiExample), frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm") )] -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Clone, Debug, PartialEq)] pub struct GenesisConfig { /// when the network (bootstrap validator) was started relative to the UNIX Epoch pub creation_time: UnixTimestamp, @@ -275,11 +281,7 @@ impl fmt::Display for GenesisConfig { #[cfg(test)] mod tests { - use { - super::*, - crate::signature::{Keypair, Signer}, - std::path::PathBuf, - }; + use {super::*, solana_signer::Signer, std::path::PathBuf}; fn make_tmp_path(name: &str) -> PathBuf { let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()); @@ -310,10 +312,10 @@ mod tests { AccountSharedData::new(10_000, 0, &Pubkey::default()), ); config.add_account( - solana_sdk::pubkey::new_rand(), + solana_pubkey::new_rand(), AccountSharedData::new(1, 0, &Pubkey::default()), ); - config.add_native_instruction_processor("hi".to_string(), solana_sdk::pubkey::new_rand()); + config.add_native_instruction_processor("hi".to_string(), solana_pubkey::new_rand()); assert_eq!(config.accounts.len(), 2); assert!(config diff --git a/sdk/rent-collector/Cargo.toml b/sdk/rent-collector/Cargo.toml new file mode 100644 index 00000000000000..ae2f48f1499be0 --- /dev/null +++ b/sdk/rent-collector/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "solana-rent-collector" +description = "Calculate and collect rent from accounts." +documentation = "https://docs.rs/solana-rent-collector" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account = { workspace = true } +solana-clock = { workspace = true } +solana-epoch-schedule = { workspace = true } +solana-frozen-abi = { workspace = true, optional = true } +solana-frozen-abi-macro = { workspace = true, optional = true } +solana-genesis-config = { workspace = true } +solana-pubkey = { workspace = true } +solana-rent = { workspace = true } +solana-sdk-ids = { workspace = true } + +[dev-dependencies] +assert_matches = { workspace = true } +solana-logger = { workspace = true } + +[features] +frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/src/rent_collector.rs b/sdk/rent-collector/src/lib.rs similarity index 95% rename from sdk/src/rent_collector.rs rename to sdk/rent-collector/src/lib.rs index 4be46786a1de12..2aabdead2151b2 100644 --- a/sdk/src/rent_collector.rs +++ b/sdk/rent-collector/src/lib.rs @@ -1,20 +1,22 @@ -#![cfg(feature = "full")] - //! calculate and collect rent from Accounts +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] + use { solana_account::{AccountSharedData, ReadableAccount, WritableAccount}, - solana_sdk::{ - clock::Epoch, - epoch_schedule::EpochSchedule, - genesis_config::GenesisConfig, - incinerator, - pubkey::Pubkey, - rent::{Rent, RentDue}, - }, + solana_clock::Epoch, + solana_epoch_schedule::EpochSchedule, + solana_genesis_config::GenesisConfig, + solana_pubkey::Pubkey, + solana_rent::{Rent, RentDue}, + solana_sdk_ids::incinerator, }; -#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Clone, Debug, PartialEq)] pub struct RentCollector { pub epoch: Epoch, pub epoch_schedule: EpochSchedule, @@ -215,7 +217,9 @@ impl std::ops::AddAssign for CollectedInfo { #[cfg(test)] mod tests { - use {super::*, assert_matches::assert_matches, solana_account::Account, solana_sdk::sysvar}; + use { + super::*, assert_matches::assert_matches, solana_account::Account, solana_sdk_ids::sysvar, + }; fn default_rent_collector_clone_with_epoch(epoch: Epoch) -> RentCollector { RentCollector::default().clone_with_epoch(epoch) @@ -374,7 +378,7 @@ mod tests { // collect rent on a newly-created account let collected = rent_collector - .collect_from_created_account(&solana_sdk::pubkey::new_rand(), &mut created_account); + .collect_from_created_account(&solana_pubkey::new_rand(), &mut created_account); assert!(created_account.lamports() < old_lamports); assert_eq!( created_account.lamports() + collected.rent_amount, @@ -385,7 +389,7 @@ mod tests { // collect rent on a already-existing account let collected = rent_collector - .collect_from_existing_account(&solana_sdk::pubkey::new_rand(), &mut existing_account); + .collect_from_existing_account(&solana_pubkey::new_rand(), &mut existing_account); assert!(existing_account.lamports() < old_lamports); assert_eq!( existing_account.lamports() + collected.rent_amount, @@ -406,7 +410,7 @@ mod tests { let epoch = 3; let huge_lamports = 123_456_789_012; let tiny_lamports = 789_012; - let pubkey = solana_sdk::pubkey::new_rand(); + let pubkey = solana_pubkey::new_rand(); assert_eq!(account.rent_epoch(), 0); @@ -441,7 +445,7 @@ mod tests { account.set_owner(sysvar::id()); account.set_lamports(tiny_lamports); - let pubkey = solana_sdk::pubkey::new_rand(); + let pubkey = solana_pubkey::new_rand(); assert_eq!(account.rent_epoch(), 0); diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index f9d1e89ce4f305..fa0afc9f7bd322 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -66,9 +66,11 @@ pub mod entrypoint; pub mod entrypoint_deprecated; pub mod example_mocks; pub mod feature; -pub mod genesis_config; #[cfg(feature = "full")] -#[deprecated(since = "2.2.0", note = "Use `solana-hard-forks` crate instead")] +#[deprecated(since = "2.2.0", note = "Use `solana_genesis_config` crate instead")] +pub use solana_genesis_config as genesis_config; +#[cfg(feature = "full")] +#[deprecated(since = "2.2.0", note = "Use `solana_hard_forks` crate instead")] pub use solana_hard_forks as hard_forks; pub mod hash; pub mod inner_instruction; @@ -78,7 +80,9 @@ pub mod net; pub mod precompiles; pub mod program_utils; pub mod pubkey; -pub mod rent_collector; +#[cfg(feature = "full")] +#[deprecated(since = "2.2.0", note = "Use `solana-rent-collector` crate instead")] +pub use solana_rent_collector as rent_collector; #[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")] pub mod reward_info { pub use solana_reward_info::RewardInfo; @@ -246,10 +250,8 @@ macro_rules! saturating_add_assign { pub extern crate bs58; extern crate log as logger; -#[cfg_attr(not(target_os = "solana"), macro_use)] extern crate serde_derive; -#[cfg_attr(feature = "frozen-abi", macro_use)] #[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/sdk/src/program_utils.rs b/sdk/src/program_utils.rs index 57ae1017f9b97b..f4444ea9552a89 100644 --- a/sdk/src/program_utils.rs +++ b/sdk/src/program_utils.rs @@ -22,7 +22,7 @@ pub mod tests { #[test] fn test_limited_deserialize() { - #[derive(Deserialize, Serialize)] + #[derive(serde_derive::Deserialize, serde_derive::Serialize)] enum Foo { Bar(Vec), } diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 10e72b4ec732ff..a2615371b5c9d3 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5588,6 +5588,35 @@ dependencies = [ "solana-native-token", ] +[[package]] +name = "solana-genesis-config" +version = "2.2.0" +dependencies = [ + "bincode", + "chrono", + "memmap2", + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-cluster-type", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-inflation", + "solana-keypair", + "solana-logger", + "solana-native-token", + "solana-poh-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sha256-hasher", + "solana-shred-version", + "solana-signer", + "solana-time-utils", +] + [[package]] name = "solana-geyser-plugin-manager" version = "2.2.0" @@ -6429,6 +6458,21 @@ dependencies = [ "solana-sysvar-id", ] +[[package]] +name = "solana-rent-collector" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-account", + "solana-clock", + "solana-epoch-schedule", + "solana-genesis-config", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", +] + [[package]] name = "solana-rent-debits" version = "2.2.0" @@ -6756,6 +6800,7 @@ dependencies = [ "solana-epoch-rewards-hasher", "solana-feature-set", "solana-fee-structure", + "solana-genesis-config", "solana-hard-forks", "solana-inflation", "solana-instruction", @@ -6772,6 +6817,7 @@ dependencies = [ "solana-program-memory", "solana-pubkey", "solana-quic-definitions", + "solana-rent-collector", "solana-rent-debits", "solana-reserved-account-keys", "solana-reward-info",