2021-01-29 07:42:40 +00:00
|
|
|
package innerring
|
|
|
|
|
|
|
|
import (
|
2021-05-04 08:50:13 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/alphabet"
|
|
|
|
timerEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/timers"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/timer"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2021-04-27 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-01-29 07:48:47 +00:00
|
|
|
"go.uber.org/zap"
|
2021-01-29 07:42:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2021-01-29 07:48:47 +00:00
|
|
|
epochState interface {
|
|
|
|
EpochCounter() uint64
|
2021-10-14 11:04:09 +00:00
|
|
|
EpochDuration() uint64
|
2021-01-29 07:48:47 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 15:24:07 +00:00
|
|
|
alphaState interface {
|
|
|
|
IsAlphabet() bool
|
|
|
|
}
|
|
|
|
|
2021-10-11 17:08:31 +00:00
|
|
|
newEpochHandler func()
|
|
|
|
|
2021-01-29 07:42:40 +00:00
|
|
|
epochTimerArgs struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
l *logger.Logger
|
2021-01-29 07:48:47 +00:00
|
|
|
|
2023-03-30 15:24:07 +00:00
|
|
|
alphabetState alphaState
|
|
|
|
|
2021-10-11 17:08:31 +00:00
|
|
|
newEpochHandlers []newEpochHandler
|
2021-01-29 07:42:40 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
cnrWrapper *container.Client // to invoke stop container estimation
|
|
|
|
epoch epochState // to specify which epoch to stop, and epoch duration
|
2021-01-29 07:48:47 +00:00
|
|
|
|
2021-10-14 11:04:09 +00:00
|
|
|
stopEstimationDMul uint32 // X: X/Y of epoch in blocks
|
|
|
|
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
|
2021-01-29 07:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emitTimerArgs struct {
|
|
|
|
ap *alphabet.Processor // to handle new emission tick
|
|
|
|
|
|
|
|
emitDuration uint32 // in blocks
|
|
|
|
}
|
2021-02-24 15:46:01 +00:00
|
|
|
|
2021-05-04 08:50:13 +00:00
|
|
|
depositor func() (util.Uint256, error)
|
|
|
|
awaiter func(context.Context, util.Uint256) error
|
2021-01-29 07:42:40 +00:00
|
|
|
)
|
|
|
|
|
2021-04-15 13:50:34 +00:00
|
|
|
func (s *Server) addBlockTimer(t *timer.BlockTimer) {
|
2021-01-29 07:42:40 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-03-30 10:16:41 +00:00
|
|
|
func (s *Server) tickTimers(h uint32) {
|
2021-01-29 07:42:40 +00:00
|
|
|
for i := range s.blockTimers {
|
2022-03-30 10:16:41 +00:00
|
|
|
s.blockTimers[i].Tick(h)
|
2021-01-29 07:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:50:34 +00:00
|
|
|
func newEpochTimer(args *epochTimerArgs) *timer.BlockTimer {
|
|
|
|
epochTimer := timer.NewBlockTimer(
|
2021-10-14 11:04:09 +00:00
|
|
|
func() (uint32, error) {
|
|
|
|
return uint32(args.epoch.EpochDuration()), nil
|
|
|
|
},
|
2021-01-29 07:42:40 +00:00
|
|
|
func() {
|
2021-10-11 17:08:31 +00:00
|
|
|
for _, handler := range args.newEpochHandlers {
|
|
|
|
handler()
|
|
|
|
}
|
2021-01-29 07:42:40 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2021-01-29 07:48:47 +00:00
|
|
|
// sub-timer for epoch timer to tick stop container estimation events at
|
|
|
|
// some block in epoch
|
|
|
|
epochTimer.OnDelta(
|
|
|
|
args.stopEstimationDMul,
|
|
|
|
args.stopEstimationDDiv,
|
|
|
|
func() {
|
2023-03-30 15:24:07 +00:00
|
|
|
if !args.alphabetState.IsAlphabet() {
|
2023-04-12 14:35:10 +00:00
|
|
|
args.l.Debug(logs.InnerringNonalphabetModeDoNotStopContainerEstimations)
|
2023-03-30 15:24:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-29 07:48:47 +00:00
|
|
|
epochN := args.epoch.EpochCounter()
|
|
|
|
if epochN == 0 { // estimates are invalid in genesis epoch
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:19:05 +00:00
|
|
|
prm := container.StopEstimationPrm{}
|
|
|
|
prm.SetEpoch(epochN - 1)
|
|
|
|
|
|
|
|
err := args.cnrWrapper.StopEstimation(prm)
|
2021-01-29 07:48:47 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
args.l.Warn(logs.InnerringCantStopEpochEstimation,
|
2021-01-29 07:48:47 +00:00
|
|
|
zap.Uint64("epoch", epochN),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-01-29 07:42:40 +00:00
|
|
|
return epochTimer
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:50:34 +00:00
|
|
|
func newEmissionTimer(args *emitTimerArgs) *timer.BlockTimer {
|
|
|
|
return timer.NewBlockTimer(
|
|
|
|
timer.StaticBlockMeter(args.emitDuration),
|
2021-01-29 07:42:40 +00:00
|
|
|
func() {
|
2021-04-15 13:50:34 +00:00
|
|
|
args.ap.HandleGasEmission(timerEvent.NewAlphabetEmitTick{})
|
2021-01-29 07:42:40 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|