mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-15 03:51:23 +01:00
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:
parent
9d79fea937
commit
55a32c951a
2 changed files with 31 additions and 18 deletions
|
@ -44,12 +44,16 @@ func newCommitSweepResolver(res lnwallet.CommitOutputResolution,
|
||||||
broadcastHeight uint32,
|
broadcastHeight uint32,
|
||||||
chanPoint wire.OutPoint, resCfg ResolverConfig) *commitSweepResolver {
|
chanPoint wire.OutPoint, resCfg ResolverConfig) *commitSweepResolver {
|
||||||
|
|
||||||
return &commitSweepResolver{
|
r := &commitSweepResolver{
|
||||||
contractResolverKit: *newContractResolverKit(resCfg),
|
contractResolverKit: *newContractResolverKit(resCfg),
|
||||||
commitResolution: res,
|
commitResolution: res,
|
||||||
broadcastHeight: broadcastHeight,
|
broadcastHeight: broadcastHeight,
|
||||||
chanPoint: chanPoint,
|
chanPoint: chanPoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.initLogger(r)
|
||||||
|
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolverKey returns an identifier which should be globally unique for this
|
// ResolverKey returns an identifier which should be globally unique for this
|
||||||
|
@ -85,7 +89,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||||
return nil, err
|
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 {
|
select {
|
||||||
case _, ok := <-confNtfn.Confirmed:
|
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
|
// With our input constructed, we'll now offer it to the
|
||||||
// sweeper.
|
// sweeper.
|
||||||
log.Infof("%T(%v): sweeping commit output", c, c.chanPoint)
|
c.log.Infof("sweeping commit output")
|
||||||
|
|
||||||
feePref := sweep.FeePreference{ConfTarget: commitOutputConfTarget}
|
feePref := sweep.FeePreference{ConfTarget: commitOutputConfTarget}
|
||||||
resultChan, err := c.Sweeper.SweepInput(&inp, feePref)
|
resultChan, err := c.Sweeper.SweepInput(&inp, feePref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%T(%v): unable to sweep input: %v",
|
c.log.Errorf("unable to sweep input: %v", err)
|
||||||
c, c.chanPoint, err)
|
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -143,14 +146,14 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||||
select {
|
select {
|
||||||
case sweepResult := <-resultChan:
|
case sweepResult := <-resultChan:
|
||||||
if sweepResult.Err != nil {
|
if sweepResult.Err != nil {
|
||||||
log.Errorf("%T(%v): unable to sweep input: %v",
|
c.log.Errorf("unable to sweep input: %v",
|
||||||
c, c.chanPoint, sweepResult.Err)
|
sweepResult.Err)
|
||||||
|
|
||||||
return nil, sweepResult.Err
|
return nil, sweepResult.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("ChannelPoint(%v) commit tx is fully resolved by "+
|
c.log.Infof("commit tx fully resolved by sweep tx: %v",
|
||||||
"sweep tx: %v", c.chanPoint, sweepResult.Tx.TxHash())
|
sweepResult.Tx.TxHash())
|
||||||
case <-c.quit:
|
case <-c.quit:
|
||||||
return nil, errResolverShuttingDown
|
return nil, errResolverShuttingDown
|
||||||
}
|
}
|
||||||
|
@ -171,8 +174,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("%T(%v): waiting for commit output to be swept", c,
|
c.log.Infof("waiting for commit output to be swept")
|
||||||
c.chanPoint)
|
|
||||||
|
|
||||||
var sweepTx *wire.MsgTx
|
var sweepTx *wire.MsgTx
|
||||||
select {
|
select {
|
||||||
|
@ -186,19 +188,17 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||||
// now consider this to be our sweep transaction.
|
// now consider this to be our sweep transaction.
|
||||||
sweepTx = commitSpend.SpendingTx
|
sweepTx = commitSpend.SpendingTx
|
||||||
|
|
||||||
log.Infof("%T(%v): commit output swept by txid=%v",
|
c.log.Infof("commit output swept by txid=%v", sweepTx.TxHash())
|
||||||
c, c.chanPoint, sweepTx.TxHash())
|
|
||||||
|
|
||||||
if err := c.Checkpoint(c); err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
case <-c.quit:
|
case <-c.quit:
|
||||||
return nil, errResolverShuttingDown
|
return nil, errResolverShuttingDown
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("%T(%v): waiting for commit sweep txid=%v conf", c, c.chanPoint,
|
c.log.Infof("waiting for commit sweep txid=%v conf", sweepTx.TxHash())
|
||||||
sweepTx.TxHash())
|
|
||||||
|
|
||||||
// Now we'll wait until the sweeping transaction has been fully
|
// Now we'll wait until the sweeping transaction has been fully
|
||||||
// confirmed. Once it's confirmed, we can mark this contract resolved.
|
// confirmed. Once it's confirmed, we can mark this contract resolved.
|
||||||
|
@ -216,8 +216,8 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||||
return nil, errResolverShuttingDown
|
return nil, errResolverShuttingDown
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("ChannelPoint(%v) commit tx is fully resolved, at height: %v",
|
c.log.Infof("commit tx is fully resolved, at height: %v",
|
||||||
c.chanPoint, confInfo.BlockHeight)
|
confInfo.BlockHeight)
|
||||||
|
|
||||||
case <-c.quit:
|
case <-c.quit:
|
||||||
return nil, errResolverShuttingDown
|
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
|
// removed this, but keep in mind that this data may still be present in
|
||||||
// the database.
|
// the database.
|
||||||
|
|
||||||
|
c.initLogger(c)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,12 @@ package contractcourt
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/btcsuite/btclog"
|
||||||
|
"github.com/lightningnetwork/lnd/build"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,6 +96,8 @@ type ResolverConfig struct {
|
||||||
type contractResolverKit struct {
|
type contractResolverKit struct {
|
||||||
ResolverConfig
|
ResolverConfig
|
||||||
|
|
||||||
|
log btclog.Logger
|
||||||
|
|
||||||
quit chan struct{}
|
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 (
|
var (
|
||||||
// errResolverShuttingDown is returned when the resolver stops
|
// errResolverShuttingDown is returned when the resolver stops
|
||||||
// progressing because it received the quit signal.
|
// progressing because it received the quit signal.
|
||||||
|
|
Loading…
Add table
Reference in a new issue