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 frozen ABI modules from solana-sdk #13008

Merged
merged 1 commit into from
Oct 20, 2020
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
60 changes: 42 additions & 18 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"dos",
"download-utils",
"faucet",
"frozen-abi",
"perf",
"validator",
"genesis",
Expand Down
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ solana-net-utils = { path = "../net-utils", version = "1.5.0" }
solana-perf = { path = "../perf", version = "1.5.0" }
solana-runtime = { path = "../runtime", version = "1.5.0" }
solana-sdk = { path = "../sdk", version = "1.5.0" }
solana-sdk-macro-frozen-abi = { path = "../sdk/macro-frozen-abi", version = "1.5.0" }
solana-frozen-abi = { path = "../frozen-abi", version = "1.5.0" }
solana-frozen-abi-macro = { path = "../frozen-abi/macro", version = "1.5.0" }
solana-stake-program = { path = "../programs/stake", version = "1.5.0" }
solana-storage-bigtable = { path = "../storage-bigtable", version = "1.5.0" }
solana-streamer = { path = "../streamer", version = "1.5.0" }
Expand Down
2 changes: 1 addition & 1 deletion core/build.rs
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern crate serde_json;
extern crate solana_metrics;

#[macro_use]
extern crate solana_sdk_macro_frozen_abi;
extern crate solana_frozen_abi_macro;

#[cfg(test)]
#[macro_use]
Expand Down
27 changes: 27 additions & 0 deletions frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "solana-frozen-abi"
version = "1.5.0"
description = "Solana Frozen ABI"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
homepage = "https://solana.com/"
license = "Apache-2.0"
edition = "2018"

[dependencies]
bs58 = "0.3.1"
bv = { version = "0.11.1", features = ["serde"] }
log = "0.4.8"
serde = "1.0.112"
serde_derive = "1.0.103"
sha2 = "0.8.2"
solana-frozen-abi-macro = { path = "macro", version = "1.5.0" }
thiserror = "1.0"

[target.'cfg(not(target_arch = "bpf"))'.dependencies]
solana-logger = { path = "../logger", version = "1.5.0" }
generic-array = { version = "0.14.3", default-features = false, features = ["serde", "more_lengths"]}
memmap = "0.7.0"

[build-dependencies]
rustc_version = "0.2"
27 changes: 27 additions & 0 deletions frozen-abi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel};

