tln: fix sweeping htlc output from remote ctx (timeout e.g. without htlc tx) - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit 51bc02557d368e3d6af8e12567dc5839eaccc70e
 (DIR) parent e56e8495059d526b6151839dcf2a7caddb5a8d18
 (HTM) Author: Janus <ysangkok@gmail.com>
       Date:   Tue, 22 Jan 2019 15:35:05 +0100
       
       ln: fix sweeping htlc output from remote ctx (timeout e.g. without htlc tx)
       
       Diffstat:
         M electrum/lnsweep.py                 |       6 +++++-
       
       1 file changed, 5 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/electrum/lnsweep.py b/electrum/lnsweep.py
       t@@ -362,6 +362,7 @@ def create_sweeptx_their_ctx_htlc(ctx: Transaction, witness_script: bytes, sweep
                                          preimage: Optional[bytes], output_idx: int,
                                          privkey: bytes, is_revocation: bool, cltv_expiry: int,
                                          fee_per_kb: int=None) -> Optional[Transaction]:
       +    assert type(cltv_expiry) is int
            preimage = preimage or b''  # preimage is required iff (not is_revocation and htlc is offered)
            val = ctx.outputs()[output_idx].value
            sweep_inputs = [{
       t@@ -381,7 +382,10 @@ def create_sweeptx_their_ctx_htlc(ctx: Transaction, witness_script: bytes, sweep
            outvalue = val - fee
            if outvalue <= dust_threshold(): return None
            sweep_outputs = [TxOutput(TYPE_ADDRESS, sweep_address, outvalue)]
       -    tx = Transaction.from_io(sweep_inputs, sweep_outputs, version=2, name=f'their_ctx_sweep_htlc_{ctx.txid()[:8]}_{output_idx}', cltv_expiry=cltv_expiry)
       +    tx = Transaction.from_io(sweep_inputs, sweep_outputs, version=2
       +            , name=f'their_ctx_sweep_htlc_{ctx.txid()[:8]}_{output_idx}'
       +            # note that cltv_expiry, and therefore also locktime will be zero when breach!
       +            , cltv_expiry=cltv_expiry, locktime=cltv_expiry)
        
            sig = bfh(tx.sign_txin(0, privkey))
            if not is_revocation: