Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Enable frozen_abi on banking trace file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Oct 3, 2023
1 parent 3eae980 commit 5674ff1
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 28 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions core/src/banking_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ pub struct BankingTracer {
active_tracer: Option<ActiveTracer>,
}

#[derive(Serialize, Deserialize, Debug)]
#[frozen_abi(digest = "Eq6YrAFtTbtPrCEvh6Et1mZZDCARUg1gcK2qiZdqyjUz")]
#[derive(Serialize, Deserialize, Debug, AbiExample)]
pub struct TimedTracedEvent(pub std::time::SystemTime, pub TracedEvent);

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, AbiExample, AbiEnumVisitor)]
pub enum TracedEvent {
PacketBatch(ChannelLabel, BankingPacketBatch),
BlockAndBankHash(Slot, Hash, Hash),
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, AbiExample, AbiEnumVisitor)]
pub enum ChannelLabel {
NonVote,
TpuVote,
Expand Down
2 changes: 1 addition & 1 deletion core/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
solana_sdk::{packet::Packet, saturating_add_assign},
};

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
pub struct SigverifyTracerPacketStats {
pub total_removed_before_sigverify_stage: usize,
pub total_tracer_packets_received_in_sigverify_stage: usize,
Expand Down
40 changes: 20 additions & 20 deletions frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
lazy_static::lazy_static,
log::*,
serde::Serialize,
std::any::type_name,
std::{any::type_name, marker::Copy},
};

pub trait AbiExample: Sized {
Expand Down Expand Up @@ -137,25 +137,12 @@ tuple_example_impls! {
}
}

// Source: https://github.com/rust-lang/rust/blob/ba18875557aabffe386a2534a1aa6118efb6ab88/src/libcore/array/mod.rs#L417
macro_rules! array_example_impls {
{$n:expr, $t:ident $($ts:ident)*} => {
impl<T> AbiExample for [T; $n] where T: AbiExample {
fn example() -> Self {
[$t::example(), $($ts::example()),*]
}
}
array_example_impls!{($n - 1), $($ts)*}
};
{$n:expr,} => {
impl<T> AbiExample for [T; $n] {
fn example() -> Self { [] }
}
};
impl<const N: usize, T: AbiExample + Copy> AbiExample for [T; N] {
fn example() -> Self {
[T::example(); N]
}
}

array_example_impls! {32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T}

// Source: https://github.com/rust-lang/rust/blob/ba18875557aabffe386a2534a1aa6118efb6ab88/src/libcore/default.rs#L137
macro_rules! example_impls {
($t:ty, $v:expr) => {
Expand Down Expand Up @@ -329,6 +316,13 @@ impl<T: AbiExample> AbiExample for std::sync::Arc<T> {
}
}

impl<T: AbiExample> AbiExample for std::sync::Weak<T> {
fn example() -> Self {
info!("AbiExample for (Arc<T>): {}", type_name::<Self>());
std::sync::Arc::downgrade(&std::sync::Arc::new(T::example()))
}
}

impl<T: AbiExample> AbiExample for std::rc::Rc<T> {
fn example() -> Self {
info!("AbiExample for (Rc<T>): {}", type_name::<Self>());
Expand Down Expand Up @@ -457,6 +451,13 @@ impl AbiExample for std::path::PathBuf {
}
}

#[cfg(not(target_os = "solana"))]
impl AbiExample for std::time::SystemTime {
fn example() -> Self {
std::time::SystemTime::now()
}
}

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
impl AbiExample for SocketAddr {
fn example() -> Self {
Expand Down Expand Up @@ -490,8 +491,7 @@ impl<T: Serialize + ?Sized> AbiEnumVisitor for T {
impl<T: Serialize + ?Sized + AbiExample> AbiEnumVisitor for T {
default fn visit_for_abi(&self, digester: &mut AbiDigester) -> DigestResult {
info!("AbiEnumVisitor for (default): {}", type_name::<T>());
T::example()
.serialize(digester.create_new())
self.serialize(digester.create_new())
.map_err(DigestError::wrap_by_type::<T>)
}
}
Expand Down
5 changes: 5 additions & 0 deletions perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ solana-metrics = { workspace = true }
solana-rayon-threadlimit = { workspace = true }
solana-sdk = { workspace = true }
solana-vote-program = { workspace = true }
solana-frozen-abi = { workspace = true }
solana-frozen-abi-macro = { workspace = true }

[target."cfg(target_os = \"linux\")".dependencies]
caps = { workspace = true }
Expand All @@ -40,6 +42,9 @@ rand_chacha = { workspace = true }
solana-logger = { workspace = true }
test-case = { workspace = true }

[build-dependencies]
rustc_version = { workspace = true }

[[bench]]
name = "sigverify"

Expand Down
26 changes: 26 additions & 0 deletions perf/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel};

fn main() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
Expand All @@ -8,4 +11,27 @@ fn main() {
println!("cargo:rustc-cfg=build_target_feature_avx2");
}
}

// Copied and adapted from
// https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example
// Licensed under Apache-2.0 + MIT
match version_meta().unwrap().channel {
Channel::Stable => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Beta => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Nightly => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
}
Channel::Dev => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
// See https://github.com/solana-labs/solana/issues/11055
// We may be running the custom `rust-bpf-builder` toolchain,
// which currently needs `#![feature(proc_macro_hygiene)]` to
// be applied.
println!("cargo:rustc-cfg=RUSTC_NEEDS_PROC_MACRO_HYGIENE");
}
}
}
2 changes: 1 addition & 1 deletion perf/src/cuda_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn unpin<T>(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)]
#[derive(Debug, Default, Serialize, Deserialize, AbiExample)]
pub struct PinnedVec<T: Default + Clone + Sized> {
x: Vec<T>,
pinned: bool,
Expand Down
4 changes: 4 additions & 0 deletions perf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(min_specialization))]
pub mod cuda_runtime;
pub mod data_budget;
pub mod deduper;
Expand All @@ -23,6 +24,9 @@ extern crate assert_matches;
#[macro_use]
extern crate solana_metrics;

