2021-01-29 07:42:40 +00:00
|
|
|
package innerring
|
|
|
|
|
|
|
|
import (
|
2021-05-04 08:50:13 +00:00
|
|
|
"context"
|
|
|
|
|
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/timer"
|
2021-04-27 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
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
|
|
|
}
|
|
|
|
|
2021-10-11 17:08:31 +00:00
|
|
|
newEpochHandler func()
|
|
|
|
|
2021-01-29 07:42:40 +00:00
|
|
|
epochTimerArgs struct {
|
2021-10-11 17:08:31 +00:00
|
|
|
newEpochHandlers []newEpochHandler
|
2021-01-29 07:42:40 +00:00
|
|
|
|
2024-11-06 12:25:02 +00:00
|
|
|
epoch epochState // to specify which epoch to stop, and epoch duration
|
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
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
depositor func(context.Context) (util.Uint256, error)
|
2021-05-04 08:50:13 +00:00
|
|
|
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 {
|
2024-11-06 12:25:02 +00:00
|
|
|
return 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
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func newEmissionTimer(ctx context.Context, args *emitTimerArgs) *timer.BlockTimer {
|
2021-04-15 13:50:34 +00:00
|
|
|
return timer.NewBlockTimer(
|
|
|
|
timer.StaticBlockMeter(args.emitDuration),
|
2021-01-29 07:42:40 +00:00
|
|
|
func() {
|
2024-10-21 13:27:28 +00:00
|
|
|
args.ap.HandleGasEmission(ctx, timerEvent.NewAlphabetEmitTick{})
|
2021-01-29 07:42:40 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|