use correct feerate when sweeping htlcs

fixes #6131
This commit is contained in:
SomberNight 2020-04-30 19:37:06 +02:00
parent ab5338b46b
commit f5eb91900a
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
3 changed files with 11 additions and 5 deletions

View file

@ -838,6 +838,7 @@ class Channel(AbstractChannel):
_script, htlc_tx = make_htlc_tx_with_open_channel(chan=self, _script, htlc_tx = make_htlc_tx_with_open_channel(chan=self,
pcp=self.config[REMOTE].next_per_commitment_point, pcp=self.config[REMOTE].next_per_commitment_point,
subject=REMOTE, subject=REMOTE,
ctn=next_remote_ctn,
htlc_direction=direction, htlc_direction=direction,
commit=pending_remote_commitment, commit=pending_remote_commitment,
ctx_output_idx=ctx_output_idx, ctx_output_idx=ctx_output_idx,
@ -886,17 +887,19 @@ class Channel(AbstractChannel):
htlc_direction=direction, htlc_direction=direction,
pcp=pcp, pcp=pcp,
ctx=pending_local_commitment, ctx=pending_local_commitment,
ctx_output_idx=ctx_output_idx) ctx_output_idx=ctx_output_idx,
ctn=next_local_ctn)
with self.db_lock: with self.db_lock:
self.hm.recv_ctx() self.hm.recv_ctx()
self.config[LOCAL].current_commitment_signature=sig self.config[LOCAL].current_commitment_signature=sig
self.config[LOCAL].current_htlc_signatures=htlc_sigs_string self.config[LOCAL].current_htlc_signatures=htlc_sigs_string
def _verify_htlc_sig(self, *, htlc: UpdateAddHtlc, htlc_sig: bytes, htlc_direction: Direction, 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, _script, htlc_tx = make_htlc_tx_with_open_channel(chan=self,
pcp=pcp, pcp=pcp,
subject=LOCAL, subject=LOCAL,
ctn=ctn,
htlc_direction=htlc_direction, htlc_direction=htlc_direction,
commit=ctx, commit=ctx,
ctx_output_idx=ctx_output_idx, ctx_output_idx=ctx_output_idx,

View file

@ -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). Sweep 'to_local', and all the HTLCs (two cases: directly from ctx, or from HTLC tx).
""" """
# prep # prep
ctn = extract_ctn_from_tx_and_chan(ctx, chan)
pcp = ecc.ECPrivkey(per_commitment_secret).get_public_key_bytes(compressed=True) 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) this_conf, other_conf = get_ordered_channel_configs(chan=chan, for_us=False)
other_revocation_privkey = derive_blinded_privkey(other_conf.revocation_basepoint.privkey, 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, htlc_tx_witness_script, htlc_tx = make_htlc_tx_with_open_channel(chan=chan,
pcp=pcp, pcp=pcp,
subject=REMOTE, subject=REMOTE,
ctn=ctn,
htlc_direction=htlc_direction, htlc_direction=htlc_direction,
commit=ctx, commit=ctx,
htlc=htlc, htlc=htlc,
@ -85,7 +87,6 @@ def create_sweeptxs_for_watchtower(chan: 'Channel', ctx: Transaction, per_commit
is_revocation=True, is_revocation=True,
config=chan.lnworker.config) 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, htlc_to_ctx_output_idx_map = map_htlcs_to_ctx_output_idxs(chan=chan,
ctx=ctx, ctx=ctx,
pcp=pcp, 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]: ctx_output_idx: int) -> Tuple[bytes, Transaction]:
assert (htlc_direction == RECEIVED) == bool(preimage), 'preimage is required iff htlc is received' assert (htlc_direction == RECEIVED) == bool(preimage), 'preimage is required iff htlc is received'
preimage = preimage or b'' 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, witness_script, htlc_tx = make_htlc_tx_with_open_channel(chan=chan,
pcp=our_pcp, pcp=our_pcp,
subject=LOCAL, subject=LOCAL,
ctn=ctn,
htlc_direction=htlc_direction, htlc_direction=htlc_direction,
commit=ctx, commit=ctx,
htlc=htlc, htlc=htlc,

View file

@ -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))} 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_direction: 'Direction', commit: Transaction, ctx_output_idx: int,
htlc: 'UpdateAddHtlc', name: str = None) -> Tuple[bytes, PartialTransaction]: htlc: 'UpdateAddHtlc', name: str = None) -> Tuple[bytes, PartialTransaction]:
amount_msat, cltv_expiry, payment_hash = htlc.amount_msat, htlc.cltv_expiry, htlc.payment_hash 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 is_htlc_success = htlc_direction == RECEIVED
witness_script_of_htlc_tx_output, htlc_tx_output = make_htlc_tx_output( witness_script_of_htlc_tx_output, htlc_tx_output = make_htlc_tx_output(
amount_msat = amount_msat, 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, revocationpubkey=other_revocation_pubkey,
local_delayedpubkey=delayedpubkey, local_delayedpubkey=delayedpubkey,
success = is_htlc_success, success = is_htlc_success,