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

Use thiserror throughout testnet/stacks-node #5413

Merged
merged 1 commit into from
Nov 1, 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
9 changes: 5 additions & 4 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 @@ -21,6 +21,7 @@ rand = "0.8"
rand_chacha = "0.3.1"
tikv-jemallocator = "0.5.4"
rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] }
thiserror = { version = "1.0.65" }

# Use a bit more than default optimization for
# dev builds to speed up test execution
Expand Down
2 changes: 1 addition & 1 deletion libsigner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ slog-term = "2.6.0"
slog-json = { version = "2.3.0", optional = true }
stacks-common = { path = "../stacks-common" }
stackslib = { path = "../stackslib"}
thiserror = "1.0"
thiserror = { workspace = true }
tiny_http = "0.12"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ slog-json = { version = "2.3.0", optional = true }
slog-term = "2.6.0"
stacks-common = { path = "../stacks-common" }
stackslib = { path = "../stackslib" }
thiserror = "1.0"
thiserror = { workspace = true }
tiny_http = { version = "0.12", optional = true }
toml = "0.5.6"
tracing = "0.1.37"
Expand Down
1 change: 1 addition & 0 deletions testnet/stacks-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rusqlite = { workspace = true }
async-h1 = { version = "2.3.2", optional = true }
async-std = { version = "1.6", optional = true, features = ["attributes"] }
http-types = { version = "2.12", optional = true }
thiserror = { workspace = true }

[target.'cfg(not(any(target_os = "macos", target_os="windows", target_arch = "arm")))'.dependencies]
tikv-jemallocator = {workspace = true}
Expand Down
36 changes: 10 additions & 26 deletions testnet/stacks-node/src/burnchains/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod bitcoin_regtest_controller;
pub mod mocknet_controller;

use std::fmt;
use std::time::Instant;

use stacks::burnchains;
Expand All @@ -16,41 +15,26 @@ pub use self::bitcoin_regtest_controller::{make_bitcoin_indexer, BitcoinRegtestC
pub use self::mocknet_controller::MocknetController;
use super::operations::BurnchainOpSigner;

#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("ChainsCoordinator closed")]
CoordinatorClosed,
IndexerError(burnchains::Error),
#[error("Indexer error: {0}")]
IndexerError(#[from] burnchains::Error),
#[error("Burnchain error")]
BurnchainError,
#[error("Max fee rate exceeded")]
MaxFeeRateExceeded,
#[error("Identical operation, not submitting")]
IdenticalOperation,
#[error("No UTXOs available")]
NoUTXOs,
#[error("Transaction submission failed: {0}")]
TransactionSubmissionFailed(String),
#[error("Serializer error: {0}")]
SerializerError(CodecError),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::CoordinatorClosed => write!(f, "ChainsCoordinator closed"),
Error::IndexerError(ref e) => write!(f, "Indexer error: {:?}", e),
Error::BurnchainError => write!(f, "Burnchain error"),
Error::MaxFeeRateExceeded => write!(f, "Max fee rate exceeded"),
Error::IdenticalOperation => write!(f, "Identical operation, not submitting"),
Error::NoUTXOs => write!(f, "No UTXOs available"),
Error::TransactionSubmissionFailed(e) => {
write!(f, "Transaction submission failed: {e}")
}
Error::SerializerError(e) => write!(f, "Serializer error: {e}"),
}
}
}

impl From<burnchains::Error> for Error {
fn from(e: burnchains::Error) -> Self {
Error::IndexerError(e)
}
}

pub trait BurnchainController {
fn start(&mut self, target_block_height_opt: Option<u64>)
-> Result<(BurnchainTip, u64), Error>;
Expand Down
13 changes: 3 additions & 10 deletions testnet/stacks-node/src/tests/bitcoin_regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@ use crate::helium::RunLoop;
use crate::tests::to_addr;
use crate::Config;

#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum BitcoinCoreError {
#[error("bitcoind spawn failed: {0}")]
SpawnFailed(String),
#[error("bitcoind stop failed: {0}")]
StopFailed(String),
}

impl std::fmt::Display for BitcoinCoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SpawnFailed(msg) => write!(f, "bitcoind spawn failed: {msg}"),
Self::StopFailed(msg) => write!(f, "bitcoind stop failed: {msg}"),
}
}
}

type BitcoinResult<T> = Result<T, BitcoinCoreError>;

pub struct BitcoinCoreController {
Expand Down