mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: save global cost factor regularly
This commit is contained in:
parent
ca8d218344
commit
82c4b716a8
1 changed files with 13 additions and 5 deletions
|
|
@ -224,6 +224,15 @@ func (ct *costTracker) gfLoop() {
|
||||||
ct.gfUpdateCh = make(chan gfUpdate, 100)
|
ct.gfUpdateCh = make(chan gfUpdate, 100)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
saveCostFactor := func() {
|
||||||
|
var data [16]byte
|
||||||
|
binary.BigEndian.PutUint64(data[0:8], math.Float64bits(gfSum))
|
||||||
|
binary.BigEndian.PutUint64(data[8:16], math.Float64bits(gfWeight))
|
||||||
|
ct.db.Put([]byte(gfDbKey), data[:])
|
||||||
|
log.Debug("global cost factor saved", "sum", time.Duration(gfSum), "weight", time.Duration(gfWeight))
|
||||||
|
}
|
||||||
|
saveTicker := time.NewTicker(time.Minute * 10)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case r := <-ct.gfUpdateCh:
|
case r := <-ct.gfUpdateCh:
|
||||||
|
|
@ -273,12 +282,11 @@ func (ct *costTracker) gfLoop() {
|
||||||
ct.logRecentUsage.Update(gfUsage)
|
ct.logRecentUsage.Update(gfUsage)
|
||||||
ct.logTotalRecharge.Update(totalRecharge)
|
ct.logTotalRecharge.Update(totalRecharge)
|
||||||
|
|
||||||
|
case <-saveTicker.C:
|
||||||
|
saveCostFactor()
|
||||||
|
|
||||||
case stopCh := <-ct.stopCh:
|
case stopCh := <-ct.stopCh:
|
||||||
var data [16]byte
|
saveCostFactor()
|
||||||
binary.BigEndian.PutUint64(data[0:8], math.Float64bits(gfSum))
|
|
||||||
binary.BigEndian.PutUint64(data[8:16], math.Float64bits(gfWeight))
|
|
||||||
ct.db.Put([]byte(gfDbKey), data[:])
|
|
||||||
log.Debug("global cost factor saved", "sum", time.Duration(gfSum), "weight", time.Duration(gfWeight))
|
|
||||||
close(stopCh)
|
close(stopCh)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue