diff --git a/Cargo.lock b/Cargo.lock index f5c6da940017bf..549e51be42d95c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6708,6 +6708,22 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-feature" +version = "2.1.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account-info", + "solana-feature", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-system-instruction", +] + [[package]] name = "solana-feature-set" version = "2.1.0" @@ -7411,6 +7427,7 @@ dependencies = [ "solana-decode-error", "solana-define-syscall", "solana-epoch-schedule", + "solana-feature", "solana-fee-calculator", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/Cargo.toml b/Cargo.toml index 2088765e1e1866..9ca7f66a3c7284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,6 +113,7 @@ members = [ "sdk/decode-error", "sdk/derivation-path", "sdk/epoch-schedule", + "sdk/feature", "sdk/feature-set", "sdk/fee-calculator", "sdk/gen-headers", @@ -422,6 +423,7 @@ solana-entry = { path = "entry", version = "=2.1.0" } solana-program-entrypoint = { path = "sdk/program-entrypoint", version = "=2.1.0" } solana-epoch-schedule = { path = "sdk/epoch-schedule", version = "=2.1.0" } solana-faucet = { path = "faucet", version = "=2.1.0" } +solana-feature = { path = "sdk/feature", version = "=2.1.0" } solana-feature-set = { path = "sdk/feature-set", version = "=2.1.0" } solana-fee-calculator = { path = "sdk/fee-calculator", version = "=2.1.0" } solana-fee = { path = "fee", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 886d8357706889..a07396545afa2e 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5344,6 +5344,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-feature" +version = "2.1.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-system-instruction", +] + [[package]] name = "solana-feature-set" version = "2.1.0" @@ -5783,6 +5798,7 @@ dependencies = [ "solana-decode-error", "solana-define-syscall", "solana-epoch-schedule", + "solana-feature", "solana-fee-calculator", "solana-hash", "solana-instruction", diff --git a/sdk/feature/Cargo.toml b/sdk/feature/Cargo.toml new file mode 100644 index 00000000000000..6e01bed95cb8c4 --- /dev/null +++ b/sdk/feature/Cargo.toml @@ -0,0 +1,43 @@ +[package] +name = "solana-feature" +description = "Solana runtime features." +documentation = "https://docs.rs/solana-feature" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bincode = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-account-info = { workspace = true, optional = true } +solana-instruction = { workspace = true, optional = true } +solana-program-error = { workspace = true, optional = true } +solana-pubkey = { workspace = true } +solana-rent = { workspace = true, optional = true } +solana-system-instruction = { workspace = true, optional = true } + +[dev-dependencies] +solana-feature = { path = ".", features = ["dev-context-only-utils"] } + +[features] +bincode = [ + "dep:bincode", + "dep:solana-account-info", + "dep:solana-instruction", + "dep:solana-program-error", + "dep:solana-rent", + "dep:solana-system-instruction", + "serde", +] +dev-context-only-utils = ["bincode"] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/program/src/feature.rs b/sdk/feature/src/lib.rs similarity index 81% rename from sdk/program/src/feature.rs rename to sdk/feature/src/lib.rs index af4ab1ad287636..2645570af5c82a 100644 --- a/sdk/program/src/feature.rs +++ b/sdk/feature/src/lib.rs @@ -11,19 +11,22 @@ //! 2. When the next epoch is entered the runtime will check for new activation requests and //! active them. When this occurs, the activation slot is recorded in the feature account +#[cfg(feature = "bincode")] use { - crate::{ - account_info::AccountInfo, instruction::Instruction, program_error::ProgramError, - pubkey::Pubkey, rent::Rent, system_instruction, - }, - solana_clock::Slot, + solana_account_info::AccountInfo, solana_instruction::Instruction, + solana_program_error::ProgramError, solana_pubkey::Pubkey, solana_rent::Rent, + solana_system_instruction as system_instruction, }; -crate::declare_id!("Feature111111111111111111111111111111111111"); +solana_pubkey::declare_id!("Feature111111111111111111111111111111111111"); -#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Default, Debug, PartialEq, Eq)] pub struct Feature { - pub activated_at: Option, + pub activated_at: Option, } impl Feature { @@ -31,6 +34,7 @@ impl Feature { 9 // see test_feature_size_of. } + #[cfg(feature = "bincode")] pub fn from_account_info(account_info: &AccountInfo) -> Result { if *account_info.owner != id() { return Err(ProgramError::InvalidAccountOwner); @@ -40,6 +44,7 @@ impl Feature { } } +#[cfg(feature = "bincode")] /// Activate a feature pub fn activate(feature_id: &Pubkey, funding_address: &Pubkey, rent: &Rent) -> Vec { activate_with_lamports( @@ -49,6 +54,7 @@ pub fn activate(feature_id: &Pubkey, funding_address: &Pubkey, rent: &Rent) -> V ) } +#[cfg(feature = "bincode")] pub fn activate_with_lamports( feature_id: &Pubkey, funding_address: &Pubkey, @@ -83,7 +89,7 @@ mod test { activated_at: Some(0), }, Feature { - activated_at: Some(Slot::MAX), + activated_at: Some(u64::MAX), }, ]; for feature in &features { diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 2548cb874712b5..37e49454bf852c 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -40,6 +40,7 @@ solana-clock = { workspace = true, features = ["serde"] } solana-cpi = { workspace = true } solana-decode-error = { workspace = true } solana-epoch-schedule = { workspace = true, features = ["serde"] } +solana-feature = { workspace = true, features = ["bincode"] } solana-fee-calculator = { workspace = true, features = ["serde"] } solana-frozen-abi = { workspace = true, optional = true, features = ["frozen-abi"] } solana-frozen-abi-macro = { workspace = true, optional = true, features = ["frozen-abi"] } diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 9e56640f5afee1..fbed6568530e1d 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -481,7 +481,6 @@ pub mod entrypoint_deprecated; pub mod epoch_rewards; pub mod epoch_schedule; pub mod epoch_stake; -pub mod feature; pub mod hash; pub mod incinerator; pub mod instruction; @@ -519,6 +518,8 @@ pub use solana_borsh::v0_10 as borsh0_10; #[cfg(feature = "borsh")] #[deprecated(since = "2.1.0", note = "Use `solana-borsh` crate instead")] pub use solana_borsh::v1 as borsh1; +#[deprecated(since = "2.1.0", note = "Use `solana-feature` crate instead")] +pub use solana_feature as feature; #[deprecated(since = "2.1.0", note = "Use `solana-fee-calculator` crate instead")] pub use solana_fee_calculator as fee_calculator; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")]