2021-04-15 14:57:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/ticker"
|
2021-04-15 14:57:29 +00:00
|
|
|
)
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
type eigenTrustTickers struct {
|
|
|
|
m sync.Mutex
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
timers map[uint64]*ticker.IterationsTicker
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
func (e *eigenTrustTickers) addEpochTimer(epoch uint64, timer *ticker.IterationsTicker) {
|
|
|
|
e.m.Lock()
|
|
|
|
defer e.m.Unlock()
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
e.timers[epoch] = timer
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
func (e *eigenTrustTickers) tick() {
|
|
|
|
e.m.Lock()
|
|
|
|
defer e.m.Unlock()
|
2021-04-15 14:57:29 +00:00
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
for epoch, t := range e.timers {
|
|
|
|
if !t.Tick() {
|
|
|
|
delete(e.timers, epoch)
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func tickBlockTimers(c *cfg) {
|
2022-03-02 16:31:56 +00:00
|
|
|
c.cfgMorph.eigenTrustTicker.tick()
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 16:31:56 +00:00
|
|
|
func newEigenTrustIterTimer(c *cfg) {
|
|
|
|
c.cfgMorph.eigenTrustTicker = &eigenTrustTickers{
|
|
|
|
// it is expected to have max 2 concurrent epoch
|
|
|
|
// in normal mode work
|
|
|
|
timers: make(map[uint64]*ticker.IterationsTicker, 2),
|
|
|
|
}
|
2021-04-15 14:57:29 +00:00
|
|
|
}
|