diff --git a/Cargo.lock b/Cargo.lock index 5857feccd4f593..a6378718915015 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5460,8 +5460,6 @@ dependencies = [ "num-derive", "num-traits", "rustc_version 0.4.0", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-program", "solana-program-runtime", "solana-sdk", diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 8a8eb1d8cd4324..642d667a8c9806 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -35,8 +35,8 @@ serde = { workspace = true, features = ["rc"] } serde_derive = { workspace = true } smallvec = { workspace = true, features = ["const_generics"] } solana-bucket-map = { 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-inline-spl = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } @@ -81,6 +81,14 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = ["dep:qualifier_attr", "dep:solana-stake-program", "dep:solana-vote-program"] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program-runtime/frozen-abi", + "solana-sdk/frozen-abi", + "solana-svm/frozen-abi", + "solana-vote-program/frozen-abi", +] [[bench]] name = "bench_accounts_file" diff --git a/accounts-db/src/account_storage.rs b/accounts-db/src/account_storage.rs index 185a3324094ee4..c5a5852de86218 100644 --- a/accounts-db/src/account_storage.rs +++ b/accounts-db/src/account_storage.rs @@ -261,7 +261,8 @@ impl<'a> ShrinkInProgress<'a> { } } -#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize, Serialize, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize, Serialize)] pub enum AccountStorageStatus { Available = 0, Full = 1, diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index b33b4ee80197fc..26a515e31ee513 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -46,7 +46,8 @@ use { pub type PubkeyAccountSlot = (Pubkey, AccountSharedData, Slot); -#[derive(Debug, Default, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default)] pub struct AccountLocks { write_locks: HashSet, readonly_locks: HashMap, @@ -99,7 +100,8 @@ impl AccountLocks { } /// This structure handles synchronization for db -#[derive(Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] pub struct Accounts { /// Single global AccountsDb pub accounts_db: Arc, diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 26a196ef0a625a..690686d0fe9514 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1273,7 +1273,8 @@ pub fn get_temp_accounts_paths(count: u32) -> IoResult<(Vec, Vec ThreadPool { .unwrap() } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for AccountsDb { fn example() -> Self { let accounts_db = AccountsDb::new_single_for_tests(); diff --git a/accounts-db/src/accounts_hash.rs b/accounts-db/src/accounts_hash.rs index 540efcbb297e06..359255b8be176a 100644 --- a/accounts-db/src/accounts_hash.rs +++ b/accounts-db/src/accounts_hash.rs @@ -1228,7 +1228,8 @@ pub enum ZeroLamportAccounts { /// Hash of an account #[repr(transparent)] -#[derive(Debug, Copy, Clone, Eq, PartialEq, Pod, Zeroable, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Pod, Zeroable)] pub struct AccountHash(pub Hash); // Ensure the newtype wrapper never changes size from the underlying Hash @@ -1273,7 +1274,8 @@ pub struct IncrementalAccountsHash(pub Hash); pub struct AccountsDeltaHash(pub Hash); /// Snapshot serde-safe accounts delta hash -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct SerdeAccountsDeltaHash(pub Hash); impl From for AccountsDeltaHash { @@ -1288,7 +1290,8 @@ impl From for SerdeAccountsDeltaHash { } /// Snapshot serde-safe accounts hash -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct SerdeAccountsHash(pub Hash); impl From for AccountsHash { @@ -1303,7 +1306,8 @@ impl From for SerdeAccountsHash { } /// Snapshot serde-safe incremental accounts hash -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct SerdeIncrementalAccountsHash(pub Hash); impl From for IncrementalAccountsHash { diff --git a/accounts-db/src/ancestors.rs b/accounts-db/src/ancestors.rs index 7072640dbf1e00..91f00c5b61a100 100644 --- a/accounts-db/src/ancestors.rs +++ b/accounts-db/src/ancestors.rs @@ -7,7 +7,8 @@ use { pub type AncestorsForSerialization = HashMap; -#[derive(Clone, PartialEq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, PartialEq)] pub struct Ancestors { ancestors: RollingBitField, } diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index 0591c418fb4b08..f18a60e7be3436 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -209,7 +209,8 @@ enum InternalFileOrMmap<'a> { Mmap(&'a MmapMut), } -#[derive(Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] enum AppendVecFileBacking { /// A file-backed block of memory that is used to store the data for each appended item. MmapOnly(MmapMut), @@ -228,7 +229,8 @@ impl AppendVecFileBacking { /// are serialized such that only one thread updates the internal `append_lock` at a time. No /// restrictions are placed on reading. That is, one may read items from one thread while another /// is appending new items. -#[derive(Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] pub struct AppendVec { /// The file path where the data is stored. path: PathBuf, diff --git a/accounts-db/src/blockhash_queue.rs b/accounts-db/src/blockhash_queue.rs index 2f40e1454cd003..823904eaca9bc8 100644 --- a/accounts-db/src/blockhash_queue.rs +++ b/accounts-db/src/blockhash_queue.rs @@ -8,7 +8,8 @@ use { std::collections::HashMap, }; -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] struct HashAge { fee_calculator: FeeCalculator, hash_index: u64, @@ -16,8 +17,12 @@ struct HashAge { } /// Low memory overhead, so can be cloned for every checkpoint -#[frozen_abi(digest = "8upYCMG37Awf4FGQ5kKtZARHP1QfD2GMpQCPnwCCsxhu")] -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "8upYCMG37Awf4FGQ5kKtZARHP1QfD2GMpQCPnwCCsxhu") +)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct BlockhashQueue { /// index of last hash to be registered last_hash_index: u64, diff --git a/accounts-db/src/lib.rs b/accounts-db/src/lib.rs index f5cc893601370b..d22ca5836c3787 100644 --- a/accounts-db/src/lib.rs +++ b/accounts-db/src/lib.rs @@ -46,5 +46,6 @@ extern crate solana_metrics; #[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; diff --git a/accounts-db/src/rolling_bit_field.rs b/accounts-db/src/rolling_bit_field.rs index 5a710d936963be..477257fc8b1529 100644 --- a/accounts-db/src/rolling_bit_field.rs +++ b/accounts-db/src/rolling_bit_field.rs @@ -8,7 +8,8 @@ use { solana_sdk::clock::Slot, }; -#[derive(Debug, AbiExample, Clone)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Clone)] pub struct RollingBitField { max_width: u64, min: u64, diff --git a/accounts-db/src/stake_rewards.rs b/accounts-db/src/stake_rewards.rs index 88ca8ef296cde6..5376af1c973a6f 100644 --- a/accounts-db/src/stake_rewards.rs +++ b/accounts-db/src/stake_rewards.rs @@ -7,7 +7,8 @@ use { }, }; -#[derive(AbiExample, Debug, Serialize, Deserialize, Clone, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct StakeReward { pub stake_pubkey: Pubkey, pub stake_reward_info: RewardInfo, diff --git a/bloom/Cargo.toml b/bloom/Cargo.toml index f47fc1f73df431..eb8a8c7b97cbe6 100644 --- a/bloom/Cargo.toml +++ b/bloom/Cargo.toml @@ -17,8 +17,8 @@ rand = { workspace = true } rayon = { workspace = true } serde = { workspace = true, features = ["rc"] } serde_derive = { 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 = { workspace = true } [lib] @@ -30,3 +30,10 @@ targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] rustc_version = { workspace = true } + +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-sdk/frozen-abi", +] diff --git a/bloom/src/bloom.rs b/bloom/src/bloom.rs index 0163b1b8a652bf..06996cb1c3ba23 100644 --- a/bloom/src/bloom.rs +++ b/bloom/src/bloom.rs @@ -24,7 +24,8 @@ pub trait BloomHashIndex { fn hash_at_index(&self, hash_index: u64) -> u64; } -#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq)] pub struct Bloom { pub keys: Vec, pub bits: BitVec, diff --git a/bloom/src/lib.rs b/bloom/src/lib.rs index 9a78bdcd9e4666..e188a9c2a1873a 100644 --- a/bloom/src/lib.rs +++ b/bloom/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))] pub mod bloom; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/core/Cargo.toml b/core/Cargo.toml index 5274aa55ed12f2..0bc48d805cd7d8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -46,8 +46,8 @@ solana-bloom = { workspace = true } solana-client = { workspace = true } solana-cost-model = { workspace = true } solana-entry = { 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-geyser-plugin-manager = { workspace = true } solana-gossip = { workspace = true } solana-ledger = { workspace = true } @@ -108,6 +108,22 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-accounts-db/frozen-abi", + "solana-bloom/frozen-abi", + "solana-cost-model/frozen-abi", + "solana-gossip/frozen-abi", + "solana-ledger/frozen-abi", + "solana-perf/frozen-abi", + "solana-program-runtime/frozen-abi", + "solana-runtime/frozen-abi", + "solana-sdk/frozen-abi", + "solana-svm/frozen-abi", + "solana-vote/frozen-abi", + "solana-vote-program/frozen-abi", +] [[bench]] name = "banking_stage" diff --git a/core/src/banking_trace.rs b/core/src/banking_trace.rs index 9f5a644899c1f1..c2b3c38695d123 100644 --- a/core/src/banking_trace.rs +++ b/core/src/banking_trace.rs @@ -62,17 +62,23 @@ pub struct BankingTracer { active_tracer: Option, } -#[frozen_abi(digest = "Eq6YrAFtTbtPrCEvh6Et1mZZDCARUg1gcK2qiZdqyjUz")] -#[derive(Serialize, Deserialize, Debug, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "Eq6YrAFtTbtPrCEvh6Et1mZZDCARUg1gcK2qiZdqyjUz") +)] +#[derive(Serialize, Deserialize, Debug)] pub struct TimedTracedEvent(pub std::time::SystemTime, pub TracedEvent); -#[derive(Serialize, Deserialize, Debug, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Debug)] pub enum TracedEvent { PacketBatch(ChannelLabel, BankingPacketBatch), BlockAndBankHash(Slot, Hash, Hash), } -#[derive(Serialize, Deserialize, Debug, Clone, Copy, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Debug, Clone, Copy)] pub enum ChannelLabel { NonVote, TpuVote, diff --git a/core/src/consensus.rs b/core/src/consensus.rs index a7fd43b54e1e4c..15eac5235db501 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -63,7 +63,8 @@ impl ThresholdDecision { } } -#[derive(PartialEq, Eq, Clone, Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(PartialEq, Eq, Clone, Debug)] pub enum SwitchForkDecision { SwitchProof(Hash), SameFork, @@ -221,7 +222,8 @@ impl TowerVersions { } } -#[derive(PartialEq, Eq, Debug, Default, Clone, Copy, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(PartialEq, Eq, Debug, Default, Clone, Copy)] pub(crate) enum BlockhashStatus { /// No vote since restart #[default] @@ -232,8 +234,12 @@ pub(crate) enum BlockhashStatus { Blockhash(Hash), } -#[frozen_abi(digest = "679XkZ4upGc389SwqAsjs5tr2qB4wisqjbwtei7fGhxC")] -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "679XkZ4upGc389SwqAsjs5tr2qB4wisqjbwtei7fGhxC") +)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] pub struct Tower { pub node_pubkey: Pubkey, threshold_depth: usize, diff --git a/core/src/consensus/tower1_14_11.rs b/core/src/consensus/tower1_14_11.rs index fe9a5b40b20517..ee96540e1cc4be 100644 --- a/core/src/consensus/tower1_14_11.rs +++ b/core/src/consensus/tower1_14_11.rs @@ -6,8 +6,12 @@ use { }, }; -#[frozen_abi(digest = "4LayQwoKrE2jPhbNtg3TSpKrtEtjcPiwsVPJN7aCavri")] -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "4LayQwoKrE2jPhbNtg3TSpKrtEtjcPiwsVPJN7aCavri") +)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] pub struct Tower1_14_11 { pub(crate) node_pubkey: Pubkey, pub(crate) threshold_depth: usize, diff --git a/core/src/consensus/tower1_7_14.rs b/core/src/consensus/tower1_7_14.rs index 725b781924d8c9..c7255bb88d9dd5 100644 --- a/core/src/consensus/tower1_7_14.rs +++ b/core/src/consensus/tower1_7_14.rs @@ -8,8 +8,12 @@ use { solana_vote_program::vote_state::{vote_state_1_14_11::VoteState1_14_11, BlockTimestamp, Vote}, }; -#[frozen_abi(digest = "9Kc3Cpak93xdL8bCnEwMWA8ZLGCBNfqh9PLo1o5RiPyT")] -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "9Kc3Cpak93xdL8bCnEwMWA8ZLGCBNfqh9PLo1o5RiPyT") +)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] pub struct Tower1_7_14 { pub(crate) node_pubkey: Pubkey, pub(crate) threshold_depth: usize, @@ -35,8 +39,12 @@ pub struct Tower1_7_14 { pub(crate) last_switch_threshold_check: Option<(Slot, SwitchForkDecision)>, } -#[frozen_abi(digest = "CxwFFxKfn6ez6wifDKr5WYr3eu2PsWUKdMYp3LX8Xj52")] -#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "CxwFFxKfn6ez6wifDKr5WYr3eu2PsWUKdMYp3LX8Xj52") +)] +#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct SavedTower1_7_14 { pub(crate) signature: Signature, pub(crate) data: Vec, diff --git a/core/src/consensus/tower_storage.rs b/core/src/consensus/tower_storage.rs index 1e81f28f47ce46..5da032633ff654 100644 --- a/core/src/consensus/tower_storage.rs +++ b/core/src/consensus/tower_storage.rs @@ -14,7 +14,8 @@ use { }, }; -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum SavedTowerVersions { V1_17_14(SavedTower1_7_14), Current(SavedTower), @@ -75,8 +76,12 @@ impl From for SavedTowerVersions { } } -#[frozen_abi(digest = "Gaxfwvx5MArn52mKZQgzHmDCyn5YfCuTHvp5Et3rFfpp")] -#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "Gaxfwvx5MArn52mKZQgzHmDCyn5YfCuTHvp5Et3rFfpp") +)] +#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct SavedTower { signature: Signature, data: Vec, diff --git a/core/src/lib.rs b/core/src/lib.rs index b6feb5e4dd54e2..c6ab7b7e9c8b3d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -59,7 +59,8 @@ extern crate serde_derive; #[macro_use] extern crate solana_metrics; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; #[cfg(test)] diff --git a/core/src/repair/serve_repair.rs b/core/src/repair/serve_repair.rs index 45b2c64e844c4d..44c221f2a97877 100644 --- a/core/src/repair/serve_repair.rs +++ b/core/src/repair/serve_repair.rs @@ -140,8 +140,12 @@ impl AncestorHashesRepairType { } } -#[derive(Debug, AbiEnumVisitor, AbiExample, Deserialize, Serialize)] -#[frozen_abi(digest = "AKpurCovzn6rsji4aQrP3hUdEHxjtXUfT7AatZXN7Rpz")] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiEnumVisitor, AbiExample), + frozen_abi(digest = "AKpurCovzn6rsji4aQrP3hUdEHxjtXUfT7AatZXN7Rpz") +)] +#[derive(Debug, Deserialize, Serialize)] pub enum AncestorHashesResponse { Hashes(Vec<(Slot, Hash)>), Ping(Ping), @@ -192,7 +196,8 @@ struct ServeRepairStats { err_id_mismatch: usize, } -#[derive(Debug, AbiExample, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Deserialize, Serialize)] pub struct RepairRequestHeader { signature: Signature, sender: Pubkey, @@ -216,8 +221,12 @@ impl RepairRequestHeader { pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>; /// Window protocol messages -#[derive(Debug, AbiEnumVisitor, AbiExample, Deserialize, Serialize)] -#[frozen_abi(digest = "5cmSdmXMgkpUH5ZCmYYjxUVQfULe9iJqCqqfrADfsEmK")] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiEnumVisitor, AbiExample), + frozen_abi(digest = "5cmSdmXMgkpUH5ZCmYYjxUVQfULe9iJqCqqfrADfsEmK") +)] +#[derive(Debug, Deserialize, Serialize)] pub enum RepairProtocol { LegacyWindowIndex, LegacyHighestWindowIndex, @@ -260,8 +269,12 @@ fn discard_malformed_repair_requests( requests.len() } -#[derive(Debug, AbiEnumVisitor, AbiExample, Deserialize, Serialize)] -#[frozen_abi(digest = "CkffjyMPCwuJgk9NiCMELXLCecAnTPZqpKEnUCb3VyVf")] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiEnumVisitor, AbiExample), + frozen_abi(digest = "CkffjyMPCwuJgk9NiCMELXLCecAnTPZqpKEnUCb3VyVf") +)] +#[derive(Debug, Deserialize, Serialize)] pub(crate) enum RepairResponse { Ping(Ping), } diff --git a/core/src/sigverify.rs b/core/src/sigverify.rs index b496452078d883..18984ecc4ef836 100644 --- a/core/src/sigverify.rs +++ b/core/src/sigverify.rs @@ -16,7 +16,8 @@ use { solana_sdk::{packet::Packet, saturating_add_assign}, }; -#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct SigverifyTracerPacketStats { pub total_removed_before_sigverify_stage: usize, pub total_tracer_packets_received_in_sigverify_stage: usize, diff --git a/cost-model/Cargo.toml b/cost-model/Cargo.toml index cf13a3377376ed..ca4c5c5e386919 100644 --- a/cost-model/Cargo.toml +++ b/cost-model/Cargo.toml @@ -17,8 +17,8 @@ solana-address-lookup-table-program = { workspace = true } solana-bpf-loader-program = { workspace = true } solana-compute-budget-program = { workspace = true } solana-config-program = { 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-loader-v4-program = { workspace = true } solana-metrics = { workspace = true } solana-program-runtime = { workspace = true } @@ -44,5 +44,14 @@ targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] rustc_version = { workspace = true } +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program-runtime/frozen-abi", + "solana-sdk/frozen-abi", + "solana-vote-program/frozen-abi", +] + [[bench]] name = "cost_tracker" diff --git a/cost-model/src/cost_tracker.rs b/cost-model/src/cost_tracker.rs index a6341ed8e276ee..36c6cb3b1e93ff 100644 --- a/cost-model/src/cost_tracker.rs +++ b/cost-model/src/cost_tracker.rs @@ -57,7 +57,8 @@ pub struct UpdatedCosts { pub updated_costliest_account_cost: u64, } -#[derive(AbiExample, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] pub struct CostTracker { account_cost_limit: u64, block_cost_limit: u64, diff --git a/cost-model/src/lib.rs b/cost-model/src/lib.rs index 2dd7269e11a435..d0e043c9ad77ed 100644 --- a/cost-model/src/lib.rs +++ b/cost-model/src/lib.rs @@ -6,5 +6,6 @@ pub mod cost_model; pub mod cost_tracker; pub mod transaction_cost; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/gossip/Cargo.toml b/gossip/Cargo.toml index 2e62bc66f6866c..c25ce914469e2d 100644 --- a/gossip/Cargo.toml +++ b/gossip/Cargo.toml @@ -33,8 +33,8 @@ solana-clap-utils = { workspace = true } solana-client = { workspace = true } solana-connection-cache = { workspace = true } solana-entry = { 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-ledger = { workspace = true } solana-logger = { workspace = true } solana-measure = { workspace = true } @@ -61,6 +61,20 @@ test-case = { workspace = true } [build-dependencies] rustc_version = { workspace = true } +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-bloom/frozen-abi", + "solana-ledger/frozen-abi", + "solana-perf/frozen-abi", + "solana-runtime/frozen-abi", + "solana-sdk/frozen-abi", + "solana-version/frozen-abi", + "solana-vote/frozen-abi", + "solana-vote-program/frozen-abi", +] + [[bench]] name = "crds" diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index b57a1b1375d20a..4e95789c374230 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -185,7 +185,8 @@ pub struct ClusterInfo { socket_addr_space: SocketAddrSpace, } -#[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub(crate) struct PruneData { /// Pubkey of the node that sent this prune data pubkey: Pubkey, @@ -269,8 +270,12 @@ struct PullData { pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>; // TODO These messages should go through the gpu pipeline for spam filtering -#[frozen_abi(digest = "ogEqvffeEkPpojAaSiUbCv2HdJcdXDQ1ykgYyvKvLo2")] -#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample, AbiEnumVisitor), + frozen_abi(digest = "ogEqvffeEkPpojAaSiUbCv2HdJcdXDQ1ykgYyvKvLo2") +)] +#[derive(Serialize, Deserialize, Debug)] #[allow(clippy::large_enum_variant)] pub(crate) enum Protocol { /// Gossip protocol messages diff --git a/gossip/src/contact_info.rs b/gossip/src/contact_info.rs index 0db138d3f5ef39..e1ef93d243a03c 100644 --- a/gossip/src/contact_info.rs +++ b/gossip/src/contact_info.rs @@ -86,7 +86,8 @@ pub struct ContactInfo { cache: [SocketAddr; SOCKET_CACHE_SIZE], } -#[derive(Copy, Clone, Debug, Eq, PartialEq, AbiExample, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] struct SocketEntry { key: u8, // Protocol identifier, e.g. tvu, tpu, etc index: u8, // IpAddr index in the accompanying addrs vector. @@ -592,7 +593,7 @@ pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result )) } -#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] +#[cfg(all(test, RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for ContactInfo { fn example() -> Self { Self { diff --git a/gossip/src/crds_gossip_pull.rs b/gossip/src/crds_gossip_pull.rs index 7f97cbd8d75897..601c2fda6a0873 100644 --- a/gossip/src/crds_gossip_pull.rs +++ b/gossip/src/crds_gossip_pull.rs @@ -55,7 +55,8 @@ const FAILED_INSERTS_RETENTION_MS: u64 = 20_000; pub const FALSE_RATE: f64 = 0.1f64; pub const KEYS: f64 = 8f64; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct CrdsFilter { pub filter: Bloom, mask: u64, diff --git a/gossip/src/crds_value.rs b/gossip/src/crds_value.rs index 12d7378d4808b8..e3f35fd66af6cc 100644 --- a/gossip/src/crds_value.rs +++ b/gossip/src/crds_value.rs @@ -41,7 +41,8 @@ pub type EpochSlotsIndex = u8; pub const MAX_EPOCH_SLOTS: EpochSlotsIndex = 255; /// CrdsValue that is replicated across the cluster -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct CrdsValue { pub signature: Signature, pub data: CrdsData, @@ -81,7 +82,8 @@ impl Signable for CrdsValue { /// * Merge Strategy - Latest wallclock is picked /// * LowestSlot index is deprecated #[allow(clippy::large_enum_variant)] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub enum CrdsData { #[allow(private_interfaces)] LegacyContactInfo(LegacyContactInfo), @@ -175,7 +177,8 @@ impl CrdsData { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct AccountsHashes { pub from: Pubkey, pub hashes: Vec<(Slot, Hash)>, @@ -223,7 +226,8 @@ impl AccountsHashes { type LegacySnapshotHashes = AccountsHashes; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct SnapshotHashes { pub from: Pubkey, pub full: (Slot, Hash), @@ -249,7 +253,8 @@ impl Sanitize for SnapshotHashes { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct LowestSlot { pub from: Pubkey, root: Slot, //deprecated @@ -303,7 +308,8 @@ impl Sanitize for LowestSlot { } } -#[derive(Clone, Debug, PartialEq, Eq, AbiExample, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] pub struct Vote { pub(crate) from: Pubkey, transaction: Transaction, @@ -370,7 +376,8 @@ impl<'de> Deserialize<'de> for Vote { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct LegacyVersion { pub from: Pubkey, pub wallclock: u64, @@ -385,7 +392,8 @@ impl Sanitize for LegacyVersion { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Version { pub from: Pubkey, pub wallclock: u64, @@ -425,7 +433,8 @@ impl Version { } } -#[derive(Clone, Debug, PartialEq, Eq, AbiExample, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct NodeInstance { from: Pubkey, wallclock: u64, diff --git a/gossip/src/deprecated.rs b/gossip/src/deprecated.rs index a838eb1a693048..73a2f37d2a0c0a 100644 --- a/gossip/src/deprecated.rs +++ b/gossip/src/deprecated.rs @@ -1,6 +1,7 @@ use solana_sdk::clock::Slot; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] enum CompressionType { Uncompressed, GZip, @@ -13,7 +14,8 @@ impl Default for CompressionType { } } -#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)] pub(crate) struct EpochIncompleteSlots { first: Slot, compression: CompressionType, diff --git a/gossip/src/duplicate_shred.rs b/gossip/src/duplicate_shred.rs index f7ac0153a5c843..4c270f61421aed 100644 --- a/gossip/src/duplicate_shred.rs +++ b/gossip/src/duplicate_shred.rs @@ -24,7 +24,8 @@ const DUPLICATE_SHRED_HEADER_SIZE: usize = 63; pub(crate) type DuplicateShredIndex = u16; pub(crate) const MAX_DUPLICATE_SHREDS: DuplicateShredIndex = 512; -#[derive(Clone, Debug, PartialEq, Eq, AbiExample, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct DuplicateShred { pub(crate) from: Pubkey, pub(crate) wallclock: u64, diff --git a/gossip/src/epoch_slots.rs b/gossip/src/epoch_slots.rs index c589e348143f7d..080d4c4d334973 100644 --- a/gossip/src/epoch_slots.rs +++ b/gossip/src/epoch_slots.rs @@ -14,7 +14,8 @@ use { }; pub const MAX_SLOTS_PER_ENTRY: usize = 2048 * 8; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Uncompressed { pub first_slot: Slot, pub num: usize, @@ -42,7 +43,8 @@ impl Sanitize for Uncompressed { } } -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] pub struct Flate2 { pub first_slot: Slot, pub num: usize, @@ -156,7 +158,8 @@ impl Uncompressed { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub enum CompressedSlots { Flate2(Flate2), Uncompressed(Uncompressed), @@ -224,7 +227,8 @@ impl CompressedSlots { } } -#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq)] pub struct EpochSlots { pub from: Pubkey, pub slots: Vec, diff --git a/gossip/src/legacy_contact_info.rs b/gossip/src/legacy_contact_info.rs index d1e875fa66ea8b..0cff87208020bc 100644 --- a/gossip/src/legacy_contact_info.rs +++ b/gossip/src/legacy_contact_info.rs @@ -16,7 +16,8 @@ use { }; /// Structure representing a node on the network -#[derive(Clone, Debug, Eq, PartialEq, AbiExample, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] pub(crate) struct LegacyContactInfo { id: Pubkey, /// gossip address diff --git a/gossip/src/lib.rs b/gossip/src/lib.rs index cd35d2c2a9480e..c164a4cd3fde96 100644 --- a/gossip/src/lib.rs +++ b/gossip/src/lib.rs @@ -37,7 +37,8 @@ extern crate assert_matches; #[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; #[macro_use] diff --git a/gossip/src/ping_pong.rs b/gossip/src/ping_pong.rs index d34f9ae343caa8..5d4839cfa90947 100644 --- a/gossip/src/ping_pong.rs +++ b/gossip/src/ping_pong.rs @@ -18,14 +18,16 @@ use { const PING_PONG_HASH_PREFIX: &[u8] = "SOLANA_PING_PONG".as_bytes(); -#[derive(AbiExample, Debug, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Deserialize, Serialize)] pub struct Ping { from: Pubkey, token: T, signature: Signature, } -#[derive(AbiExample, Debug, Deserialize, Serialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Deserialize, Serialize)] pub struct Pong { from: Pubkey, hash: Hash, // Hash of received ping token. diff --git a/gossip/src/restart_crds_values.rs b/gossip/src/restart_crds_values.rs index 4a2606335b65ca..578675cad9bef0 100644 --- a/gossip/src/restart_crds_values.rs +++ b/gossip/src/restart_crds_values.rs @@ -13,7 +13,8 @@ use { thiserror::Error, }; -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, AbiExample, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] pub struct RestartLastVotedForkSlots { pub from: Pubkey, pub wallclock: u64, @@ -29,7 +30,8 @@ pub enum RestartLastVotedForkSlotsError { LastVotedForkEmpty, } -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, AbiExample, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] pub struct RestartHeaviestFork { pub from: Pubkey, pub wallclock: u64, @@ -39,21 +41,25 @@ pub struct RestartHeaviestFork { pub shred_version: u16, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample, AbiEnumVisitor)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] enum SlotsOffsets { RunLengthEncoding(RunLengthEncoding), RawOffsets(RawOffsets), } -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] struct U16(#[serde(with = "serde_varint")] u16); // The vector always starts with 1. Encode number of 1's and 0's consecutively. // For example, 110000111 is [2, 4, 3]. -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] struct RunLengthEncoding(Vec); -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)] struct RawOffsets(BitVec); impl Sanitize for RestartLastVotedForkSlots { diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index 452de261492071..8ac69167384bf2 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -44,8 +44,8 @@ solana-accounts-db = { workspace = true } solana-bpf-loader-program = { workspace = true } solana-cost-model = { workspace = true } solana-entry = { 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-measure = { workspace = true } solana-metrics = { workspace = true } solana-perf = { workspace = true } @@ -91,6 +91,11 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-runtime/frozen-abi", +] [lib] crate-type = ["lib"] diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index f92647df7878c7..62c274a74e4550 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -43,5 +43,6 @@ extern crate solana_metrics; #[macro_use] extern crate log; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index d19ffa073bce95..79d0c9ff79bab6 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -170,19 +170,9 @@ pub enum Error { } #[repr(u8)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] #[derive( - Clone, - Copy, - Debug, - Eq, - Hash, - PartialEq, - AbiEnumVisitor, - AbiExample, - Deserialize, - IntoPrimitive, - Serialize, - TryFromPrimitive, + Clone, Copy, Debug, Eq, Hash, PartialEq, Deserialize, IntoPrimitive, Serialize, TryFromPrimitive, )] #[serde(into = "u8", try_from = "u8")] pub enum ShredType { diff --git a/perf/Cargo.toml b/perf/Cargo.toml index e2e802908e14c2..8b7b4c6cb12747 100644 --- a/perf/Cargo.toml +++ b/perf/Cargo.toml @@ -21,8 +21,8 @@ log = { workspace = true } rand = { workspace = true } rayon = { workspace = true } serde = { 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-metrics = { workspace = true } solana-rayon-threadlimit = { workspace = true } solana-sdk = { workspace = true } @@ -45,6 +45,14 @@ test-case = { workspace = true } [build-dependencies] rustc_version = { workspace = true } +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-sdk/frozen-abi", + "solana-vote-program/frozen-abi", +] + [[bench]] name = "sigverify" diff --git a/perf/src/cuda_runtime.rs b/perf/src/cuda_runtime.rs index 5b44099aecb36c..1aa3b95153816d 100644 --- a/perf/src/cuda_runtime.rs +++ b/perf/src/cuda_runtime.rs @@ -54,7 +54,8 @@ fn unpin(mem: *mut T) { // A vector wrapper where the underlying memory can be // page-pinned. Controlled by flags in case user only wants // to pin in certain circumstances. -#[derive(Debug, Default, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct PinnedVec { x: Vec, pinned: bool, diff --git a/perf/src/lib.rs b/perf/src/lib.rs index 83cefe1f319145..b3d09c91eb99d0 100644 --- a/perf/src/lib.rs +++ b/perf/src/lib.rs @@ -24,7 +24,8 @@ extern crate assert_matches; #[macro_use] extern crate solana_metrics; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; fn is_rosetta_emulated() -> bool { diff --git a/perf/src/packet.rs b/perf/src/packet.rs index fbb8a437d6bd32..f5a704fe40c6eb 100644 --- a/perf/src/packet.rs +++ b/perf/src/packet.rs @@ -18,7 +18,8 @@ pub const NUM_PACKETS: usize = 1024 * 8; pub const PACKETS_PER_BATCH: usize = 64; pub const NUM_RCVMMSGS: usize = 64; -#[derive(Debug, Default, Clone, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct PacketBatch { packets: PinnedVec, } diff --git a/perf/src/recycler.rs b/perf/src/recycler.rs index f940dc36c8ad3e..6251f4a5e4e1eb 100644 --- a/perf/src/recycler.rs +++ b/perf/src/recycler.rs @@ -57,7 +57,7 @@ impl Default for RecyclerX { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for RecyclerX> { diff --git a/program-runtime/Cargo.toml b/program-runtime/Cargo.toml index 0a0a93999cfce0..3bad1a75ee0da4 100644 --- a/program-runtime/Cargo.toml +++ b/program-runtime/Cargo.toml @@ -22,8 +22,8 @@ num-traits = { workspace = true } percentage = { workspace = true } rand = { workspace = true } serde = { 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-measure = { workspace = true } solana-metrics = { workspace = true } solana-sdk = { workspace = true } @@ -45,3 +45,10 @@ targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] rustc_version = { workspace = true } + +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-sdk/frozen-abi", +] diff --git a/program-runtime/src/compute_budget.rs b/program-runtime/src/compute_budget.rs index 0657df5c8a364b..3d4d22facb850e 100644 --- a/program-runtime/src/compute_budget.rs +++ b/program-runtime/src/compute_budget.rs @@ -3,7 +3,7 @@ use { solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, transaction::Result}, }; -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for ComputeBudget { fn example() -> Self { // ComputeBudget is not Serialize so just rely on Default. diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 271da7637ee1b4..42e192f493bb30 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -1322,7 +1322,7 @@ impl ProgramCache { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for ProgramCacheEntry { fn example() -> Self { // ProgramCacheEntry isn't serializable by definition. @@ -1330,7 +1330,7 @@ impl solana_frozen_abi::abi_example::AbiExample for ProgramCacheEntry { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for ProgramCache { fn example() -> Self { // ProgramCache isn't serializable by definition. diff --git a/program-runtime/src/sysvar_cache.rs b/program-runtime/src/sysvar_cache.rs index 952f5726eb83f7..313faec6e11b02 100644 --- a/program-runtime/src/sysvar_cache.rs +++ b/program-runtime/src/sysvar_cache.rs @@ -16,7 +16,7 @@ use { std::sync::Arc, }; -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for SysvarCache { fn example() -> Self { // SysvarCache is not Serialize so just rely on Default. diff --git a/programs/address-lookup-table/Cargo.toml b/programs/address-lookup-table/Cargo.toml index 9a9fcf45ceffd4..f11b127b541898 100644 --- a/programs/address-lookup-table/Cargo.toml +++ b/programs/address-lookup-table/Cargo.toml @@ -15,8 +15,6 @@ bytemuck = { workspace = true } log = { workspace = true } num-derive = { workspace = true } num-traits = { workspace = true } -solana-frozen-abi = { workspace = true } -solana-frozen-abi-macro = { workspace = true } solana-program = { workspace = true } thiserror = { workspace = true } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 43020b15c2fc99..ddcd8367b83df2 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -4660,8 +4660,6 @@ dependencies = [ "serde_derive", "smallvec", "solana-bucket-map", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-inline-spl", "solana-measure", "solana-metrics", @@ -4686,8 +4684,6 @@ dependencies = [ "num-derive", "num-traits", "rustc_version", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-program", "solana-program-runtime", "solana-sdk", @@ -4749,8 +4745,6 @@ dependencies = [ "rustc_version", "serde", "serde_derive", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-sdk", ] @@ -4959,8 +4953,6 @@ dependencies = [ "solana-client", "solana-cost-model", "solana-entry", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-geyser-plugin-manager", "solana-gossip", "solana-ledger", @@ -5009,8 +5001,6 @@ dependencies = [ "solana-bpf-loader-program", "solana-compute-budget-program", "solana-config-program", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-loader-v4-program", "solana-metrics", "solana-program-runtime", @@ -5074,34 +5064,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "solana-frozen-abi" -version = "2.0.0" -dependencies = [ - "bs58", - "bv", - "generic-array 0.14.7", - "im", - "log", - "memmap2", - "rustc_version", - "serde", - "serde_derive", - "sha2 0.10.8", - "solana-frozen-abi-macro", - "thiserror", -] - -[[package]] -name = "solana-frozen-abi-macro" -version = "2.0.0" -dependencies = [ - "proc-macro2", - "quote", - "rustc_version", - "syn 2.0.58", -] - [[package]] name = "solana-genesis-utils" version = "2.0.0" @@ -5166,8 +5128,6 @@ dependencies = [ "solana-client", "solana-connection-cache", "solana-entry", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-ledger", "solana-logger", "solana-measure", @@ -5235,8 +5195,6 @@ dependencies = [ "solana-bpf-loader-program", "solana-cost-model", "solana-entry", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-measure", "solana-metrics", "solana-perf", @@ -5358,8 +5316,6 @@ dependencies = [ "rayon", "rustc_version", "serde", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-metrics", "solana-rayon-threadlimit", "solana-sdk", @@ -5446,8 +5402,6 @@ dependencies = [ "rand 0.8.5", "rustc_version", "serde", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-measure", "solana-metrics", "solana-sdk", @@ -5719,8 +5673,6 @@ dependencies = [ "solana-compute-budget-program", "solana-config-program", "solana-cost-model", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-inline-spl", "solana-loader-v4-program", "solana-measure", @@ -6210,8 +6162,6 @@ dependencies = [ "sha2 0.10.8", "sha3 0.10.8", "siphasher", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-program", "solana-sdk-macro", "thiserror", @@ -6353,8 +6303,6 @@ dependencies = [ "serde", "serde_derive", "solana-bpf-loader-program", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-loader-v4-program", "solana-measure", "solana-metrics", @@ -6562,8 +6510,6 @@ dependencies = [ "semver", "serde", "serde_derive", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-sdk", ] @@ -6577,8 +6523,6 @@ dependencies = [ "rustc_version", "serde", "serde_derive", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-sdk", "thiserror", ] @@ -6594,8 +6538,6 @@ dependencies = [ "rustc_version", "serde", "serde_derive", - "solana-frozen-abi", - "solana-frozen-abi-macro", "solana-metrics", "solana-program", "solana-program-runtime", diff --git a/programs/vote/Cargo.toml b/programs/vote/Cargo.toml index 4028c70cb2097d..220175951cac7b 100644 --- a/programs/vote/Cargo.toml +++ b/programs/vote/Cargo.toml @@ -16,8 +16,8 @@ num-derive = { workspace = true } num-traits = { workspace = true } serde = { workspace = true } serde_derive = { 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-metrics = { workspace = true } solana-program = { workspace = true } solana-program-runtime = { workspace = true } @@ -38,3 +38,12 @@ name = "solana_vote_program" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] + +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program/frozen-abi", + "solana-program-runtime/frozen-abi", + "solana-sdk/frozen-abi", +] diff --git a/programs/vote/src/lib.rs b/programs/vote/src/lib.rs index cf3c4c12a8d951..b63eaa1c5eb643 100644 --- a/programs/vote/src/lib.rs +++ b/programs/vote/src/lib.rs @@ -7,7 +7,8 @@ pub mod vote_transaction; #[macro_use] extern crate solana_metrics; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; pub use solana_sdk::vote::{ diff --git a/programs/vote/src/vote_state/mod.rs b/programs/vote/src/vote_state/mod.rs index 28e29ffe588054..8d8ec0cf24b255 100644 --- a/programs/vote/src/vote_state/mod.rs +++ b/programs/vote/src/vote_state/mod.rs @@ -28,8 +28,12 @@ use { }, }; -#[frozen_abi(digest = "EcS3xgfomytEAQ1eVd8R76ZejwyHp2Ed8dHqQWh6zi5v")] -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, AbiEnumVisitor, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample, AbiEnumVisitor), + frozen_abi(digest = "EcS3xgfomytEAQ1eVd8R76ZejwyHp2Ed8dHqQWh6zi5v") +)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub enum VoteTransaction { Vote(Vote), VoteStateUpdate(VoteStateUpdate), diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f5ec09fa678856..ab3e4d28ce50b0 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -53,8 +53,8 @@ solana-bucket-map = { workspace = true } solana-compute-budget-program = { workspace = true } solana-config-program = { workspace = true } solana-cost-model = { 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-inline-spl = { workspace = true } solana-loader-v4-program = { workspace = true } solana-measure = { workspace = true } @@ -106,6 +106,19 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-accounts-db/frozen-abi", + "solana-cost-model/frozen-abi", + "solana-perf/frozen-abi", + "solana-program-runtime/frozen-abi", + "solana-sdk/frozen-abi", + "solana-svm/frozen-abi", + "solana-version/frozen-abi", + "solana-vote/frozen-abi", + "solana-vote-program/frozen-abi", +] [[bench]] name = "prioritization_fee_cache" diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index b99989ca4a2cf0..04694d37ffbbc3 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -243,7 +243,10 @@ struct RentMetrics { } pub type BankStatusCache = StatusCache>; -#[frozen_abi(digest = "9Pf3NTGr1AEzB4nKaVBY24uNwoQR4aJi8vc96W6kGvNk")] +#[cfg_attr( + feature = "frozen-abi", + frozen_abi(digest = "9Pf3NTGr1AEzB4nKaVBY24uNwoQR4aJi8vc96W6kGvNk") +)] pub type BankSlotDelta = SlotDelta>; #[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] @@ -266,7 +269,8 @@ impl AddAssign for SquashTiming { } } -#[derive(AbiExample, Debug, Default, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default, PartialEq)] pub(crate) struct CollectorFeeDetails { transaction_fee: u64, priority_fee: u64, @@ -310,10 +314,10 @@ pub struct BankRc { pub(crate) bank_id_generator: Arc, } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] use solana_frozen_abi::abi_example::AbiExample; -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl AbiExample for BankRc { fn example() -> Self { BankRc { @@ -379,7 +383,8 @@ impl TransactionBalancesSet { } pub type TransactionBalances = Vec>; -#[derive(Serialize, Deserialize, AbiExample, AbiEnumVisitor, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum TransactionLogCollectorFilter { All, AllWithVotes, @@ -393,13 +398,15 @@ impl Default for TransactionLogCollectorFilter { } } -#[derive(AbiExample, Debug, Default)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Default)] pub struct TransactionLogCollectorConfig { pub mentioned_addresses: HashSet, pub filter: TransactionLogCollectorFilter, } -#[derive(AbiExample, Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct TransactionLogInfo { pub signature: Signature, pub result: Result<()>, @@ -407,7 +414,8 @@ pub struct TransactionLogInfo { pub log_messages: TransactionLogMessages, } -#[derive(AbiExample, Default, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Debug)] pub struct TransactionLogCollector { // All the logs collected for from this Bank. Exact contents depend on the // active `TransactionLogCollectorFilter` @@ -648,7 +656,7 @@ pub trait DropCallback: fmt::Debug { #[derive(Debug, Default)] pub struct OptionalDropCallback(Option>); -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl AbiExample for OptionalDropCallback { fn example() -> Self { Self(None) @@ -658,7 +666,8 @@ impl AbiExample for OptionalDropCallback { /// Manager for the state of all accounts and programs after processing its entries. /// AbiExample is needed even without Serialize/Deserialize; actual (de-)serialization /// are implemented elsewhere for versioning -#[derive(AbiExample, Debug)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] pub struct Bank { /// References to accounts, parent and signature status pub rc: BankRc, diff --git a/runtime/src/bank/builtins/prototypes.rs b/runtime/src/bank/builtins/prototypes.rs index 26ba8c59c79df5..813d948a3bd1e5 100644 --- a/runtime/src/bank/builtins/prototypes.rs +++ b/runtime/src/bank/builtins/prototypes.rs @@ -23,7 +23,7 @@ impl std::fmt::Debug for BuiltinPrototype { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::AbiExample for BuiltinPrototype { fn example() -> Self { // BuiltinPrototype isn't serializable by definition. diff --git a/runtime/src/bank/partitioned_epoch_rewards/mod.rs b/runtime/src/bank/partitioned_epoch_rewards/mod.rs index b626f0429c4cea..b87ee5f1e797ee 100644 --- a/runtime/src/bank/partitioned_epoch_rewards/mod.rs +++ b/runtime/src/bank/partitioned_epoch_rewards/mod.rs @@ -26,7 +26,8 @@ use { /// Distributing rewards to stake accounts begins AFTER this many blocks. const REWARD_CALCULATION_NUM_BLOCKS: u64 = 1; -#[derive(AbiExample, Debug, Serialize, Deserialize, Clone, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub(crate) struct PartitionedStakeReward { /// Stake account address pub stake_pubkey: Pubkey, @@ -54,7 +55,8 @@ impl PartitionedStakeReward { type PartitionedStakeRewards = Vec; -#[derive(AbiExample, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub(crate) struct StartBlockHeightAndRewards { /// the block height of the slot at which rewards distribution began pub(crate) distribution_starting_block_height: u64, @@ -63,7 +65,8 @@ pub(crate) struct StartBlockHeightAndRewards { } /// Represent whether bank is in the reward phase or not. -#[derive(AbiExample, AbiEnumVisitor, Debug, Clone, PartialEq, Serialize, Deserialize, Default)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] pub(crate) enum EpochRewardStatus { /// this bank is in the reward phase. /// Contents are the start point for epoch reward calculation, diff --git a/runtime/src/bank/serde_snapshot.rs b/runtime/src/bank/serde_snapshot.rs index 90399dca24feec..d973f13717eed1 100644 --- a/runtime/src/bank/serde_snapshot.rs +++ b/runtime/src/bank/serde_snapshot.rs @@ -549,8 +549,12 @@ mod tests { // This some what long test harness is required to freeze the ABI of // Bank's serialization due to versioned nature - #[frozen_abi(digest = "7Cze6NqwQMsqcEjtkMSQhLPykCW8dYffwkHpNuysjwTN")] - #[derive(Serialize, AbiExample)] + #[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "7Cze6NqwQMsqcEjtkMSQhLPykCW8dYffwkHpNuysjwTN") + )] + #[derive(Serialize)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper")] bank: Bank, diff --git a/runtime/src/epoch_stakes.rs b/runtime/src/epoch_stakes.rs index 1124906e2eb0cc..8ca7c1ba8ccf8f 100644 --- a/runtime/src/epoch_stakes.rs +++ b/runtime/src/epoch_stakes.rs @@ -9,13 +9,15 @@ use { pub type NodeIdToVoteAccounts = HashMap; pub type EpochAuthorizedVoters = HashMap; -#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, Eq)] pub struct NodeVoteAccounts { pub vote_accounts: Vec, pub total_stake: u64, } -#[derive(Clone, Debug, Serialize, Deserialize, AbiExample, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct EpochStakes { #[serde(with = "crate::stakes::serde_stakes_enum_compat")] stakes: Arc, diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index dd681045d24840..f71617b4343729 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -40,7 +40,8 @@ extern crate solana_metrics; #[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; // Don't make crates import the SVM if all they need is this module. diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 65da72edba9c6f..5611404219fdab 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -71,7 +71,8 @@ pub(crate) use { const MAX_STREAM_SIZE: u64 = 32 * 1024 * 1024 * 1024; -#[derive(Clone, Debug, Deserialize, Serialize, AbiExample, PartialEq, Eq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct AccountsDbFields( HashMap>, StoredMetaWriteVersion, @@ -93,7 +94,8 @@ pub struct AccountsDbFields( /// NOT be consistent with the bank's capitalization. It is not feasible to /// calculate a capitalization delta that is correct given just incremental /// slots account data and the full snapshot's capitalization. -#[derive(Serialize, Deserialize, AbiExample, Clone, Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)] pub struct BankIncrementalSnapshotPersistence { /// slot of full snapshot pub full_slot: Slot, @@ -107,14 +109,16 @@ pub struct BankIncrementalSnapshotPersistence { pub incremental_capitalization: u64, } -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] struct BankHashInfo { accounts_delta_hash: SerdeAccountsDeltaHash, accounts_hash: SerdeAccountsHash, stats: BankHashStats, } -#[derive(Default, Clone, PartialEq, Eq, Debug, Deserialize, Serialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] struct UnusedAccounts { unused1: HashSet, unused2: HashSet, @@ -279,7 +283,7 @@ impl<'a> From> for SerializableVersionedB } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl<'a> solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableVersionedBank<'a> {} /// Helper type to wrap BufReader streams when deserializing and reconstructing from either just a @@ -827,7 +831,7 @@ impl<'a> Serialize for SerializableAccountsDb<'a> { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl<'a> solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountsDb<'a> {} #[allow(clippy::too_many_arguments)] diff --git a/runtime/src/serde_snapshot/storage.rs b/runtime/src/serde_snapshot/storage.rs index da4bf1e4920f98..5b8bed48fa90b1 100644 --- a/runtime/src/serde_snapshot/storage.rs +++ b/runtime/src/serde_snapshot/storage.rs @@ -36,5 +36,5 @@ impl From<&AccountStorageEntry> for SerializableAccountStorageEntry { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl solana_frozen_abi::abi_example::IgnoreAsHelper for SerializableAccountStorageEntry {} diff --git a/runtime/src/serde_snapshot/utils.rs b/runtime/src/serde_snapshot/utils.rs index 1651d224401bd0..d12edd21222876 100644 --- a/runtime/src/serde_snapshot/utils.rs +++ b/runtime/src/serde_snapshot/utils.rs @@ -2,7 +2,7 @@ use serde::{ ser::{SerializeSeq, SerializeTuple}, Serialize, Serializer, }; -#[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] +#[cfg(all(test, RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] use solana_frozen_abi::abi_example::IgnoreAsHelper; // consumes an iterator and returns an object that will serialize as a serde seq @@ -17,7 +17,7 @@ where iter: std::cell::RefCell>, } - #[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] + #[cfg(all(test, RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl IgnoreAsHelper for SerializableSequencedIterator {} impl Serialize for SerializableSequencedIterator @@ -56,7 +56,7 @@ where iter: std::cell::RefCell>, } - #[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] + #[cfg(all(test, RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl IgnoreAsHelper for SerializableSequencedIterator {} impl Serialize for SerializableSequencedIterator @@ -95,7 +95,7 @@ where iter: std::cell::RefCell>, } - #[cfg(all(test, RUSTC_WITH_SPECIALIZATION))] + #[cfg(all(test, RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl IgnoreAsHelper for SerializableMappedIterator {} impl Serialize for SerializableMappedIterator diff --git a/runtime/src/stake_account.rs b/runtime/src/stake_account.rs index 7ee3c96c444045..ea4ed6dd0f624c 100644 --- a/runtime/src/stake_account.rs +++ b/runtime/src/stake_account.rs @@ -1,4 +1,4 @@ -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] use solana_frozen_abi::abi_example::AbiExample; use { solana_sdk::{ @@ -91,7 +91,7 @@ impl PartialEq> for StakeAccount { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl AbiExample for StakeAccount { fn example() -> Self { use solana_sdk::{ diff --git a/runtime/src/stake_history.rs b/runtime/src/stake_history.rs index 85a5a8c60a73ae..9c9a6cbd4a33a5 100644 --- a/runtime/src/stake_history.rs +++ b/runtime/src/stake_history.rs @@ -6,7 +6,8 @@ use std::{ }; /// The SDK's stake history with clone-on-write semantics -#[derive(Default, Clone, PartialEq, Eq, Debug, Deserialize, Serialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct StakeHistory(Arc); impl Deref for StakeHistory { diff --git a/runtime/src/stakes.rs b/runtime/src/stakes.rs index 263b2bea223313..15f816affd9801 100644 --- a/runtime/src/stakes.rs +++ b/runtime/src/stakes.rs @@ -50,7 +50,8 @@ pub enum InvalidCacheEntryReason { type StakeAccount = stake_account::StakeAccount; -#[derive(Default, Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Debug)] pub(crate) struct StakesCache(RwLock>); impl StakesCache { @@ -179,7 +180,8 @@ impl StakesCache { /// account and StakeStateV2 deserialized from the account. Doing so, will remove /// the need to load the stake account from accounts-db when working with /// stake-delegations. -#[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize)] pub struct Stakes { /// vote accounts vote_accounts: VoteAccounts, @@ -204,7 +206,8 @@ pub struct Stakes { // Below type allows EpochStakes to include either a Stakes or // Stakes and so bypass the conversion cost between the two at the // epoch boundary. -#[derive(Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] pub enum StakesEnum { Accounts(Stakes), Delegations(Stakes), diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 10c00b576f3ef6..52b43eeaaa25fc 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -34,7 +34,8 @@ type SlotDeltaMap = HashMap>; // construct a new one. Usually derived from a status cache's `SlotDeltaMap` pub type SlotDelta = (Slot, bool, Status); -#[derive(Clone, Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug)] pub struct StatusCache { cache: KeyStatusMap, roots: HashSet, diff --git a/scripts/coverage-in-disk.sh b/scripts/coverage-in-disk.sh index a6d8e34814130f..3279f7735017da 100755 --- a/scripts/coverage-in-disk.sh +++ b/scripts/coverage-in-disk.sh @@ -72,8 +72,8 @@ fi #shellcheck source=ci/common/limit-threads.sh source ci/common/limit-threads.sh -RUST_LOG=solana=trace _ "$cargo" nightly test --jobs "$JOBS" --target-dir target/cov --no-run "${packages[@]}" -if RUST_LOG=solana=trace _ "$cargo" nightly test --jobs "$JOBS" --target-dir target/cov "${packages[@]}" 2> target/cov/coverage-stderr.log; then +RUST_LOG=solana=trace _ "$cargo" nightly test --features frozen-abi --jobs "$JOBS" --target-dir target/cov --no-run "${packages[@]}" +if RUST_LOG=solana=trace _ "$cargo" nightly test --features frozen-abi --jobs "$JOBS" --target-dir target/cov "${packages[@]}" 2> target/cov/coverage-stderr.log; then test_status=0 else test_status=$? diff --git a/scripts/coverage.sh b/scripts/coverage.sh index a9875e553e5a2f..9fc43be5eba03b 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -57,7 +57,7 @@ TEST_ARGS=( # redirecting the stderr altogether on CI, where all tests are run unlike # developing. RUST_LOG="solana=trace,agave=trace,$RUST_LOG" INTERCEPT_OUTPUT=/dev/null "$here/../ci/intercept.sh" \ - cargo +"$rust_nightly" test --target-dir "$here/../target/cov" "${PACKAGES[@]}" -- "${TEST_ARGS[@]}" + cargo +"$rust_nightly" test --features frozen-abi --target-dir "$here/../target/cov" "${PACKAGES[@]}" -- "${TEST_ARGS[@]}" # Generate test reports echo "--- grcov" diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index f31b2d6d8c993a..f7395a4f0bafcd 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -36,6 +36,11 @@ full = [ dev-context-only-utils = [ "qualifier_attr" ] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program/frozen-abi", +] [dependencies] bincode = { workspace = true } @@ -72,8 +77,8 @@ serde_with = { workspace = true, features = ["macros"] } sha2 = { workspace = true } sha3 = { workspace = true, optional = true } siphasher = { 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-program = { workspace = true } solana-sdk-macro = { workspace = true } thiserror = { workspace = true } @@ -90,7 +95,6 @@ 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 } diff --git a/sdk/src/account.rs b/sdk/src/account.rs index 26355569a481f5..291b0bcb31f1c7 100644 --- a/sdk/src/account.rs +++ b/sdk/src/account.rs @@ -27,8 +27,12 @@ use { /// An Account with data that is stored on chain #[repr(C)] -#[frozen_abi(digest = "HawRVHh7t4d3H3bitWHFt25WhhoDmbJMCfWdESQQoYEy")] -#[derive(Deserialize, PartialEq, Eq, Clone, Default, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "HawRVHh7t4d3H3bitWHFt25WhhoDmbJMCfWdESQQoYEy") +)] +#[derive(Deserialize, PartialEq, Eq, Clone, Default)] #[serde(rename_all = "camelCase")] pub struct Account { /// lamports in the account @@ -51,8 +55,12 @@ mod account_serialize { serde::{ser::Serializer, Serialize}, }; #[repr(C)] - #[frozen_abi(digest = "HawRVHh7t4d3H3bitWHFt25WhhoDmbJMCfWdESQQoYEy")] - #[derive(Serialize, AbiExample)] + #[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "HawRVHh7t4d3H3bitWHFt25WhhoDmbJMCfWdESQQoYEy") + )] + #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct Account<'a> { lamports: u64, @@ -104,7 +112,8 @@ impl Serialize for AccountSharedData { /// An Account with data that is stored on chain /// This will be the in-memory representation of the 'Account' struct data. /// The existing 'Account' structure cannot easily change due to downstream projects. -#[derive(PartialEq, Eq, Clone, Default, AbiExample, Deserialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(PartialEq, Eq, Clone, Default, Deserialize)] #[serde(from = "Account")] pub struct AccountSharedData { /// lamports in the account diff --git a/sdk/src/compute_budget.rs b/sdk/src/compute_budget.rs index c903be13c21446..701fc587854138 100644 --- a/sdk/src/compute_budget.rs +++ b/sdk/src/compute_budget.rs @@ -10,18 +10,8 @@ use { crate::declare_id!("ComputeBudget111111111111111111111111111111"); /// Compute Budget Instructions -#[derive( - AbiExample, - AbiEnumVisitor, - BorshDeserialize, - BorshSerialize, - Clone, - Debug, - Deserialize, - PartialEq, - Eq, - Serialize, -)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub enum ComputeBudgetInstruction { Unused, // deprecated variant, reserved value. /// Request a specific transaction-wide program heap region size in bytes. diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index 2e0b286806afaf..7d9dc148a5869d 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -1039,7 +1039,8 @@ lazy_static! { } /// `FeatureSet` holds the set of currently active/inactive runtime features -#[derive(AbiExample, Debug, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct FeatureSet { pub active: HashMap, pub inactive: HashSet, diff --git a/sdk/src/fee.rs b/sdk/src/fee.rs index 80745cc2eaed71..5f44d62be5d61d 100644 --- a/sdk/src/fee.rs +++ b/sdk/src/fee.rs @@ -192,7 +192,7 @@ impl Default for FeeStructure { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for FeeStructure { fn example() -> Self { FeeStructure::default() diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index 05ba706a62d71a..c27793c5e20eec 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -41,7 +41,8 @@ pub const DEFAULT_GENESIS_DOWNLOAD_PATH: &str = "/genesis.tar.bz2"; pub const UNUSED_DEFAULT: u64 = 1024; // The order can't align with release lifecycle only to remain ABI-compatible... -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, AbiEnumVisitor, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] pub enum ClusterType { Testnet, MainnetBeta, @@ -83,8 +84,12 @@ impl FromStr for ClusterType { } } -#[frozen_abi(digest = "3V3ZVRyzNhRfe8RJwDeGpeTP8xBWGGFBEbwTkvKKVjEa")] -#[derive(Serialize, Deserialize, Debug, Clone, AbiExample, PartialEq)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "3V3ZVRyzNhRfe8RJwDeGpeTP8xBWGGFBEbwTkvKKVjEa") +)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig { /// when the network (bootstrap validator) was started relative to the UNIX Epoch pub creation_time: UnixTimestamp, diff --git a/sdk/src/hard_forks.rs b/sdk/src/hard_forks.rs index 61f7d7a0d3edcb..dda66a2949138d 100644 --- a/sdk/src/hard_forks.rs +++ b/sdk/src/hard_forks.rs @@ -8,7 +8,8 @@ use { solana_sdk::clock::Slot, }; -#[derive(Default, Clone, Debug, Deserialize, Serialize, AbiExample, PartialEq, Eq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Default, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct HardForks { hard_forks: Vec<(Slot, usize)>, } diff --git a/sdk/src/inflation.rs b/sdk/src/inflation.rs index 6392417ef5b3c1..b2fb0df610f88d 100644 --- a/sdk/src/inflation.rs +++ b/sdk/src/inflation.rs @@ -1,6 +1,7 @@ //! configuration for network inflation -#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, Copy, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, Copy)] #[serde(rename_all = "camelCase")] pub struct Inflation { /// Initial inflation percentage, from time=0 diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 6c18ea169b383e..fb6402dc2ac8e7 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -178,7 +178,8 @@ extern crate serde_derive; pub extern crate bs58; extern crate log as logger; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; #[cfg(test)] diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs index 661e8acee6855a..0f45dd4e6311c0 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -40,7 +40,8 @@ bitflags! { } } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[repr(C)] pub struct Meta { pub size: usize, @@ -49,17 +50,17 @@ pub struct Meta { pub flags: PacketFlags, } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for PacketFlags { fn example() -> Self { Self::empty() } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::IgnoreAsHelper for PacketFlags {} -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::EvenAsOpaque for PacketFlags { const TYPE_NAME_MATCHER: &'static str = "::_::InternalBitFlags"; } @@ -90,7 +91,8 @@ impl ::solana_frozen_abi::abi_example::EvenAsOpaque for PacketFlags { // ryoqun's dirty experiments: // https://github.com/ryoqun/serde-array-comparisons #[serde_as] -#[derive(Clone, Eq, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Eq, Serialize, Deserialize)] #[repr(C)] pub struct Packet { // Bytes past Packet.meta.size are not valid to read from. diff --git a/sdk/src/poh_config.rs b/sdk/src/poh_config.rs index 20176326cfe1af..8e3d12719ef8a9 100644 --- a/sdk/src/poh_config.rs +++ b/sdk/src/poh_config.rs @@ -5,7 +5,8 @@ use { std::time::Duration, }; -#[derive(Serialize, Deserialize, Clone, Debug, AbiExample, Eq, PartialEq)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] pub struct PohConfig { /// The target tick rate of the cluster. pub target_tick_duration: Duration, diff --git a/sdk/src/rent_collector.rs b/sdk/src/rent_collector.rs index 1dd8c4a0292bdb..96a7e479db76a6 100644 --- a/sdk/src/rent_collector.rs +++ b/sdk/src/rent_collector.rs @@ -11,7 +11,8 @@ use solana_sdk::{ rent::{Rent, RentDue}, }; -#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] pub struct RentCollector { pub epoch: Epoch, pub epoch_schedule: EpochSchedule, diff --git a/sdk/src/reserved_account_keys.rs b/sdk/src/reserved_account_keys.rs index 74386ed297f391..a1a1d367d18ffd 100644 --- a/sdk/src/reserved_account_keys.rs +++ b/sdk/src/reserved_account_keys.rs @@ -24,7 +24,7 @@ mod zk_token_proof_program { // ReservedAccountKeys is not serialized into or deserialized from bank // snapshots but the bank requires this trait to be implemented anyways. -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for ReservedAccountKeys { fn example() -> Self { // ReservedAccountKeys is not Serialize so just rely on Default. diff --git a/sdk/src/reward_info.rs b/sdk/src/reward_info.rs index b3b3d4a121c3ef..9153d7032da39e 100644 --- a/sdk/src/reward_info.rs +++ b/sdk/src/reward_info.rs @@ -1,6 +1,7 @@ use crate::reward_type::RewardType; -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample, Clone, Copy)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] pub struct RewardInfo { pub reward_type: RewardType, /// Reward amount diff --git a/sdk/src/reward_type.rs b/sdk/src/reward_type.rs index 84bddfcfb97a47..a0765e0b745f02 100644 --- a/sdk/src/reward_type.rs +++ b/sdk/src/reward_type.rs @@ -2,7 +2,8 @@ use std::fmt; -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample, AbiEnumVisitor, Clone, Copy)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] pub enum RewardType { Fee, Rent, diff --git a/sdk/src/signature.rs b/sdk/src/signature.rs index e3cc900e49efc1..158fa5ceeaf136 100644 --- a/sdk/src/signature.rs +++ b/sdk/src/signature.rs @@ -21,9 +21,8 @@ pub const SIGNATURE_BYTES: usize = 64; const MAX_BASE58_SIGNATURE_LEN: usize = 88; #[repr(transparent)] -#[derive( - Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash, AbiExample, -)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Signature(GenericArray); impl crate::sanitize::Sanitize for Signature {} diff --git a/sdk/src/transaction/error.rs b/sdk/src/transaction/error.rs index ffd4e70795e7a8..41d2d94348180c 100644 --- a/sdk/src/transaction/error.rs +++ b/sdk/src/transaction/error.rs @@ -9,9 +9,8 @@ use { }; /// Reasons a transaction might be rejected. -#[derive( - Error, Serialize, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample, AbiEnumVisitor, -)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] +#[derive(Error, Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum TransactionError { /// An account is already being processed in another transaction in a way /// that does not support parallelism diff --git a/sdk/src/transaction/mod.rs b/sdk/src/transaction/mod.rs index 00095510876b22..d9043cea83394e 100644 --- a/sdk/src/transaction/mod.rs +++ b/sdk/src/transaction/mod.rs @@ -168,8 +168,12 @@ pub type Result = result::Result; /// transaction's `Message` is both a signer and the expected fee-payer, then /// redundantly specifying the fee-payer is not strictly required. #[wasm_bindgen] -#[frozen_abi(digest = "FZtncnS1Xk8ghHfKiXE5oGiUbw2wJhmfXQuNgQR3K6Mc")] -#[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize, AbiExample)] +#[cfg_attr( + feature = "frozen-abi", + derive(AbiExample), + frozen_abi(digest = "FZtncnS1Xk8ghHfKiXE5oGiUbw2wJhmfXQuNgQR3K6Mc") +)] +#[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize)] pub struct Transaction { /// A set of signatures of a serialized [`Message`], signed by the first /// keys of the `Message`'s [`account_keys`], where the number of signatures diff --git a/sdk/src/transaction/versioned/mod.rs b/sdk/src/transaction/versioned/mod.rs index ea06037d030587..6c3376f8bf969c 100644 --- a/sdk/src/transaction/versioned/mod.rs +++ b/sdk/src/transaction/versioned/mod.rs @@ -47,7 +47,8 @@ impl TransactionVersion { // NOTE: Serialization-related changes must be paired with the direct read at sigverify. /// An atomic transaction -#[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize)] pub struct VersionedTransaction { /// List of signatures #[serde(with = "short_vec")] diff --git a/svm/Cargo.toml b/svm/Cargo.toml index 9d2f4557cbadc8..de85885948de65 100644 --- a/svm/Cargo.toml +++ b/svm/Cargo.toml @@ -16,8 +16,8 @@ percentage = { workspace = true } serde = { workspace = true, features = ["rc"] } serde_derive = { workspace = true } solana-bpf-loader-program = { 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-loader-v4-program = { workspace = true } solana-measure = { workspace = true } solana-metrics = { workspace = true } @@ -45,3 +45,9 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-program-runtime/frozen-abi", + "solana-sdk/frozen-abi", +] diff --git a/svm/src/lib.rs b/svm/src/lib.rs index dfafb84cff1909..f15a854354dd10 100644 --- a/svm/src/lib.rs +++ b/svm/src/lib.rs @@ -17,5 +17,6 @@ pub mod transaction_results; #[macro_use] extern crate solana_metrics; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; diff --git a/svm/src/message_processor.rs b/svm/src/message_processor.rs index f7ca5321a7a3ff..40c7c778282c89 100644 --- a/svm/src/message_processor.rs +++ b/svm/src/message_processor.rs @@ -18,7 +18,7 @@ use { #[derive(Debug, Default, Clone, serde_derive::Deserialize, serde_derive::Serialize)] pub struct MessageProcessor {} -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for MessageProcessor { fn example() -> Self { // MessageProcessor's fields are #[serde(skip)]-ed and not Serialize diff --git a/svm/src/runtime_config.rs b/svm/src/runtime_config.rs index 09d3c2ca1fdbfb..4c56c1b67b607d 100644 --- a/svm/src/runtime_config.rs +++ b/svm/src/runtime_config.rs @@ -1,6 +1,6 @@ use solana_program_runtime::compute_budget::ComputeBudget; -#[cfg(RUSTC_WITH_SPECIALIZATION)] +#[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] impl ::solana_frozen_abi::abi_example::AbiExample for RuntimeConfig { fn example() -> Self { // RuntimeConfig is not Serialize so just rely on Default. diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index 8f845028fedb95..9043ee9858d3c4 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -84,7 +84,7 @@ impl ExecutionRecordingConfig { } } -#[derive(AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] pub struct TransactionBatchProcessor { /// Bank slot (i.e. block) slot: Slot, diff --git a/test-abi.sh b/test-abi.sh index 5cda8446f89066..27cfb454336908 100755 --- a/test-abi.sh +++ b/test-abi.sh @@ -5,4 +5,4 @@ here=$(dirname "$0") set -x -exec "${here}/cargo" nightly test --lib -- test_abi_ --nocapture +exec "${here}/cargo" nightly test --features frozen-abi --lib -- test_abi_ --nocapture diff --git a/version/Cargo.toml b/version/Cargo.toml index 2b7e2eb2a5cc00..b4dfd0bc36017e 100644 --- a/version/Cargo.toml +++ b/version/Cargo.toml @@ -14,12 +14,17 @@ log = { workspace = true } semver = { workspace = true } serde = { workspace = true } serde_derive = { 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 = { workspace = true } [features] dummy-for-ci-check = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-sdk/frozen-abi", +] [lib] name = "solana_version" diff --git a/version/src/legacy.rs b/version/src/legacy.rs index 658ffd5e631526..4c9d7d3073f054 100644 --- a/version/src/legacy.rs +++ b/version/src/legacy.rs @@ -6,7 +6,8 @@ use { }; // Older version structure used earlier 1.3.x releases -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct LegacyVersion1 { major: u16, minor: u16, @@ -16,7 +17,8 @@ pub struct LegacyVersion1 { impl Sanitize for LegacyVersion1 {} -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct LegacyVersion2 { pub major: u16, pub minor: u16, diff --git a/version/src/lib.rs b/version/src/lib.rs index 8b818bd4b8fea1..f570188f1d12b0 100644 --- a/version/src/lib.rs +++ b/version/src/lib.rs @@ -7,7 +7,8 @@ use { solana_sdk::{sanitize::Sanitize, serde_varint}, std::{convert::TryInto, fmt}, }; -#[macro_use] +#[cfg_attr(feature = "frozen-abi", macro_use)] +#[cfg(feature = "frozen-abi")] extern crate solana_frozen_abi_macro; mod legacy; @@ -22,7 +23,8 @@ enum ClientId { Unknown(u16), } -#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct Version { #[serde(with = "serde_varint")] pub major: u16, diff --git a/vote/Cargo.toml b/vote/Cargo.toml index 221b21a617bbe9..9925e3ba03c901 100644 --- a/vote/Cargo.toml +++ b/vote/Cargo.toml @@ -15,8 +15,8 @@ itertools = { workspace = true } log = { workspace = true } serde = { workspace = true, features = ["rc"] } serde_derive = { 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 = { workspace = true } thiserror = { workspace = true } @@ -36,3 +36,8 @@ rustc_version = { workspace = true } [features] dev-context-only-utils = [] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", + "solana-sdk/frozen-abi", +] diff --git a/vote/src/lib.rs b/vote/src/lib.rs index a2271971d8900e..641c46b7b520d2 100644 --- a/vote/src/lib.rs +++ b/vote/src/lib.rs @@ -9,5 +9,6 @@ pub mod vote_transaction; #[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; diff --git a/vote/src/vote_account.rs b/vote/src/vote_account.rs index 1725dd987f3f0c..11df8c734d1c7b 100644 --- a/vote/src/vote_account.rs +++ b/vote/src/vote_account.rs @@ -16,7 +16,8 @@ use { thiserror::Error, }; -#[derive(Clone, Debug, PartialEq, AbiExample, Deserialize)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, PartialEq, Deserialize)] #[serde(try_from = "AccountSharedData")] pub struct VoteAccount(Arc); @@ -28,7 +29,8 @@ pub enum Error { InvalidOwner(/*owner:*/ Pubkey), } -#[derive(Debug, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Debug)] struct VoteAccountInner { account: AccountSharedData, vote_state: OnceLock>, @@ -36,7 +38,8 @@ struct VoteAccountInner { pub type VoteAccountsHashMap = HashMap; -#[derive(Clone, Debug, Deserialize, AbiExample)] +#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] +#[derive(Clone, Debug, Deserialize)] #[serde(from = "Arc")] pub struct VoteAccounts { vote_accounts: Arc,