Skip to content

Commit adace9c

Browse files
committed
client-rust: deprecate ConfigState
1 parent fc5fa7d commit adace9c

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

clients/rust/src/instructions_bincode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ use {
1111
};
1212

1313
/// Trait defining config state to be stored at the end of the account data.
14+
#[deprecated(since = "1.0.0", note = "This trait is no longer supported")]
1415
pub trait ConfigState: serde::Serialize + Default {
1516
/// Maximum space that the serialized representation will require
1617
fn max_space() -> u64;
1718
}
1819

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

2526
/// Create a new, empty configuration account
26-
pub fn create_account<T: ConfigState>(
27+
pub fn create_account<T: Default + serde::Serialize>(
2728
from_account_pubkey: &Pubkey,
2829
config_account_pubkey: &Pubkey,
2930
lamports: u64,
31+
max_space: u64,
3032
keys: Vec<(Pubkey, bool)>,
3133
) -> Vec<Instruction> {
32-
let space = T::max_space().saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
34+
let space = max_space.saturating_add(serialized_size(&ConfigKeys { keys }).unwrap());
3335
vec![
3436
system_instruction::create_account(
3537
from_account_pubkey,
@@ -43,7 +45,7 @@ pub fn create_account<T: ConfigState>(
4345
}
4446

4547
/// Store new data in a configuration account
46-
pub fn store<T: ConfigState>(
48+
pub fn store<T: serde::Serialize>(
4749
config_account_pubkey: &Pubkey,
4850
is_config_signer: bool,
4951
keys: Vec<(Pubkey, bool)>,

program/benches/setup.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
mollusk_svm_bencher::Bench,
33
serde::Serialize,
44
solana_config_program::state::ConfigKeys,
5-
solana_config_program_client::instructions_bincode::{store, ConfigState},
5+
solana_config_program_client::instructions_bincode::store,
66
solana_sdk::{
77
account::Account,
88
hash::Hash,
@@ -28,17 +28,17 @@ impl BenchContext {
2828

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

3434
fn default_account_state(keys: Vec<(Pubkey, bool)>) -> (ConfigKeys, Self) {
3535
(ConfigKeys { keys }, Self::default())
3636
}
3737

3838
fn default_space(keys: Vec<(Pubkey, bool)>) -> usize {
39-
(Self::max_space()
40-
.checked_add(bincode::serialized_size(&ConfigKeys { keys }).unwrap())
41-
.unwrap()) as usize
39+
let config_keys_space = bincode::serialized_size(&ConfigKeys { keys }).unwrap();
40+
let config_state_space = bincode::serialized_size(&Self::default()).unwrap();
41+
(config_keys_space.checked_add(config_state_space).unwrap()) as usize
4242
}
4343

4444
fn keys(keys_len: usize) -> Vec<(Pubkey, bool)> {
@@ -103,12 +103,6 @@ pub struct ConfigSmall {
103103
pub item: u64,
104104
}
105105

106-
impl ConfigState for ConfigSmall {
107-
fn max_space() -> u64 {
108-
bincode::serialized_size(&Self::default()).unwrap()
109-
}
110-
}
111-
112106
impl BenchSetup for ConfigSmall {
113107
const BENCH_ID: &'static str = "config_small";
114108
}
@@ -119,12 +113,6 @@ pub struct ConfigMedium {
119113
pub hashes: [Hash; 32], // 32 x 32 = 1024 bytes
120114
}
121115

122-
impl ConfigState for ConfigMedium {
123-
fn max_space() -> u64 {
124-
bincode::serialized_size(&Self::default()).unwrap()
125-
}
126-
}
127-
128116
impl BenchSetup for ConfigMedium {
129117
const BENCH_ID: &'static str = "config_medium";
130118
}
@@ -135,12 +123,6 @@ pub struct ConfigLarge {
135123
pub hashes: [[Hash; 32]; 32], // 32 x 32 x 32 = 32_768 bytes
136124
}
137125

138-
impl ConfigState for ConfigLarge {
139-
fn max_space() -> u64 {
140-
bincode::serialized_size(&Self::default()).unwrap()
141-
}
142-
}
143-
144126
impl BenchSetup for ConfigLarge {
145127
const BENCH_ID: &'static str = "config_large";
146128
}

program/tests/functional.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
mollusk_svm::{result::Check, Mollusk},
77
serde::{Deserialize, Serialize},
88
solana_config_program::{error::ConfigError, state::ConfigKeys},
9-
solana_config_program_client::instructions_bincode::{self as config_instruction, ConfigState},
9+
solana_config_program_client::instructions_bincode::{self as config_instruction},
1010
solana_sdk::{
1111
account::Account,
1212
instruction::{AccountMeta, Instruction},
@@ -30,12 +30,6 @@ impl MyConfig {
3030
}
3131
}
3232

33-
impl ConfigState for MyConfig {
34-
fn max_space() -> u64 {
35-
serialized_size(&Self::default()).unwrap()
36-
}
37-
}
38-
3933
fn setup() -> Mollusk {
4034
Mollusk::new(&solana_config_program::id(), "solana_config_program")
4135
}
@@ -549,9 +543,15 @@ fn test_config_initialize_no_panic() {
549543
let mollusk = setup();
550544

551545
let config = Pubkey::new_unique();
546+
let max_space = serialized_size(&MyConfig::default()).unwrap();
552547

553-
let instructions =
554-
config_instruction::create_account::<MyConfig>(&Pubkey::new_unique(), &config, 1, vec![]);
548+
let instructions = config_instruction::create_account::<MyConfig>(
549+
&Pubkey::new_unique(),
550+
&config,
551+
1,
552+
max_space,
553+
vec![],
554+
);
555555
let mut instruction = instructions[1].clone();
556556
instruction.accounts = vec![];
557557

0 commit comments

Comments
 (0)