Skip to content
Merged
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
18 changes: 17 additions & 1 deletion Cargo.lock

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

14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[workspace]
resolver = "2"
members = ["clients/rust", "program"]
members = [
"clients/rust",
"interface",
"program",
]

[workspace.package]
authors = ["Anza Technology Maintainers <[email protected]>"]
Expand Down Expand Up @@ -28,7 +32,15 @@ mollusk-svm-bencher = "0.1.3"
num-derive = "0.4"
num-traits = "0.2"
serde = "1.0.193"
serde_derive = "1.0.193"
solana-account = "2.2.1"
solana-client = "2.2.1"
solana-config-interface = { path = "interface", version = "1.0.0" }
solana-instruction = "2.2.1"
solana-program = "2.2.1"
solana-pubkey = "2.2.1"
solana-sdk = "2.2.1"
solana-sdk-ids = "2.2.1"
solana-short-vec = "2.2.1"
solana-system-interface = "1.0.0"
thiserror = "1.0.61"
9 changes: 8 additions & 1 deletion clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ edition = { workspace = true }

[features]
fetch = ["dep:solana-client", "dep:solana-sdk"]
serde = ["dep:bincode", "dep:serde", "kaigan/serde"]
serde = [
"dep:bincode",
"dep:serde",
"dep:solana-config-interface",
"kaigan/serde",
"solana-config-interface/bincode"
]
test-sbf = []

[dependencies]
Expand All @@ -19,6 +25,7 @@ borsh = { workspace = true }
kaigan = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
solana-client = { workspace = true, optional = true }
solana-config-interface = { workspace = true, optional = true }
solana-program = { workspace = true, features = ["borsh"] }
solana-sdk = { workspace = true, optional = true }

Expand Down
55 changes: 2 additions & 53 deletions clients/rust/src/instructions_bincode.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
//! Program instruction helpers.

use {
crate::{ConfigKeys, ID},
bincode::serialized_size,
solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
system_instruction,
},
};
pub use solana_config_interface::instruction::{create_account_with_max_config_space, store};
use solana_program::{instruction::Instruction, pubkey::Pubkey};

/// Trait defining config state to be stored at the end of the account data.
#[deprecated(since = "1.0.0", note = "This trait is no longer supported")]
Expand All @@ -17,12 +10,6 @@ pub trait ConfigState: serde::Serialize + Default {
fn max_space() -> u64;
}

fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction {
let account_metas = vec![AccountMeta::new(*config_pubkey, true)];
let account_data = (ConfigKeys { keys: vec![] }, T::default());
Instruction::new_with_bincode(ID, &account_data, account_metas)
}

/// Create a new, empty configuration account
#[deprecated(
since = "1.0.0",
Expand All @@ -43,41 +30,3 @@ pub fn create_account<T: ConfigState>(
keys,
)
}

/// Create a new, empty configuration account
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
lamports: u64,
max_config_space: u64,
keys: Vec<(Pubkey, bool)>,
) -> Vec<Instruction> {
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
vec![
system_instruction::create_account(
from_account_pubkey,
config_account_pubkey,
lamports,
space,
&ID,
),
initialize_account::<T>(config_account_pubkey),
]
}

/// Store new data in a configuration account
pub fn store<T: serde::Serialize>(
config_account_pubkey: &Pubkey,
is_config_signer: bool,
keys: Vec<(Pubkey, bool)>,
data: &T,
) -> Instruction {
let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)];
for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) {
if signer_pubkey != config_account_pubkey {
account_metas.push(AccountMeta::new(*signer_pubkey, true));
}
}
let account_data = (ConfigKeys { keys }, data);
Instruction::new_with_bincode(ID, &account_data, account_metas)
}
2 changes: 1 addition & 1 deletion clients/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod generated;
mod hooked;

#[deprecated(since = "1.0.0", note = "use `solana_config_interface` crate instead")]
#[cfg(feature = "serde")]
pub mod instructions_bincode;

Expand Down
44 changes: 44 additions & 0 deletions interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "solana-config-interface"
description = "Solana config program interface."
documentation = "https://docs.rs/solana-config-interface"
version = "1.0.0"
authors = { workspace = true }
repository = { workspace = true }
license-file = { workspace = true }
edition = { workspace = true }

[dependencies]
bincode = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-account = { workspace = true, optional = true }
solana-instruction = { workspace = true, optional = true, features = [
"bincode",
] }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-short-vec = { workspace = true, optional = true }
solana-system-interface = { workspace = true, optional = true, features = [
"bincode",
] }

