htlcswitch: fix error when calculating the switch's 10 second stats

This commit fixes an error within the logic previously used to compute
the switch’s 10 seconds stats. The prior error would reset the number
of sat sent and received each 10 seconds to zero, rather than running a
delta over the accumulate amount.
This commit is contained in:
Olaoluwa Osuntokun 2017-03-24 16:30:08 -07:00
parent d6c863e2d1
commit b7fa816bce
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -235,8 +235,12 @@ func (h *htlcSwitch) htlcForwarder() {
// (src, htlcKey). // (src, htlcKey).
// TODO(roasbeef): cleared vs settled distinction // TODO(roasbeef): cleared vs settled distinction
var numUpdates uint64 var (
var satSent, satRecv btcutil.Amount deltaNumUpdates, totalNumUpdates uint64
deltaSatSent, deltaSatRecv btcutil.Amount
totalSatSent, totalSatRecv btcutil.Amount
)
logTicker := time.NewTicker(10 * time.Second) logTicker := time.NewTicker(10 * time.Second)
out: out:
for { for {
@ -289,7 +293,7 @@ out:
htlcPkt.err <- fmt.Errorf("Insufficient capacity") htlcPkt.err <- fmt.Errorf("Insufficient capacity")
case pkt := <-h.htlcPlex: case pkt := <-h.htlcPlex:
// TODO(roasbeef): properly account with cleared vs settled // TODO(roasbeef): properly account with cleared vs settled
numUpdates++ deltaNumUpdates++
hswcLog.Tracef("plex packet: %v", newLogClosure(func() string { hswcLog.Tracef("plex packet: %v", newLogClosure(func() string {
return spew.Sdump(pkt) return spew.Sdump(pkt)
@ -395,7 +399,7 @@ out:
hswcLog.Tracef("Decrementing link %v bandwidth to %v", hswcLog.Tracef("Decrementing link %v bandwidth to %v",
circuit.clear.chanPoint, n) circuit.clear.chanPoint, n)
satRecv += pkt.amt deltaSatRecv += pkt.amt
// We've just received a settle message which means we // We've just received a settle message which means we
// can finalize the payment circuit by forwarding the // can finalize the payment circuit by forwarding the
@ -413,7 +417,7 @@ out:
if !ok { if !ok {
hswcLog.Debugf("No existing circuit "+ hswcLog.Debugf("No existing circuit "+
"for %x to settle", rHash[:]) "for %x to settle", rHash[:])
satSent += pkt.amt deltaSatSent += pkt.amt
continue continue
} }
@ -436,7 +440,7 @@ out:
hswcLog.Tracef("Incrementing link %v bandwidth to %v", hswcLog.Tracef("Incrementing link %v bandwidth to %v",
circuit.settle.chanPoint, n) circuit.settle.chanPoint, n)
satSent += pkt.amt deltaSatSent += pkt.amt
delete(h.paymentCircuits, cKey) delete(h.paymentCircuits, cKey)
@ -478,18 +482,35 @@ out:
delete(h.paymentCircuits, pkt.payHash) delete(h.paymentCircuits, pkt.payHash)
} }
case <-logTicker.C: case <-logTicker.C:
if numUpdates == 0 { if deltaNumUpdates == 0 {
continue continue
} }
oldSatSent := totalSatRecv
oldSatRecv := totalSatRecv
oldNumUpdates := totalNumUpdates
newSatSent := oldSatRecv + deltaSatSent
newSatRecv := totalSatRecv + deltaSatRecv
newNumUpdates := totalNumUpdates + deltaNumUpdates
satSent := newSatSent - oldSatSent
satRecv := newSatRecv - oldSatRecv
numUpdates := newNumUpdates - oldNumUpdates
hswcLog.Infof("Sent %v satoshis, received %v satoshis in "+ hswcLog.Infof("Sent %v satoshis, received %v satoshis in "+
"the last 10 seconds (%v tx/sec)", "the last 10 seconds (%v tx/sec)",
satSent.ToUnit(btcutil.AmountSatoshi), satSent.ToUnit(btcutil.AmountSatoshi),
satRecv.ToUnit(btcutil.AmountSatoshi), satRecv.ToUnit(btcutil.AmountSatoshi),
float64(numUpdates)/10) numUpdates)
satSent = 0
satRecv = 0 totalSatSent += deltaSatSent
numUpdates = 0 deltaSatSent = 0
totalSatRecv += deltaSatRecv
deltaSatRecv = 0
totalNumUpdates += deltaNumUpdates
deltaNumUpdates = 0
case <-h.quit: case <-h.quit:
break out break out
} }