Skip to content

Commit

Permalink
Make solana-frozen-abi optional in all remaining crates (#1278)
Browse files Browse the repository at this point in the history
* put most AbiExample derivations behind a cfg_attr

* feature gate all `extern crate solana_frozen_abi_macro;`

* use cfg_attr wherever we were deriving both AbiExample and AbiEnumVisitor

* fix cases where AbiEnumVisitor was still being derived unconditionally

* fix a case where AbiExample was derived unconditionally

* fix more cases where both AbiEnumVisitor and AbiExample were derived unconditionally

* two more cases where AbiExample and AbiEnumVisitor were unconditionally derived

* fix remaining unconditional derivations of AbiEnumVisitor

* fix cases where AbiExample is the first thing derived

* fix most remaining unconditional derivations of AbiExample

* move all `frozen_abi(digest =` behind cfg_attr

* replace incorrect cfg with cfg_attr

* fix one more unconditionally derived AbiExample

* feature gate AbiExample impls

* add frozen-abi feature to required Cargo.toml files

* make frozen-abi features activate recursively

* fmt

* add missing feature gating

* fix accidentally changed digest

* activate frozen-abi in relevant test scripts

* don't activate solana-program's frozen-abi in sdk dev-dependencies

* update to handle AbiExample derivation on new AppendVecFileBacking enum

* revert toml formatting

* remove unused frozen-abi entries from address-lookup-table Cargo.toml

* remove toml references to solana-address-lookup-table-program/frozen-abi

* update lock file

* remove no-longer-used generic param
  • Loading branch information
kevinheavey authored May 17, 2024
1 parent 20ee70c commit cadba68
Show file tree
Hide file tree
Showing 103 changed files with 499 additions and 292 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion accounts-db/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pubkey>,
readonly_locks: HashMap<Pubkey, u64>,
Expand Down Expand Up @@ -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<AccountsDb>,
Expand Down
5 changes: 3 additions & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,8 @@ pub fn get_temp_accounts_paths(count: u32) -> IoResult<(Vec<TempDir>, Vec<PathBu
Ok((temp_dirs, paths))
}

#[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 BankHashStats {
pub num_updated_accounts: u64,
pub num_removed_accounts: u64,
Expand Down Expand Up @@ -2231,7 +2232,7 @@ pub fn make_min_priority_thread_pool() -> 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();
Expand Down
12 changes: 8 additions & 4 deletions accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SerdeAccountsDeltaHash> for AccountsDeltaHash {
Expand All @@ -1288,7 +1290,8 @@ impl From<AccountsDeltaHash> 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<SerdeAccountsHash> for AccountsHash {
Expand All @@ -1303,7 +1306,8 @@ impl From<AccountsHash> 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<SerdeIncrementalAccountsHash> for IncrementalAccountsHash {
Expand Down
3 changes: 2 additions & 1 deletion accounts-db/src/ancestors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use {

pub type AncestorsForSerialization = HashMap<Slot, usize>;

#[derive(Clone, PartialEq, AbiExample)]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Clone, PartialEq)]
pub struct Ancestors {
ancestors: RollingBitField,
}
Expand Down
6 changes: 4 additions & 2 deletions accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions accounts-db/src/blockhash_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ 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,
timestamp: u64,
}

/// 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,
Expand Down
3 changes: 2 additions & 1 deletion accounts-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion accounts-db/src/rolling_bit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion accounts-db/src/stake_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions bloom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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",
]
3 changes: 2 additions & 1 deletion bloom/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: BloomHashIndex> {
pub keys: Vec<u64>,
pub bits: BitVec<u64>,
Expand Down
3 changes: 2 additions & 1 deletion bloom/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 18 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 10 additions & 4 deletions core/src/banking_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@ pub struct BankingTracer {
active_tracer: Option<ActiveTracer>,
}

#[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,
Expand Down
14 changes: 10 additions & 4 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions core/src/consensus/tower1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions core/src/consensus/tower1_7_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<u8>,
Expand Down
Loading

0 comments on commit cadba68

Please sign in to comment.