#[macro_use]
extern crate solana_frozen_abi_macro;

fn is_rosetta_emulated() -> bool {
#[cfg(target_os = "macos")]
{
Expand Down
2 changes: 1 addition & 1 deletion perf/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, AbiExample)]
pub struct PacketBatch {
packets: PinnedVec<Packet>,
}
Expand Down
9 changes: 9 additions & 0 deletions perf/src/recycler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ impl<T: Default> Default for RecyclerX<T> {
}
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl solana_frozen_abi::abi_example::AbiExample
for RecyclerX<crate::cuda_runtime::PinnedVec<solana_sdk::packet::Packet>>
{
fn example() -> Self {
Self::default()
}
}

pub trait Reset {
fn reset(&mut self);
fn warm(&mut self, size_hint: usize);
Expand Down
3 changes: 3 additions & 0 deletions programs/sbf/Cargo.lock

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

11 changes: 9 additions & 2 deletions sdk/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bitflags! {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
#[repr(C)]
pub struct Meta {
pub size: usize,
Expand All @@ -45,6 +45,13 @@ pub struct Meta {
pub flags: PacketFlags,
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl ::solana_frozen_abi::abi_example::AbiExample for PacketFlags {
fn example() -> Self {
Self::empty()
}
}

// serde_as is used as a work around because array isn't supported by serde
// (and serde_bytes).
//
Expand All @@ -71,7 +78,7 @@ pub struct Meta {
// ryoqun's dirty experiments:
// https://github.com/ryoqun/serde-array-comparisons
#[serde_as]
#[derive(Clone, Eq, Serialize, Deserialize)]
#[derive(Clone, Eq, Serialize, Deserialize, AbiExample)]
#[repr(C)]
pub struct Packet {
// Bytes past Packet.meta.size are not valid to read from.
Expand Down

0 comments on commit 5674ff1

Please sign in to comment.