contractcourt: add verbose logging in resolvers

We now put the outpoint in the resolvers's logging so it's easier to
debug.
This commit is contained in:
yyforyongyu
2024-06-20 21:56:52 +08:00
parent 0bab6b3419
commit 1f2cfc6a60
6 changed files with 44 additions and 31 deletions

View File

@@ -2,6 +2,7 @@ package contractcourt
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"sync" "sync"
@@ -71,7 +72,7 @@ func newAnchorResolver(anchorSignDescriptor input.SignDescriptor,
currentReport: report, currentReport: report,
} }
r.initLogger(r) r.initLogger(fmt.Sprintf("%T(%v)", r, r.anchor))
return r return r
} }

View File

@@ -2,6 +2,7 @@ package contractcourt
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
@@ -32,7 +33,7 @@ func newBreachResolver(resCfg ResolverConfig) *breachResolver {
replyChan: make(chan struct{}), replyChan: make(chan struct{}),
} }
r.initLogger(r) r.initLogger(fmt.Sprintf("%T(%v)", r, r.ChanPoint))
return r return r
} }
@@ -114,7 +115,7 @@ func newBreachResolverFromReader(r io.Reader, resCfg ResolverConfig) (
return nil, err return nil, err
} }
b.initLogger(b) b.initLogger(fmt.Sprintf("%T(%v)", b, b.ChanPoint))
return b, nil return b, nil
} }

View File

@@ -88,7 +88,7 @@ func newCommitSweepResolver(res lnwallet.CommitOutputResolution,
chanPoint: chanPoint, chanPoint: chanPoint,
} }
r.initLogger(r) r.initLogger(fmt.Sprintf("%T(%v)", r, r.commitResolution.SelfOutPoint))
r.initReport() r.initReport()
return r return r
@@ -484,7 +484,7 @@ func newCommitSweepResolverFromReader(r io.Reader, resCfg ResolverConfig) (
// removed this, but keep in mind that this data may still be present in // removed this, but keep in mind that this data may still be present in
// the database. // the database.
c.initLogger(c) c.initLogger(fmt.Sprintf("%T(%v)", c, c.commitResolution.SelfOutPoint))
c.initReport() c.initReport()
return c, nil return c, nil

View File

@@ -120,8 +120,10 @@ func newContractResolverKit(cfg ResolverConfig) *contractResolverKit {
} }
// initLogger initializes the resolver-specific logger. // initLogger initializes the resolver-specific logger.
func (r *contractResolverKit) initLogger(resolver ContractResolver) { func (r *contractResolverKit) initLogger(prefix string) {
logPrefix := fmt.Sprintf("%T(%v):", resolver, r.ChanPoint) logPrefix := fmt.Sprintf("ChannelArbitrator(%v): %s:", r.ChanPoint,
prefix)
r.log = log.WithPrefix(logPrefix) r.log = log.WithPrefix(logPrefix)
} }

View File

@@ -2,6 +2,7 @@ package contractcourt
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"sync" "sync"
@@ -81,27 +82,30 @@ func newSuccessResolver(res lnwallet.IncomingHtlcResolution,
} }
h.initReport() h.initReport()
h.initLogger(fmt.Sprintf("%T(%v)", h, h.outpoint()))
return h return h
} }
// outpoint returns the outpoint of the HTLC output we're attempting to sweep.
func (h *htlcSuccessResolver) outpoint() wire.OutPoint {
// The primary key for this resolver will be the outpoint of the HTLC
// on the commitment transaction itself. If this is our commitment,
// then the output can be found within the signed success tx,
// otherwise, it's just the ClaimOutpoint.
if h.htlcResolution.SignedSuccessTx != nil {
return h.htlcResolution.SignedSuccessTx.TxIn[0].PreviousOutPoint
}
return h.htlcResolution.ClaimOutpoint
}
// ResolverKey returns an identifier which should be globally unique for this // ResolverKey returns an identifier which should be globally unique for this
// particular resolver within the chain the original contract resides within. // particular resolver within the chain the original contract resides within.
// //
// NOTE: Part of the ContractResolver interface. // NOTE: Part of the ContractResolver interface.
func (h *htlcSuccessResolver) ResolverKey() []byte { func (h *htlcSuccessResolver) ResolverKey() []byte {
// The primary key for this resolver will be the outpoint of the HTLC key := newResolverID(h.outpoint())
// on the commitment transaction itself. If this is our commitment,
// then the output can be found within the signed success tx,
// otherwise, it's just the ClaimOutpoint.
var op wire.OutPoint
if h.htlcResolution.SignedSuccessTx != nil {
op = h.htlcResolution.SignedSuccessTx.TxIn[0].PreviousOutPoint
} else {
op = h.htlcResolution.ClaimOutpoint
}
key := newResolverID(op)
return key[:] return key[:]
} }
@@ -679,6 +683,7 @@ func newSuccessResolverFromReader(r io.Reader, resCfg ResolverConfig) (
} }
h.initReport() h.initReport()
h.initLogger(fmt.Sprintf("%T(%v)", h, h.outpoint()))
return h, nil return h, nil
} }

View File

@@ -82,6 +82,7 @@ func newTimeoutResolver(res lnwallet.OutgoingHtlcResolution,
} }
h.initReport() h.initReport()
h.initLogger(fmt.Sprintf("%T(%v)", h, h.outpoint()))
return h return h
} }
@@ -93,23 +94,25 @@ func (h *htlcTimeoutResolver) isTaproot() bool {
) )
} }
// outpoint returns the outpoint of the HTLC output we're attempting to sweep.
func (h *htlcTimeoutResolver) outpoint() wire.OutPoint {
// The primary key for this resolver will be the outpoint of the HTLC
// on the commitment transaction itself. If this is our commitment,
// then the output can be found within the signed timeout tx,
// otherwise, it's just the ClaimOutpoint.
if h.htlcResolution.SignedTimeoutTx != nil {
return h.htlcResolution.SignedTimeoutTx.TxIn[0].PreviousOutPoint
}
return h.htlcResolution.ClaimOutpoint
}
// ResolverKey returns an identifier which should be globally unique for this // ResolverKey returns an identifier which should be globally unique for this
// particular resolver within the chain the original contract resides within. // particular resolver within the chain the original contract resides within.
// //
// NOTE: Part of the ContractResolver interface. // NOTE: Part of the ContractResolver interface.
func (h *htlcTimeoutResolver) ResolverKey() []byte { func (h *htlcTimeoutResolver) ResolverKey() []byte {
// The primary key for this resolver will be the outpoint of the HTLC key := newResolverID(h.outpoint())
// on the commitment transaction itself. If this is our commitment,
// then the output can be found within the signed timeout tx,
// otherwise, it's just the ClaimOutpoint.
var op wire.OutPoint
if h.htlcResolution.SignedTimeoutTx != nil {
op = h.htlcResolution.SignedTimeoutTx.TxIn[0].PreviousOutPoint
} else {
op = h.htlcResolution.ClaimOutpoint
}
key := newResolverID(op)
return key[:] return key[:]
} }
@@ -1038,6 +1041,7 @@ func newTimeoutResolverFromReader(r io.Reader, resCfg ResolverConfig) (
} }
h.initReport() h.initReport()
h.initLogger(fmt.Sprintf("%T(%v)", h, h.outpoint()))
return h, nil return h, nil
} }