From b7fa816bce3df8805cb8c563310863ed3c452a6f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 24 Mar 2017 16:30:08 -0700 Subject: [PATCH] htlcswitch: fix error when calculating the switch's 10 second stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- htlcswitch.go | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/htlcswitch.go b/htlcswitch.go index 5e27456b..5b9a6b7c 100644 --- a/htlcswitch.go +++ b/htlcswitch.go @@ -235,8 +235,12 @@ func (h *htlcSwitch) htlcForwarder() { // (src, htlcKey). // TODO(roasbeef): cleared vs settled distinction - var numUpdates uint64 - var satSent, satRecv btcutil.Amount + var ( + deltaNumUpdates, totalNumUpdates uint64 + + deltaSatSent, deltaSatRecv btcutil.Amount + totalSatSent, totalSatRecv btcutil.Amount + ) logTicker := time.NewTicker(10 * time.Second) out: for { @@ -289,7 +293,7 @@ out: htlcPkt.err <- fmt.Errorf("Insufficient capacity") case pkt := <-h.htlcPlex: // TODO(roasbeef): properly account with cleared vs settled - numUpdates++ + deltaNumUpdates++ hswcLog.Tracef("plex packet: %v", newLogClosure(func() string { return spew.Sdump(pkt) @@ -395,7 +399,7 @@ out: hswcLog.Tracef("Decrementing link %v bandwidth to %v", circuit.clear.chanPoint, n) - satRecv += pkt.amt + deltaSatRecv += pkt.amt // We've just received a settle message which means we // can finalize the payment circuit by forwarding the @@ -413,7 +417,7 @@ out: if !ok { hswcLog.Debugf("No existing circuit "+ "for %x to settle", rHash[:]) - satSent += pkt.amt + deltaSatSent += pkt.amt continue } @@ -436,7 +440,7 @@ out: hswcLog.Tracef("Incrementing link %v bandwidth to %v", circuit.settle.chanPoint, n) - satSent += pkt.amt + deltaSatSent += pkt.amt delete(h.paymentCircuits, cKey) @@ -478,18 +482,35 @@ out: delete(h.paymentCircuits, pkt.payHash) } case <-logTicker.C: - if numUpdates == 0 { + if deltaNumUpdates == 0 { 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 "+ "the last 10 seconds (%v tx/sec)", satSent.ToUnit(btcutil.AmountSatoshi), satRecv.ToUnit(btcutil.AmountSatoshi), - float64(numUpdates)/10) - satSent = 0 - satRecv = 0 - numUpdates = 0 + numUpdates) + + totalSatSent += deltaSatSent + deltaSatSent = 0 + + totalSatRecv += deltaSatRecv + deltaSatRecv = 0 + + totalNumUpdates += deltaNumUpdates + deltaNumUpdates = 0 case <-h.quit: break out }