[#355] innerring: Refactor block timer constructors
This small refactoring adds `blocktimer.go` file with all timer related function and constructors. This way we can create all timers in one place (at the end of innerring.Server constructor). To do that we had to move timer reset into global server state so it can be accessed by netmap processor. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
402192c8c4
commit
6848a816f9
5 changed files with 106 additions and 68 deletions
61
pkg/innerring/blocktimer.go
Normal file
61
pkg/innerring/blocktimer.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package innerring
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/alphabet"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
|
||||
)
|
||||
|
||||
type (
|
||||
epochTimerArgs struct {
|
||||
nm *netmap.Processor // to handle new epoch tick
|
||||
|
||||
epochDuration uint32 // in blocks
|
||||
}
|
||||
|
||||
emitTimerArgs struct {
|
||||
ap *alphabet.Processor // to handle new emission tick
|
||||
|
||||
emitDuration uint32 // in blocks
|
||||
}
|
||||
)
|
||||
|
||||
func (s *Server) addBlockTimer(t *timers.BlockTimer) {
|
||||
s.blockTimers = append(s.blockTimers, t)
|
||||
}
|
||||
|
||||
func (s *Server) startBlockTimers() error {
|
||||
for i := range s.blockTimers {
|
||||
if err := s.blockTimers[i].Reset(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) tickTimers() {
|
||||
for i := range s.blockTimers {
|
||||
s.blockTimers[i].Tick()
|
||||
}
|
||||
}
|
||||
|
||||
func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer {
|
||||
epochTimer := timers.NewBlockTimer(
|
||||
timers.StaticBlockMeter(args.epochDuration),
|
||||
func() {
|
||||
args.nm.HandleNewEpochTick(timers.NewEpochTick{})
|
||||
},
|
||||
)
|
||||
|
||||
return epochTimer
|
||||
}
|
||||
|
||||
func newEmissionTimer(args *emitTimerArgs) *timers.BlockTimer {
|
||||
return timers.NewBlockTimer(
|
||||
timers.StaticBlockMeter(args.emitDuration),
|
||||
func() {
|
||||
args.ap.HandleGasEmission(timers.NewAlphabetEmitTick{})
|
||||
},
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue