Skip to content

Commit

Permalink
extract feature crate
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Oct 28, 2024
1 parent 6f10763 commit 774c4c6
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 10 deletions.
17 changes: 17 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 @@ -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",
Expand Down Expand Up @@ -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" }
Expand Down
16 changes: 16 additions & 0 deletions programs/sbf/Cargo.lock

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

43 changes: 43 additions & 0 deletions sdk/feature/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 15 additions & 9 deletions sdk/program/src/feature.rs → sdk/feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@
//! 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<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 @@ -40,6 +44,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 @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 2 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 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;
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 774c4c6

Please sign in to comment.