payment log: show whether channel have been blacklisted

This commit is contained in:
ThomasV 2019-10-12 18:36:25 +02:00
parent 3897cf725d
commit fe550c6c73
2 changed files with 24 additions and 22 deletions

View file

@ -173,19 +173,20 @@ class InvoiceList(MyTreeView):
d = WindowModalDialog(self, _("Payment log")) d = WindowModalDialog(self, _("Payment log"))
vbox = QVBoxLayout(d) vbox = QVBoxLayout(d)
log_w = QTreeWidget() log_w = QTreeWidget()
log_w.setHeaderLabels([_('Route'), _('Channel ID'), _('Message')]) log_w.setHeaderLabels([_('Route'), _('Channel ID'), _('Message'), _('Blacklist')])
for i, (route, success, failure_data) in enumerate(log): for i, (route, success, failure_log) in enumerate(log):
route_str = '%d'%len(route) route_str = '%d'%len(route)
if not success: if not success:
sender_idx, failure_msg = failure_data sender_idx, failure_msg, blacklist = failure_log
short_channel_id = route[sender_idx+1].short_channel_id short_channel_id = route[sender_idx+1].short_channel_id
data = failure_msg.data data = failure_msg.data
message = repr(failure_msg.code) message = repr(failure_msg.code)
else: else:
short_channel_id = route[-1].short_channel_id short_channel_id = route[-1].short_channel_id
message = _('Success') message = _('Success')
blacklist = False
chan_str = format_short_channel_id(short_channel_id) chan_str = format_short_channel_id(short_channel_id)
x = QTreeWidgetItem([route_str, chan_str, message]) x = QTreeWidgetItem([route_str, chan_str, message, repr(blacklist)])
log_w.addTopLevelItem(x) log_w.addTopLevelItem(x)
vbox.addWidget(log_w) vbox.addWidget(log_w)
vbox.addLayout(Buttons(CloseButton(d))) vbox.addLayout(Buttons(CloseButton(d)))

View file

@ -864,12 +864,12 @@ class LNWallet(LNWorker):
success = False success = False
break break
self.network.trigger_callback('invoice_status', key, PR_INFLIGHT, log) self.network.trigger_callback('invoice_status', key, PR_INFLIGHT, log)
success, preimage, sender_idx, failure_msg = await self._pay_to_route(route, lnaddr) success, preimage, failure_log = await self._pay_to_route(route, lnaddr)
if success: if success:
log.append((route, True, preimage)) log.append((route, True, preimage))
break break
else: else:
log.append((route, False, (sender_idx, failure_msg))) log.append((route, False, failure_log))
self.network.trigger_callback('invoice_status', key, PR_PAID if success else PR_FAILED, log) self.network.trigger_callback('invoice_status', key, PR_PAID if success else PR_FAILED, log)
return success return success
@ -885,15 +885,25 @@ class LNWallet(LNWorker):
self.network.trigger_callback('htlc_added', htlc, lnaddr, SENT) self.network.trigger_callback('htlc_added', htlc, lnaddr, SENT)
success, preimage, reason = await self.await_payment(lnaddr.paymenthash) success, preimage, reason = await self.await_payment(lnaddr.paymenthash)
if success: if success:
failure_msg = None failure_log = None
sender_idx = None
else: else:
failure_msg, sender_idx = chan.decode_onion_error(reason, route, htlc.htlc_id) failure_msg, sender_idx = chan.decode_onion_error(reason, route, htlc.htlc_id)
code, data = failure_msg.code, failure_msg.data blacklist = self.handle_error_code_from_failed_htlc(failure_msg, sender_idx, route, peer)
self.handle_error_code_from_failed_htlc(code, data, sender_idx, route, peer) if blacklist:
return success, preimage, sender_idx, failure_msg # blacklist channel after reporter node
# TODO this should depend on the error (even more granularity)
# also, we need finer blacklisting (directed edges; nodes)
try:
short_chan_id = route[sender_idx + 1].short_channel_id
except IndexError:
self.logger.info("payment destination reported error")
else:
self.network.path_finder.add_to_blacklist(short_chan_id)
failure_log = (sender_idx, failure_msg, blacklist)
return success, preimage, failure_log
def handle_error_code_from_failed_htlc(self, code, data, sender_idx, route, peer): def handle_error_code_from_failed_htlc(self, failure_msg, sender_idx, route, peer):
code, data = failure_msg.code, failure_msg.data
self.logger.info(f"UPDATE_FAIL_HTLC {repr(code)} {data}") self.logger.info(f"UPDATE_FAIL_HTLC {repr(code)} {data}")
self.logger.info(f"error reported by {bh2u(route[sender_idx].node_id)}") self.logger.info(f"error reported by {bh2u(route[sender_idx].node_id)}")
# handle some specific error codes # handle some specific error codes
@ -935,16 +945,7 @@ class LNWallet(LNWorker):
blacklist = True blacklist = True
else: else:
blacklist = True blacklist = True
if blacklist: return blacklist
# blacklist channel after reporter node
# TODO this should depend on the error (even more granularity)
# also, we need finer blacklisting (directed edges; nodes)
try:
short_chan_id = route[sender_idx + 1].short_channel_id
except IndexError:
self.logger.info("payment destination reported error")
else:
self.network.path_finder.add_to_blacklist(short_chan_id)
@staticmethod @staticmethod
def _check_invoice(invoice, amount_sat=None): def _check_invoice(invoice, amount_sat=None):