on_close_channel: fix output index, and simplify lnsweep
This commit is contained in:
@@ -151,7 +151,7 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction,
|
|||||||
remote_revocation_pubkey=other_revocation_pubkey,
|
remote_revocation_pubkey=other_revocation_pubkey,
|
||||||
to_self_delay=to_self_delay)
|
to_self_delay=to_self_delay)
|
||||||
if sweep_tx:
|
if sweep_tx:
|
||||||
txs.append((ctx.txid(), EncumberedTransaction('our_ctx_to_local', sweep_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
txs.append(EncumberedTransaction('our_ctx_to_local', sweep_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||||
# HTLCs
|
# HTLCs
|
||||||
def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]:
|
def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]:
|
||||||
if is_received_htlc:
|
if is_received_htlc:
|
||||||
@@ -184,16 +184,16 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction,
|
|||||||
for htlc in offered_htlcs:
|
for htlc in offered_htlcs:
|
||||||
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=False)
|
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=False)
|
||||||
if htlc_tx and to_wallet_tx:
|
if htlc_tx and to_wallet_tx:
|
||||||
txs.append((htlc_tx.txid(), EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
txs.append(EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||||
txs.append((ctx.txid(), EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry)))
|
txs.append(EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry))
|
||||||
# received HTLCs, in our ctx --> "success"
|
# received HTLCs, in our ctx --> "success"
|
||||||
# TODO consider carefully if "included_htlcs" is what we need here
|
# TODO consider carefully if "included_htlcs" is what we need here
|
||||||
received_htlcs = list(chan.included_htlcs(LOCAL, REMOTE)) # type: List[UpdateAddHtlc]
|
received_htlcs = list(chan.included_htlcs(LOCAL, REMOTE)) # type: List[UpdateAddHtlc]
|
||||||
for htlc in received_htlcs:
|
for htlc in received_htlcs:
|
||||||
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=True)
|
htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=True)
|
||||||
if htlc_tx and to_wallet_tx:
|
if htlc_tx and to_wallet_tx:
|
||||||
txs.append((htlc_tx.txid(), EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0)))
|
txs.append(EncumberedTransaction(f'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0))
|
||||||
txs.append((ctx.txid(), EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0)))
|
txs.append(EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0))
|
||||||
return txs
|
return txs
|
||||||
|
|
||||||
|
|
||||||
@@ -244,13 +244,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
|
|||||||
delayed_pubkey=this_delayed_pubkey,
|
delayed_pubkey=this_delayed_pubkey,
|
||||||
sweep_address=sweep_address)
|
sweep_address=sweep_address)
|
||||||
if sweep_tx:
|
if sweep_tx:
|
||||||
txs.append((ctx.txid(), EncumberedTransaction('their_ctx_to_local', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
txs.append(EncumberedTransaction('their_ctx_to_local', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||||
# to_remote
|
# to_remote
|
||||||
sweep_tx = maybe_create_sweeptx_for_their_ctx_to_remote(ctx=ctx,
|
sweep_tx = maybe_create_sweeptx_for_their_ctx_to_remote(ctx=ctx,
|
||||||
sweep_address=sweep_address,
|
sweep_address=sweep_address,
|
||||||
our_payment_privkey=other_payment_privkey)
|
our_payment_privkey=other_payment_privkey)
|
||||||
if sweep_tx:
|
if sweep_tx:
|
||||||
txs.append((ctx.txid(), EncumberedTransaction('their_ctx_to_remote', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
txs.append(EncumberedTransaction('their_ctx_to_remote', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||||
# HTLCs
|
# HTLCs
|
||||||
# from their ctx, we can only redeem HTLCs if the ctx was not revoked,
|
# from their ctx, we can only redeem HTLCs if the ctx was not revoked,
|
||||||
# as old HTLCs are not stored. (if it was revoked, then we should have presigned txns
|
# as old HTLCs are not stored. (if it was revoked, then we should have presigned txns
|
||||||
@@ -286,13 +286,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
|
|||||||
for htlc in received_htlcs:
|
for htlc in received_htlcs:
|
||||||
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True)
|
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True)
|
||||||
if sweep_tx:
|
if sweep_tx:
|
||||||
txs.append((ctx.txid(), EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry)))
|
txs.append(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=htlc.cltv_expiry))
|
||||||
# offered HTLCs, in their ctx --> "success"
|
# offered HTLCs, in their ctx --> "success"
|
||||||
offered_htlcs = chan.included_htlcs_in_their_latest_ctxs(REMOTE)[ctn] # type: List[UpdateAddHtlc]
|
offered_htlcs = chan.included_htlcs_in_their_latest_ctxs(REMOTE)[ctn] # type: List[UpdateAddHtlc]
|
||||||
for htlc in offered_htlcs:
|
for htlc in offered_htlcs:
|
||||||
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False)
|
sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False)
|
||||||
if sweep_tx:
|
if sweep_tx:
|
||||||
txs.append((ctx.txid(), EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0)))
|
txs.append(EncumberedTransaction(f'their_ctx_sweep_htlc_{bh2u(htlc.payment_hash)}', sweep_tx, csv_delay=0, cltv_expiry=0))
|
||||||
return txs
|
return txs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from . import constants
|
|||||||
from . import keystore
|
from . import keystore
|
||||||
from .keystore import BIP32_KeyStore
|
from .keystore import BIP32_KeyStore
|
||||||
from .bitcoin import COIN
|
from .bitcoin import COIN
|
||||||
|
from .transaction import Transaction
|
||||||
from .crypto import sha256
|
from .crypto import sha256
|
||||||
from .bip32 import bip32_root
|
from .bip32 import bip32_root
|
||||||
from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
|
from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
|
||||||
@@ -330,8 +331,11 @@ class LNWorker(PrintError):
|
|||||||
encumbered_sweeptxs = []
|
encumbered_sweeptxs = []
|
||||||
|
|
||||||
local_height = self.network.get_local_height()
|
local_height = self.network.get_local_height()
|
||||||
for prev_txid, e_tx in encumbered_sweeptxs:
|
for e_tx in encumbered_sweeptxs:
|
||||||
spender = spenders.get(prev_txid + ':0') # we assume output index is 0
|
txin = e_tx.tx.inputs()[0]
|
||||||
|
prev_txid = txin['prevout_hash']
|
||||||
|
txin_outpoint = Transaction.get_outpoint_from_txin(txin)
|
||||||
|
spender = spenders.get(txin_outpoint)
|
||||||
if spender is not None:
|
if spender is not None:
|
||||||
self.print_error('prev_tx already spent', prev_txid)
|
self.print_error('prev_tx already spent', prev_txid)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user