electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 3019aa35cf3b6deca9ec42d30af782d8a74a9389
parent 729ddb8ec30494ee9c22284625d2c0f3196ac987
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 12 Dec 2018 18:02:55 +0100

on_close_channel: fix output index, and simplify lnsweep

Diffstat:
Melectrum/lnsweep.py | 18+++++++++---------
Melectrum/lnworker.py | 8++++++--
2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/electrum/lnsweep.py b/electrum/lnsweep.py @@ -151,7 +151,7 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction, remote_revocation_pubkey=other_revocation_pubkey, to_self_delay=to_self_delay) 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 def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]: if is_received_htlc: @@ -184,16 +184,16 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction, for htlc in offered_htlcs: htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=False) 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((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'second_stage_to_wallet_{bh2u(htlc.payment_hash)}', to_wallet_tx, csv_delay=to_self_delay, cltv_expiry=0)) + 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" # TODO consider carefully if "included_htlcs" is what we need here received_htlcs = list(chan.included_htlcs(LOCAL, REMOTE)) # type: List[UpdateAddHtlc] for htlc in received_htlcs: htlc_tx, to_wallet_tx = create_txns_for_htlc(htlc, is_received_htlc=True) 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((ctx.txid(), EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, 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(EncumberedTransaction(f'our_ctx_htlc_tx_{bh2u(htlc.payment_hash)}', htlc_tx, csv_delay=0, cltv_expiry=0)) return txs @@ -244,13 +244,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction, delayed_pubkey=this_delayed_pubkey, sweep_address=sweep_address) 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 sweep_tx = maybe_create_sweeptx_for_their_ctx_to_remote(ctx=ctx, sweep_address=sweep_address, our_payment_privkey=other_payment_privkey) 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 # 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 @@ -286,13 +286,13 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction, for htlc in received_htlcs: sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=True) 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 = chan.included_htlcs_in_their_latest_ctxs(REMOTE)[ctn] # type: List[UpdateAddHtlc] for htlc in offered_htlcs: sweep_tx = create_sweeptx_for_htlc(htlc, is_received_htlc=False) 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 diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -21,6 +21,7 @@ from . import constants from . import keystore from .keystore import BIP32_KeyStore from .bitcoin import COIN +from .transaction import Transaction from .crypto import sha256 from .bip32 import bip32_root from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions @@ -330,8 +331,11 @@ class LNWorker(PrintError): encumbered_sweeptxs = [] local_height = self.network.get_local_height() - for prev_txid, e_tx in encumbered_sweeptxs: - spender = spenders.get(prev_txid + ':0') # we assume output index is 0 + for e_tx in encumbered_sweeptxs: + 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: self.print_error('prev_tx already spent', prev_txid) continue