cnct: prefix logger for commit sweep resolver

Unify resolver specific log statements. Leaves modification of
the other resolvers for a later moment when it can be combined with a
real change.
This commit is contained in:
Joost Jager 2019-10-30 11:32:27 +01:00
parent 9d79fea937
commit 55a32c951a
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 31 additions and 18 deletions

View File

@ -44,12 +44,16 @@ func newCommitSweepResolver(res lnwallet.CommitOutputResolution,
broadcastHeight uint32,
chanPoint wire.OutPoint, resCfg ResolverConfig) *commitSweepResolver {
return &commitSweepResolver{
r := &commitSweepResolver{
contractResolverKit: *newContractResolverKit(resCfg),
commitResolution: res,
broadcastHeight: broadcastHeight,
chanPoint: chanPoint,
}
r.initLogger(r)
return r
}
// ResolverKey returns an identifier which should be globally unique for this
@ -85,7 +89,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
return nil, err
}
log.Debugf("%T(%v): waiting for commit tx to confirm", c, c.chanPoint)
c.log.Debugf("waiting for commit tx to confirm")
select {
case _, ok := <-confNtfn.Confirmed:
@ -125,13 +129,12 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
// With our input constructed, we'll now offer it to the
// sweeper.
log.Infof("%T(%v): sweeping commit output", c, c.chanPoint)
c.log.Infof("sweeping commit output")
feePref := sweep.FeePreference{ConfTarget: commitOutputConfTarget}
resultChan, err := c.Sweeper.SweepInput(&inp, feePref)
if err != nil {
log.Errorf("%T(%v): unable to sweep input: %v",
c, c.chanPoint, err)
c.log.Errorf("unable to sweep input: %v", err)
return nil, err
}
@ -143,14 +146,14 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
select {
case sweepResult := <-resultChan:
if sweepResult.Err != nil {
log.Errorf("%T(%v): unable to sweep input: %v",
c, c.chanPoint, sweepResult.Err)
c.log.Errorf("unable to sweep input: %v",
sweepResult.Err)
return nil, sweepResult.Err
}
log.Infof("ChannelPoint(%v) commit tx is fully resolved by "+
"sweep tx: %v", c.chanPoint, sweepResult.Tx.TxHash())
c.log.Infof("commit tx fully resolved by sweep tx: %v",
sweepResult.Tx.TxHash())
case <-c.quit:
return nil, errResolverShuttingDown
}
@ -171,8 +174,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
return nil, err
}
log.Infof("%T(%v): waiting for commit output to be swept", c,
c.chanPoint)
c.log.Infof("waiting for commit output to be swept")
var sweepTx *wire.MsgTx
select {
@ -186,19 +188,17 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
// now consider this to be our sweep transaction.
sweepTx = commitSpend.SpendingTx
log.Infof("%T(%v): commit output swept by txid=%v",
c, c.chanPoint, sweepTx.TxHash())
c.log.Infof("commit output swept by txid=%v", sweepTx.TxHash())
if err := c.Checkpoint(c); err != nil {
log.Errorf("unable to Checkpoint: %v", err)
c.log.Errorf("unable to Checkpoint: %v", err)
return nil, err
}
case <-c.quit:
return nil, errResolverShuttingDown
}
log.Infof("%T(%v): waiting for commit sweep txid=%v conf", c, c.chanPoint,
sweepTx.TxHash())
c.log.Infof("waiting for commit sweep txid=%v conf", sweepTx.TxHash())
// Now we'll wait until the sweeping transaction has been fully
// confirmed. Once it's confirmed, we can mark this contract resolved.
@ -216,8 +216,8 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
return nil, errResolverShuttingDown
}
log.Infof("ChannelPoint(%v) commit tx is fully resolved, at height: %v",
c.chanPoint, confInfo.BlockHeight)
c.log.Infof("commit tx is fully resolved, at height: %v",
confInfo.BlockHeight)
case <-c.quit:
return nil, errResolverShuttingDown
@ -308,6 +308,8 @@ func newCommitSweepResolverFromReader(r io.Reader, resCfg ResolverConfig) (
// removed this, but keep in mind that this data may still be present in
// the database.
c.initLogger(c)
return c, nil
}

View File

@ -3,9 +3,12 @@ package contractcourt
import (
"encoding/binary"
"errors"
"fmt"
"io"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/channeldb"
)
@ -93,6 +96,8 @@ type ResolverConfig struct {
type contractResolverKit struct {
ResolverConfig
log btclog.Logger
quit chan struct{}
}
@ -104,6 +109,12 @@ func newContractResolverKit(cfg ResolverConfig) *contractResolverKit {
}
}
// initLogger initializes the resolver-specific logger.
func (r *contractResolverKit) initLogger(resolver ContractResolver) {
logPrefix := fmt.Sprintf("%T(%v):", resolver, r.ChanPoint)
r.log = build.NewPrefixLog(logPrefix, log)
}
var (
// errResolverShuttingDown is returned when the resolver stops
// progressing because it received the quit signal.