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

Support thiserror in no_std #3214

Merged
merged 1 commit into from
Nov 7, 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
390 changes: 205 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-com
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
thiserror = "1.0.64"
thiserror = "2.0.0"
tracing = "0.1.40"
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-codin
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }
subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
thiserror = "1.0.64"
thiserror = "2.0.0"
tokio = { version = "1.40.0", features = ["sync", "time"] }
tracing = "0.1.40"

Expand Down
2 changes: 1 addition & 1 deletion crates/sc-subspace-block-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ sp-runtime = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e
strum_macros = "0.26.4"
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
substrate-prometheus-endpoint = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42" }
thiserror = "1.0.64"
thiserror = "2.0.0"
tracing = "0.1.40"
4 changes: 2 additions & 2 deletions crates/sp-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primiti
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg", optional = true }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", default-features = false }
subspace-verification = { version = "0.1.0", path = "../subspace-verification", default-features = false }
thiserror = { version = "1.0.64", optional = true }
thiserror = { version = "2.0.0", default-features = false }

[features]
default = ["std"]
Expand All @@ -59,5 +59,5 @@ std = [
"subspace-proof-of-space/std",
"subspace-verification/kzg",
"subspace-verification/std",
"thiserror",
"thiserror/std",
]
25 changes: 6 additions & 19 deletions crates/sp-consensus-subspace/src/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,37 +375,24 @@ impl fmt::Display for ErrorDigestType {
}

/// Digest error
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
pub enum Error {
/// Subspace digest missing
#[cfg_attr(feature = "thiserror", error("Subspace {0} digest not found"))]
#[error("Subspace {0} digest not found")]
Missing(ErrorDigestType),
/// Failed to decode Subspace digest
#[cfg_attr(
feature = "thiserror",
error("Failed to decode Subspace {0} digest: {1}")
)]
#[error("Failed to decode Subspace {0} digest: {1}")]
FailedToDecode(ErrorDigestType, codec::Error),
/// Duplicate Subspace digests
#[cfg_attr(
feature = "thiserror",
error("Duplicate Subspace {0} digests, rejecting!")
)]
#[error("Duplicate Subspace {0} digests, rejecting!")]
Duplicate(ErrorDigestType),

/// Error when deriving next digests
#[cfg_attr(
feature = "thiserror",
error("Failed to derive next {0} digest, rejecting!")
)]
#[error("Failed to derive next {0} digest, rejecting!")]
NextDigestDerivationError(ErrorDigestType),

