[#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/alphabet"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap" "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/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" 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/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -29,9 +30,9 @@ type (
cnrWrapper *container.Wrapper // to invoke stop container estimation cnrWrapper *container.Wrapper // to invoke stop container estimation
epoch epochState // to specify which epoch to stop epoch epochState // to specify which epoch to stop
epochDuration timers.BlockMeter // in blocks epochDuration timer.BlockMeter // in blocks
stopEstimationDMul uint32 // X: X/Y of epoch in blocks stopEstimationDMul uint32 // X: X/Y of epoch in blocks
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
collectBasicIncome subEpochEventHandler collectBasicIncome subEpochEventHandler
distributeBasicIncome 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) s.blockTimers = append(s.blockTimers, t)
} }
@ -72,11 +73,11 @@ func (s *Server) tickTimers() {
} }
} }
func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer { func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
epochTimer := timers.NewBlockTimer( epochTimer := timer.NewBlockTimer(
args.epochDuration, args.epochDuration,
func() { func() {
args.nm.HandleNewEpochTick(timers.NewEpochTick{}) args.nm.HandleNewEpochTick(timerEvent.NewEpochTick{})
}, },
) )
@ -130,18 +131,18 @@ func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer {
return epochTimer return epochTimer
} }
func newEmissionTimer(args *emitTimerArgs) *timers.BlockTimer { func newEmissionTimer(args *emitTimerArgs) *timer.BlockTimer {
return timers.NewBlockTimer( return timer.NewBlockTimer(
timers.StaticBlockMeter(args.emitDuration), timer.StaticBlockMeter(args.emitDuration),
func() { func() {
args.ap.HandleGasEmission(timers.NewAlphabetEmitTick{}) args.ap.HandleGasEmission(timerEvent.NewAlphabetEmitTick{})
}, },
) )
} }
func newNotaryDepositTimer(args *notaryDepositArgs) *timers.BlockTimer { func newNotaryDepositTimer(args *notaryDepositArgs) *timer.BlockTimer {
return timers.NewBlockTimer( return timer.NewBlockTimer(
timers.StaticBlockMeter(args.notaryDuration), timer.StaticBlockMeter(args.notaryDuration),
func() { func() {
err := args.depositor() err := args.depositor()
if err != nil { 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/reputation"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit" 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" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper" 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/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber" "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" audittask "github.com/nspcc-dev/neofs-node/pkg/services/audit/taskmanager"
util2 "github.com/nspcc-dev/neofs-node/pkg/util" util2 "github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/precision" "github.com/nspcc-dev/neofs-node/pkg/util/precision"
@ -46,8 +46,8 @@ type (
// event producers // event producers
morphListener event.Listener morphListener event.Listener
mainnetListener event.Listener mainnetListener event.Listener
blockTimers []*timers.BlockTimer blockTimers []*timer.BlockTimer
epochTimer *timers.BlockTimer epochTimer *timer.BlockTimer
// global state // global state
morphClient *client.Client morphClient *client.Client

View file

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

View file

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