Merge pull request #2908 from joostjager/chan-arb-logging

cnct+invoices: improve logging
This commit is contained in:
Joost Jager authored and GitHub committed 2019-04-09 22:34:12 +02:00
commit a2aeb646e7
2 files changed
+41 -23

No files matched your search

+28 -14
View File
@@ -1097,26 +1097,27 @@ func (c *ChannelArbitrator) checkChainActions(height uint32,
// outgoing HTLC's to decide if we need to go on chain at all. // outgoing HTLC's to decide if we need to go on chain at all.
haveChainActions := false haveChainActions := false
for _, htlc := range c.activeHTLCs.outgoingHTLCs { for _, htlc := range c.activeHTLCs.outgoingHTLCs {
// If any of our HTLC's triggered an on-chain action, then we
// can break early.
if haveChainActions {
break
}
// We'll need to go on-chain for an outgoing HTLC if it was // We'll need to go on-chain for an outgoing HTLC if it was
// never resolved downstream, and it's "close" to timing out. // never resolved downstream, and it's "close" to timing out.
haveChainActions = haveChainActions || c.shouldGoOnChain( toChain := c.shouldGoOnChain(
htlc.RefundTimeout, c.cfg.OutgoingBroadcastDelta, htlc.RefundTimeout, c.cfg.OutgoingBroadcastDelta,
height, height,
) )
}
for _, htlc := range c.activeHTLCs.incomingHTLCs { if toChain {
// If any of our HTLC's triggered an on-chain action, then we log.Debugf("ChannelArbitrator(%v): go to chain for "+
// can break early. "outgoing htlc %x: timeout=%v, "+
if haveChainActions { "blocks_until_expiry=%v, broadcast_delta=%v",
break c.cfg.ChanPoint, htlc.RHash[:],
htlc.RefundTimeout, htlc.RefundTimeout-height,
c.cfg.OutgoingBroadcastDelta,
)
} }
haveChainActions = haveChainActions || toChain
}
for _, htlc := range c.activeHTLCs.incomingHTLCs {
// We'll need to go on-chain to pull an incoming HTLC iff we // We'll need to go on-chain to pull an incoming HTLC iff we
// know the pre-image and it's close to timing out. We need to // know the pre-image and it's close to timing out. We need to
// ensure that we claim the funds that our rightfully ours // ensure that we claim the funds that our rightfully ours
@@ -1124,10 +1125,23 @@ func (c *ChannelArbitrator) checkChainActions(height uint32,
if _, ok := c.cfg.PreimageDB.LookupPreimage(htlc.RHash); !ok { if _, ok := c.cfg.PreimageDB.LookupPreimage(htlc.RHash); !ok {
continue continue
} }
haveChainActions = haveChainActions || c.shouldGoOnChain(
toChain := c.shouldGoOnChain(
htlc.RefundTimeout, c.cfg.IncomingBroadcastDelta, htlc.RefundTimeout, c.cfg.IncomingBroadcastDelta,
height, height,
) )
if toChain {
log.Debugf("ChannelArbitrator(%v): go to chain for "+
"incoming htlc %x: timeout=%v, "+
"blocks_until_expiry=%v, broadcast_delta=%v",
c.cfg.ChanPoint, htlc.RHash[:],
htlc.RefundTimeout, htlc.RefundTimeout-height,
c.cfg.IncomingBroadcastDelta,
)
}
haveChainActions = haveChainActions || toChain
} }
// If we don't have any actions to make, then we'll return an empty // If we don't have any actions to make, then we'll return an empty
+13 -9
View File
@@ -408,9 +408,11 @@ func (i *InvoiceRegistry) AddInvoice(invoice *channeldb.Invoice,
i.Lock() i.Lock()
defer i.Unlock() defer i.Unlock()
log.Debugf("Adding invoice %v", newLogClosure(func() string { log.Debugf("Invoice(%v): added %v", paymentHash,
return spew.Sdump(invoice) newLogClosure(func() string {
})) return spew.Sdump(invoice)
}),
)
addIndex, err := i.cdb.AddInvoice(invoice, paymentHash) addIndex, err := i.cdb.AddInvoice(invoice, paymentHash)
if err != nil { if err != nil {
@@ -476,7 +478,7 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
i.Lock() i.Lock()
defer i.Unlock() defer i.Unlock()
log.Debugf("Settling invoice %x", rHash[:]) log.Debugf("Invoice(%x): htlc accepted", rHash[:])
createEvent := func(preimage *lntypes.Preimage) *HodlEvent { createEvent := func(preimage *lntypes.Preimage) *HodlEvent {
return &HodlEvent{ return &HodlEvent{
@@ -519,6 +521,8 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
i.notifyClients(rHash, invoice, invoice.Terms.State) i.notifyClients(rHash, invoice, invoice.Terms.State)
switch invoice.Terms.State { switch invoice.Terms.State {
case channeldb.ContractSettled: case channeldb.ContractSettled:
log.Debugf("Invoice(%x): settled", rHash[:])
return createEvent(&invoice.Terms.PaymentPreimage), nil return createEvent(&invoice.Terms.PaymentPreimage), nil
case channeldb.ContractAccepted: case channeldb.ContractAccepted:
// Subscribe to updates to this invoice. // Subscribe to updates to this invoice.
@@ -541,12 +545,12 @@ func (i *InvoiceRegistry) SettleHodlInvoice(preimage lntypes.Preimage) error {
invoice, err := i.cdb.SettleHoldInvoice(preimage) invoice, err := i.cdb.SettleHoldInvoice(preimage)
if err != nil { if err != nil {
log.Errorf("Invoice SetPreimage %v: %v", preimage, err) log.Errorf("SettleHodlInvoice with preimage %v: %v", preimage, err)
return err return err
} }
hash := preimage.Hash() hash := preimage.Hash()
log.Infof("Notifying clients of set preimage to %v", log.Debugf("Invoice(%v): settled with preimage %v", hash,
invoice.Terms.PaymentPreimage) invoice.Terms.PaymentPreimage)
i.notifyHodlSubscribers(HodlEvent{ i.notifyHodlSubscribers(HodlEvent{
@@ -564,21 +568,21 @@ func (i *InvoiceRegistry) CancelInvoice(payHash lntypes.Hash) error {
i.Lock() i.Lock()
defer i.Unlock() defer i.Unlock()
log.Debugf("Canceling invoice %v", payHash) log.Debugf("Invoice(%v): canceling invoice", payHash)
invoice, err := i.cdb.CancelInvoice(payHash) invoice, err := i.cdb.CancelInvoice(payHash)
// Implement idempotency by returning success if the invoice was already // Implement idempotency by returning success if the invoice was already
// canceled. // canceled.
if err == channeldb.ErrInvoiceAlreadyCanceled { if err == channeldb.ErrInvoiceAlreadyCanceled {
log.Debugf("Invoice %v already canceled", payHash) log.Debugf("Invoice(%v): already canceled", payHash)
return nil return nil
} }
if err != nil { if err != nil {
return err return err
} }
log.Infof("Invoice %v canceled", payHash) log.Debugf("Invoice(%v): canceled", payHash)
i.notifyHodlSubscribers(HodlEvent{ i.notifyHodlSubscribers(HodlEvent{
Hash: payHash, Hash: payHash,
}) })