From 164de3c524f0f4edc99700dafa058e9e50a31944 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 19 Feb 2021 17:09:53 +1100 Subject: [PATCH] Properly calculate the confirmations for Bitcoin tx Once the transaction was included into a block it has one confirmation - before inclusion it has zero. current-block-height - transaction-block-height = zero; but that means one confirmation. Hence, the confirmation calculation was adapted to: Current-block-height - (transaction-block-height - 1). --- swap/src/bitcoin/wallet.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 39accc48..d482e4b3 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -273,7 +273,11 @@ impl WaitForTransactionFinality for Wallet { tracing::debug!("tx_block_height: {:?}", tx_block_height); let block_height = self.get_block_height().await?; tracing::debug!("latest_block_height: {:?}", block_height); - if let Some(confirmations) = block_height.checked_sub(tx_block_height) { + if let Some(confirmations) = block_height.checked_sub( + tx_block_height + .checked_sub(BlockHeight::new(1)) + .expect("transaction must be included in block with height >= 1"), + ) { tracing::debug!("confirmations: {:?}", confirmations); if u32::from(confirmations) >= execution_params.bitcoin_finality_confirmations { break;