Skip to content

Commit

Permalink
Extract commitment-config crate (#2136)
Browse files Browse the repository at this point in the history
* extract commitment-config crate from sdk

* make serde optional in commitment-config crate

* update lock file

* remove thiserror

* remove thiserror from Cargo.toml too

* sort deps
  • Loading branch information
kevinheavey authored Oct 30, 2024
1 parent 1724832 commit 96486f3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ members = [
"sdk/cargo-build-sbf",
"sdk/cargo-test-sbf",
"sdk/clock",
"sdk/commitment-config",
"sdk/cpi",
"sdk/decode-error",
"sdk/derivation-path",
Expand Down Expand Up @@ -410,6 +411,7 @@ solana-cli-config = { path = "cli-config", version = "=2.2.0" }
solana-cli-output = { path = "cli-output", version = "=2.2.0" }
solana-client = { path = "client", version = "=2.2.0" }
solana-clock = { path = "sdk/clock", version = "=2.2.0" }
solana-commitment-config = { path = "sdk/commitment-config", version = "=2.2.0" }
solana-compute-budget = { path = "compute-budget", version = "=2.2.0" }
solana-compute-budget-program = { path = "programs/compute-budget", version = "=2.2.0" }
solana-config-program = { path = "programs/config", version = "=2.2.0" }
Expand Down
9 changes: 9 additions & 0 deletions programs/sbf/Cargo.lock

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

2 changes: 2 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ full = [
"ed25519-dalek-bip32",
"libsecp256k1",
"sha3",
"solana-commitment-config",
"digest",
"solana-pubkey/rand",
"dep:solana-precompile-error",
Expand Down Expand Up @@ -91,6 +92,7 @@ sha3 = { workspace = true, optional = true }
siphasher = { workspace = true }
solana-account = { workspace = true, features = ["bincode"] }
solana-bn254 = { workspace = true }
solana-commitment-config = { workspace = true, optional = true, features = ["serde"] }
solana-decode-error = { workspace = true }
solana-derivation-path = { workspace = true }
solana-feature-set = { workspace = true }
Expand Down
20 changes: 20 additions & 0 deletions sdk/commitment-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "solana-commitment-config"
description = "Solana commitment config."
documentation = "https://docs.rs/solana-commitment-config"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }

[features]
serde = ["dep:serde", "dep:serde_derive"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
35 changes: 25 additions & 10 deletions sdk/src/commitment_config.rs → sdk/commitment-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Definitions of commitment levels.
#![cfg(feature = "full")]

use {std::str::FromStr, thiserror::Error};

#[derive(Serialize, Deserialize, Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
use core::{fmt, str::FromStr};

#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct CommitmentConfig {
pub commitment: CommitmentLevel,
}
Expand Down Expand Up @@ -70,8 +72,12 @@ impl FromStr for CommitmentConfig {
}
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize),
serde(rename_all = "camelCase")
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// An attribute of a slot. It describes how finalized a block is at some point in time. For example, a slot
/// is said to be at the max level immediately after the cluster recognizes the block at that slot as
/// finalized. When querying the ledger state, use lower levels of commitment to report progress and higher
Expand Down Expand Up @@ -123,8 +129,17 @@ impl std::fmt::Display for CommitmentLevel {
}
}

#[derive(Error, Debug)]
#[derive(Debug)]
pub enum ParseCommitmentLevelError {
#[error("invalid variant")]
Invalid,
}

impl std::error::Error for ParseCommitmentLevelError {}

impl fmt::Display for ParseCommitmentLevelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Invalid => f.write_str("invalid variant"),
}
}
}
3 changes: 2 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern crate self as solana_sdk;

#[cfg(feature = "full")]
pub use signer::signers;
#[cfg(feature = "full")]
pub use solana_commitment_config as commitment_config;
#[cfg(not(target_os = "solana"))]
pub use solana_program::program_stubs;
// These solana_program imports could be *-imported, but that causes a bunch of
Expand All @@ -59,7 +61,6 @@ pub use solana_program::{
#[cfg(feature = "borsh")]
pub use solana_program::{borsh, borsh0_10, borsh1};
pub mod client;
pub mod commitment_config;
pub mod compute_budget;
pub mod deserialize_utils;
pub mod ed25519_instruction;
Expand Down

0 comments on commit 96486f3

Please sign in to comment.