[#873] innerring/timers: Add multihandlers functionality for new epoch timer

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-10-11 20:08:31 +03:00 committed by Alex Vanin
parent 39b04ff749
commit a25bd2112d

View file

@ -5,7 +5,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"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/settlement" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
timerEvent "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"
@ -25,10 +24,12 @@ type (
durationDiv uint32 // Y: X/Y of epoch in blocks durationDiv uint32 // Y: X/Y of epoch in blocks
} }
newEpochHandler func()
epochTimerArgs struct { epochTimerArgs struct {
l *zap.Logger l *zap.Logger
nm *netmap.Processor // to handle new epoch tick newEpochHandlers []newEpochHandler
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
@ -54,8 +55,6 @@ type (
l *zap.Logger l *zap.Logger
depositor depositor depositor depositor
notaryDuration uint32 // in blocks
} }
) )
@ -83,7 +82,9 @@ func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
epochTimer := timer.NewBlockTimer( epochTimer := timer.NewBlockTimer(
args.epochDuration, args.epochDuration,
func() { func() {
args.nm.HandleNewEpochTick(timerEvent.NewEpochTick{}) for _, handler := range args.newEpochHandlers {
handler()
}
}, },
) )
@ -146,15 +147,12 @@ func newEmissionTimer(args *emitTimerArgs) *timer.BlockTimer {
) )
} }
func newNotaryDepositTimer(args *notaryDepositArgs) *timer.BlockTimer { func newNotaryDepositHandler(args *notaryDepositArgs) newEpochHandler {
return timer.NewBlockTimer( return func() {
timer.StaticBlockMeter(args.notaryDuration), _, err := args.depositor()
func() { if err != nil {
_, err := args.depositor() args.l.Warn("can't deposit notary contract",
if err != nil { zap.String("error", err.Error()))
args.l.Warn("can't deposit notary contract", }
zap.String("error", err.Error())) }
}
},
)
} }