Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GenericArray #2857

Merged
merged 10 commits into from
Nov 20, 2024
Merged
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
18 changes: 14 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ fs_extra = "1.3.0"
futures = "0.3.31"
futures-util = "0.3.29"
gag = "1.0.0"
generic-array = { version = "0.14.7", default-features = false }
gethostname = "0.2.3"
getrandom = "0.2.10"
goauth = "0.13.1"
Expand Down Expand Up @@ -385,6 +384,7 @@ scopeguard = "1.2.0"
semver = "1.0.23"
seqlock = "0.2.0"
serde = "1.0.215" # must match the serde_derive version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde-big-array = "0.5.1"
serde_bytes = "0.11.15"
serde_derive = "1.0.215" # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_json = "1.0.132"
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower1_7_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Tower1_7_14 {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "2ngfAgnN19JwF6FnFYPYp2aHQiZnnjzaYP1vSRMRiSaq")
frozen_abi(digest = "2bgXEjDjQqkHrXtffNA6jusFLNt4rJBMVEsRctYABnn1")
)]
#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct SavedTower1_7_14 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl From<SavedTower1_7_14> for SavedTowerVersions {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "JBXfVQ6BXHBGSNY919yEkXN4H7XxmAMA7QcGrf7DiWHP")
frozen_abi(digest = "2XiuhmDfRzWGdwZdMbpH5NcjGnTRi9zY1XTNHSknddA7")
)]
#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct SavedTower {
Expand Down
6 changes: 3 additions & 3 deletions core/src/repair/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl AncestorHashesRepairType {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "9SdneX58ekpqLJBzUwfwJsK2fZc9mN4vTcaS4temEjkP")
frozen_abi(digest = "GPS6e6pgUdbXLwXN6XHTqrUVMwAL2YKLPDawgMi5hHzi")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum AncestorHashesResponse {
Expand Down Expand Up @@ -225,7 +225,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "3E2R8jiSt9QfVHdX3MgW3UdeNWfor7zNjJcLJLz2K1JY")
frozen_abi(digest = "9KN64WUT7XDYj9zZopS1hztGyAP9y4N4QznsyC4mqsGs")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum RepairProtocol {
Expand Down Expand Up @@ -273,7 +273,7 @@ fn discard_malformed_repair_requests(
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "CpKVYghdpMDRMiGjZpa71dcnB7rCVHLVogZbB3AGDKAK")
frozen_abi(digest = "9A6ae44qpdT7PaxiDZbybMM2mewnSnPs3C4CxhpbbYuV")
)]
#[derive(Debug, Deserialize, Serialize)]
pub(crate) enum RepairResponse {
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) const PULL_RESPONSE_MIN_SERIALIZED_SIZE: usize = 161;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "DBz7mUjknfMiea98WMx9b5jYyT9X9bmQV2JxmMN1VggR")
frozen_abi(digest = "D8HvpYCkdo6JweUW61WQ9ZQH2AFvzh3G1qthicnvz4E8")
)]
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down
12 changes: 10 additions & 2 deletions programs/sbf/Cargo.lock

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

