|
|
@ -27,6 +27,7 @@ import hashlib |
|
|
|
import hmac |
|
|
|
from collections import namedtuple |
|
|
|
from typing import Sequence |
|
|
|
from enum import IntEnum, IntFlag |
|
|
|
|
|
|
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms |
|
|
|
from cryptography.hazmat.backends import default_backend |
|
|
@ -299,33 +300,46 @@ def get_failure_msg_from_onion_error(decrypted_error_packet: bytes) -> OnionRout |
|
|
|
return OnionRoutingFailureMessage(failure_code, failure_data) |
|
|
|
|
|
|
|
|
|
|
|
ONION_FC_BADONION = BADONION = 0x8000 |
|
|
|
ONION_FC_PERM = PERM = 0x4000 |
|
|
|
ONION_FC_NODE = NODE = 0x2000 |
|
|
|
ONION_FC_UPDATE = UPDATE = 0x1000 |
|
|
|
ONION_FAILURE_CODE_MAP = { |
|
|
|
PERM | 1 : 'invalid_realm', |
|
|
|
NODE | 2 : 'temporary_node_failure', |
|
|
|
PERM | NODE | 2 : 'permanent_node_failure', |
|
|
|
PERM | NODE | 3 : 'required_node_feature_missing', |
|
|
|
BADONION | PERM | 4 : 'invalid_onion_version', |
|
|
|
BADONION | PERM | 5 : 'invalid_onion_hmac', |
|
|
|
BADONION | PERM | 6 : 'invalid_onion_key', |
|
|
|
UPDATE | 7 : 'temporary_channel_failure', |
|
|
|
PERM | 8 : 'permanent_channel_failure', |
|
|
|
PERM | 9 : 'required_channel_feature_missing', |
|
|
|
PERM | 10 : 'unknown_next_peer', |
|
|
|
UPDATE | 11 : 'amount_below_minimum', |
|
|
|
UPDATE | 12 : 'fee_insufficient', |
|
|
|
UPDATE | 13 : 'incorrect_cltv_expiry', |
|
|
|
UPDATE | 14 : 'expiry_too_soon', |
|
|
|
PERM | 15 : 'unknown_payment_hash', |
|
|
|
PERM | 16 : 'incorrect_payment_amount', |
|
|
|
17 : 'final_expiry_too_soon', |
|
|
|
18 : 'final_incorrect_cltv_expiry', |
|
|
|
19 : 'final_incorrect_htlc_amount', |
|
|
|
UPDATE | 20 : 'channel_disabled', |
|
|
|
21 : 'expiry_too_far', |
|
|
|
} |
|
|
|
class OnionFailureCodeMetaFlag(IntFlag): |
|
|
|
BADONION = 0x8000 |
|
|
|
PERM = 0x4000 |
|
|
|
NODE = 0x2000 |
|
|
|
UPDATE = 0x1000 |
|
|
|
|
|
|
|
BADONION = OnionFailureCodeMetaFlag.BADONION |
|
|
|
PERM = OnionFailureCodeMetaFlag.PERM |
|
|
|
NODE = OnionFailureCodeMetaFlag.NODE |
|
|
|
UPDATE = OnionFailureCodeMetaFlag.UPDATE |
|
|
|
class OnionFailureCode(IntEnum): |
|
|
|
INVALID_REALM = PERM | 1 |
|
|
|
TEMPORARY_NODE_FAILURE = NODE | 2 |
|
|
|
PERMANENT_NODE_FAILURE = PERM | NODE | 2 |
|
|
|
REQUIRED_NODE_FEATURE_MISSING = PERM | NODE | 3 |
|
|
|
INVALID_ONION_VERSION = BADONION | PERM | 4 |
|
|
|
INVALID_ONION_HMAC = BADONION | PERM | 5 |
|
|
|
INVALID_ONION_KEY = BADONION | PERM | 6 |
|
|
|
TEMPORARY_CHANNEL_FAILURE = UPDATE | 7 |
|
|
|
PERMANENT_CHANNEL_FAILURE = PERM | 8 |
|
|
|
REQUIRED_CHANNEL_FEATURE_MISSING = PERM | 9 |
|
|
|
UNKNOWN_NEXT_PEER = PERM | 10 |
|
|
|
AMOUNT_BELOW_MINIMUM = UPDATE | 11 |
|
|
|
FEE_INSUFFICIENT = UPDATE | 12 |
|
|
|
INCORRECT_CLTV_EXPIRY = UPDATE | 13 |
|
|
|
EXPIRY_TOO_SOON = UPDATE | 14 |
|
|
|
UNKNOWN_PAYMENT_HASH = PERM | 15 |
|
|
|
INCORRECT_PAYMENT_AMOUNT = PERM | 16 |
|
|
|
FINAL_EXPIRY_TOO_SOON = 17 |
|
|
|
FINAL_INCORRECT_CLTV_EXPIRY = 18 |
|
|
|
FINAL_INCORRECT_HTLC_AMOUNT = 19 |
|
|
|
CHANNEL_DISABLED = UPDATE | 20 |
|
|
|
EXPIRY_TOO_FAR = 21 |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def _missing_(cls, value: int) -> int: |
|
|
|
# note that for unknown error codes, we return an int, |
|
|
|
# not an instance of cls |
|
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|
# don't use these elsewhere, the names are ambiguous without context |
|
|
|
del BADONION; del PERM; del NODE; del UPDATE |
|
|
|