From dccf9c77ca075b59e73b2c36ab00eabaddfc6de8 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 7 Apr 2023 13:47:38 +0800 Subject: [PATCH] lnd+contractcourt: add more debug logs This commit adds more debug logs for witness beacon and channel arbitrator. --- contractcourt/channel_arbitrator.go | 12 ++++++++++-- contractcourt/htlc_incoming_contest_resolver.go | 3 +++ witness_beacon.go | 13 ++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 57d6675a3..4df8364fb 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -1589,11 +1589,15 @@ func (c *ChannelArbitrator) checkCommitChainActions(height uint32, ) if toChain { + // Convert to int64 in case of overflow. + remainingBlocks := int64(htlc.RefundTimeout) - + int64(height) + log.Infof("ChannelArbitrator(%v): go to chain for "+ "outgoing htlc %x: timeout=%v, "+ "blocks_until_expiry=%v, broadcast_delta=%v", c.cfg.ChanPoint, htlc.RHash[:], - htlc.RefundTimeout, htlc.RefundTimeout-height, + htlc.RefundTimeout, remainingBlocks, c.cfg.OutgoingBroadcastDelta, ) } @@ -1620,11 +1624,15 @@ func (c *ChannelArbitrator) checkCommitChainActions(height uint32, ) if toChain { + // Convert to int64 in case of overflow. + remainingBlocks := int64(htlc.RefundTimeout) - + int64(height) + log.Infof("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, + htlc.RefundTimeout, remainingBlocks, c.cfg.IncomingBroadcastDelta, ) } diff --git a/contractcourt/htlc_incoming_contest_resolver.go b/contractcourt/htlc_incoming_contest_resolver.go index a8576a8d1..79f29e494 100644 --- a/contractcourt/htlc_incoming_contest_resolver.go +++ b/contractcourt/htlc_incoming_contest_resolver.go @@ -140,6 +140,9 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) { return nil, errResolverShuttingDown } + log.Debugf("%T(%v): Resolving incoming HTLC(expiry=%v, height=%v)", h, + h.htlcResolution.ClaimOutpoint, h.htlcExpiry, currentHeight) + // We'll first check if this HTLC has been timed out, if so, we can // return now and mark ourselves as resolved. If we're past the point of // expiry of the HTLC, then at this point the sender can sweep it, so diff --git a/witness_beacon.go b/witness_beacon.go index dbc4c83f9..4fd44e283 100644 --- a/witness_beacon.go +++ b/witness_beacon.go @@ -1,6 +1,7 @@ package lnd import ( + "errors" "sync" "github.com/lightningnetwork/lnd/channeldb" @@ -127,6 +128,11 @@ func (p *preimageBeacon) LookupPreimage( // Otherwise, we'll perform a final check using the witness cache. preimage, err := p.wCache.LookupSha256Witness(payHash) + if errors.Is(err, channeldb.ErrNoWitnesses) { + ltndLog.Debugf("No witness for payment %v", payHash) + return lntypes.Preimage{}, false + } + if err != nil { ltndLog.Errorf("Unable to lookup witness: %v", err) return lntypes.Preimage{}, false @@ -147,7 +153,9 @@ func (p *preimageBeacon) AddPreimages(preimages ...lntypes.Preimage) error { // the caller when delivering notifications. preimageCopies := make([]lntypes.Preimage, 0, len(preimages)) for _, preimage := range preimages { - srvrLog.Infof("Adding preimage=%v to witness cache", preimage) + srvrLog.Infof("Adding preimage=%v to witness cache for %v", + preimage, preimage.Hash()) + preimageCopies = append(preimageCopies, preimage) } @@ -174,6 +182,9 @@ func (p *preimageBeacon) AddPreimages(preimages ...lntypes.Preimage) error { }(client) } + srvrLog.Debugf("Added %d preimage(s) to witness cache", + len(preimageCopies)) + return nil }