lnpeer: use INVALID_ONION_VERSION for unparsable onions
Use the `OnionFailureCode.INVALID_ONION_VERSION` (BADONION | PERM | 4) code when sending back `update_fail_malformed_htlc` as just sending a plain `BADONION` is not explicitly mentioned as correct in the spec.
This commit is contained in:
@@ -577,7 +577,14 @@ class OnionRoutingFailure(Exception):
|
|||||||
return error_bytes
|
return error_bytes
|
||||||
|
|
||||||
|
|
||||||
class OnionParsingError(OnionRoutingFailure): pass
|
class OnionParsingError(OnionRoutingFailure):
|
||||||
|
"""
|
||||||
|
Onion parsing error will cause a htlc to get failed with update_fail_malformed_htlc.
|
||||||
|
Using INVALID_ONION_VERSION as there is no unspecific BADONION failure code defined in the spec
|
||||||
|
for the case we just cannot parse the onion.
|
||||||
|
"""
|
||||||
|
def __init__(self, data: bytes):
|
||||||
|
OnionRoutingFailure.__init__(self, code=OnionFailureCode.INVALID_ONION_VERSION, data=data)
|
||||||
|
|
||||||
|
|
||||||
def construct_onion_error(
|
def construct_onion_error(
|
||||||
|
|||||||
@@ -3229,7 +3229,6 @@ class Peer(Logger, EventListener):
|
|||||||
except Exception as parsing_exc:
|
except Exception as parsing_exc:
|
||||||
self.logger.warning(f"unable to parse onion: {str(parsing_exc)}")
|
self.logger.warning(f"unable to parse onion: {str(parsing_exc)}")
|
||||||
onion_parsing_error = OnionParsingError(
|
onion_parsing_error = OnionParsingError(
|
||||||
code=OnionFailureCodeMetaFlag.BADONION,
|
|
||||||
data=sha256(onion_packet_bytes or b''),
|
data=sha256(onion_packet_bytes or b''),
|
||||||
)
|
)
|
||||||
raise onion_parsing_error
|
raise onion_parsing_error
|
||||||
@@ -3259,9 +3258,9 @@ class Peer(Logger, EventListener):
|
|||||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_HMAC, data=onion_hash)
|
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_HMAC, data=onion_hash)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning(f"error processing onion packet: {e!r}")
|
self.logger.warning(f"error processing onion packet: {e!r}")
|
||||||
raise OnionParsingError(code=OnionFailureCodeMetaFlag.BADONION, data=onion_hash)
|
raise OnionParsingError(data=onion_hash)
|
||||||
if self.network.config.TEST_FAIL_HTLCS_AS_MALFORMED:
|
if self.network.config.TEST_FAIL_HTLCS_AS_MALFORMED:
|
||||||
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_VERSION, data=onion_hash)
|
raise OnionParsingError(data=onion_hash)
|
||||||
if self.network.config.TEST_FAIL_HTLCS_WITH_TEMP_NODE_FAILURE:
|
if self.network.config.TEST_FAIL_HTLCS_WITH_TEMP_NODE_FAILURE:
|
||||||
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_NODE_FAILURE, data=b'')
|
raise OnionRoutingFailure(code=OnionFailureCode.TEMPORARY_NODE_FAILURE, data=b'')
|
||||||
return processed_onion
|
return processed_onion
|
||||||
|
|||||||
Reference in New Issue
Block a user