p2p: pass start time to flowrate and cleanup constructors (#7838)

After poking around #7828, I saw the oppertunity for this cleanup,
which I think is both reasonable on its own, and quite low impact, and
removes the math around process start time.
This commit is contained in:
Sam Kleinman
2022-02-18 13:30:19 +00:00
committed by GitHub
parent cb26c5238a
commit be83ec6664
6 changed files with 41 additions and 64 deletions
+12 -15
View File
@@ -331,8 +331,16 @@ func (pool *BlockPool) SetPeerRange(peerID types.NodeID, base int64, height int6
peer.base = base
peer.height = height
} else {
peer = newBPPeer(pool, peerID, base, height)
peer.logger = pool.logger.With("peer", peerID)
peer = &bpPeer{
pool: pool,
id: peerID,
base: base,
height: height,
numPending: 0,
logger: pool.logger.With("peer", peerID),
startAt: time.Now(),
}
pool.peers[peerID] = peer
}
@@ -490,24 +498,13 @@ type bpPeer struct {
recvMonitor *flowrate.Monitor
timeout *time.Timer
startAt time.Time
logger log.Logger
}
func newBPPeer(pool *BlockPool, peerID types.NodeID, base int64, height int64) *bpPeer {
peer := &bpPeer{
pool: pool,
id: peerID,
base: base,
height: height,
numPending: 0,
logger: log.NewNopLogger(),
}
return peer
}
func (peer *bpPeer) resetMonitor() {
peer.recvMonitor = flowrate.New(time.Second, time.Second*40)
peer.recvMonitor = flowrate.New(peer.startAt, time.Second, time.Second*40)
initialValue := float64(minRecvRate) * math.E
peer.recvMonitor.SetREMA(initialValue)
}