Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ solana-cli-output = { path = "cli-output", version = "=2.0.0" }
solana-client = { path = "client", version = "=2.0.0" }
solana-compute-budget-program = { path = "programs/compute-budget", version = "=2.0.0" }
solana-config-program = { path = "programs/config", version = "=2.0.0" }
solana-config-program-api = { path = "programs/config-api", version = "=0.0.1" }
solana-connection-cache = { path = "connection-cache", version = "=2.0.0", default-features = false }
solana-core = { path = "core", version = "=2.0.0" }
solana-cost-model = { path = "cost-model", version = "=2.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy_static = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-config-program = { workspace = true }
solana-config-program-api = { workspace = true }
solana-sdk = { workspace = true }
spl-token = { workspace = true, features = ["no-entrypoint"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
lazy_static! {
static ref ADDRESS_LOOKUP_PROGRAM_ID: Pubkey = address_lookup_table::program::id();
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
static ref CONFIG_PROGRAM_ID: Pubkey = solana_config_program::id();
static ref CONFIG_PROGRAM_ID: Pubkey = solana_sdk::config::program::id();
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
static ref SYSVAR_PROGRAM_ID: Pubkey = sysvar::id();
Expand Down
4 changes: 2 additions & 2 deletions account-decoder/src/parse_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
},
bincode::deserialize,
serde_json::Value,
solana_config_program::{get_config_data, ConfigKeys},
solana_config_program_api::{get_config_data, ConfigKeys},
solana_sdk::{
pubkey::Pubkey,
stake::config::{
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct UiConfig<T> {
mod test {
use {
super::*, crate::validator_info::ValidatorInfo, serde_json::json,
solana_config_program::create_config_account, solana_sdk::account::ReadableAccount,
solana_config_program_api::create_config_account, solana_sdk::account::ReadableAccount,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion account-decoder/src/validator_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use solana_config_program::ConfigState;
use solana_config_program_api::ConfigState;

pub const MAX_SHORT_FIELD_LENGTH: usize = 80;
pub const MAX_LONG_FIELD_LENGTH: usize = 300;
Expand Down
19 changes: 19 additions & 0 deletions programs/config-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "solana-config-program-api"
description = "Solana Config program API"
documentation = "https://docs.rs/solana-config-program-api"
version = "0.0.1"
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
bincode = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
solana-sdk = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
60 changes: 60 additions & 0 deletions programs/config-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#[allow(deprecated)]
use solana_sdk::stake::config::Config as StakeConfig;
use {
bincode::{deserialize, serialize, serialized_size},
serde_derive::{Deserialize, Serialize},
solana_sdk::{
account::{Account, AccountSharedData},
pubkey::Pubkey,
short_vec,
},
};

pub trait ConfigState: serde::Serialize + Default {
/// Maximum space that the serialized representation will require
fn max_space() -> u64;
}

#[allow(deprecated)]
impl ConfigState for StakeConfig {
fn max_space() -> u64 {
serialized_size(&StakeConfig::default()).unwrap()
}
}

/// A collection of keys to be stored in Config account data.
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct ConfigKeys {
// Each key tuple comprises a unique `Pubkey` identifier,
// and `bool` whether that key is a signer of the data
#[serde(with = "short_vec")]
pub keys: Vec<(Pubkey, bool)>,
}

impl ConfigKeys {
pub fn serialized_size(keys: Vec<(Pubkey, bool)>) -> u64 {
serialized_size(&ConfigKeys { keys }).unwrap()
}
}

pub fn get_config_data(bytes: &[u8]) -> Result<&[u8], bincode::Error> {
deserialize::<ConfigKeys>(bytes)
.and_then(|keys| serialized_size(&keys))
.map(|offset| &bytes[offset as usize..])
}

// utility for pre-made Accounts
pub fn create_config_account<T: ConfigState>(
keys: Vec<(Pubkey, bool)>,
config_data: &T,
lamports: u64,
) -> AccountSharedData {
let mut data = serialize(&ConfigKeys { keys }).unwrap();
data.extend_from_slice(&serialize(config_data).unwrap());
AccountSharedData::from(Account {
lamports,
data,
owner: solana_sdk::config::program::id(),
..Account::default()
})
}
1 change: 1 addition & 0 deletions programs/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bincode = { workspace = true }
chrono = { workspace = true, features = ["default", "serde"] }
serde = { workspace = true }
serde_derive = { workspace = true }
solana-config-program-api = { workspace = true }
solana-program-runtime = { workspace = true }
solana-sdk = { workspace = true }

Expand Down
64 changes: 3 additions & 61 deletions programs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,7 @@ pub mod config_instruction;
pub mod config_processor;
pub mod date_instruction;

pub use solana_sdk::config::program::id;
#[allow(deprecated)]
use solana_sdk::stake::config::Config as StakeConfig;
use {
bincode::{deserialize, serialize, serialized_size},
serde_derive::{Deserialize, Serialize},
solana_sdk::{
account::{Account, AccountSharedData},
pubkey::Pubkey,
short_vec,
},
pub use {
solana_config_program_api::{create_config_account, get_config_data, ConfigKeys, ConfigState},
solana_sdk::config::program::id,
};

pub trait ConfigState: serde::Serialize + Default {
/// Maximum space that the serialized representation will require
fn max_space() -> u64;
}

// TODO move ConfigState into `solana_program` to implement trait locally
#[allow(deprecated)]
impl ConfigState for StakeConfig {
fn max_space() -> u64 {
serialized_size(&StakeConfig::default()).unwrap()
}
}

/// A collection of keys to be stored in Config account data.
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct ConfigKeys {
// Each key tuple comprises a unique `Pubkey` identifier,
// and `bool` whether that key is a signer of the data
#[serde(with = "short_vec")]
pub keys: Vec<(Pubkey, bool)>,
}

impl ConfigKeys {
pub fn serialized_size(keys: Vec<(Pubkey, bool)>) -> u64 {
serialized_size(&ConfigKeys { keys }).unwrap()
}
}

pub fn get_config_data(bytes: &[u8]) -> Result<&[u8], bincode::Error> {
deserialize::<ConfigKeys>(bytes)
.and_then(|keys| serialized_size(&keys))
.map(|offset| &bytes[offset as usize..])
}

// utility for pre-made Accounts
pub fn create_config_account<T: ConfigState>(
keys: Vec<(Pubkey, bool)>,
config_data: &T,
lamports: u64,
) -> AccountSharedData {
let mut data = serialize(&ConfigKeys { keys }).unwrap();
data.extend_from_slice(&serialize(config_data).unwrap());
AccountSharedData::from(Account {
lamports,
data,
owner: id(),
..Account::default()
})
}
13 changes: 12 additions & 1 deletion programs/sbf/Cargo.lock

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