/// Error when verifying next digests
#[cfg_attr(
feature = "thiserror",
error("Failed to verify next {0} digest, rejecting!")
)]
#[error("Failed to verify next {0} digest, rejecting!")]
NextDigestVerificationError(ErrorDigestType),
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sp-domains-fraud-proof/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sp-weights = { default-features = false, git = "https://github.com/subspace/polk
subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
trie-db = { version = "0.29.1", default-features = false }
thiserror = { version = "1.0.64", optional = true }
thiserror = { version = "2.0.0", default-features = false }

[dev-dependencies]
domain-block-builder = { version = "0.1.0", path = "../../domains/client/block-builder" }
Expand Down Expand Up @@ -98,6 +98,6 @@ std = [
"subspace-core-primitives/std",
"subspace-runtime-primitives/std",
"trie-db/std",
"thiserror",
"thiserror/std",
]
runtime-benchmarks = []
100 changes: 32 additions & 68 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,126 +222,90 @@ impl ExecutionPhase {
}

/// Error type of fraud proof verification on consensus node.
#[derive(Debug)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
#[derive(Debug, thiserror::Error)]
pub enum VerificationError<DomainHash> {
/// Failed to pass the execution proof check.
#[cfg_attr(
feature = "thiserror",
error("Failed to pass the execution proof check")
)]
#[error("Failed to pass the execution proof check")]
BadExecutionProof,
/// The fraud proof prove nothing invalid
#[cfg_attr(feature = "thiserror", error("The fraud proof prove nothing invalid"))]
#[error("The fraud proof prove nothing invalid")]
InvalidProof,
/// Failed to decode the return value of `initialize_block` and `apply_extrinsic`.
#[cfg_attr(
feature = "thiserror",
error(
"Failed to decode the return value of `initialize_block` and `apply_extrinsic`: {0}"
)
)]
#[error("Failed to decode the return value of `initialize_block` and `apply_extrinsic`: {0}")]
InitializeBlockOrApplyExtrinsicDecode(codec::Error),
/// Failed to decode the storage root produced by verifying `initialize_block` or `apply_extrinsic`.
#[cfg_attr(
feature = "thiserror",
#[
error(
"Failed to decode the storage root from verifying `initialize_block` and `apply_extrinsic`: {0}"
)
)]
]
StorageRootDecode(codec::Error),
/// Failed to decode the header produced by `finalize_block`.
#[cfg_attr(
feature = "thiserror",
error("Failed to decode the header from verifying `finalize_block`: {0}")
)]
#[error("Failed to decode the header from verifying `finalize_block`: {0}")]
HeaderDecode(codec::Error),
#[cfg_attr(
feature = "thiserror",
error("The receipt's execution_trace have less than 2 traces")
)]
#[error("The receipt's execution_trace have less than 2 traces")]
InvalidExecutionTrace,
#[cfg_attr(feature = "thiserror", error("Invalid ApplyExtrinsic trace index"))]
#[error("Invalid ApplyExtrinsic trace index")]
InvalidApplyExtrinsicTraceIndex,
#[cfg_attr(feature = "thiserror", error("Invalid longer mismatch trace index"))]
#[error("Invalid longer mismatch trace index")]
InvalidLongerMismatchTraceIndex,
#[cfg_attr(feature = "thiserror", error("Invalid ApplyExtrinsic call data"))]
#[error("Invalid ApplyExtrinsic call data")]
InvalidApplyExtrinsicCallData,
/// Invalid bundle digest
#[cfg_attr(feature = "thiserror", error("Invalid Bundle Digest"))]
#[error("Invalid Bundle Digest")]
InvalidBundleDigest,
/// Bundle with requested index not found in execution receipt
#[cfg_attr(
feature = "thiserror",
error("Bundle with requested index not found in execution receipt")
)]
#[error("Bundle with requested index not found in execution receipt")]
BundleNotFound,
/// Invalid bundle entry in bad receipt was expected to be valid but instead found invalid entry
#[cfg_attr(
feature = "thiserror",
error("Unexpected bundle entry at {bundle_index} in bad receipt found: {targeted_entry_bundle:?} with fraud proof's type of proof: {fraud_proof_invalid_type_of_proof:?}")
#[error(
"Unexpected bundle entry at {bundle_index} in bad receipt found: \
{targeted_entry_bundle:?} with fraud proof's type of proof: \
{fraud_proof_invalid_type_of_proof:?}"
)]
UnexpectedTargetedBundleEntry {
bundle_index: u32,
fraud_proof_invalid_type_of_proof: InvalidBundleType,
targeted_entry_bundle: BundleValidity<DomainHash>,
},
/// Failed to derive bundle digest
#[cfg_attr(feature = "thiserror", error("Failed to derive bundle digest"))]
#[error("Failed to derive bundle digest")]
FailedToDeriveBundleDigest,
/// The target valid bundle not found from the target bad receipt
#[cfg_attr(
feature = "thiserror",
error("The target valid bundle not found from the target bad receipt")
)]
#[error("The target valid bundle not found from the target bad receipt")]
TargetValidBundleNotFound,
/// Failed to check extrinsics in single context
#[cfg_attr(
feature = "thiserror",
error("Failed to check extrinsics in single context")
)]
#[error("Failed to check extrinsics in single context")]
FailedToCheckExtrinsicsInSingleContext,
#[cfg_attr(
feature = "thiserror",
error(
"Bad MMR proof, the proof is probably expired or is generated against a different fork"
)
#[error(
"Bad MMR proof, the proof is probably expired or is generated against a different fork"
)]
BadMmrProof,
#[cfg_attr(feature = "thiserror", error("Unexpected MMR proof"))]
#[error("Unexpected MMR proof")]
UnexpectedMmrProof,
#[cfg_attr(feature = "thiserror", error("Failed to verify storage proof"))]
#[error("Failed to verify storage proof")]
StorageProof(storage_proof::VerificationError),
/// Failed to derive domain inherent extrinsic
#[cfg_attr(
feature = "thiserror",
error("Failed to derive domain inherent extrinsic")
)]
#[error("Failed to derive domain inherent extrinsic")]
FailedToDeriveDomainInherentExtrinsic,
/// Failed to derive domain storage key
#[cfg_attr(feature = "thiserror", error("Failed to derive domain storage key"))]
#[error("Failed to derive domain storage key")]
FailedToGetDomainStorageKey,
/// Unexpected invalid bundle proof data
#[cfg_attr(feature = "thiserror", error("Unexpected invalid bundle proof data"))]
#[error("Unexpected invalid bundle proof data")]
UnexpectedInvalidBundleProofData,
/// Extrinsic with requested index not found in bundle
#[cfg_attr(
feature = "thiserror",
error("Extrinsic with requested index not found in bundle")
)]
#[error("Extrinsic with requested index not found in bundle")]
ExtrinsicNotFound,
/// Failed to get domain runtime call response
#[cfg_attr(
feature = "thiserror",
error("Failed to get domain runtime call response")
)]
#[error("Failed to get domain runtime call response")]
FailedToGetDomainRuntimeCallResponse,
/// Failed to get bundle weight
#[cfg_attr(feature = "thiserror", error("Failed to get bundle weight"))]
#[error("Failed to get bundle weight")]
FailedToGetBundleWeight,
#[cfg_attr(feature = "thiserror", error("Failed to extract xdm mmr proof"))]
#[error("Failed to extract xdm mmr proof")]
FailedToGetExtractXdmMmrProof,
#[cfg_attr(feature = "thiserror", error("Failed to decode xdm mmr proof"))]
#[error("Failed to decode xdm mmr proof")]
FailedToDecodeXdmMmrProof,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-archiving/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = { version = "1.0.110", optional = true, features = ["derive"] }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives", default-features = false }
subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding", default-features = false }
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg", default-features = false }
thiserror = { version = "1.0.64", optional = true }
thiserror = { version = "2.0.0", default-features = false }

