Skip to content

Commit fcd8b92

Browse files
authored
deps: Bump sdk v3 crates (#79)
* sysvar: Move stake-history implementation from sdk * error: Fixup post-upgrade * Remove borsh 0.10 support * Use solana-sdk-ids instead * Bump the crates * Add anyhow and example-mocks for doctests
1 parent 76fc336 commit fcd8b92

File tree

12 files changed

+1475
-1050
lines changed

12 files changed

+1475
-1050
lines changed

Cargo.lock

Lines changed: 1157 additions & 621 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ build = "1.86.0"
2828
format = "nightly-2025-02-16"
2929
lint = "nightly-2025-02-16"
3030
test = "nightly-2025-02-16"
31-
32-
[patch.crates-io]
33-
solana-stake-interface = { path = "interface" }

interface/Cargo.toml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = { workspace = true }
88
homepage = { workspace = true }
99
license = { workspace = true }
1010
edition = { workspace = true }
11+
rust-version = "1.81.0"
1112

1213
[lib]
1314
crate-type = ["rlib"]
@@ -17,27 +18,30 @@ program-id = "Stake11111111111111111111111111111111111111"
1718

1819
[dependencies]
1920
borsh = { version = "1.5.1", features = ["derive", "unstable__schema"], optional = true }
20-
borsh0-10 = { package = "borsh", version = "0.10.3", optional = true }
2121
num-traits = "0.2"
2222
serde = { version = "1.0.210", optional = true }
2323
serde_derive = { version = "1.0.210", optional = true }
24-
solana-decode-error = "2.2.1"
25-
solana-clock = "2.2.1"
26-
solana-cpi = { version = "2.2.1", optional = true }
27-
solana-frozen-abi = { version = "2.2.1", features = ["frozen-abi"], optional = true }
28-
solana-frozen-abi-macro = { version = "2.2.1", features = ["frozen-abi"], optional = true }
29-
solana-instruction = "2.2.1"
30-
solana-program-error = "2.2.1"
31-
solana-pubkey = { version = "2.2.1", default-features = false }
32-
solana-system-interface = "1.0.0"
33-
solana-sysvar-id = "2.2.1"
24+
solana-clock = "3.0.0"
25+
solana-cpi = { version = "3.0.0", optional = true }
26+
solana-frozen-abi = { version = "3.0.0", features = ["frozen-abi"], optional = true }
27+
solana-frozen-abi-macro = { version = "3.0.0", features = ["frozen-abi"], optional = true }
28+
solana-instruction = "3.0.0"
29+
solana-program-error = "3.0.0"
30+
solana-pubkey = { version = "3.0.0", default-features = false }
31+
solana-system-interface = "2.0.0"
32+
solana-sysvar = { version = "3.0.0", optional = true }
33+
solana-sysvar-id = { version = "3.0.0", optional = true }
3434

3535
[dev-dependencies]
36+
anyhow = "1"
3637
assert_matches = "1.5.0"
3738
bincode = "1.3.3"
38-
solana-account = {version = "2.2.1", features = ["bincode"] }
39-
solana-borsh = "2.2.1"
40-
solana-program = { version = "2.2.1", default-features = false }
39+
serial_test = "2.0.0"
40+
solana-account = {version = "3.0.0", features = ["bincode"] }
41+
solana-borsh = "3.0.0"
42+
solana-example-mocks = "3.0.0"
43+
solana-sdk-ids = "3.0.0"
44+
solana-stake-interface = { path = ".", features = ["bincode", "borsh", "sysvar"] }
4145
static_assertions = "1.1.0"
4246
strum = "0.24"
4347
strum_macros = "0.24"
@@ -54,11 +58,11 @@ bincode = [
5458
"solana-instruction/bincode",
5559
"solana-instruction/serde",
5660
"solana-system-interface/bincode",
61+
"solana-sysvar/bincode",
5762
"serde"
5863
]
5964
borsh = [
6065
"dep:borsh",
61-
"dep:borsh0-10",
6266
"solana-instruction/borsh",
6367
"solana-program-error/borsh",
6468
"solana-pubkey/borsh"
@@ -67,6 +71,8 @@ frozen-abi = [
6771
"dep:solana-frozen-abi",
6872
"dep:solana-frozen-abi-macro",
6973
"solana-instruction/frozen-abi",
70-
"solana-pubkey/frozen-abi"
74+
"solana-pubkey/frozen-abi",
75+
"solana-sysvar/frozen-abi",
7176
]
72-
serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"]
77+
serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde", "solana-sysvar/serde"]
78+
sysvar = ["dep:solana-sysvar", "dep:solana-sysvar-id"]

interface/src/error.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use {
22
num_traits::{FromPrimitive, ToPrimitive},
3-
solana_decode_error::DecodeError,
43
solana_program_error::ProgramError,
54
};
65

@@ -157,7 +156,7 @@ impl ToPrimitive for StakeError {
157156
}
158157
}
159158

160-
impl std::error::Error for StakeError {}
159+
impl core::error::Error for StakeError {}
161160

162161
impl core::fmt::Display for StakeError {
163162
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
@@ -204,18 +203,9 @@ impl core::fmt::Display for StakeError {
204203
}
205204
}
206205

207-
impl<E> DecodeError<E> for StakeError {
208-
fn type_of() -> &'static str {
209-
"StakeError"
210-
}
211-
}
212-
213206
#[cfg(test)]
214207
mod tests {
215-
use {
216-
super::StakeError, num_traits::FromPrimitive, solana_decode_error::DecodeError,
217-
solana_instruction::error::InstructionError, strum::IntoEnumIterator,
218-
};
208+
use {super::StakeError, num_traits::FromPrimitive, strum::IntoEnumIterator};
219209

220210
#[test]
221211
fn test_stake_error_from_primitive_exhaustive() {
@@ -227,30 +217,4 @@ mod tests {
227217
);
228218
}
229219
}
230-
231-
#[test]
232-
fn test_custom_error_decode() {
233-
use num_traits::FromPrimitive;
234-
fn pretty_err<T>(err: InstructionError) -> String
235-
where
236-
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
237-
{
238-
if let InstructionError::Custom(code) = err {
239-
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
240-
format!(
241-
"{:?}: {}::{:?} - {}",
242-
err,
243-
T::type_of(),
244-
specific_error,
245-
specific_error,
246-
)
247-
} else {
248-
"".to_string()
249-
}
250-
}
251-
assert_eq!(
252-
"Custom(0): StakeError::NoCreditsToRedeem - not enough credits to redeem",
253-
pretty_err::<StakeError>(StakeError::NoCreditsToRedeem.into())
254-
)
255-
}
256220
}

