htlcswitch/switch: add log/fwd event tickers to Config
This commit is contained in:
parent
1c456a5144
commit
e3253a4f3b
@ -21,6 +21,17 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/ticker"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultFwdEventInterval is the duration between attempts to flush
|
||||||
|
// pending forwarding events to disk.
|
||||||
|
DefaultFwdEventInterval = 15 * time.Second
|
||||||
|
|
||||||
|
// DefaultLogInterval is the duration between attempts to log statistics
|
||||||
|
// about forwarding events.
|
||||||
|
DefaultLogInterval = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -146,6 +157,14 @@ type Config struct {
|
|||||||
// Notifier is an instance of a chain notifier that we'll use to signal
|
// Notifier is an instance of a chain notifier that we'll use to signal
|
||||||
// the switch when a new block has arrived.
|
// the switch when a new block has arrived.
|
||||||
Notifier chainntnfs.ChainNotifier
|
Notifier chainntnfs.ChainNotifier
|
||||||
|
|
||||||
|
// FwdEventTicker is a signal that instructs the htlcswitch to flush any
|
||||||
|
// pending forwarding events.
|
||||||
|
FwdEventTicker ticker.Ticker
|
||||||
|
|
||||||
|
// LogEventTicker is a signal instructing the htlcswitch to log
|
||||||
|
// aggregate stats about it's forwarding during the last interval.
|
||||||
|
LogEventTicker ticker.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch is the central messaging bus for all incoming/outgoing HTLCs.
|
// Switch is the central messaging bus for all incoming/outgoing HTLCs.
|
||||||
@ -1390,13 +1409,13 @@ func (s *Switch) htlcForwarder() {
|
|||||||
totalSatSent btcutil.Amount
|
totalSatSent btcutil.Amount
|
||||||
totalSatRecv btcutil.Amount
|
totalSatRecv btcutil.Amount
|
||||||
)
|
)
|
||||||
logTicker := time.NewTicker(10 * time.Second)
|
s.cfg.LogEventTicker.Resume()
|
||||||
defer logTicker.Stop()
|
defer s.cfg.LogEventTicker.Stop()
|
||||||
|
|
||||||
// Every 15 seconds, we'll flush out the forwarding events that
|
// Every 15 seconds, we'll flush out the forwarding events that
|
||||||
// occurred during that period.
|
// occurred during that period.
|
||||||
fwdEventTicker := time.NewTicker(15 * time.Second)
|
s.cfg.FwdEventTicker.Resume()
|
||||||
defer fwdEventTicker.Stop()
|
defer s.cfg.FwdEventTicker.Stop()
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
@ -1474,7 +1493,7 @@ out:
|
|||||||
// When this time ticks, then it indicates that we should
|
// When this time ticks, then it indicates that we should
|
||||||
// collect all the forwarding events since the last internal,
|
// collect all the forwarding events since the last internal,
|
||||||
// and write them out to our log.
|
// and write them out to our log.
|
||||||
case <-fwdEventTicker.C:
|
case <-s.cfg.FwdEventTicker.Ticks():
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
@ -1488,7 +1507,7 @@ out:
|
|||||||
// The log ticker has fired, so we'll calculate some forwarding
|
// The log ticker has fired, so we'll calculate some forwarding
|
||||||
// stats for the last 10 seconds to display within the logs to
|
// stats for the last 10 seconds to display within the logs to
|
||||||
// users.
|
// users.
|
||||||
case <-logTicker.C:
|
case <-s.cfg.LogEventTicker.Ticks():
|
||||||
// First, we'll collate the current running tally of
|
// First, we'll collate the current running tally of
|
||||||
// our forwarding stats.
|
// our forwarding stats.
|
||||||
prevSatSent := totalSatSent
|
prevSatSent := totalSatSent
|
||||||
|
Loading…
Reference in New Issue
Block a user