Skip to content

Commit

Permalink
sdk: Extract hash and hasher crates (anza-xyz#2015)
Browse files Browse the repository at this point in the history
* extract hash and hasher crates and re-export their contents in solana_program::hash

* make bytemuck and serde optional, and activate features in solana-program

* fix frozen-abi support

* fix import

* update lock file

* cargo sort

* fix wasm_bindgen import

* typo

* fmt

* make the inner field of Hash pub(crate) again because otherwise wasm_bindgen breaks

* move program/src/wasm/hash.rs contents to solana-hash crate

* update lock file

* remove duplicate frozen-abi stuff

* fix specialization stuff

* delete tmp tests

* update BlockhashQueue digest

* Revert "update BlockhashQueue digest"

This reverts commit 591302b.

* update expected digests after confirming that the change is merely from moving the Hash struct and not a real ABI change

* update another digest

* update digests in sdk and program

* update digests in runtime

* update VoteTransaction digest

* conditionally activate solana-hash/borsh in solana-program

* move js-sys dep under cfg(target_arch = "wasm32")

* remove thiserror from hash crate

* remove solana-program dependency from merkle-tree

* make solana-hash no_std by default

* fmt

* fmt after rebase

* make std feature default

* make sha2 an optional dep when target_os = "solana", because it's unlikely to be used in that case

* fmt

* make rustc_version optional

* update lock file

* fix frozen-abi lint

* another lint fix

* add comment about sha2 removal

* avoid Vec in FromStr

Co-authored-by: Jon C <[email protected]>

* put Hash::new_unique behind #[cfg(feature = "dev-context-only-utils")]

* move tests from solana-hasher to solana-hash

* rename solana-hasher to solana-sha256-hasher

* fmt

* make conditional import more consistent

Co-authored-by: Jon C <[email protected]>

* don't use std feature of bs58 in solana-hash

* undo putting new_unique behind dev-context-only-utils

* missing feature

* rename to write_as_base58 and reorder params

Co-authored-by: Jon C <[email protected]>

* update write_as_base58 usage

* fix feature activation for tests

* remove part of doc that no longer makes sense

Co-authored-by: Jon C <[email protected]>

---------

Co-authored-by: Jon C <[email protected]>
  • Loading branch information
2 people authored and ray-kast committed Nov 27, 2024
1 parent a9b624e commit 0c5108f
Show file tree
Hide file tree
Showing 32 changed files with 521 additions and 326 deletions.
34 changes: 33 additions & 1 deletion Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ members = [
"sdk/clock",
"sdk/decode-error",
"sdk/gen-headers",
"sdk/hash",
"sdk/macro",
"sdk/msg",
"sdk/package-metadata-macro",
"sdk/program",
"sdk/program-memory",
"sdk/serde-varint",
"sdk/sha256-hasher",
"send-transaction-service",
"short-vec",
"stake-accounts",
Expand Down Expand Up @@ -198,7 +200,7 @@ bincode = "1.3.3"
bitflags = { version = "2.6.0" }
blake3 = "1.5.1"
borsh = { version = "1.5.1", features = ["derive", "unstable__schema"] }
bs58 = "0.5.1"
bs58 = { version = "0.5.1", default-features = false }
bv = "0.11.1"
byte-unit = "4.0.19"
bytecount = "0.6.8"
Expand Down Expand Up @@ -390,6 +392,7 @@ solana-genesis-utils = { path = "genesis-utils", version = "=2.1.0" }
agave-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=2.1.0" }
solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.1.0" }
solana-gossip = { path = "gossip", version = "=2.1.0" }
solana-hash = { path = "sdk/hash", version = "=2.1.0" }
solana-inline-spl = { path = "inline-spl", version = "=2.1.0" }
solana-lattice-hash = { path = "lattice-hash", version = "=2.1.0" }
solana-ledger = { path = "ledger", version = "=2.1.0" }
Expand Down Expand Up @@ -418,6 +421,7 @@ solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.1.0" }
solana-remote-wallet = { path = "remote-wallet", version = "=2.1.0", default-features = false }
solana-sanitize = { path = "sanitize", version = "=2.1.0" }
solana-serde-varint = { path = "sdk/serde-varint", version = "=2.1.0" }
solana-sha256-hasher = { path = "sdk/sha256-hasher", version = "=2.1.0" }
solana-timings = { path = "timings", version = "=2.1.0" }
solana-unified-scheduler-logic = { path = "unified-scheduler-logic", version = "=2.1.0" }
solana-unified-scheduler-pool = { path = "unified-scheduler-pool", version = "=2.1.0" }
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/blockhash_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl HashInfo {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "HzbCqb1YtCodkx6Fu57SpzkgaLp9WSrtw8texsjBhEDH")
frozen_abi(digest = "BxykY65dC2NCcDm17rHQPjEY8wK55sKAhfhKVFGc5T1u")
)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlockhashQueue {
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct BankingTracer {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "Eq6YrAFtTbtPrCEvh6Et1mZZDCARUg1gcK2qiZdqyjUz")
frozen_abi(digest = "F5GH1poHbPqipU4DB3MczhSxHZw4o27f3C7QnMVirFci")
)]
#[derive(Serialize, Deserialize, Debug)]
pub struct TimedTracedEvent(pub std::time::SystemTime, pub TracedEvent);
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) enum BlockhashStatus {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "H6T5A66kgJYANFXVrUprxV76WD5ce7Gf62q9SiBC2uYk")
frozen_abi(digest = "5BUswzvu7Qe44HbR4eBwPX4Jn9GSfhjmg8eijnBjoKUd")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower {
Expand Down
2 changes: 1 addition & 1 deletion core/src/consensus/tower1_14_11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "EqYa8kwY9Z1Zbjxgs2aBbqKyCK4f7WAG8gJ7pVSQyKzk")
frozen_abi(digest = "9P6J8ZtVLR5zbUxWT83q1iUsJMH6B7SwcomSqcoomPmg")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_14_11 {
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 @@ -11,7 +11,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "9Kc3Cpak93xdL8bCnEwMWA8ZLGCBNfqh9PLo1o5RiPyT")
frozen_abi(digest = "DJVvkk4EFFCbA37vsKcFPGuwEULh2wEvMUESsTyvABzU")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_7_14 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/repair/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl AncestorHashesRepairType {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "AKpurCovzn6rsji4aQrP3hUdEHxjtXUfT7AatZXN7Rpz")
frozen_abi(digest = "98D6KvXCBxAHTxXgqiywLTugTp6WFUHSf559yy4VvKE7")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum AncestorHashesResponse {
Expand Down Expand Up @@ -224,7 +224,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiEnumVisitor, AbiExample),
frozen_abi(digest = "5cmSdmXMgkpUH5ZCmYYjxUVQfULe9iJqCqqfrADfsEmK")
frozen_abi(digest = "DzofXbeBFKJpbA88nUEnDpCGKvMEcguNphyQoVr7FyLh")
)]
#[derive(Debug, Deserialize, Serialize)]
pub enum RepairProtocol {
Expand Down
2 changes: 1 addition & 1 deletion frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
bs58 = { workspace = true }
bs58 = { workspace = true, features = ["alloc"] }
bv = { workspace = true, features = ["serde"] }
log = { workspace = true, features = ["std"] }
serde = { workspace = true, features = ["rc"] }
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "6YaMJand6tKtNLUrqvusC5QVDmVLCWYRg5LtxYNi6XN4")
frozen_abi(digest = "7jwuQ3oFEy8bMnmr5XHSR2jqivZniG8ZjxHx3YKTfR6C")
)]
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down
3 changes: 2 additions & 1 deletion merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ edition = { workspace = true }

