From 376bb293b458267ee53b1c6ecba9a53ad4367f7a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 15 Apr 2021 16:50:34 +0300 Subject: [PATCH] [#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 --- pkg/innerring/blocktimer.go | 31 ++++++++++--------- pkg/innerring/innerring.go | 6 ++-- .../timers => morph/timer}/block.go | 2 +- .../timers => morph/timer}/block_test.go | 14 ++++----- 4 files changed, 27 insertions(+), 26 deletions(-) rename pkg/{innerring/timers => morph/timer}/block.go (99%) rename pkg/{innerring/timers => morph/timer}/block_test.go (82%) diff --git a/pkg/innerring/blocktimer.go b/pkg/innerring/blocktimer.go index 8085020184..2357b0f614 100644 --- a/pkg/innerring/blocktimer.go +++ b/pkg/innerring/blocktimer.go @@ -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 { diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index e2438cd42f..0c989c033d 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -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 diff --git a/pkg/innerring/timers/block.go b/pkg/morph/timer/block.go similarity index 99% rename from pkg/innerring/timers/block.go rename to pkg/morph/timer/block.go index e44379f1a2..043347ff93 100644 --- a/pkg/innerring/timers/block.go +++ b/pkg/morph/timer/block.go @@ -1,4 +1,4 @@ -package timers +package timer import ( "sync" diff --git a/pkg/innerring/timers/block_test.go b/pkg/morph/timer/block_test.go similarity index 82% rename from pkg/innerring/timers/block_test.go rename to pkg/morph/timer/block_test.go index 34529959cc..03e4ec38e7 100644 --- a/pkg/innerring/timers/block_test.go +++ b/pkg/morph/timer/block_test.go @@ -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++ })