Skip to content

Commit

Permalink
Change to irecoverrable error
Browse files Browse the repository at this point in the history
  • Loading branch information
ninegua committed Oct 25, 2024
1 parent f0f20f1 commit 98e4a98
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions rs/bitcoin/kyt/btc_kyt_canister.did
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type CheckTransactionIrrecoverableError = variant {
ResponseTooLarge : record { txid: blob };
// Invalid transaction id.
InvalidTransactionId : text;
// Invalid transaction.
InvalidTransaction : text;
};

type InitArg = record {
Expand Down
17 changes: 11 additions & 6 deletions rs/bitcoin/kyt/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::state::{
FetchGuardError, FetchTxStatus, FetchTxStatusError, FetchedTx, HttpGetTxError,
TransactionKytData,
};
use crate::types::{CheckTransactionResponse, CheckTransactionRetriable, CheckTransactionStatus};
use crate::types::{
CheckTransactionIrrecoverableError, CheckTransactionResponse, CheckTransactionRetriable,
CheckTransactionStatus,
};
use crate::{blocklist_contains, providers, state, BtcNetwork};
use bitcoin::Transaction;
use futures::future::try_join_all;
Expand Down Expand Up @@ -222,10 +225,12 @@ pub trait FetchEnv {
state::set_fetched_address(txid, index, address.clone());
} else {
// This error shouldn't happen unless blockdata is corrupted.
return CheckTransactionRetriable::TransientInternalError(format!(
"Tx {} vout {} has no address, but is vin {} of tx {}",
input.txid, input.vout, index, txid
))
return CheckTransactionIrrecoverableError::InvalidTransaction(
format!(
"Tx {} vout {} has no address, but is vin {} of tx {}",
input.txid, input.vout, index, txid
),
)
.into();
}
}
Expand Down Expand Up @@ -258,7 +263,7 @@ pub trait FetchEnv {
} else {
// This error shouldn't happen unless blockdata is corrupted.
error = Some(
CheckTransactionRetriable::TransientInternalError(format!(
CheckTransactionIrrecoverableError::InvalidTransaction(format!(
"Tx {} vout {} has no address, but is vin {} of tx {}",
input_txid, vout, index, txid
))
Expand Down
4 changes: 2 additions & 2 deletions rs/bitcoin/kyt/src/fetch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ async fn test_check_fetched() {
env.expect_get_tx_with_reply(Ok(mock_transaction_with_output_but_no_address(2)));
assert!(matches!(
env.check_fetched(txid_0, &fetched).await,
CheckTransactionResponse::Unknown(CheckTransactionStatus::Retriable(
CheckTransactionRetriable::TransientInternalError(err)
CheckTransactionResponse::Unknown(CheckTransactionStatus::Error(
CheckTransactionIrrecoverableError::InvalidTransaction(err)
)) if err.contains("has no address")
));
}
2 changes: 2 additions & 0 deletions rs/bitcoin/kyt/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum CheckTransactionIrrecoverableError {
ResponseTooLarge { txid: Vec<u8> },
/// Invalid transaction id because it fails to decode.
InvalidTransactionId(String),
/// Invalid transaction.
InvalidTransaction(String),
}

impl From<CheckTransactionIrrecoverableError> for CheckTransactionResponse {
Expand Down

0 comments on commit 98e4a98

Please sign in to comment.