fn main() {
// 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");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "solana-sdk-macro-frozen-abi"
name = "solana-frozen-abi-macro"
version = "1.5.0"
description = "Solana SDK Macro frozen abi"
description = "Solana Frozen ABI Macro"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
homepage = "https://solana.com/"
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions sdk/macro-frozen-abi/src/lib.rs → frozen-abi/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn derive_abi_sample_enum_type(input: ItemEnum) -> TokenStream {
#injection
#[automatically_derived]
#( #attrs )*
impl #impl_generics ::solana_sdk::abi_example::AbiExample for #type_name #ty_generics #where_clause {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause {
fn example() -> Self {
::log::info!(
"AbiExample for enum: {}",
Expand Down Expand Up @@ -221,13 +221,13 @@ fn derive_abi_sample_struct_type(input: ItemStruct) -> TokenStream {
#injection
#[automatically_derived]
#( #attrs )*
impl #impl_generics ::solana_sdk::abi_example::AbiExample for #type_name #ty_generics #where_clause {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause {
fn example() -> Self {
::log::info!(
"AbiExample for struct: {}",
std::any::type_name::<#type_name #ty_generics>()
);
use ::solana_sdk::abi_example::AbiExample;
use ::solana_frozen_abi::abi_example::AbiExample;

#type_name #turbofish #sample_fields
}
Expand Down Expand Up @@ -272,11 +272,11 @@ fn do_derive_abi_enum_visitor(input: ItemEnum) -> TokenStream {

let type_str = format!("{}", type_name);
(quote! {
impl #impl_generics ::solana_sdk::abi_example::AbiEnumVisitor for #type_name #ty_generics #where_clause {
fn visit_for_abi(&self, digester: &mut ::solana_sdk::abi_digester::AbiDigester) -> ::solana_sdk::abi_digester::DigestResult {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiEnumVisitor for #type_name #ty_generics #where_clause {
fn visit_for_abi(&self, digester: &mut ::solana_frozen_abi::abi_digester::AbiDigester) -> ::solana_frozen_abi::abi_digester::DigestResult {
let enum_name = #type_str;
use ::serde::ser::Serialize;
use ::solana_sdk::abi_example::AbiExample;
use ::solana_frozen_abi::abi_example::AbiExample;
digester.update_with_string(format!("enum {} (variants = {})", enum_name, #variant_count));
#serialized_variants
Ok(digester.create_child())
Expand Down Expand Up @@ -310,12 +310,12 @@ fn quote_for_test(
#[cfg(test)]
mod #test_mod_ident {
use super::*;
use ::solana_sdk::abi_example::{AbiExample, AbiEnumVisitor};
use ::solana_frozen_abi::abi_example::{AbiExample, AbiEnumVisitor};

#[test]
fn test_abi_digest() {
::solana_logger::setup();
let mut digester = ::solana_sdk::abi_digester::AbiDigester::create();
let mut digester = ::solana_frozen_abi::abi_digester::AbiDigester::create();
let example = <#type_name>::example();
let result = <_>::visit_for_abi(&&example, &mut digester);
let mut hash = digester.finalize();
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/abi_digester.rs → frozen-abi/src/abi_digester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ mod tests {
test_field2: i8,
}

#[frozen_abi(digest = "Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v")]
#[frozen_abi(digest = "GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryoqun - These two hashes changed on me for some reason. Seems harmless though. Maybe it's due to the crate rename somenow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it detects such renames because it need to consider XX::Hash to be different from YY::Hash.

$ diff -U3 /tmp/abi8/*Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v* /tmp/abi8/*GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk*
--- /tmp/abi8/abi_digester__tests__TestNest_frozen_abi__test_abi_digest_Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v    2020-10-20 21:17:01.936993559 +0900
+++ /tmp/abi8/abi_digester__tests__TestNest_frozen_abi__test_abi_digest_GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk    2020-10-20 21:21:09.115486766 +0900
@@ -1,31 +1,31 @@
 struct TestNest (fields = 1)
-    field nested_field: [solana_sdk::abi_digester::tests::TestStruct; 5]
+    field nested_field: [solana_frozen_abi::abi_digester::tests::TestStruct; 5]
         tuple (elements = 5)
-            element solana_sdk::abi_digester::tests::TestStruct
+            element solana_frozen_abi::abi_digester::tests::TestStruct
                 struct TestStruct (fields = 2)
                     field test_field: i8
                         primitive i8
                     field test_field2: i8
                         primitive i8
-            element solana_sdk::abi_digester::tests::TestStruct
+            element solana_frozen_abi::abi_digester::tests::TestStruct
                 struct TestStruct (fields = 2)
                     field test_field: i8
                         primitive i8
                     field test_field2: i8
                         primitive i8
-            element solana_sdk::abi_digester::tests::TestStruct
+            element solana_frozen_abi::abi_digester::tests::TestStruct
                 struct TestStruct (fields = 2)
                     field test_field: i8
                         primitive i8
                     field test_field2: i8
                         primitive i8
-            element solana_sdk::abi_digester::tests::TestStruct
+            element solana_frozen_abi::abi_digester::tests::TestStruct
                 struct TestStruct (fields = 2)
                     field test_field: i8
                         primitive i8
                     field test_field2: i8
                         primitive i8
-            element solana_sdk::abi_digester::tests::TestStruct
+            element solana_frozen_abi::abi_digester::tests::TestStruct
                 struct TestStruct (fields = 2)
                     field test_field: i8
                         primitive i8
$ sha256sum /tmp/abi8/abi_digester__tests__TestNest_frozen_abi__test_abi_digest_Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v | xxd -r -p - | base58 && echo
Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v

$ sha256sum /tmp/abi8/abi_digester__tests__TestNest_frozen_abi__test_abi_digest_GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk | xxd -r -p - | base58 && echo
GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk

#[derive(Serialize, AbiExample)]
struct TestNest {
nested_field: [TestStruct; 5],
Expand All @@ -573,7 +573,7 @@ mod tests {
VARIANT2(u8, u16),
}

#[frozen_abi(digest = "CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q")]
#[frozen_abi(digest = "DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it is:

$ diff -U3 /tmp/abi8/*CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q* /tmp/abi8/*DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG*
--- /tmp/abi8/abi_digester__tests__TestVecEnum_frozen_abi__test_abi_digest_CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q 2020-10-20 21:17:02.036989718 +0900
+++ /tmp/abi8/abi_digester__tests__TestVecEnum_frozen_abi__test_abi_digest_DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG 2020-10-20 21:21:09.171484610 +0900
@@ -1,7 +1,7 @@
 struct TestVecEnum (fields = 1)
-    field enums: alloc::vec::Vec<solana_sdk::abi_digester::tests::TestTupleVariant>
+    field enums: alloc::vec::Vec<solana_frozen_abi::abi_digester::tests::TestTupleVariant>
         seq (elements = 1)
-            element solana_sdk::abi_digester::tests::TestTupleVariant
+            element solana_frozen_abi::abi_digester::tests::TestTupleVariant
                 enum TestTupleVariant (variants = 2)
                     variant(0) VARIANT1 (fields = 2)
                         field u8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ sha256sum /tmp/abi8/abi_digester__tests__TestVecEnum_frozen_abi__test_abi_digest_CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q | xxd -r -p - | base58 && echo
CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q

$ sha256sum /tmp/abi8/abi_digester__tests__TestVecEnum_frozen_abi__test_abi_digest_DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG | xxd -r -p - | base58 && echo
DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG

#[derive(Serialize, AbiExample)]
struct TestVecEnum {
enums: Vec<TestTupleVariant>,
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/abi_example.rs → frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ atomic_example_impls! { AtomicI64 }
atomic_example_impls! { AtomicIsize }
atomic_example_impls! { AtomicBool }

#[cfg(feature = "everything")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature removal!

#[cfg(not(target_arch = "bpf"))]
use generic_array::{ArrayLength, GenericArray};
#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl<T: Default, U: ArrayLength<T>> AbiExample for GenericArray<T, U> {
fn example() -> Self {
Self::default()
Expand Down Expand Up @@ -413,14 +413,14 @@ impl<T: std::cmp::Ord + AbiExample> AbiExample for BTreeSet<T> {
}
}

#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl AbiExample for memmap::MmapMut {
fn example() -> Self {
memmap::MmapMut::map_anon(1).expect("failed to map the data file")
}
}

#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl AbiExample for std::path::PathBuf {
fn example() -> Self {
std::path::PathBuf::from(String::example())
Expand Down
28 changes: 28 additions & 0 deletions frozen-abi/src/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use sha2::{Digest, Sha256};
use std::{convert::TryFrom, fmt};

const HASH_BYTES: usize = 32;
#[derive(AbiExample)]
pub struct Hash(pub [u8; HASH_BYTES]);

#[derive(Default)]
pub struct Hasher {
hasher: Sha256,
}

impl Hasher {
pub fn hash(&mut self, val: &[u8]) {
self.hasher.input(val);
}
pub fn result(self) -> Hash {
// At the time of this writing, the sha2 library is stuck on an old version
// of generic_array (0.9.0). Decouple ourselves with a clone to our version.
Hash(<[u8; HASH_BYTES]>::try_from(self.hasher.result().as_slice()).unwrap())
}
}

impl fmt::Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
22 changes: 22 additions & 0 deletions frozen-abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]

// Allows macro expansion of `use ::solana_frozen_abi::*` to work within this crate
extern crate self as solana_frozen_abi;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
pub mod abi_digester;
#[cfg(RUSTC_WITH_SPECIALIZATION)]
pub mod abi_example;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
mod hash;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
#[macro_use]
extern crate solana_frozen_abi_macro;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
#[cfg(test)]
#[macro_use]
extern crate serde_derive;
Loading