interface/src/instruction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,12 @@ mod tests {
909909
#[test]
910910
fn test_constants() {
911911
// Ensure that the constants are in sync with the solana program.
912-
assert_eq!(CLOCK_ID, solana_program::sysvar::clock::ID);
912+
assert_eq!(CLOCK_ID, solana_sdk_ids::sysvar::clock::ID);
913913

914914
// Ensure that the constants are in sync with the solana program.
915-
assert_eq!(STAKE_HISTORY_ID, solana_program::sysvar::stake_history::ID);
915+
assert_eq!(STAKE_HISTORY_ID, solana_sdk_ids::sysvar::stake_history::ID);
916916

917917
// Ensure that the constants are in sync with the solana rent.
918-
assert_eq!(RENT_ID, solana_program::sysvar::rent::ID);
918+
assert_eq!(RENT_ID, solana_sdk_ids::sysvar::rent::ID);
919919
}
920920
}

interface/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub mod instruction;
1010
pub mod stake_flags;
1111
pub mod stake_history;
1212
pub mod state;
13+
#[cfg(feature = "sysvar")]
14+
pub mod sysvar;
1315
pub mod tools;
1416

1517
pub mod program {

interface/src/stake_flags.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,6 @@ pub struct StakeFlags {
1717
bits: u8,
1818
}
1919

20-
#[cfg(feature = "borsh")]
21-
impl borsh0_10::de::BorshDeserialize for StakeFlags {
22-
fn deserialize_reader<R: borsh0_10::maybestd::io::Read>(
23-
reader: &mut R,
24-
) -> ::core::result::Result<Self, borsh0_10::maybestd::io::Error> {
25-
Ok(Self {
26-
bits: borsh0_10::BorshDeserialize::deserialize_reader(reader)?,
27-
})
28-
}
29-
}
30-
31-
#[cfg(feature = "borsh")]
32-
impl borsh0_10::BorshSchema for StakeFlags {
33-
fn declaration() -> borsh0_10::schema::Declaration {
34-
"StakeFlags".to_string()
35-
}
36-
fn add_definitions_recursively(
37-
definitions: &mut borsh0_10::maybestd::collections::HashMap<
38-
borsh0_10::schema::Declaration,
39-
borsh0_10::schema::Definition,
40-
>,
41-
) {
42-
let fields = borsh0_10::schema::Fields::NamedFields(<[_]>::into_vec(
43-
borsh0_10::maybestd::boxed::Box::new([(
44-
"bits".to_string(),
45-
<u8 as borsh0_10::BorshSchema>::declaration(),
46-
)]),
47-
));
48-
let definition = borsh0_10::schema::Definition::Struct { fields };
49-
Self::add_definition(
50-
<Self as borsh0_10::BorshSchema>::declaration(),
51-
definition,
52-
definitions,
53-
);
54-
<u8 as borsh0_10::BorshSchema>::add_definitions_recursively(definitions);
55-
}
56-
}
57-
58-
#[cfg(feature = "borsh")]
59-
impl borsh0_10::ser::BorshSerialize for StakeFlags {
60-
fn serialize<W: borsh0_10::maybestd::io::Write>(
61-
&self,
62-
writer: &mut W,
63-
) -> ::core::result::Result<(), borsh0_10::maybestd::io::Error> {
64-
borsh0_10::BorshSerialize::serialize(&self.bits, writer)?;
65-
Ok(())
66-
}
67-
}
68-
6920
/// Currently, only bit 1 is used. The other 7 bits are reserved for future usage.
7021
impl StakeFlags {
7122
/// Stake must be fully activated before deactivation is allowed (bit 1).

interface/src/stake_history.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! [sv]: https://docs.solanalabs.com/runtime/sysvars#stakehistory
44
55
pub use solana_clock::Epoch;
6-
use {solana_sysvar_id::declare_sysvar_id, std::ops::Deref};
6+
use std::ops::Deref;
77

88
pub const MAX_ENTRIES: usize = 512; // it should never take as many as 512 epochs to warm up or cool down
99

@@ -65,8 +65,6 @@ impl std::ops::Add for StakeHistoryEntry {
6565
#[derive(Debug, PartialEq, Eq, Default, Clone)]
6666
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);
6767

68-
declare_sysvar_id!("SysvarStakeHistory1111111111111111111111111", StakeHistory);
69-
7068
impl StakeHistory {
7169
pub fn get(&self, epoch: Epoch) -> Option<&StakeHistoryEntry> {
7270
self.binary_search_by(|probe| epoch.cmp(&probe.0))
@@ -135,7 +133,7 @@ mod tests {
135133
fn test_id() {
136134
assert_eq!(
137135
StakeHistory::id(),
138-
solana_program::sysvar::stake_history::id()
136+
solana_sdk_ids::sysvar::stake_history::id()
139137
);
140138
}
141139
}

0 commit comments

Comments
 (0)