[features]
bincode = [
"dep:bincode",
"dep:solana-account",
"dep:solana-instruction",
"dep:solana-system-interface",
"serde",
]
serde = [
"dep:serde",
"dep:serde_derive",
"dep:solana-short-vec",
"solana-pubkey/serde",
]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]
52 changes: 52 additions & 0 deletions interface/src/instruction.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! Program instruction helpers.

use {
crate::{id, state::ConfigKeys},
bincode::serialized_size,
solana_instruction::{AccountMeta, Instruction},
solana_pubkey::Pubkey,
};

fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction {
let account_metas = vec![AccountMeta::new(*config_pubkey, true)];
let account_data = (ConfigKeys { keys: vec![] }, T::default());
Instruction::new_with_bincode(id(), &account_data, account_metas)
}

/// Create a new, empty configuration account
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
lamports: u64,
max_config_space: u64,
keys: Vec<(Pubkey, bool)>,
) -> Vec<Instruction> {
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
vec![
solana_system_interface::instruction::create_account(
from_account_pubkey,
config_account_pubkey,
lamports,
space,
&id(),
),
initialize_account::<T>(config_account_pubkey),
]
}

/// Store new data in a configuration account
pub fn store<T: serde::Serialize>(
config_account_pubkey: &Pubkey,
is_config_signer: bool,
keys: Vec<(Pubkey, bool)>,
data: &T,
) -> Instruction {
let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)];
for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) {
if signer_pubkey != config_account_pubkey {
account_metas.push(AccountMeta::new(*signer_pubkey, true));
}
}
let account_data = (ConfigKeys { keys }, data);
Instruction::new_with_bincode(id(), &account_data, account_metas)
}
6 changes: 6 additions & 0 deletions interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::arithmetic_side_effects)]
#[cfg(feature = "bincode")]
pub mod instruction;
pub mod state;
pub use solana_sdk_ids::config::id;
16 changes: 16 additions & 0 deletions interface/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use solana_pubkey::Pubkey;
#[cfg(feature = "serde")]
use {
serde_derive::{Deserialize, Serialize},
solana_short_vec as short_vec,
};

/// A collection of keys to be stored in Config account data.
#[derive(Debug, Default)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct ConfigKeys {
// Each key tuple comprises a unique `Pubkey` identifier,
// and `bool` whether that key is a signer of the data
#[cfg_attr(feature = "serde", serde(with = "short_vec"))]
pub keys: Vec<(Pubkey, bool)>,
}
3 changes: 2 additions & 1 deletion program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ bincode = { workspace = true }
num-derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true, features = ["derive"] }
solana-config-interface = { workspace = true, features = ["serde"] }
solana-program = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
mollusk-svm = { workspace = true, features = ["fuzz-fd"] }
mollusk-svm-bencher = { workspace = true }
solana-config-program-client = { path = "../clients/rust", features = ["serde"] }
solana-config-interface = { workspace = true, features = ["bincode", "serde"] }
solana-sdk = { workspace = true }

[lib]
Expand Down
5 changes: 2 additions & 3 deletions program/benches/setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use {
mollusk_svm_bencher::Bench,
serde::Serialize,
solana_config_program::state::ConfigKeys,
solana_config_program_client::instructions_bincode::store,
solana_config_interface::{instruction::store, state::ConfigKeys},
solana_sdk::{
account::Account,
hash::Hash,
Expand All @@ -27,7 +26,7 @@ impl BenchContext {
}

/// Trait to avoid re-defining the same instruction and account constructors
/// for each `ConfigState`.
/// for each config state.
pub trait BenchSetup: Default + serde::Serialize {
const BENCH_ID: &'static str;

Expand Down
1 change: 0 additions & 1 deletion program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
mod entrypoint;
pub mod error;
pub mod processor;
pub mod state;

solana_program::declare_id!("Config1111111111111111111111111111111111111");
3 changes: 2 additions & 1 deletion program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Config program processor.

use {
crate::{error::ConfigError, state::ConfigKeys},
crate::error::ConfigError,
solana_config_interface::state::ConfigKeys,
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError,
pubkey::Pubkey,
Expand Down
15 changes: 0 additions & 15 deletions program/src/state.rs

This file was deleted.

7 changes: 5 additions & 2 deletions program/tests/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use {
bincode::serialized_size,
mollusk_svm::{result::Check, Mollusk},
serde::{Deserialize, Serialize},
solana_config_program::{error::ConfigError, state::ConfigKeys},
solana_config_program_client::instructions_bincode::{self as config_instruction},
solana_config_interface::{
instruction::{self as config_instruction},
state::ConfigKeys,
},
solana_config_program::error::ConfigError,
solana_sdk::{
account::Account,
instruction::{AccountMeta, Instruction},
Expand Down