|
|
|
|
@ -299,6 +299,7 @@ class SwapManager(Logger):
|
|
|
|
|
self._add_or_reindex_swap(swap) # to update _swaps_by_funding_outpoint |
|
|
|
|
funding_height = self.lnwatcher.adb.get_tx_height(txin.prevout.txid.hex()) |
|
|
|
|
spent_height = txin.spent_height |
|
|
|
|
should_bump_fee = False |
|
|
|
|
if spent_height is not None: |
|
|
|
|
swap.spending_txid = txin.spent_txid |
|
|
|
|
if spent_height > 0: |
|
|
|
|
@ -326,18 +327,27 @@ class SwapManager(Logger):
|
|
|
|
|
if not swap.is_reverse: |
|
|
|
|
if swap.preimage is None and spent_height is not None: |
|
|
|
|
# extract the preimage, add it to lnwatcher |
|
|
|
|
tx = self.lnwatcher.adb.get_transaction(txin.spent_txid) |
|
|
|
|
preimage = tx.inputs()[0].witness_elements()[1] |
|
|
|
|
claim_tx = self.lnwatcher.adb.get_transaction(txin.spent_txid) |
|
|
|
|
preimage = claim_tx.inputs()[0].witness_elements()[1] |
|
|
|
|
if sha256(preimage) == swap.payment_hash: |
|
|
|
|
swap.preimage = preimage |
|
|
|
|
self.logger.info(f'found preimage: {preimage.hex()}') |
|
|
|
|
self.lnworker.preimages[swap.payment_hash.hex()] = preimage.hex() |
|
|
|
|
# note: we must check the payment secret before we broadcast the funding tx |
|
|
|
|
else: |
|
|
|
|
# refund tx |
|
|
|
|
# this is our refund tx |
|
|
|
|
if spent_height > 0: |
|
|
|
|
self.logger.info(f'refund tx confirmed: {txin.spent_txid} {spent_height}') |
|
|
|
|
self._fail_swap(swap, 'refund tx confirmed') |
|
|
|
|
return |
|
|
|
|
else: |
|
|
|
|
claim_tx.add_info_from_wallet(self.wallet) |
|
|
|
|
claim_tx_fee = claim_tx.get_fee() |
|
|
|
|
recommended_fee = self.get_claim_fee() |
|
|
|
|
if claim_tx_fee * 1.1 < recommended_fee: |
|
|
|
|
should_bump_fee = True |
|
|
|
|
self.logger.info(f'claim tx fee too low {claim_tx_fee} < {recommended_fee}. we will bump the fee') |
|
|
|
|
|
|
|
|
|
if remaining_time > 0: |
|
|
|
|
# too early for refund |
|
|
|
|
return |
|
|
|
|
@ -362,7 +372,7 @@ class SwapManager(Logger):
|
|
|
|
|
# for testing: do not create claim tx |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if spent_height is not None: |
|
|
|
|
if spent_height is not None and not should_bump_fee: |
|
|
|
|
return |
|
|
|
|
try: |
|
|
|
|
tx = self._create_and_sign_claim_tx(txin=txin, swap=swap, config=self.wallet.config) |
|
|
|
|
|