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