|
|
|
|
@ -22,7 +22,7 @@ from . import ecc
|
|
|
|
|
from .ecc import sig_string_from_r_and_s, der_sig_from_sig_string |
|
|
|
|
from . import constants |
|
|
|
|
from .util import (bfh, log_exceptions, ignore_exceptions, chunks, OldTaskGroup, |
|
|
|
|
UnrelatedTransactionException) |
|
|
|
|
UnrelatedTransactionException, error_text_bytes_to_safe_str) |
|
|
|
|
from . import transaction |
|
|
|
|
from .bitcoin import make_op_return |
|
|
|
|
from .transaction import PartialTxOutput, match_script_against_template, Sighash |
|
|
|
|
@ -241,13 +241,14 @@ class Peer(Logger):
|
|
|
|
|
|
|
|
|
|
def on_warning(self, payload): |
|
|
|
|
chan_id = payload.get("channel_id") |
|
|
|
|
err_bytes = payload['data'] |
|
|
|
|
self.logger.info(f"remote peer sent warning [DO NOT TRUST THIS MESSAGE]: " |
|
|
|
|
f"{payload['data'].decode('ascii')}. chan_id={chan_id.hex()}") |
|
|
|
|
f"{error_text_bytes_to_safe_str(err_bytes)}. chan_id={chan_id.hex()}") |
|
|
|
|
if chan_id in self.channels: |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'warning': payload['data']})) |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'warning': err_bytes})) |
|
|
|
|
elif chan_id in self.temp_id_to_id: |
|
|
|
|
chan_id = self.temp_id_to_id[chan_id] or chan_id |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'warning': payload['data']})) |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'warning': err_bytes})) |
|
|
|
|
else: |
|
|
|
|
# if no existing channel is referred to by channel_id: |
|
|
|
|
# - MUST ignore the message. |
|
|
|
|
@ -256,20 +257,21 @@ class Peer(Logger):
|
|
|
|
|
|
|
|
|
|
def on_error(self, payload): |
|
|
|
|
chan_id = payload.get("channel_id") |
|
|
|
|
err_bytes = payload['data'] |
|
|
|
|
self.logger.info(f"remote peer sent error [DO NOT TRUST THIS MESSAGE]: " |
|
|
|
|
f"{payload['data'].decode('ascii')}. chan_id={chan_id.hex()}") |
|
|
|
|
f"{error_text_bytes_to_safe_str(err_bytes)}. chan_id={chan_id.hex()}") |
|
|
|
|
if chan_id in self.channels: |
|
|
|
|
self.schedule_force_closing(chan_id) |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'error': payload['data']})) |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'error': err_bytes})) |
|
|
|
|
elif chan_id in self.temp_id_to_id: |
|
|
|
|
chan_id = self.temp_id_to_id[chan_id] or chan_id |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'error': payload['data']})) |
|
|
|
|
self.ordered_message_queues[chan_id].put_nowait((None, {'error': err_bytes})) |
|
|
|
|
elif chan_id == bytes(32): |
|
|
|
|
# if channel_id is all zero: |
|
|
|
|
# - MUST fail all channels with the sending node. |
|
|
|
|
for cid in self.channels: |
|
|
|
|
self.schedule_force_closing(cid) |
|
|
|
|
self.ordered_message_queues[cid].put_nowait((None, {'error': payload['data']})) |
|
|
|
|
self.ordered_message_queues[cid].put_nowait((None, {'error': err_bytes})) |
|
|
|
|
else: |
|
|
|
|
# if no existing channel is referred to by channel_id: |
|
|
|
|
# - MUST ignore the message. |
|
|
|
|
@ -337,12 +339,11 @@ class Peer(Logger):
|
|
|
|
|
q = self.ordered_message_queues[channel_id] |
|
|
|
|
name, payload = await asyncio.wait_for(q.get(), LN_P2P_NETWORK_TIMEOUT) |
|
|
|
|
# raise exceptions for errors/warnings, so that the caller sees them |
|
|
|
|
if payload.get('error'): |
|
|
|
|
if (err_bytes := (payload.get("error") or payload.get("warning"))) is not None: |
|
|
|
|
err_type = "error" if payload.get("error") else "warning" |
|
|
|
|
err_text = error_text_bytes_to_safe_str(err_bytes) |
|
|
|
|
raise GracefulDisconnect( |
|
|
|
|
f"remote peer sent error [DO NOT TRUST THIS MESSAGE]: {payload['error'].decode('ascii')}") |
|
|
|
|
elif payload.get('warning'): |
|
|
|
|
raise GracefulDisconnect( |
|
|
|
|
f"remote peer sent warning [DO NOT TRUST THIS MESSAGE]: {payload['warning'].decode('ascii')}") |
|
|
|
|
f"remote peer sent {err_type} [DO NOT TRUST THIS MESSAGE]: {err_text}") |
|
|
|
|
if name != expected_name: |
|
|
|
|
raise Exception(f"Received unexpected '{name}'") |
|
|
|
|
return payload |
|
|
|
|
|