File tree Expand file tree Collapse file tree 5 files changed +21
-1
lines changed
Expand file tree Collapse file tree 5 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -954,7 +954,8 @@ impl Maker {
954954 self . config. network_port,
955955 incoming_txid
956956 ) ;
957- wallet. save_to_disk ( ) ?;
957+ // Sync to update utxo_cache with the swept UTXO so it's classified as SweptCoin
958+ wallet. sync_and_save ( ) ?;
958959 }
959960
960961 let outgoing_privkey_handover_message = PrivateKeyHandover {
@@ -991,6 +992,10 @@ impl Maker {
991992 // Get the contract output value (assuming it's the first output)
992993 let contract_value = incoming_contract_tx. output [ 0 ] . value ;
993994
995+ // sync wallet to update utxo cache before getting destination address
996+ // ensuring we get a fresh address different from any change address
997+ self . wallet . write ( ) ?. sync_and_save ( ) ?;
998+
994999 // Get a fresh internal address for the destination
9951000 let destination_address = {
9961001 let wallet = self . wallet . read ( ) ?;
Original file line number Diff line number Diff line change @@ -1459,6 +1459,10 @@ impl Taker {
14591459 . checked_sub ( fee)
14601460 . ok_or_else ( || TakerError :: General ( "Insufficient amount for fee" . to_string ( ) ) ) ?;
14611461
1462+ // sync wallet to update utxo cache before getting destination address
1463+ // ensuring we get a fresh address different from any change address
1464+ self . wallet . sync_and_save ( ) ?;
1465+
14621466 let destination_address = self
14631467 . wallet
14641468 . get_next_internal_addresses ( 1 , AddressType :: P2TR )
Original file line number Diff line number Diff line change @@ -2483,6 +2483,9 @@ impl Wallet {
24832483 witness : Witness :: new ( ) , // Will be filled later
24842484 } ;
24852485
2486+ // sync wallet to update utxo cache before getting destination address
2487+ self . sync_and_save ( ) ?;
2488+
24862489 // Get destination address
24872490 let destination = self . get_next_internal_addresses ( 1 , AddressType :: P2WPKH ) ?[ 0 ] . clone ( ) ;
24882491
@@ -2628,6 +2631,9 @@ impl Wallet {
26282631 witness : Witness :: new ( ) ,
26292632 } ;
26302633
2634+ // sync wallet to update utxo cache before getting destination address
2635+ self . sync_and_save ( ) ?;
2636+
26312637 // Get destination
26322638 let destination = self . get_next_internal_addresses ( 1 , AddressType :: P2WPKH ) ?[ 0 ] . clone ( ) ;
26332639
Original file line number Diff line number Diff line change @@ -211,6 +211,7 @@ fn test_taproot_hashlock_recovery_end_to_end() {
211211 14999518 , // No fund loss (with slight fee variance)
212212 15020989 , // 1st Maker completed the swap via hashlock path spending and earned some sats.
213213 15021003 , // 1st Maker (with slight fee variance)
214+ 15031710 , // 2nd Maker (with fee variance after sync fix)
214215 15032496 , // 2nd Maker completed the swap via hashlock path spending and earned some sats.
215216 ] ,
216217 "Taproot Maker after hashlock recovery balance check."
@@ -225,6 +226,8 @@ fn test_taproot_hashlock_recovery_end_to_end() {
225226 18 , // No fund gain/lost (with slight fee variance)
226227 21485 , // 1st Maker gained fee (with slight variance)
227228 21489 , // 1st Maker gained fee after completing the swap via hashlock path spending.
229+ 31710 , // 2nd Maker gained fee (with fee variance after sync fix)
230+ 32192 , // 1st Maker gained fee (with fee variance)
228231 32996 // 2nd Maker gained fee after completing the swap via hashlock path spending.
229232 ] ,
230233 "Taproot Maker fee gained by recovering via hashlock"
Original file line number Diff line number Diff line change @@ -184,6 +184,7 @@ fn test_taproot_maker_abort2() {
184184 14999518 , // No fund loss (with slight fee variance)
185185 15020989 , // 1st Maker completed the swap via hashlock path spending and earned some sats.
186186 15021003 , // 1st Maker (with slight fee variance)
187+ 15031710 , // 1st Maker (with fee variance after sync fix)
187188 15032496 , // 2nd Maker completed the swap via hashlock path spending and earned some sats.
188189 ] ,
189190 "Taproot Maker after hashlock recovery balance check."
@@ -197,6 +198,7 @@ fn test_taproot_maker_abort2() {
197198 0 , // No fund gain/lost for a maker,if it was not having any incoming contract(so no swap for this maker)
198199 21485 , // 1st Maker gained fee (with slight variance)
199200 21489 , // 1st Maker gained fee after completing the swap via hashlock path spending.
201+ 32192 , // 1st Maker gained fee (with fee variance after sync fix)
200202 32996 // 2nd Maker gained fee after completing the swap via hashlock path spending.
201203 ] ,
202204 "Taproot Maker should have gained some fees here."
You can’t perform that action at this time.
0 commit comments