From cf199b44960d17799176eae754ed05744952ec91 Mon Sep 17 00:00:00 2001 From: Viktar Makouski Date: Mon, 6 Jan 2025 13:48:40 +0300 Subject: [PATCH] get_tenure_raw error message upgrade --- signer/src/error.rs | 4 ++++ signer/src/stacks/api.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/signer/src/error.rs b/signer/src/error.rs index 210df565f..769c7361d 100644 --- a/signer/src/error.rs +++ b/signer/src/error.rs @@ -114,6 +114,10 @@ pub enum Error { #[error("observed a tenure identified by a StacksBlockId with with no blocks")] EmptyStacksTenure, + /// This should never happen + #[error("get_tenure_raw returned unexpected responce: {0}. Expected: {1}")] + GetTenureRawMismatch(StacksBlockId, StacksBlockId), + /// Received an error in call to estimatesmartfee RPC call #[error("failed to get fee estimate from bitcoin-core for target {1}. {0}")] EstimateSmartFee(#[source] bitcoincore_rpc::Error, u16), diff --git a/signer/src/stacks/api.rs b/signer/src/stacks/api.rs index c9f045c61..a7f05de85 100644 --- a/signer/src/stacks/api.rs +++ b/signer/src/stacks/api.rs @@ -810,7 +810,15 @@ impl StacksClient { // The first block in the GET /v3/tenures/ response // is always the block related to the given . But we // already have that block, so we can skip adding it again. - debug_assert_eq!(blocks.first().map(|b| b.block_id()), Some(last_block_id)); + + if let Some(received_id) = blocks.first().map(|b| b.block_id()) { + if received_id != last_block_id { + return Err(Error::GetTenureRawMismatch(received_id, last_block_id)); + } + } else { + return Err(Error::EmptyStacksTenure); + } + tenure_blocks.extend(blocks.into_iter().skip(1)) }