Skip to content

Commit

Permalink
solana-program: Make frozen-abi optional (#1222)
Browse files Browse the repository at this point in the history
* make frozen-abi optional in solana-program

* fix syntax error

* activate solana-program's frozen-abi feature in dev deps of program and sdk

* undo putting solana-program itself in solana-program dev deps

* add missing whitespace

Co-authored-by: Tyera <[email protected]>

---------

Co-authored-by: Tyera <[email protected]>
  • Loading branch information
kevinheavey and CriesofCarrots authored May 8, 2024
1 parent 2bc026d commit 5a9906e
Show file tree
Hide file tree
Showing 29 changed files with 124 additions and 72 deletions.
2 changes: 0 additions & 2 deletions programs/sbf/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 sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ assert_matches = { workspace = true }
curve25519-dalek = { workspace = true }
hex = { workspace = true }
solana-logger = { workspace = true }
solana-program = { workspace = true, features = ["frozen-abi"] }
solana-sdk = { path = ".", features = ["dev-context-only-utils"] }
static_assertions = { workspace = true }
tiny-bip39 = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ serde_bytes = { workspace = true }
serde_derive = { workspace = true }
sha2 = { workspace = true }
sha3 = { workspace = true }
solana-frozen-abi = { workspace = true }
solana-frozen-abi-macro = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-sdk-macro = { workspace = true }
thiserror = { workspace = true }

Expand Down Expand Up @@ -97,3 +97,4 @@ crate-type = ["cdylib", "rlib"]

[features]
default = []
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]
12 changes: 8 additions & 4 deletions sdk/program/src/address_lookup_table/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample};
use {
serde::{Deserialize, Serialize},
solana_frozen_abi_macro::{AbiEnumVisitor, AbiExample},
solana_program::{
address_lookup_table::error::AddressLookupError,
clock::Slot,
Expand All @@ -26,7 +27,8 @@ pub enum LookupTableStatus {
}

/// Address lookup table metadata
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct LookupTableMeta {
/// Lookup tables cannot be closed until the deactivation slot is
/// no longer "recent" (not accessible in the `SlotHashes` sysvar).
Expand Down Expand Up @@ -103,7 +105,8 @@ impl LookupTableMeta {
}

/// Program account states
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, AbiExample, AbiEnumVisitor)]
#[cfg_attr(feature = "frozen-abi", derive(AbiEnumVisitor, AbiExample))]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum ProgramState {
/// Account is not initialized.
Expand All @@ -112,7 +115,8 @@ pub enum ProgramState {
LookupTable(LookupTableMeta),
}

#[derive(Debug, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct AddressLookupTable<'a> {
pub meta: LookupTableMeta,
pub addresses: Cow<'a, [Pubkey]>,
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/blake3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub const HASH_BYTES: usize = 32;
const MAX_BASE58_LEN: usize = 44;

/// A blake3 hash.
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
Serialize,
Deserialize,
Expand All @@ -29,7 +30,6 @@ const MAX_BASE58_LEN: usize = 44;
Ord,
PartialOrd,
Hash,
AbiExample,
)]
#[borsh(crate = "borsh")]
#[repr(transparent)]
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/bpf_loader_upgradeable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::{
crate::declare_id!("BPFLoaderUpgradeab1e11111111111111111111111");

/// Upgradeable loader account states
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
pub enum UpgradeableLoaderState {
/// Account is not initialized.
Uninitialized,
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/epoch_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use {crate::hash::Hash, solana_sdk_macro::CloneZeroed, std::ops::AddAssign};

#[repr(C, align(16))]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, AbiExample, CloneZeroed)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, CloneZeroed)]
pub struct EpochRewards {
/// The starting block height of the rewards distribution in the current
/// epoch
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/epoch_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub const MAX_LEADER_SCHEDULE_EPOCH_OFFSET: u64 = 3;
pub const MINIMUM_SLOTS_PER_EPOCH: u64 = 32;

#[repr(C)]
#[derive(Debug, CloneZeroed, PartialEq, Eq, Deserialize, Serialize, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, CloneZeroed, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EpochSchedule {
/// The maximum number of slots in each epoch.
Expand Down
6 changes: 4 additions & 2 deletions sdk/program/src/fee_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use {
};

#[repr(C)]
#[derive(Serialize, Deserialize, Default, PartialEq, Eq, Clone, Copy, Debug, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Default, PartialEq, Eq, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FeeCalculator {
/// The current cost of a signature.
Expand Down Expand Up @@ -48,7 +49,8 @@ impl FeeCalculator {
}
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FeeRateGovernor {
// The current cost of a signature This amount may increase/decrease over time based on
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const MAX_BASE58_LEN: usize = 44;
/// [`blake3`]: crate::blake3
/// [`Message::hash`]: crate::message::Message::hash
#[wasm_bindgen]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
Serialize,
Deserialize,
Expand All @@ -42,7 +43,6 @@ const MAX_BASE58_LEN: usize = 44;
Ord,
PartialOrd,
Hash,
AbiExample,
Pod,
Zeroable,
)]
Expand Down
5 changes: 3 additions & 2 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {
/// an error be consistent across software versions. For example, it is
/// dangerous to include error strings from 3rd party crates because they could
/// change at any time and changes to them are difficult to detect.
#[cfg_attr(not(target_os = "solana"), derive(AbiExample, AbiEnumVisitor))]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))]
#[derive(Serialize, Deserialize, Debug, Error, PartialEq, Eq, Clone)]
pub enum InstructionError {
/// Deprecated! Use CustomError instead!
Expand Down Expand Up @@ -628,7 +628,8 @@ impl AccountMeta {
/// construction of `Message`. Most users will not interact with it directly.
///
/// [`Message`]: crate::message::Message
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CompiledInstruction {
/// Index into the transaction keys array indicating the program account that executes this instruction.
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use {
pub const HASH_BYTES: usize = 32;
/// Maximum string length of a base58 encoded hash
const MAX_BASE58_LEN: usize = 44;
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
Serialize,
Deserialize,
Expand All @@ -27,7 +28,6 @@ const MAX_BASE58_LEN: usize = 44;
Ord,
PartialOrd,
Hash,
AbiExample,
)]
#[borsh(crate = "borsh")]
#[repr(transparent)]
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ pub use solana_sdk_macro::program_pubkey as pubkey;
#[macro_use]
extern crate serde_derive;

#[macro_use]
#[cfg_attr(feature = "frozen-abi", macro_use)]
#[cfg(feature = "frozen-abi")]
extern crate solana_frozen_abi_macro;

/// Convenience macro for doing integer division where the operation's safety
Expand Down
6 changes: 4 additions & 2 deletions sdk/program/src/loader_v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ crate::declare_id!("LoaderV411111111111111111111111111111111111");
pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 750;

#[repr(u64)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum LoaderV4Status {
/// Program is in maintenance
Retracted,
Expand All @@ -27,7 +28,8 @@ pub enum LoaderV4Status {

/// LoaderV4 account states
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct LoaderV4State {
/// Slot in which the program was last deployed, retracted or initialized.
pub slot: u64,
Expand Down
8 changes: 6 additions & 2 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ fn compile_instructions(ixs: &[Instruction], keys: &[Pubkey]) -> Vec<CompiledIns
// NOTE: Serialization-related changes must be paired with the custom serialization
// for versioned messages in the `RemainingLegacyMessage` struct.
#[wasm_bindgen]
#[frozen_abi(digest = "2KnLEqfLcTBQqitE22Pp8JYkaqVVbAkGbCfdeHoyxcAU")]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "2KnLEqfLcTBQqitE22Pp8JYkaqVVbAkGbCfdeHoyxcAU"),
derive(AbiExample)
)]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Message {
/// The message header, identifying signed and read-only `account_keys`.
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ pub const MESSAGE_HEADER_LENGTH: usize = 3;
/// access the same read-write accounts are processed sequentially.
///
/// [PoH]: https://docs.solanalabs.com/consensus/synchronization
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, Copy, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, Copy)]
#[serde(rename_all = "camelCase")]
pub struct MessageHeader {
/// The number of signatures required for this message to be considered
Expand Down
8 changes: 6 additions & 2 deletions sdk/program/src/message/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ pub const MESSAGE_VERSION_PREFIX: u8 = 0x80;
/// which message version is serialized starting from version `0`. If the first
/// is bit is not set, all bytes are used to encode the legacy `Message`
/// format.
#[frozen_abi(digest = "G4EAiqmGgBprgf5ePYemLJcoFfx4R7rhC1Weo2FVJ7fn")]
#[derive(Debug, PartialEq, Eq, Clone, AbiEnumVisitor, AbiExample)]
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "G4EAiqmGgBprgf5ePYemLJcoFfx4R7rhC1Weo2FVJ7fn"),
derive(AbiEnumVisitor, AbiExample)
)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum VersionedMessage {
Legacy(LegacyMessage),
V0(v0::Message),
Expand Down
6 changes: 4 additions & 2 deletions sdk/program/src/message/versions/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ mod loaded;

/// Address table lookups describe an on-chain address lookup table to use
/// for loading more readonly and writable accounts in a single tx.
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MessageAddressTableLookup {
/// Address lookup table account key
Expand All @@ -52,7 +53,8 @@ pub struct MessageAddressTableLookup {
/// See the [`message`] module documentation for further description.
///
/// [`message`]: crate::message
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Message {
/// The message header, identifying signed and read-only `account_keys`.
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl From<u64> for PubkeyError {
/// [`Keypair`]: https://docs.rs/solana-sdk/latest/solana_sdk/signer/keypair/struct.Keypair.html
#[wasm_bindgen]
#[repr(transparent)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
AbiExample,
BorshDeserialize,
BorshSchema,
BorshSerialize,
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use {crate::clock::DEFAULT_SLOTS_PER_EPOCH, solana_sdk_macro::CloneZeroed};

/// Configuration of network rent.
#[repr(C)]
#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Debug, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, PartialEq, CloneZeroed, Debug)]
pub struct Rent {
/// Rental rate in lamports/byte-year.
pub lamports_per_byte_year: u64,
Expand Down
13 changes: 2 additions & 11 deletions sdk/program/src/secp256k1_recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,9 @@ pub const SECP256K1_SIGNATURE_LENGTH: usize = 64;
pub const SECP256K1_PUBLIC_KEY_LENGTH: usize = 64;

#[repr(transparent)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
BorshSerialize,
BorshDeserialize,
BorshSchema,
Clone,
Copy,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
AbiExample,
BorshSerialize, BorshDeserialize, BorshSchema, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash,
)]
#[borsh(crate = "borsh")]
pub struct Secp256k1Pubkey(pub [u8; SECP256K1_PUBLIC_KEY_LENGTH]);
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/short_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
/// bytes. Each byte follows the same pattern until the 3rd byte. The 3rd
/// byte, if needed, uses all 8 bits to store the last byte of the original
/// value.
#[derive(AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
pub struct ShortU16(pub u16);

impl Serialize for ShortU16 {
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/stake/stake_flags.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};

/// Additional flags for stake state.
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(
Serialize,
Deserialize,
AbiExample,
BorshDeserialize,
BorshSchema,
BorshSerialize,
Expand Down
Loading

0 comments on commit 5a9906e

Please sign in to comment.