Skip to content
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
7 changes: 6 additions & 1 deletion src/maker/api2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ impl Maker {
self.config.network_port,
incoming_txid
);
wallet.save_to_disk()?;
// Sync to update utxo_cache with the swept UTXO so it's classified as SweptCoin
wallet.sync_and_save()?;
}

let outgoing_privkey_handover_message = PrivateKeyHandover {
Expand Down Expand Up @@ -991,6 +992,10 @@ impl Maker {
// Get the contract output value (assuming it's the first output)
let contract_value = incoming_contract_tx.output[0].value;

// sync wallet to update utxo cache before getting destination address
// ensuring we get a fresh address different from any change address
self.wallet.write()?.sync_and_save()?;

// Get a fresh internal address for the destination
let destination_address = {
let wallet = self.wallet.read()?;
Expand Down
10 changes: 2 additions & 8 deletions src/maker/server2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,7 @@ fn handle_client_taproot(maker: &Arc<Maker>, stream: &mut TcpStream) -> Result<(
);
let message = match serde_cbor::from_slice::<TakerToMakerMessage>(&message_bytes) {
Ok(msg) => {
log::debug!(
"[{}] Successfully decoded message: {:?}",
maker.config.network_port,
msg
);
log::info!("[{}] <=== {}", maker.config.network_port, msg);
msg
}
Err(e) => {
Expand Down Expand Up @@ -596,7 +592,7 @@ fn handle_client_taproot(maker: &Arc<Maker>, stream: &mut TcpStream) -> Result<(
}
// Send response if we have one (only applies to taker messages)
if let Some(response_msg) = response {
log::info!("[{}] Sending response", maker.config.network_port,);
log::info!("[{}] ===> {}", maker.config.network_port, response_msg);

if let Err(e) = send_message(stream, &response_msg) {
log::error!(
Expand Down Expand Up @@ -778,8 +774,6 @@ pub fn start_maker_server_taproot(maker: Arc<Maker>) -> Result<(), MakerError> {
while !maker.shutdown.load(Relaxed) {
match listener.accept() {
Ok((mut stream, _)) => {
log::info!("[{network_port}] Received incoming connection");

if let Err(e) = handle_client_taproot(&maker, &mut stream) {
log::error!("[{network_port}] Error Handling client request {e:?}");
}
Expand Down
4 changes: 4 additions & 0 deletions src/taker/api2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,10 @@ impl Taker {
.checked_sub(fee)
.ok_or_else(|| TakerError::General("Insufficient amount for fee".to_string()))?;

// sync wallet to update utxo cache before getting destination address
// ensuring we get a fresh address different from any change address
self.wallet.sync_and_save()?;

let destination_address = self
.wallet
.get_next_internal_addresses(1, AddressType::P2TR)
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,9 @@ impl Wallet {
witness: Witness::new(), // Will be filled later
};

// sync wallet to update utxo cache before getting destination address
self.sync_and_save()?;

// Get destination address
let destination = self.get_next_internal_addresses(1, AddressType::P2WPKH)?[0].clone();

Expand Down Expand Up @@ -2628,6 +2631,9 @@ impl Wallet {
witness: Witness::new(),
};

// sync wallet to update utxo cache before getting destination address
self.sync_and_save()?;

// Get destination
let destination = self.get_next_internal_addresses(1, AddressType::P2WPKH)?[0].clone();

Expand Down
3 changes: 3 additions & 0 deletions tests/taproot_hashlock_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fn test_taproot_hashlock_recovery_end_to_end() {
14999518, // No fund loss (with slight fee variance)
15020989, // 1st Maker completed the swap via hashlock path spending and earned some sats.
15021003, // 1st Maker (with slight fee variance)
15031710, // 2nd Maker (with fee variance after sync fix)
15032496, // 2nd Maker completed the swap via hashlock path spending and earned some sats.
],
"Taproot Maker after hashlock recovery balance check."
Expand All @@ -225,6 +226,8 @@ fn test_taproot_hashlock_recovery_end_to_end() {
18, // No fund gain/lost (with slight fee variance)
21485, // 1st Maker gained fee (with slight variance)
21489, // 1st Maker gained fee after completing the swap via hashlock path spending.
31710, // 2nd Maker gained fee (with fee variance after sync fix)
32192, // 1st Maker gained fee (with fee variance)
32996 // 2nd Maker gained fee after completing the swap via hashlock path spending.
],
"Taproot Maker fee gained by recovering via hashlock"
Expand Down
2 changes: 2 additions & 0 deletions tests/taproot_maker_abort2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn test_taproot_maker_abort2() {
14999518, // No fund loss (with slight fee variance)
15020989, // 1st Maker completed the swap via hashlock path spending and earned some sats.
15021003, // 1st Maker (with slight fee variance)
15031710, // 1st Maker (with fee variance after sync fix)
15032496, // 2nd Maker completed the swap via hashlock path spending and earned some sats.
],
"Taproot Maker after hashlock recovery balance check."
Expand All @@ -197,6 +198,7 @@ fn test_taproot_maker_abort2() {
0, // No fund gain/lost for a maker,if it was not having any incoming contract(so no swap for this maker)
21485, // 1st Maker gained fee (with slight variance)
21489, // 1st Maker gained fee after completing the swap via hashlock path spending.
32192, // 1st Maker gained fee (with fee variance after sync fix)
32996 // 2nd Maker gained fee after completing the swap via hashlock path spending.
],
"Taproot Maker should have gained some fees here."
Expand Down