[dev-dependencies]
criterion = "0.5.1"
Expand All @@ -48,7 +48,7 @@ std = [
"subspace-core-primitives/std",
"subspace-erasure-coding/std",
"subspace-kzg/std",
"thiserror",
"thiserror/std",
]

[[bench]]
Expand Down
14 changes: 5 additions & 9 deletions crates/subspace-archiving/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,15 @@ pub struct ArchiveBlockOutcome {
}

/// Archiver instantiation error
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, thiserror::Error)]
pub enum ArchiverInstantiationError {
/// Invalid last archived block, its size is the same as encoded block
#[cfg_attr(
feature = "thiserror",
error("Invalid last archived block, its size {0} bytes is the same as encoded block")
)]
#[error("Invalid last archived block, its size {0} bytes is the same as encoded block")]
InvalidLastArchivedBlock(BlockNumber),
/// Invalid block, its size is smaller than already archived number of bytes
#[cfg_attr(
feature = "thiserror",
error("Invalid block, its size {block_bytes} bytes is smaller than already archived {archived_block_bytes} bytes")
#[error(
"Invalid block, its size {block_bytes} bytes is smaller than already archived \
{archived_block_bytes} bytes"
)]
InvalidBlockSmallSize {
/// Full block size
Expand Down
12 changes: 4 additions & 8 deletions crates/subspace-archiving/src/piece_reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::{Commitment, Kzg, Polynomial, Scalar};

/// Reconstructor-related instantiation error
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum ReconstructorError {
/// Segment size is not bigger than record size
#[cfg_attr(
feature = "thiserror",
error("Error during data shards reconstruction: {0}")
)]
#[error("Error during data shards reconstruction: {0}")]
DataShardsReconstruction(String),

/// Commitment of input piece is invalid.
#[cfg_attr(feature = "thiserror", error("Commitment of input piece is invalid."))]
#[error("Commitment of input piece is invalid.")]
InvalidInputPieceCommitment,

/// Incorrect piece position provided.
#[cfg_attr(feature = "thiserror", error("Incorrect piece position provided."))]
#[error("Incorrect piece position provided.")]
IncorrectPiecePosition,
}

Expand Down
16 changes: 6 additions & 10 deletions crates/subspace-archiving/src/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ use subspace_erasure_coding::ErasureCoding;
use subspace_kzg::Scalar;

/// Reconstructor-related instantiation error
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum ReconstructorError {
/// Error during data shards reconstruction
#[cfg_attr(
feature = "thiserror",
error("Error during data shards reconstruction: {0}")
)]
#[error("Error during data shards reconstruction: {0}")]
DataShardsReconstruction(String),
/// Segment size is not bigger than record size
#[cfg_attr(feature = "thiserror", error("Error during segment decoding: {0}"))]
#[error("Error during segment decoding: {0}")]
SegmentDecoding(parity_scale_codec::Error),
/// Incorrect segment order, each next segment must have monotonically increasing segment index
#[cfg_attr(
feature = "thiserror",
error("Incorrect segment order, expected index {expected_segment_index}, actual {actual_segment_index}")
#[error(
"Incorrect segment order, expected index {expected_segment_index}, actual \
{actual_segment_index}"
)]
IncorrectSegmentOrder {
expected_segment_index: SegmentIndex,
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-farmer-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-codin
subspace-kzg = { version = "0.1.0", path = "../../shared/subspace-kzg" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", features = ["parallel"] }
subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
thiserror = "1.0.64"
thiserror = "2.0.0"
tokio = { version = "1.40.0", features = ["macros", "parking_lot", "rt-multi-thread", "signal", "sync"] }
tracing = "0.1.40"

Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
substrate-bip39 = "0.6.0"
supports-color = { version = "3.0.1", optional = true }
tempfile = "3.13.0"
thiserror = "1.0.64"
thiserror = "2.0.0"
thread-priority = "1.1.0"
tokio = { version = "1.40.0", features = ["macros", "parking_lot", "rt-multi-thread", "signal", "time"] }
tokio-stream = { version = "0.1.16", features = ["sync"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-gateway-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jsonrpsee = { version = "0.24.5", features = ["client-core", "server-core", "mac
serde = { version = "1.0.110", default-features = false, features = ["alloc", "derive"] }
subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
subspace-data-retrieval = { version = "0.1.0", path = "../../shared/subspace-data-retrieval" }
thiserror = "1.0.64"
thiserror = "2.0.0"
tracing = "0.1.40"
2 changes: 1 addition & 1 deletion crates/subspace-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
subspace-verification = { version = "0.1.0", path = "../subspace-verification", default-features = false }
supports-color = "3.0.1"
thiserror = "1.0.64"
thiserror = "2.0.0"
tokio = { version = "1.40.0", features = ["rt-multi-thread", "signal", "macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
Loading
Loading