commit f5eb91900ab0a1c3bb776d14f417e566932e596e
parent ab5338b46b78152eb0f430837133ffd1ed855783
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 30 Apr 2020 19:37:06 +0200
use correct feerate when sweeping htlcs
fixes #6131
Diffstat:
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -838,6 +838,7 @@ class Channel(AbstractChannel):
_script, htlc_tx = make_htlc_tx_with_open_channel(chan=self,
pcp=self.config[REMOTE].next_per_commitment_point,
subject=REMOTE,
+ ctn=next_remote_ctn,
htlc_direction=direction,
commit=pending_remote_commitment,
ctx_output_idx=ctx_output_idx,
@@ -886,17 +887,19 @@ class Channel(AbstractChannel):
htlc_direction=direction,
pcp=pcp,
ctx=pending_local_commitment,
- ctx_output_idx=ctx_output_idx)
+ ctx_output_idx=ctx_output_idx,
+ ctn=next_local_ctn)
with self.db_lock:
self.hm.recv_ctx()
self.config[LOCAL].current_commitment_signature=sig
self.config[LOCAL].current_htlc_signatures=htlc_sigs_string
def _verify_htlc_sig(self, *, htlc: UpdateAddHtlc, htlc_sig: bytes, htlc_direction: Direction,
- pcp: bytes, ctx: Transaction, ctx_output_idx: int) -> None:
+ pcp: bytes, ctx: Transaction, ctx_output_idx: int, ctn: int) -> None:
_script, htlc_tx = make_htlc_tx_with_open_channel(chan=self,
pcp=pcp,
subject=LOCAL,
+ ctn=ctn,
htlc_direction=htlc_direction,
commit=ctx,
ctx_output_idx=ctx_output_idx,
diff --git a/electrum/lnsweep.py b/electrum/lnsweep.py
@@ -41,6 +41,7 @@ def create_sweeptxs_for_watchtower(chan: 'Channel', ctx: Transaction, per_commit
Sweep 'to_local', and all the HTLCs (two cases: directly from ctx, or from HTLC tx).
"""
# prep
+ ctn = extract_ctn_from_tx_and_chan(ctx, chan)
pcp = ecc.ECPrivkey(per_commitment_secret).get_public_key_bytes(compressed=True)
this_conf, other_conf = get_ordered_channel_configs(chan=chan, for_us=False)
other_revocation_privkey = derive_blinded_privkey(other_conf.revocation_basepoint.privkey,
@@ -72,6 +73,7 @@ def create_sweeptxs_for_watchtower(chan: 'Channel', ctx: Transaction, per_commit
htlc_tx_witness_script, htlc_tx = make_htlc_tx_with_open_channel(chan=chan,
pcp=pcp,
subject=REMOTE,
+ ctn=ctn,
htlc_direction=htlc_direction,
commit=ctx,
htlc=htlc,
@@ -85,7 +87,6 @@ def create_sweeptxs_for_watchtower(chan: 'Channel', ctx: Transaction, per_commit
is_revocation=True,
config=chan.lnworker.config)
- ctn = extract_ctn_from_tx_and_chan(ctx, chan)
htlc_to_ctx_output_idx_map = map_htlcs_to_ctx_output_idxs(chan=chan,
ctx=ctx,
pcp=pcp,
@@ -425,9 +426,11 @@ def create_htlctx_that_spends_from_our_ctx(chan: 'Channel', our_pcp: bytes,
ctx_output_idx: int) -> Tuple[bytes, Transaction]:
assert (htlc_direction == RECEIVED) == bool(preimage), 'preimage is required iff htlc is received'
preimage = preimage or b''
+ ctn = extract_ctn_from_tx_and_chan(ctx, chan)
witness_script, htlc_tx = make_htlc_tx_with_open_channel(chan=chan,
pcp=our_pcp,
subject=LOCAL,
+ ctn=ctn,
htlc_direction=htlc_direction,
commit=ctx,
htlc=htlc,
diff --git a/electrum/lnutil.py b/electrum/lnutil.py
@@ -564,7 +564,7 @@ def map_htlcs_to_ctx_output_idxs(*, chan: 'Channel', ctx: Transaction, pcp: byte
for htlc_relative_idx, ctx_output_idx in enumerate(sorted(inverse_map))}
-def make_htlc_tx_with_open_channel(*, chan: 'Channel', pcp: bytes, subject: 'HTLCOwner',
+def make_htlc_tx_with_open_channel(*, chan: 'Channel', pcp: bytes, subject: 'HTLCOwner', ctn: int,
htlc_direction: 'Direction', commit: Transaction, ctx_output_idx: int,
htlc: 'UpdateAddHtlc', name: str = None) -> Tuple[bytes, PartialTransaction]:
amount_msat, cltv_expiry, payment_hash = htlc.amount_msat, htlc.cltv_expiry, htlc.payment_hash
@@ -580,7 +580,7 @@ def make_htlc_tx_with_open_channel(*, chan: 'Channel', pcp: bytes, subject: 'HTL
is_htlc_success = htlc_direction == RECEIVED
witness_script_of_htlc_tx_output, htlc_tx_output = make_htlc_tx_output(
amount_msat = amount_msat,
- local_feerate = chan.get_next_feerate(LOCAL if for_us else REMOTE),
+ local_feerate = chan.get_feerate(subject, ctn=ctn),
revocationpubkey=other_revocation_pubkey,
local_delayedpubkey=delayedpubkey,
success = is_htlc_success,