mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-09-24 06:44:43 -04:00
Reimplement tx_punish check without breaking database changes
This commit is contained in:
parent
d79eaca32b
commit
ab33bcde8f
3 changed files with 34 additions and 30 deletions
|
@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Record tx_punish address in state `State6`. This solves issues where the CLI was offline for too long after sending the BTC transaction and Alice punished Bob, resulting in CLI being in an incorrect state. This is a breaking database change! Swaps that were saved prior to this change may fail to load if they are in states `State3`, `State4` and `State6`. Make sure to finish your swaps before upgrading.
|
|
||||||
|
|
||||||
## [0.13.0] - 2024-05-29
|
## [0.13.0] - 2024-05-29
|
||||||
|
|
||||||
- Minimum Supported Rust Version (MSRV) bumped to 1.74
|
- Minimum Supported Rust Version (MSRV) bumped to 1.74
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::bitcoin::{parse_rpc_error_code, RpcErrorCode, Wallet};
|
use crate::bitcoin::{parse_rpc_error_code, RpcErrorCode, Wallet};
|
||||||
use crate::protocol::bob::BobState;
|
use crate::protocol::bob::BobState;
|
||||||
use crate::protocol::Database;
|
use crate::protocol::{Database, State};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use bitcoin::Txid;
|
use bitcoin::Txid;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -123,7 +123,19 @@ pub async fn refund(
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
if state6
|
let state3 = db
|
||||||
|
.get_states(swap_id)
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.find_map(|state| {
|
||||||
|
if let State::Bob(BobState::BtcLocked { state3, .. }) = state {
|
||||||
|
Some(state3.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if state3
|
||||||
|
.expect("Error: weren't able to extract State3 from database.")
|
||||||
.check_for_tx_punish(bitcoin_wallet.as_ref())
|
.check_for_tx_punish(bitcoin_wallet.as_ref())
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
|
|
|
@ -436,7 +436,6 @@ impl State3 {
|
||||||
cancel_timelock: self.cancel_timelock,
|
cancel_timelock: self.cancel_timelock,
|
||||||
punish_timelock: self.punish_timelock,
|
punish_timelock: self.punish_timelock,
|
||||||
refund_address: self.refund_address.clone(),
|
refund_address: self.refund_address.clone(),
|
||||||
punish_address: self.punish_address.clone(),
|
|
||||||
tx_lock: self.tx_lock.clone(),
|
tx_lock: self.tx_lock.clone(),
|
||||||
tx_cancel_sig_a: self.tx_cancel_sig_a.clone(),
|
tx_cancel_sig_a: self.tx_cancel_sig_a.clone(),
|
||||||
tx_refund_encsig: self.tx_refund_encsig.clone(),
|
tx_refund_encsig: self.tx_refund_encsig.clone(),
|
||||||
|
@ -472,6 +471,26 @@ impl State3 {
|
||||||
tx_cancel_status,
|
tx_cancel_status,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
pub async fn check_for_tx_punish(
|
||||||
|
&self,
|
||||||
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
|
) -> Result<Transaction> {
|
||||||
|
let tx_cancel = bitcoin::TxCancel::new(
|
||||||
|
&self.tx_lock,
|
||||||
|
self.cancel_timelock,
|
||||||
|
self.A,
|
||||||
|
self.b.public(),
|
||||||
|
self.tx_cancel_fee,
|
||||||
|
)?;
|
||||||
|
let tx_punish = bitcoin::TxPunish::new(
|
||||||
|
&tx_cancel,
|
||||||
|
&self.punish_address,
|
||||||
|
self.punish_timelock,
|
||||||
|
self.tx_punish_fee,
|
||||||
|
);
|
||||||
|
let tx = bitcoin_wallet.get_raw_transaction(tx_punish.txid()).await?;
|
||||||
|
Ok(tx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||||
|
@ -586,7 +605,6 @@ impl State4 {
|
||||||
cancel_timelock: self.cancel_timelock,
|
cancel_timelock: self.cancel_timelock,
|
||||||
punish_timelock: self.punish_timelock,
|
punish_timelock: self.punish_timelock,
|
||||||
refund_address: self.refund_address,
|
refund_address: self.refund_address,
|
||||||
punish_address: self.punish_address,
|
|
||||||
tx_lock: self.tx_lock,
|
tx_lock: self.tx_lock,
|
||||||
tx_cancel_sig_a: self.tx_cancel_sig_a,
|
tx_cancel_sig_a: self.tx_cancel_sig_a,
|
||||||
tx_refund_encsig: self.tx_refund_encsig,
|
tx_refund_encsig: self.tx_refund_encsig,
|
||||||
|
@ -628,7 +646,6 @@ pub struct State6 {
|
||||||
cancel_timelock: CancelTimelock,
|
cancel_timelock: CancelTimelock,
|
||||||
punish_timelock: PunishTimelock,
|
punish_timelock: PunishTimelock,
|
||||||
refund_address: bitcoin::Address,
|
refund_address: bitcoin::Address,
|
||||||
punish_address: bitcoin::Address,
|
|
||||||
tx_lock: bitcoin::TxLock,
|
tx_lock: bitcoin::TxLock,
|
||||||
tx_cancel_sig_a: Signature,
|
tx_cancel_sig_a: Signature,
|
||||||
tx_refund_encsig: bitcoin::EncryptedSignature,
|
tx_refund_encsig: bitcoin::EncryptedSignature,
|
||||||
|
@ -681,27 +698,6 @@ impl State6 {
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_for_tx_punish(
|
|
||||||
&self,
|
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
|
||||||
) -> Result<Transaction> {
|
|
||||||
let tx_cancel = bitcoin::TxCancel::new(
|
|
||||||
&self.tx_lock,
|
|
||||||
self.cancel_timelock,
|
|
||||||
self.A,
|
|
||||||
self.b.public(),
|
|
||||||
self.tx_cancel_fee,
|
|
||||||
)?;
|
|
||||||
let tx_punish = bitcoin::TxPunish::new(
|
|
||||||
&tx_cancel,
|
|
||||||
&self.punish_address,
|
|
||||||
self.punish_timelock,
|
|
||||||
self.tx_punish_fee,
|
|
||||||
);
|
|
||||||
let tx = bitcoin_wallet.get_raw_transaction(tx_punish.txid()).await?;
|
|
||||||
Ok(tx)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn submit_tx_cancel(
|
pub async fn submit_tx_cancel(
|
||||||
&self,
|
&self,
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue