LNWorker: do not save PR_INFLIGHT status, detect it on startup instead
This commit is contained in:
@@ -195,7 +195,11 @@ class ChannelDetailsDialog(QtWidgets.QDialog):
|
|||||||
vbox.addWidget(QLabel(_('Payments (HTLCs):')))
|
vbox.addWidget(QLabel(_('Payments (HTLCs):')))
|
||||||
w = QtWidgets.QTreeView(self)
|
w = QtWidgets.QTreeView(self)
|
||||||
htlc_dict = chan.get_payments()
|
htlc_dict = chan.get_payments()
|
||||||
w.setModel(self.make_model(htlc_dict))
|
htlc_list = []
|
||||||
|
for rhash, _list in htlc_dict.items():
|
||||||
|
for _tuple in _list:
|
||||||
|
htlc_list.append((rhash.hex(),) + _tuple)
|
||||||
|
w.setModel(self.make_model(htlc_list))
|
||||||
w.header().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
|
w.header().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
|
||||||
vbox.addWidget(w)
|
vbox.addWidget(w)
|
||||||
vbox.addLayout(Buttons(CloseButton(self)))
|
vbox.addLayout(Buttons(CloseButton(self)))
|
||||||
|
|||||||
@@ -670,27 +670,19 @@ class Channel(AbstractChannel):
|
|||||||
def get_next_feerate(self, subject: HTLCOwner) -> int:
|
def get_next_feerate(self, subject: HTLCOwner) -> int:
|
||||||
return self.hm.get_feerate_in_next_ctx(subject)
|
return self.hm.get_feerate_in_next_ctx(subject)
|
||||||
|
|
||||||
def get_payments(self):
|
def get_payments(self, status=None):
|
||||||
out = []
|
|
||||||
for direction, htlc in self.hm.all_htlcs_ever():
|
|
||||||
htlc_proposer = LOCAL if direction is SENT else REMOTE
|
|
||||||
if self.hm.was_htlc_failed(htlc_id=htlc.htlc_id, htlc_proposer=htlc_proposer):
|
|
||||||
status = 'failed'
|
|
||||||
elif self.hm.was_htlc_preimage_released(htlc_id=htlc.htlc_id, htlc_proposer=htlc_proposer):
|
|
||||||
status = 'settled'
|
|
||||||
else:
|
|
||||||
status = 'inflight'
|
|
||||||
rhash = htlc.payment_hash.hex()
|
|
||||||
out.append((rhash, self.channel_id, htlc, direction, status))
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_settled_payments(self):
|
|
||||||
out = defaultdict(list)
|
out = defaultdict(list)
|
||||||
for direction, htlc in self.hm.all_htlcs_ever():
|
for direction, htlc in self.hm.all_htlcs_ever():
|
||||||
htlc_proposer = LOCAL if direction is SENT else REMOTE
|
htlc_proposer = LOCAL if direction is SENT else REMOTE
|
||||||
if self.hm.was_htlc_preimage_released(htlc_id=htlc.htlc_id, htlc_proposer=htlc_proposer):
|
if self.hm.was_htlc_failed(htlc_id=htlc.htlc_id, htlc_proposer=htlc_proposer):
|
||||||
rhash = htlc.payment_hash.hex()
|
_status = 'failed'
|
||||||
out[rhash].append((self.channel_id, htlc, direction))
|
elif self.hm.was_htlc_preimage_released(htlc_id=htlc.htlc_id, htlc_proposer=htlc_proposer):
|
||||||
|
_status = 'settled'
|
||||||
|
else:
|
||||||
|
_status = 'inflight'
|
||||||
|
if status and status != _status:
|
||||||
|
continue
|
||||||
|
out[htlc.payment_hash].append((self.channel_id, htlc, direction, _status))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def open_with_first_pcp(self, remote_pcp: bytes, remote_sig: bytes) -> None:
|
def open_with_first_pcp(self, remote_pcp: bytes, remote_sig: bytes) -> None:
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ if TYPE_CHECKING:
|
|||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
|
|
||||||
SAVED_PR_STATUS = [PR_PAID, PR_UNPAID, PR_INFLIGHT] # status that are persisted
|
SAVED_PR_STATUS = [PR_PAID, PR_UNPAID] # status that are persisted
|
||||||
|
|
||||||
|
|
||||||
NUM_PEERS_TARGET = 4
|
NUM_PEERS_TARGET = 4
|
||||||
@@ -583,6 +583,9 @@ class LNWallet(LNWorker):
|
|||||||
self.pending_payments = defaultdict(asyncio.Future) # type: Dict[bytes, asyncio.Future[BarePaymentAttemptLog]]
|
self.pending_payments = defaultdict(asyncio.Future) # type: Dict[bytes, asyncio.Future[BarePaymentAttemptLog]]
|
||||||
|
|
||||||
self.swap_manager = SwapManager(wallet=self.wallet, lnworker=self)
|
self.swap_manager = SwapManager(wallet=self.wallet, lnworker=self)
|
||||||
|
# detect inflight payments
|
||||||
|
for payment_hash in self.get_payments(status='inflight').keys():
|
||||||
|
self.set_invoice_status(payment_hash.hex(), PR_INFLIGHT)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channels(self) -> Mapping[bytes, Channel]:
|
def channels(self) -> Mapping[bytes, Channel]:
|
||||||
@@ -672,12 +675,12 @@ class LNWallet(LNWorker):
|
|||||||
util.trigger_callback('channel', self.wallet, chan)
|
util.trigger_callback('channel', self.wallet, chan)
|
||||||
super().peer_closed(peer)
|
super().peer_closed(peer)
|
||||||
|
|
||||||
def get_settled_payments(self):
|
def get_payments(self, *, status=None):
|
||||||
# return one item per payment_hash
|
# return one item per payment_hash
|
||||||
# note: with AMP we will have several channels per payment
|
# note: with AMP we will have several channels per payment
|
||||||
out = defaultdict(list)
|
out = defaultdict(list)
|
||||||
for chan in self.channels.values():
|
for chan in self.channels.values():
|
||||||
d = chan.get_settled_payments()
|
d = chan.get_payments(status=status)
|
||||||
for k, v in d.items():
|
for k, v in d.items():
|
||||||
out[k] += v
|
out[k] += v
|
||||||
return out
|
return out
|
||||||
@@ -685,19 +688,19 @@ class LNWallet(LNWorker):
|
|||||||
def get_payment_value(self, info: Optional['PaymentInfo'], plist):
|
def get_payment_value(self, info: Optional['PaymentInfo'], plist):
|
||||||
amount_msat = 0
|
amount_msat = 0
|
||||||
fee_msat = None
|
fee_msat = None
|
||||||
for chan_id, htlc, _direction in plist:
|
for chan_id, htlc, _direction, _status in plist:
|
||||||
amount_msat += int(_direction) * htlc.amount_msat
|
amount_msat += int(_direction) * htlc.amount_msat
|
||||||
if _direction == SENT and info and info.amount_msat:
|
if _direction == SENT and info and info.amount_msat:
|
||||||
fee_msat = (fee_msat or 0) - info.amount_msat - amount_msat
|
fee_msat = (fee_msat or 0) - info.amount_msat - amount_msat
|
||||||
timestamp = min([htlc.timestamp for chan_id, htlc, _direction in plist])
|
timestamp = min([htlc.timestamp for chan_id, htlc, _direction, _status in plist])
|
||||||
return amount_msat, fee_msat, timestamp
|
return amount_msat, fee_msat, timestamp
|
||||||
|
|
||||||
def get_lightning_history(self):
|
def get_lightning_history(self):
|
||||||
out = {}
|
out = {}
|
||||||
for key, plist in self.get_settled_payments().items():
|
for payment_hash, plist in self.get_payments(status='settled').items():
|
||||||
if len(plist) == 0:
|
if len(plist) == 0:
|
||||||
continue
|
continue
|
||||||
payment_hash = bytes.fromhex(key)
|
key = payment_hash.hex()
|
||||||
info = self.get_payment_info(payment_hash)
|
info = self.get_payment_info(payment_hash)
|
||||||
amount_msat, fee_msat, timestamp = self.get_payment_value(info, plist)
|
amount_msat, fee_msat, timestamp = self.get_payment_value(info, plist)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
@@ -766,15 +769,16 @@ class LNWallet(LNWorker):
|
|||||||
}
|
}
|
||||||
out[closing_txid] = item
|
out[closing_txid] = item
|
||||||
# add info about submarine swaps
|
# add info about submarine swaps
|
||||||
settled_payments = self.get_settled_payments()
|
settled_payments = self.get_payments(status='settled')
|
||||||
current_height = self.wallet.get_local_height()
|
current_height = self.wallet.get_local_height()
|
||||||
for payment_hash_hex, swap in self.swap_manager.swaps.items():
|
for payment_hash_hex, swap in self.swap_manager.swaps.items():
|
||||||
txid = swap.spending_txid if swap.is_reverse else swap.funding_txid
|
txid = swap.spending_txid if swap.is_reverse else swap.funding_txid
|
||||||
if txid is None:
|
if txid is None:
|
||||||
continue
|
continue
|
||||||
if payment_hash_hex in settled_payments:
|
payment_hash = bytes.fromhex(payment_hash_hex)
|
||||||
plist = settled_payments[payment_hash_hex]
|
if payment_hash in settled_payments:
|
||||||
info = self.get_payment_info(bytes.fromhex(payment_hash_hex))
|
plist = settled_payments[payment_hash]
|
||||||
|
info = self.get_payment_info(payment_hash)
|
||||||
amount_msat, fee_msat, timestamp = self.get_payment_value(info, plist)
|
amount_msat, fee_msat, timestamp = self.get_payment_value(info, plist)
|
||||||
else:
|
else:
|
||||||
amount_msat = 0
|
amount_msat = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user