wtclient/session_negotiator: add prefix logging
This commit is contained in:
parent
505901d7b8
commit
de09b8d9bd
@ -339,6 +339,7 @@ func New(config *Config) (*TowerClient, error) {
|
||||
Candidates: c.candidateTowers,
|
||||
MinBackoff: cfg.MinBackoff,
|
||||
MaxBackoff: cfg.MaxBackoff,
|
||||
Log: plog,
|
||||
})
|
||||
|
||||
// Reconstruct the highest commit height processed for each channel
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||
@ -85,6 +86,10 @@ type NegotiatorConfig struct {
|
||||
// exponential backoff produces a timeout greater than this value, the
|
||||
// backoff duration will be clamped to MaxBackoff.
|
||||
MaxBackoff time.Duration
|
||||
|
||||
// Log specifies the desired log output, which should be prefixed by the
|
||||
// client type, e.g. anchor or legacy.
|
||||
Log btclog.Logger
|
||||
}
|
||||
|
||||
// sessionNegotiator is concrete SessionNegotiator that is able to request new
|
||||
@ -97,6 +102,7 @@ type sessionNegotiator struct {
|
||||
localInit *wtwire.Init
|
||||
|
||||
cfg *NegotiatorConfig
|
||||
log btclog.Logger
|
||||
|
||||
dispatcher chan struct{}
|
||||
newSessions chan *wtdb.ClientSession
|
||||
@ -130,6 +136,7 @@ func newSessionNegotiator(cfg *NegotiatorConfig) *sessionNegotiator {
|
||||
|
||||
return &sessionNegotiator{
|
||||
cfg: cfg,
|
||||
log: cfg.Log,
|
||||
localInit: localInit,
|
||||
dispatcher: make(chan struct{}, 1),
|
||||
newSessions: make(chan *wtdb.ClientSession),
|
||||
@ -141,7 +148,7 @@ func newSessionNegotiator(cfg *NegotiatorConfig) *sessionNegotiator {
|
||||
// Start safely starts up the sessionNegotiator.
|
||||
func (n *sessionNegotiator) Start() error {
|
||||
n.started.Do(func() {
|
||||
log.Debugf("Starting session negotiator")
|
||||
n.log.Debugf("Starting session negotiator")
|
||||
|
||||
n.wg.Add(1)
|
||||
go n.negotiationDispatcher()
|
||||
@ -153,7 +160,7 @@ func (n *sessionNegotiator) Start() error {
|
||||
// Stop safely shutsdown the sessionNegotiator.
|
||||
func (n *sessionNegotiator) Stop() error {
|
||||
n.stopped.Do(func() {
|
||||
log.Debugf("Stopping session negotiator")
|
||||
n.log.Debugf("Stopping session negotiator")
|
||||
|
||||
close(n.quit)
|
||||
n.wg.Wait()
|
||||
@ -191,7 +198,7 @@ func (n *sessionNegotiator) negotiationDispatcher() {
|
||||
pendingNegotiations++
|
||||
|
||||
if pendingNegotiations > 1 {
|
||||
log.Debugf("Already negotiating session, " +
|
||||
n.log.Debugf("Already negotiating session, " +
|
||||
"waiting for existing negotiation to " +
|
||||
"complete")
|
||||
continue
|
||||
@ -199,7 +206,7 @@ func (n *sessionNegotiator) negotiationDispatcher() {
|
||||
|
||||
// TODO(conner): consider reusing good towers
|
||||
|
||||
log.Debugf("Dispatching session negotiation")
|
||||
n.log.Debugf("Dispatching session negotiation")
|
||||
|
||||
n.wg.Add(1)
|
||||
go n.negotiate()
|
||||
@ -213,7 +220,7 @@ func (n *sessionNegotiator) negotiationDispatcher() {
|
||||
}
|
||||
|
||||
if pendingNegotiations > 0 {
|
||||
log.Debugf("Dispatching pending session " +
|
||||
n.log.Debugf("Dispatching pending session " +
|
||||
"negotiation")
|
||||
|
||||
n.wg.Add(1)
|
||||
@ -278,7 +285,7 @@ retryWithBackoff:
|
||||
// We've run out of addresses, update our backoff.
|
||||
updateBackoff()
|
||||
|
||||
log.Debugf("Unable to get new tower candidate, "+
|
||||
n.log.Debugf("Unable to get new tower candidate, "+
|
||||
"retrying after %v -- reason: %v", backoff, err)
|
||||
|
||||
// Only reset the iterator once we've exhausted all
|
||||
@ -292,7 +299,7 @@ retryWithBackoff:
|
||||
}
|
||||
|
||||
towerPub := tower.IdentityKey.SerializeCompressed()
|
||||
log.Debugf("Attempting session negotiation with tower=%x",
|
||||
n.log.Debugf("Attempting session negotiation with tower=%x",
|
||||
towerPub)
|
||||
|
||||
// Before proceeding, we will reserve a session key index to use
|
||||
@ -302,7 +309,7 @@ retryWithBackoff:
|
||||
tower.ID, n.cfg.Policy.BlobType,
|
||||
)
|
||||
if err != nil {
|
||||
log.Debugf("Unable to reserve session key index "+
|
||||
n.log.Debugf("Unable to reserve session key index "+
|
||||
"for tower=%x: %v", towerPub, err)
|
||||
continue
|
||||
}
|
||||
@ -314,7 +321,7 @@ retryWithBackoff:
|
||||
// An unexpected error occurred, updpate our backoff.
|
||||
updateBackoff()
|
||||
|
||||
log.Debugf("Session negotiation with tower=%x "+
|
||||
n.log.Debugf("Session negotiation with tower=%x "+
|
||||
"failed, trying again -- reason: %v",
|
||||
tower.IdentityKey.SerializeCompressed(), err)
|
||||
|
||||
@ -360,7 +367,7 @@ func (n *sessionNegotiator) createSession(tower *wtdb.Tower,
|
||||
fallthrough
|
||||
|
||||
case err != nil:
|
||||
log.Debugf("Request for session negotiation with "+
|
||||
n.log.Debugf("Request for session negotiation with "+
|
||||
"tower=%s failed, trying again -- reason: "+
|
||||
"%v", lnAddr, err)
|
||||
continue
|
||||
@ -467,7 +474,7 @@ func (n *sessionNegotiator) tryAddress(sessionKey keychain.SingleKeyECDH,
|
||||
err)
|
||||
}
|
||||
|
||||
log.Debugf("New session negotiated with %s, policy: %s",
|
||||
n.log.Debugf("New session negotiated with %s, policy: %s",
|
||||
lnAddr, clientSession.Policy)
|
||||
|
||||
// We have a newly negotiated session, return it to the
|
||||
|
Loading…
Reference in New Issue
Block a user