Reorganize code so that we can send Multi Part Payments:
- LNWorker is notified about htlc events and creates payment events. - LNWorker._pay is a while loop that calls create_routes_from_invoice. - create_route_from_invoices should decide whether to split the payment, using graph knowledge and feedback from previous attempts (not in this commit) - data structures for payment logs are simplified into a single type, HtlcLog
This commit is contained in:
@@ -249,52 +249,36 @@ class Outpoint(StoredObject):
|
||||
return "{}:{}".format(self.txid, self.output_index)
|
||||
|
||||
|
||||
class PaymentAttemptFailureDetails(NamedTuple):
|
||||
sender_idx: Optional[int]
|
||||
failure_msg: 'OnionRoutingFailureMessage'
|
||||
is_blacklisted: bool
|
||||
|
||||
|
||||
class PaymentAttemptLog(NamedTuple):
|
||||
class HtlcLog(NamedTuple):
|
||||
success: bool
|
||||
amount_msat: int
|
||||
route: Optional['LNPaymentRoute'] = None
|
||||
preimage: Optional[bytes] = None
|
||||
failure_details: Optional[PaymentAttemptFailureDetails] = None
|
||||
exception: Optional[Exception] = None
|
||||
error_bytes: Optional[bytes] = None
|
||||
failure_msg: Optional['OnionRoutingFailureMessage'] = None
|
||||
sender_idx: Optional[int] = None
|
||||
|
||||
def formatted_tuple(self):
|
||||
if not self.exception:
|
||||
route = self.route
|
||||
route_str = '%d'%len(route)
|
||||
short_channel_id = None
|
||||
if not self.success:
|
||||
sender_idx = self.failure_details.sender_idx
|
||||
failure_msg = self.failure_details.failure_msg
|
||||
if sender_idx is not None:
|
||||
try:
|
||||
short_channel_id = route[sender_idx + 1].short_channel_id
|
||||
except IndexError:
|
||||
# payment destination reported error
|
||||
short_channel_id = _("Destination node")
|
||||
message = failure_msg.code_name()
|
||||
else:
|
||||
short_channel_id = route[-1].short_channel_id
|
||||
message = _('Success')
|
||||
chan_str = str(short_channel_id) if short_channel_id else _("Unknown")
|
||||
route = self.route
|
||||
route_str = '%d'%len(route)
|
||||
short_channel_id = None
|
||||
if not self.success:
|
||||
sender_idx = self.sender_idx
|
||||
failure_msg = self.failure_msg
|
||||
if sender_idx is not None:
|
||||
try:
|
||||
short_channel_id = route[sender_idx + 1].short_channel_id
|
||||
except IndexError:
|
||||
# payment destination reported error
|
||||
short_channel_id = _("Destination node")
|
||||
message = failure_msg.code_name()
|
||||
else:
|
||||
route_str = 'None'
|
||||
chan_str = 'N/A'
|
||||
message = str(self.exception)
|
||||
short_channel_id = route[-1].short_channel_id
|
||||
message = _('Success')
|
||||
chan_str = str(short_channel_id) if short_channel_id else _("Unknown")
|
||||
return route_str, chan_str, message
|
||||
|
||||
|
||||
class BarePaymentAttemptLog(NamedTuple):
|
||||
success: bool
|
||||
preimage: Optional[bytes] = None
|
||||
error_bytes: Optional[bytes] = None
|
||||
failure_message: Optional['OnionRoutingFailureMessage'] = None
|
||||
|
||||
|
||||
class LightningError(Exception): pass
|
||||
class LightningPeerConnectionClosed(LightningError): pass
|
||||
class UnableToDeriveSecret(LightningError): pass
|
||||
|
||||
Reference in New Issue
Block a user