Skip to content

Commit

Permalink
Extract solana-feature crate (#3120)
Browse files Browse the repository at this point in the history
* extract feature crate

* rename to solana-feature-gate-interface

* rename dir

* fmt
  • Loading branch information
kevinheavey authored Dec 5, 2024
1 parent 5d98c6a commit 9b0364f
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 9 deletions.
18 changes: 18 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 @@ -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",
Expand Down Expand Up @@ -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" }
Expand Down
17 changes: 17 additions & 0 deletions programs/sbf/Cargo.lock

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

46 changes: 46 additions & 0 deletions sdk/feature-gate-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@
//! 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<Slot>,
pub activated_at: Option<u64>,
}

impl Feature {
pub const fn size_of() -> usize {
9 // see test_feature_size_of.
}

#[cfg(feature = "bincode")]
pub fn from_account_info(account_info: &AccountInfo) -> Result<Self, ProgramError> {
if *account_info.owner != id() {
return Err(ProgramError::InvalidAccountOwner);
Expand All @@ -39,6 +43,7 @@ impl Feature {
}
}

#[cfg(feature = "bincode")]
/// Activate a feature
pub fn activate(feature_id: &Pubkey, funding_address: &Pubkey, rent: &Rent) -> Vec<Instruction> {
activate_with_lamports(
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 5 additions & 1 deletion sdk/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand Down
17 changes: 17 additions & 0 deletions 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 9b0364f

Please sign in to comment.