Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

24 changes: 21 additions & 3 deletions account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use qualifier_attr::qualifiers;
#[cfg(feature = "serde")]
use serde::ser::{Serialize, Serializer};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
#[cfg(feature = "bincode")]
use solana_sysvar::SysvarSerialize;
use {
Expand All @@ -32,8 +32,11 @@ pub mod state_traits;
#[repr(C)]
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "62EqVoynUFvuui7DVfqWCvZP7bxKGJGioeSBnWrdjRME")
derive(AbiExample, StableAbi),
frozen_abi(
api_digest = "62EqVoynUFvuui7DVfqWCvZP7bxKGJGioeSBnWrdjRME",
abi_digest = "Cms628BvHUgXEPDU1qV6sAXNr875LnMAMLskNohMngu"
)
)]
#[cfg_attr(
feature = "serde",
Expand All @@ -55,6 +58,21 @@ pub struct Account {
pub rent_epoch: Epoch,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<Account>
for solana_frozen_abi::rand::distributions::Standard
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Account {
Account {
lamports: rng.r#gen(),
data: (0..1000).map(|_| rng.r#gen()).collect(),
owner: Pubkey::new_from_array(rng.r#gen()),
executable: rng.r#gen(),
rent_epoch: rng.r#gen(),
}
}
}

// mod because we need 'Account' below to have the name 'Account' to match expected serialization
#[cfg(feature = "serde")]
mod account_serialize {
Expand Down
6 changes: 3 additions & 3 deletions frozen-abi-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ fn quote_for_test(
quote! {
#[test]
fn test_abi_digest() {
use ::rand::{SeedableRng, RngCore};
use ::rand_chacha::ChaCha8Rng;
use ::bincode;
use ::solana_frozen_abi::rand::{SeedableRng, RngCore};
use ::solana_frozen_abi::rand_chacha::ChaCha8Rng;
use ::solana_frozen_abi::bincode;
use ::solana_frozen_abi::stable_abi::StableAbi;

let mut rng = ChaCha8Rng::seed_from_u64(20666175621446498);
Expand Down
7 changes: 6 additions & 1 deletion frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ solana-frozen-abi-macro = { workspace = true }
thiserror = { workspace = true }

[target.'cfg(not(target_os = "solana"))'.dependencies]
# This dependency is used only to back `frozen-abi` StableAbi API
bincode = "1.3.3"
im = { workspace = true, features = ["rayon", "serde"] }
memmap2 = { workspace = true }
rand = { workspace = true }
# These dependencies are used only to back `frozen-abi` StableAbi API,
# to avoid version skew and keep digest computation stable regardless of consumer dependencies.
rand = "0.8.5"
rand_chacha = "0.3.1"

[target.'cfg(not(target_os = "solana"))'.dev-dependencies]
bitflags = { workspace = true, features = ["serde"] }
Expand Down
10 changes: 10 additions & 0 deletions frozen-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ pub mod stable_abi;
#[macro_use]
extern crate solana_frozen_abi_macro;

#[cfg(feature = "frozen-abi")]
#[cfg(not(target_os = "solana"))]
pub use bincode;
#[cfg(feature = "frozen-abi")]
#[cfg(not(target_os = "solana"))]
pub use rand;
#[cfg(feature = "frozen-abi")]
#[cfg(not(target_os = "solana"))]
pub use rand_chacha;

// Not public API. Previously referenced by macro-generated code. Remove the
// `log` dependency from Cargo.toml when this is cleaned up in the next major
// version bump
Expand Down
2 changes: 1 addition & 1 deletion frozen-abi/src/stable_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub trait StableAbi: Sized {
where
Standard: rand::distributions::Distribution<Self>,
{
rng.gen::<Self>()
rng.r#gen::<Self>()
}
}