Skip to content

Commit 82d07a1

Browse files
committed
client: deprecate instructions_bincode
1 parent 20dc653 commit 82d07a1

File tree

14 files changed

+32
-111
lines changed

14 files changed

+32
-111
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ solana-pubkey = "2.2.1"
4242
solana-sdk = "2.2.1"
4343
solana-sdk-ids = "2.2.1"
4444
solana-short-vec = "2.2.1"
45-
solana-stake-interface = "1.2.1"
4645
solana-system-interface = "1.0.0"
4746
thiserror = "1.0.61"

clients/rust/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ edition = { workspace = true }
1010

1111
[features]
1212
fetch = ["dep:solana-client", "dep:solana-sdk"]
13-
serde = ["dep:bincode", "dep:serde", "kaigan/serde"]
13+
serde = [
14+
"dep:bincode",
15+
"dep:serde",
16+
"dep:solana-config-interface",
17+
"kaigan/serde",
18+
"solana-config-interface/bincode"
19+
]
1420
test-sbf = []
1521

1622
[dependencies]
@@ -19,6 +25,7 @@ borsh = { workspace = true }
1925
kaigan = { workspace = true }
2026
serde = { workspace = true, features = ["derive"], optional = true }
2127
solana-client = { workspace = true, optional = true }
28+
solana-config-interface = { workspace = true, optional = true }
2229
solana-program = { workspace = true, features = ["borsh"] }
2330
solana-sdk = { workspace = true, optional = true }
2431

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
//! Program instruction helpers.
22
3-
use {
4-
crate::{ConfigKeys, ID},
5-
bincode::serialized_size,
6-
solana_program::{
7-
instruction::{AccountMeta, Instruction},
8-
pubkey::Pubkey,
9-
system_instruction,
10-
},
11-
};
3+
pub use solana_config_interface::instruction::{create_account_with_max_config_space, store};
4+
use solana_program::{instruction::Instruction, pubkey::Pubkey};
125

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

20-
fn initialize_account<T: Default + serde::Serialize>(config_pubkey: &Pubkey) -> Instruction {
21-
let account_metas = vec![AccountMeta::new(*config_pubkey, true)];
22-
let account_data = (ConfigKeys { keys: vec![] }, T::default());
23-
Instruction::new_with_bincode(ID, &account_data, account_metas)
24-
}
25-
2613
/// Create a new, empty configuration account
2714
#[deprecated(
2815
since = "1.0.0",
@@ -43,41 +30,3 @@ pub fn create_account<T: ConfigState>(
4330
keys,
4431
)
4532
}
46-
47-
/// Create a new, empty configuration account
48-
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
49-
from_account_pubkey: &Pubkey,
50-
config_account_pubkey: &Pubkey,
51-
lamports: u64,
52-
max_config_space: u64,
53-
keys: Vec<(Pubkey, bool)>,
54-
) -> Vec<Instruction> {
55-
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
56-
vec![
57-
system_instruction::create_account(
58-
from_account_pubkey,
59-
config_account_pubkey,
60-
lamports,
61-
space,
62-
&ID,
63-
),
64-
initialize_account::<T>(config_account_pubkey),
65-
]
66-
}
67-
68-
/// Store new data in a configuration account
69-
pub fn store<T: serde::Serialize>(
70-
config_account_pubkey: &Pubkey,
71-
is_config_signer: bool,
72-
keys: Vec<(Pubkey, bool)>,
73-
data: &T,
74-
) -> Instruction {
75-
let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)];
76-
for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) {
77-
if signer_pubkey != config_account_pubkey {
78-
account_metas.push(AccountMeta::new(*signer_pubkey, true));
79-
}
80-
}
81-
let account_data = (ConfigKeys { keys }, data);
82-
Instruction::new_with_bincode(ID, &account_data, account_metas)
83-
}

clients/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod generated;
44
mod hooked;
5-
5+
#[deprecated(since = "1.0.0", note = "use `solana_config_interface` crate instead")]
66
#[cfg(feature = "serde")]
77
pub mod instructions_bincode;
88

