lnaddr: fix outdated doc reference to lnworker._check_invoice

(and clean some imports/whitespace while we're at it)
This commit is contained in:
Sander van Grieken
2025-05-02 15:57:01 +02:00
parent d8551990e4
commit eda88b2972
2 changed files with 15 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ import time
from hashlib import sha256
from binascii import hexlify
from decimal import Decimal
from typing import Optional, TYPE_CHECKING, Type, Dict, Any, Union, Sequence, List, Tuple
from typing import Optional, TYPE_CHECKING, Type, Dict, Any, Sequence, Tuple
import random
import electrum_ecc as ecc
@@ -535,7 +535,7 @@ def lndecode(invoice: str, *, verbose=False, net=None) -> LnAddr:
features = int_from_data5(tagdata)
addr.tags.append(('9', features))
# note: The features are not validated here in the parser,
# instead, validation is done just before we try paying the invoice (in lnworker._check_invoice).
# instead, validation is done just before we try paying the invoice (in lnworker._check_bolt11_invoice).
# Context: invoice parsing happens when opening a wallet. If there was a backwards-incompatible
# change to a feature, and we raised, some existing wallets could not be opened. Such a change
# can happen to features not-yet-merged-to-BOLTs (e.g. trampoline feature bit was moved and reused).
@@ -565,8 +565,10 @@ def lndecode(invoice: str, *, verbose=False, net=None) -> LnAddr:
if not ecc.ECPubkey(addr.pubkey).ecdsa_verify(sigdecoded[:64], hrp_hash):
raise LnDecodeException("bad signature")
pubkey_copy = addr.pubkey
class WrappedBytesKey:
serialize = lambda: pubkey_copy
addr.pubkey = WrappedBytesKey
else: # Recover pubkey from signature.
addr.pubkey = SerializableKey(ecc.ECPubkey.from_ecdsa_sig64(sigdecoded[:64], sigdecoded[64], hrp_hash))

View File

@@ -1,6 +1,5 @@
from copy import deepcopy
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, Set
import threading
from typing import Sequence, Tuple, Dict, TYPE_CHECKING, Set
from .lnutil import SENT, RECEIVED, LOCAL, REMOTE, HTLCOwner, UpdateAddHtlc, Direction, FeeUpdate
from .util import bfh, with_lock
@@ -490,8 +489,7 @@ class HTLCManager:
return d
@with_lock
def all_settled_htlcs_ever(self, subject: HTLCOwner, ctn: int = None) \
-> Sequence[Tuple[Direction, UpdateAddHtlc]]:
def all_settled_htlcs_ever(self, subject: HTLCOwner, ctn: int = None) -> Sequence[Tuple[Direction, UpdateAddHtlc]]:
"""Return the list of all HTLCs that have been ever settled in subject's
ctx up to ctn.
"""
@@ -527,14 +525,16 @@ class HTLCManager:
# sent htlcs
for htlc_id in considered_sent_htlc_ids:
ctns = self.log[whose]['settles'].get(htlc_id, None)
if ctns is None: continue
if ctns is None:
continue
if ctns[ctx_owner] is not None and ctns[ctx_owner] <= ctn:
htlc = self.log[whose]['adds'][htlc_id]
balance -= htlc.amount_msat
# recv htlcs
for htlc_id in considered_recv_htlc_ids:
ctns = self.log[-whose]['settles'].get(htlc_id, None)
if ctns is None: continue
if ctns is None:
continue
if ctns[ctx_owner] is not None and ctns[ctx_owner] <= ctn:
htlc = self.log[-whose]['adds'][htlc_id]
balance += htlc.amount_msat
@@ -551,7 +551,8 @@ class HTLCManager:
htlcs = []
for htlc_id in considered_htlc_ids:
ctns = self.log[htlc_proposer][log_action].get(htlc_id, None)
if ctns is None: continue
if ctns is None:
continue
if ctns[ctx_owner] == ctn:
htlcs.append(self.log[htlc_proposer]['adds'][htlc_id])
return htlcs