4 changes: 0 additions & 4 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ chrono = { workspace = true, features = ["alloc"], optional = true }
curve25519-dalek = { workspace = true, optional = true }
digest = { workspace = true, optional = true }
ed25519-dalek = { workspace = true, optional = true }
generic-array = { workspace = true, features = [
"serde",
"more_lengths",
], optional = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
libsecp256k1 = { workspace = true, optional = true, features = ["hmac"] }
Expand Down
1 change: 0 additions & 1 deletion sdk/frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ solana-frozen-abi-macro = { workspace = true }
thiserror = { workspace = true }

[target.'cfg(not(target_os = "solana"))'.dependencies]
generic-array = { workspace = true, features = ["serde", "more_lengths"] }
im = { workspace = true, features = ["rayon", "serde"] }
memmap2 = { workspace = true }

Expand Down
9 changes: 0 additions & 9 deletions sdk/frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,6 @@ atomic_example_impls! { AtomicI64 }
atomic_example_impls! { AtomicIsize }
atomic_example_impls! { AtomicBool }

#[cfg(not(target_os = "solana"))]
use generic_array::{ArrayLength, GenericArray};
#[cfg(not(target_os = "solana"))]
impl<T: Default, U: ArrayLength<T>> AbiExample for GenericArray<T, U> {
fn example() -> Self {
Self::default()
}
}

use bv::{BitVec, BlockType};
impl<T: BlockType> AbiExample for BitVec<T> {
fn example() -> Self {
Expand Down
9 changes: 7 additions & 2 deletions sdk/signature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ edition = { workspace = true }
[dependencies]
bs58 = { workspace = true }
ed25519-dalek = { workspace = true, optional = true }
generic-array = { workspace = true, features = ["more_lengths"] }
rand = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde-big-array = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
Expand All @@ -25,9 +25,14 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [
solana-sanitize = { workspace = true }

[dev-dependencies]
bincode = { workspace = true }
curve25519-dalek = { workspace = true }
ed25519-dalek = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-program = { workspace = true }
solana-short-vec = { workspace = true }
solana-signature = { path = ".", features = ["serde"] }

[features]
default = ["std"]
Expand All @@ -37,7 +42,7 @@ frozen-abi = [
"std"
]
rand = ["dep:rand"]
serde = ["dep:serde", "dep:serde_derive", "generic-array/serde"]
serde = ["dep:serde", "dep:serde_derive", "dep:serde-big-array"]
std = []
verify = ["dep:ed25519-dalek"]

Expand Down
72 changes: 59 additions & 13 deletions sdk/signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
#[cfg(any(test, feature = "verify"))]
use core::convert::TryInto;
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
use {
core::{
fmt,
str::{from_utf8, FromStr},
},
generic_array::{typenum::U64, GenericArray},
use core::{
fmt,
str::{from_utf8, FromStr},
};
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
use std::{error::Error, vec::Vec};
#[cfg(feature = "serde")]
use {
serde_big_array::BigArray,
serde_derive::{Deserialize, Serialize},
};

/// Number of bytes in a signature
pub const SIGNATURE_BYTES: usize = 64;
Expand All @@ -25,9 +25,17 @@ const MAX_BASE58_SIGNATURE_LEN: usize = 88;

#[repr(transparent)]
#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Signature(GenericArray<u8, U64>);
pub struct Signature(
#[cfg_attr(feature = "serde", serde(with = "BigArray"))] [u8; SIGNATURE_BYTES],
);

impl Default for Signature {
fn default() -> Self {
Self([0u8; 64])
}
}

impl solana_sanitize::Sanitize for Signature {}

Expand Down Expand Up @@ -85,14 +93,14 @@ impl fmt::Display for Signature {

impl From<Signature> for [u8; 64] {
fn from(signature: Signature) -> Self {
signature.0.into()
signature.0
}
}

impl From<[u8; SIGNATURE_BYTES]> for Signature {
#[inline]
fn from(signature: [u8; SIGNATURE_BYTES]) -> Self {
Self(GenericArray::from(signature))
Self(signature)
}
}

Expand Down Expand Up @@ -156,7 +164,11 @@ impl FromStr for Signature {

#[cfg(test)]
mod tests {
use {super::*, solana_program::pubkey::Pubkey};
use {
super::*,
serde_derive::{Deserialize, Serialize},
solana_program::pubkey::Pubkey,
};

#[test]
fn test_off_curve_pubkey_verify_fails() {
Expand All @@ -178,4 +190,38 @@ mod tests {
// can do is `is_err()` here.
assert!(signature.verify_verbose(pubkey.as_ref(), &[0u8]).is_err());
}

#[test]
fn test_short_vec() {
#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct SigShortVec {
#[serde(with = "solana_short_vec")]
pub signatures: Vec<Signature>,
}
let sig = Signature::from([
120, 138, 162, 185, 59, 209, 241, 157, 71, 157, 74, 131, 4, 87, 54, 28, 38, 180, 222,
82, 64, 62, 61, 62, 22, 46, 17, 203, 187, 136, 62, 43, 11, 38, 235, 17, 239, 82, 240,
139, 130, 217, 227, 214, 9, 242, 141, 223, 94, 29, 184, 110, 62, 32, 87, 137, 63, 139,
100, 221, 20, 137, 4, 5,
]);
let to_serialize = SigShortVec {
signatures: std::vec![sig],
};
let json_serialized = serde_json::to_string(&to_serialize).unwrap();
assert_eq!(json_serialized, "{\"signatures\":[[1],[120,138,162,185,59,209,241,157,71,157,74,131,4,87,54,28,38,180,222,82,64,62,61,62,22,46,17,203,187,136,62,43,11,38,235,17,239,82,240,139,130,217,227,214,9,242,141,223,94,29,184,110,62,32,87,137,63,139,100,221,20,137,4,5]]}");
let json_deserialized: SigShortVec = serde_json::from_str(&json_serialized).unwrap();
assert_eq!(json_deserialized, to_serialize);
let bincode_serialized = bincode::serialize(&to_serialize).unwrap();
assert_eq!(
bincode_serialized,
[
1, 120, 138, 162, 185, 59, 209, 241, 157, 71, 157, 74, 131, 4, 87, 54, 28, 38, 180,
222, 82, 64, 62, 61, 62, 22, 46, 17, 203, 187, 136, 62, 43, 11, 38, 235, 17, 239,
82, 240, 139, 130, 217, 227, 214, 9, 242, 141, 223, 94, 29, 184, 110, 62, 32, 87,
137, 63, 139, 100, 221, 20, 137, 4, 5
]
);
let bincode_deserialized: SigShortVec = bincode::deserialize(&bincode_serialized).unwrap();
assert_eq!(bincode_deserialized, to_serialize);
}
}
2 changes: 1 addition & 1 deletion sdk/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub type Result<T> = result::Result<T, TransactionError>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "686AAhRhjXpqKidmJEdHHcJCL9XxCxebu8Xmku9shp83")
frozen_abi(digest = "GESn6AYYNhpNfzJXdQ6kGjqz4VjpMw3ye9rghqaEqks7")
)]
#[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize)]
pub struct Transaction {
Expand Down
Loading