interface/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ solana-instruction = { workspace = true, optional = true, features = [
1919
solana-pubkey = { workspace = true }
2020
solana-sdk-ids = { workspace = true }
2121
solana-short-vec = { workspace = true, optional = true }
22-
solana-stake-interface = { workspace = true, optional = true, features = [
23-
"bincode",
24-
] }
2522
solana-system-interface = { workspace = true, optional = true, features = [
2623
"bincode",
2724
] }
@@ -31,7 +28,6 @@ bincode = [
3128
"dep:bincode",
3229
"dep:solana-account",
3330
"dep:solana-instruction",
34-
"dep:solana-stake-interface",
3531
"dep:solana-system-interface",
3632
"serde",
3733
]

interface/src/instruction.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1+
//! Program instruction helpers.
2+
13
use {
2-
crate::{
3-
id,
4-
state::{ConfigKeys, ConfigState},
5-
},
4+
crate::{id, state::ConfigKeys},
5+
bincode::serialized_size,
66
solana_instruction::{AccountMeta, Instruction},
77
solana_pubkey::Pubkey,
8-
solana_system_interface::instruction as system_instruction,
98
};
109

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

1716
/// Create a new, empty configuration account
18-
pub fn create_account<T: ConfigState>(
17+
pub fn create_account_with_max_config_space<T: Default + serde::Serialize>(
1918
from_account_pubkey: &Pubkey,
2019
config_account_pubkey: &Pubkey,
2120
lamports: u64,
21+
max_config_space: u64,
2222
keys: Vec<(Pubkey, bool)>,
2323
) -> Vec<Instruction> {
24-
let space = T::max_space() + bincode::serialized_size(&ConfigKeys { keys }).unwrap();
24+
let space = max_config_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
2525
vec![
26-
system_instruction::create_account(
26+
solana_system_interface::instruction::create_account(
2727
from_account_pubkey,
2828
config_account_pubkey,
2929
lamports,
@@ -35,7 +35,7 @@ pub fn create_account<T: ConfigState>(
3535
}
3636

3737
/// Store new data in a configuration account
38-
pub fn store<T: ConfigState>(
38+
pub fn store<T: serde::Serialize>(
3939
config_account_pubkey: &Pubkey,
4040
is_config_signer: bool,
4141
keys: Vec<(Pubkey, bool)>,

interface/src/state.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
use solana_pubkey::Pubkey;
2-
#[cfg(feature = "bincode")]
3-
#[allow(deprecated)]
4-
use {
5-
bincode::{deserialize, serialized_size},
6-
solana_stake_interface::config::Config as StakeConfig,
7-
};
82
#[cfg(feature = "serde")]
93
use {
104
serde_derive::{Deserialize, Serialize},
115
solana_short_vec as short_vec,
126
};
137

14-
#[cfg(feature = "serde")]
15-
pub trait ConfigState: serde::Serialize + Default {
16-
/// Maximum space that the serialized representation will require
17-
fn max_space() -> u64;
18-
}
19-
20-
// TODO move ConfigState into `solana_program` to implement trait locally
21-
#[cfg(feature = "bincode")]
22-
#[allow(deprecated)]
23-
impl ConfigState for StakeConfig {
24-
fn max_space() -> u64 {
25-
serialized_size(&StakeConfig::default()).unwrap()
26-
}
27-
}
28-
298
/// A collection of keys to be stored in Config account data.
309
#[derive(Debug, Default)]
3110
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
@@ -35,10 +14,3 @@ pub struct ConfigKeys {
3514
#[cfg_attr(feature = "serde", serde(with = "short_vec"))]
3615
pub keys: Vec<(Pubkey, bool)>,
3716
}
38-
39-
#[cfg(feature = "bincode")]
40-
pub fn get_config_data(bytes: &[u8]) -> Result<&[u8], bincode::Error> {
41-
deserialize::<ConfigKeys>(bytes)
42-
.and_then(|keys| serialized_size(&keys))
43-
.map(|offset| &bytes[offset as usize..])
44-
}

program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ thiserror = { workspace = true }
2727
[dev-dependencies]
2828
mollusk-svm = { workspace = true, features = ["fuzz-fd"] }
2929
mollusk-svm-bencher = { workspace = true }
30-
solana-config-program-client = { path = "../clients/rust", features = ["serde"] }
30+
solana-config-interface = { workspace = true, features = ["bincode", "serde"] }
3131
solana-sdk = { workspace = true }
3232

3333
[lib]

program/benches/setup.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use {
22
mollusk_svm_bencher::Bench,
33
serde::Serialize,
4-
solana_config_program::state::ConfigKeys,
5-
solana_config_program_client::instructions_bincode::store,
4+
solana_config_interface::{instruction::store, state::ConfigKeys},
65
solana_sdk::{
76
account::Account,
87
hash::Hash,
@@ -27,7 +26,7 @@ impl BenchContext {
2726
}
2827

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

0 commit comments

Comments
 (0)