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.

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>()
}
}
4 changes: 2 additions & 2 deletions scripts/test-frozen-abi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ here="$(dirname "$0")"
src_root="$(readlink -f "${here}/..")"
cd "${src_root}"

./cargo nightly hack --features frozen-abi --ignore-unknown-features test --lib -- test_abi_digest --nocapture
./cargo nightly hack --features frozen-abi --ignore-unknown-features test --lib -- test_api_digest --nocapture
./cargo nightly test --features frozen-abi --lib -- test_abi_digest --nocapture
./cargo nightly test --features frozen-abi --lib -- test_api_digest --nocapture
41 changes: 39 additions & 2 deletions transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
//! # Ok::<(), anyhow::Error>(())
//! ```

#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};

#[cfg(feature = "serde")]
use {
serde_derive::{Deserialize, Serialize},
Expand Down Expand Up @@ -176,8 +179,11 @@ const NONCED_TX_MARKER_IX_INDEX: u8 = 0;
/// redundantly specifying the fee-payer is not strictly required.
#[cfg_attr(
feature = "frozen-abi",
derive(solana_frozen_abi_macro::AbiExample),
solana_frozen_abi_macro::frozen_abi(digest = "BLig4G2ysd7dcensK9bhKtnKvCQc1n65XdanyzsdWGXN")
derive(AbiExample, StableAbi),
frozen_abi(
api_digest = "BLig4G2ysd7dcensK9bhKtnKvCQc1n65XdanyzsdWGXN",
abi_digest = "BrQZ2jZhf9FDME3M3yNdhDBga8bHuLiAwWvZRvGwFrGh"
)
)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug, PartialEq, Default, Eq, Clone)]
Expand All @@ -198,6 +204,37 @@ pub struct Transaction {
pub message: Message,
}

#[cfg(feature = "frozen-abi")]
impl solana_frozen_abi::rand::prelude::Distribution<Transaction>
for solana_frozen_abi::rand::distributions::Standard
{
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Transaction {
let signatures: Vec<Signature> = (0..rng.r#gen_range(1..100))
.map(|_| Signature::from(std::array::from_fn(|_| rng.r#gen::<u8>())))
.collect();
let accounts: Vec<AccountMeta> = (0..rng.r#gen_range(1..100))
.map(|_| AccountMeta {
pubkey: Address::new_from_array(rng.r#gen()),
is_signer: rng.r#gen(),
is_writable: rng.r#gen(),
})
.collect();
let data: Vec<u8> = (0..rng.r#gen_range(1..1000)).map(|_| rng.r#gen()).collect();
let instructions: Vec<Instruction> = (0..rng.r#gen_range(1..100))
.map(|_| Instruction {
program_id: Address::new_from_array(rng.r#gen()),
accounts: accounts.clone(),
data: data.clone(),
})
.collect();

Transaction {
signatures,
message: Message::new(&instructions, Some(&Address::new_from_array(rng.r#gen()))),
}
}
}

impl Sanitize for Transaction {
fn sanitize(&self) -> result::Result<(), SanitizeError> {
if self.message.header.num_required_signatures as usize > self.signatures.len() {
Expand Down