[dependencies]
fast-math = { workspace = true }
solana-program = { workspace = true }
solana-hash = { workspace = true }
solana-sha256-hasher = { workspace = true }

[dev-dependencies]
hex = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion merkle-tree/src/merkle_tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use solana_program::hash::{hashv, Hash};
use {solana_hash::Hash, solana_sha256_hasher::hashv};

// We need to discern between leaf and intermediate nodes to prevent trivial second
// pre-image attacks.
Expand Down
30 changes: 29 additions & 1 deletion programs/sbf/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 programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "3R2hRL3FM6jovbYubq2UWeiVDEVzrhH6M1ihoCPZWLsk")
frozen_abi(digest = "3dbyMxwfCN43orGKa5YiyY1EqN2K97pTicNhKYTZSUQH")
)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum VoteTransaction {
Expand Down
2 changes: 1 addition & 1 deletion rpc-client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = { workspace = true }
[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
bs58 = { workspace = true }
bs58 = { workspace = true, features = ["std"] }
jsonrpc-core = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] }
reqwest-middleware = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct RentMetrics {
pub type BankStatusCache = StatusCache<Result<()>>;
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "9Pf3NTGr1AEzB4nKaVBY24uNwoQR4aJi8vc96W6kGvNk")
frozen_abi(digest = "EQwW6Ym6ECKaAREnAgkhXYisBQovuraBKSALdJ8koZzq")
)]
pub type BankSlotDelta = SlotDelta<Result<()>>;

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ mod tests {
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "HQYDRuCaM5V1ggSuMPTKT5Mu2vE5HX4y4ZM1Xuorx6My")
frozen_abi(digest = "FuFBQtx7rGruVC3cyh4zvZ3uN4RUtBiwh1pXJRwUCcoS")
)]
#[derive(Serialize)]
pub struct BankAbiTestWrapper {
Expand Down
52 changes: 52 additions & 0 deletions sdk/hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "solana-hash"
description = "Solana wrapper for the 32-byte output of a hashing algorithm."
documentation = "https://docs.rs/solana-hash"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
borsh = { workspace = true, optional = true }
bs58 = { workspace = true, default-features = false }
bytemuck = { workspace = true, optional = true }
bytemuck_derive = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-atomic-u64 = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-sanitize = { workspace = true }

[dev-dependencies]
solana-hash = { path = ".", features = ["dev-context-only-utils"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }

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

[features]
borsh = ["dep:borsh", "std"]
bytemuck = ["dep:bytemuck", "dep:bytemuck_derive"]
default = ["std"]
dev-context-only-utils = ["bs58/alloc"]
frozen-abi = [
"dep:rustc_version",
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"std"
]
serde = ["dep:serde", "dep:serde_derive"]
std = []

[lints]
workspace = true
1 change: 1 addition & 0 deletions sdk/hash/build.rs
Loading

0 comments on commit 0c5108f

Please sign in to comment.