diff --git a/Cargo.lock b/Cargo.lock index ee3750e4d546b6..56752bd1c58695 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7011,6 +7011,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-feature-gate-interface" +version = "2.2.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account-info", + "solana-feature-gate-interface", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", +] + [[package]] name = "solana-feature-set" version = "2.2.0" @@ -7892,6 +7909,7 @@ dependencies = [ "solana-define-syscall", "solana-epoch-rewards", "solana-epoch-schedule", + "solana-feature-gate-interface", "solana-fee-calculator", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/Cargo.toml b/Cargo.toml index 4eb6e6bbe29e92..1a93b9a3f9ce43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,6 +122,7 @@ members = [ "sdk/epoch-info", "sdk/epoch-rewards", "sdk/epoch-schedule", + "sdk/feature-gate-interface", "sdk/feature-set", "sdk/fee-calculator", "sdk/fee-structure", @@ -471,6 +472,7 @@ solana-epoch-info = { path = "sdk/epoch-info", version = "=2.2.0" } solana-epoch-rewards = { path = "sdk/epoch-rewards", version = "=2.2.0" } solana-epoch-schedule = { path = "sdk/epoch-schedule", version = "=2.2.0" } solana-faucet = { path = "faucet", version = "=2.2.0" } +solana-feature-gate-interface = { path = "sdk/feature-gate-interface", version = "=2.2.0" } solana-feature-set = { path = "sdk/feature-set", version = "=2.2.0" } solana-fee-calculator = { path = "sdk/fee-calculator", version = "=2.2.0" } solana-fee = { path = "fee", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 655ab1471f4066..89ecaf40432478 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5623,6 +5623,22 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-feature-gate-interface" +version = "2.2.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", +] + [[package]] name = "solana-feature-set" version = "2.2.0" @@ -6202,6 +6218,7 @@ dependencies = [ "solana-define-syscall", "solana-epoch-rewards", "solana-epoch-schedule", + "solana-feature-gate-interface", "solana-fee-calculator", "solana-hash", "solana-instruction", diff --git a/sdk/feature-gate-interface/Cargo.toml b/sdk/feature-gate-interface/Cargo.toml new file mode 100644 index 00000000000000..e2dfe4bbd2a74e --- /dev/null +++ b/sdk/feature-gate-interface/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "solana-feature-gate-interface" +description = "Solana feature gate program interface." +documentation = "https://docs.rs/solana-feature-gate-interface" +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-sdk-ids = { workspace = true } +solana-system-interface = { workspace = true, optional = true, features = [ + "bincode", +] } + +[dev-dependencies] +solana-feature-gate-interface = { 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-interface", + "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-gate-interface/src/lib.rs similarity index 82% rename from sdk/program/src/feature.rs rename to sdk/feature-gate-interface/src/lib.rs index 2f4e8a9c9b73f3..28395a3524bd66 100644 --- a/sdk/program/src/feature.rs +++ b/sdk/feature-gate-interface/src/lib.rs @@ -12,17 +12,20 @@ //! active them. When this occurs, the activation slot is recorded in the feature account pub use solana_sdk_ids::feature::{check_id, id, ID}; +#[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_interface::instruction as system_instruction, }; -#[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 { @@ -30,6 +33,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); @@ -39,6 +43,7 @@ impl Feature { } } +#[cfg(feature = "bincode")] /// Activate a feature pub fn activate(feature_id: &Pubkey, funding_address: &Pubkey, rent: &Rent) -> Vec { activate_with_lamports( @@ -48,6 +53,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, @@ -82,7 +88,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 f13f704c22a022..3cffa149de2066 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -41,6 +41,7 @@ solana-cpi = { workspace = true } solana-decode-error = { workspace = true } solana-epoch-rewards = { workspace = true, features = ["serde", "sysvar"] } solana-epoch-schedule = { workspace = true, features = ["serde", "sysvar"] } +solana-feature-gate-interface = { 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 ee1561f2dfdf65..6ba5230302fd7b 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -481,7 +481,6 @@ pub mod ed25519_program; pub mod entrypoint_deprecated; pub mod epoch_schedule; pub mod epoch_stake; -pub mod feature; pub mod hash; pub mod incinerator; pub mod instruction; @@ -518,6 +517,11 @@ pub use solana_borsh::v0_10 as borsh0_10; pub use solana_borsh::v1 as borsh1; #[deprecated(since = "2.1.0", note = "Use `solana-epoch-rewards` crate instead")] pub use solana_epoch_rewards as epoch_rewards; +#[deprecated( + since = "2.2.0", + note = "Use `solana-feature-gate-interface` crate instead" +)] +pub use solana_feature_gate_interface 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.2.0", note = "Use `solana-keccak-hasher` crate instead")] diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index c61a01f945fe01..bbb01effe3246b 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5464,6 +5464,22 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-feature-gate-interface" +version = "2.2.0" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", +] + [[package]] name = "solana-feature-set" version = "2.2.0" @@ -6022,6 +6038,7 @@ dependencies = [ "solana-define-syscall", "solana-epoch-rewards", "solana-epoch-schedule", + "solana-feature-gate-interface", "solana-fee-calculator", "solana-hash", "solana-instruction",