1
0

simplify maybe_fulfill_htlc

- move some checks in two helper methods:
    - invariant checks are performed in check_accepted_htlc
    - mpp checks are performed in check_mpp_is waiting
 - in order to avoid passing local_height to check_accepted_htlc,
   the height in the error message is added by create_onion_error.
This commit is contained in:
ThomasV
2024-11-19 11:00:50 +01:00
parent 5704276cbe
commit 81aed0f6c9
2 changed files with 78 additions and 42 deletions

View File

@@ -391,12 +391,16 @@ class OnionRoutingFailure(Exception):
def construct_onion_error(
reason: OnionRoutingFailure,
error: OnionRoutingFailure,
their_public_key: bytes,
our_onion_private_key: bytes,
local_height: int
) -> bytes:
# add local height
if error.code == OnionFailureCode.INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
error.data += local_height.to_bytes(4, byteorder="big")
# create payload
failure_msg = reason.to_bytes()
failure_msg = error.to_bytes()
failure_len = len(failure_msg)
pad_len = 256 - failure_len
assert pad_len >= 0