[#479] morph/timer: Move block timer to morph package

Block timer is going to be reused in storage node to tick
EigenTrust calculation rounds.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-15 16:50:34 +03:00 committed by Alex Vanin
parent 434ecb41da
commit 376bb293b4
4 changed files with 27 additions and 26 deletions

View file

@ -4,9 +4,10 @@ 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/processors/settlement"
"github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
timerEvent "github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
"go.uber.org/zap"
)
@ -29,9 +30,9 @@ type (
cnrWrapper *container.Wrapper // to invoke stop container estimation
epoch epochState // to specify which epoch to stop
epochDuration timers.BlockMeter // in blocks
stopEstimationDMul uint32 // X: X/Y of epoch in blocks
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
epochDuration timer.BlockMeter // in blocks
stopEstimationDMul uint32 // X: X/Y of epoch in blocks
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
collectBasicIncome subEpochEventHandler
distributeBasicIncome subEpochEventHandler
@ -52,7 +53,7 @@ type (
}
)
func (s *Server) addBlockTimer(t *timers.BlockTimer) {
func (s *Server) addBlockTimer(t *timer.BlockTimer) {
s.blockTimers = append(s.blockTimers, t)
}
@ -72,11 +73,11 @@ func (s *Server) tickTimers() {
}
}
func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer {
epochTimer := timers.NewBlockTimer(
func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
epochTimer := timer.NewBlockTimer(
args.epochDuration,
func() {
args.nm.HandleNewEpochTick(timers.NewEpochTick{})
args.nm.HandleNewEpochTick(timerEvent.NewEpochTick{})
},
)
@ -130,18 +131,18 @@ func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer {
return epochTimer
}
func newEmissionTimer(args *emitTimerArgs) *timers.BlockTimer {
return timers.NewBlockTimer(
timers.StaticBlockMeter(args.emitDuration),
func newEmissionTimer(args *emitTimerArgs) *timer.BlockTimer {
return timer.NewBlockTimer(
timer.StaticBlockMeter(args.emitDuration),
func() {
args.ap.HandleGasEmission(timers.NewAlphabetEmitTick{})
args.ap.HandleGasEmission(timerEvent.NewAlphabetEmitTick{})
},
)
}
func newNotaryDepositTimer(args *notaryDepositArgs) *timers.BlockTimer {
return timers.NewBlockTimer(
timers.StaticBlockMeter(args.notaryDuration),
func newNotaryDepositTimer(args *notaryDepositArgs) *timer.BlockTimer {
return timer.NewBlockTimer(
timer.StaticBlockMeter(args.notaryDuration),
func() {
err := args.depositor()
if err != nil {

View file

@ -22,11 +22,11 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/reputation"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit"
"github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
audittask "github.com/nspcc-dev/neofs-node/pkg/services/audit/taskmanager"
util2 "github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/precision"
@ -46,8 +46,8 @@ type (
// event producers
morphListener event.Listener
mainnetListener event.Listener
blockTimers []*timers.BlockTimer
epochTimer *timers.BlockTimer
blockTimers []*timer.BlockTimer
epochTimer *timer.BlockTimer
// global state
morphClient *client.Client

View file

@ -1,4 +1,4 @@
package timers
package timer
import (
"sync"

View file

@ -1,13 +1,13 @@
package timers_test
package timer_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
"github.com/stretchr/testify/require"
)
func tickN(t *timers.BlockTimer, n uint32) {
func tickN(t *timer.BlockTimer, n uint32) {
for i := uint32(0); i < n; i++ {
t.Tick()
}
@ -17,7 +17,7 @@ func TestBlockTimer(t *testing.T) {
blockDur := uint32(10)
baseCallCounter := uint32(0)
bt := timers.NewBlockTimer(timers.StaticBlockMeter(blockDur), func() {
bt := timer.NewBlockTimer(timer.StaticBlockMeter(blockDur), func() {
baseCallCounter++
})
@ -59,7 +59,7 @@ func TestDeltaPulse(t *testing.T) {
blockDur := uint32(9)
baseCallCounter := uint32(0)
bt := timers.NewBlockTimer(timers.StaticBlockMeter(blockDur), func() {
bt := timer.NewBlockTimer(timer.StaticBlockMeter(blockDur), func() {
baseCallCounter++
})
@ -69,7 +69,7 @@ func TestDeltaPulse(t *testing.T) {
bt.OnDelta(1, div, func() {
deltaCallCounter++
}, timers.WithPulse())
}, timer.WithPulse())
require.NoError(t, bt.Reset())
@ -85,7 +85,7 @@ func TestDeltaReset(t *testing.T) {
blockDur := uint32(6)
baseCallCounter := 0
bt := timers.NewBlockTimer(timers.StaticBlockMeter(blockDur), func() {
bt := timer.NewBlockTimer(timer.StaticBlockMeter(blockDur), func() {
baseCallCounter++
})