From dc0bd782d277ba781114af36383a75fff411bfcb Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 15 Apr 2021 09:43:49 +0300 Subject: [PATCH] [#478] innerring: Use dynamic epoch duration in epoch timer Signed-off-by: Alex Vanin --- pkg/innerring/blocktimer.go | 8 ++++---- pkg/innerring/config/config.go | 14 ++++++++++++++ pkg/innerring/innerring.go | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/innerring/blocktimer.go b/pkg/innerring/blocktimer.go index f423f5e5f..808502018 100644 --- a/pkg/innerring/blocktimer.go +++ b/pkg/innerring/blocktimer.go @@ -29,9 +29,9 @@ type ( cnrWrapper *container.Wrapper // to invoke stop container estimation epoch epochState // to specify which epoch to stop - epochDuration uint32 // in blocks - stopEstimationDMul uint32 // X: X/Y of epoch in blocks - stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks + epochDuration timers.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 @@ -74,7 +74,7 @@ func (s *Server) tickTimers() { func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer { epochTimer := timers.NewBlockTimer( - timers.StaticBlockMeter(args.epochDuration), + args.epochDuration, func() { args.nm.HandleNewEpochTick(timers.NewEpochTick{}) }, diff --git a/pkg/innerring/config/config.go b/pkg/innerring/config/config.go index 0ecaa4578..73c0aed1b 100644 --- a/pkg/innerring/config/config.go +++ b/pkg/innerring/config/config.go @@ -46,3 +46,17 @@ func (c *GlobalConfig) AuditFee() (uint64, error) { return c.nm.AuditFee() } + +func (c *GlobalConfig) EpochDuration() (uint32, error) { + value := c.cfg.GetUint32("timers.epoch") + if value != 0 { + return value, nil + } + + epochDuration, err := c.nm.EpochDuration() + if err != nil { + return 0, err + } + + return uint32(epochDuration), nil +} diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 31f6586f2..e2438cd42 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -585,7 +585,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error nm: netmapProcessor, cnrWrapper: cnrClient, epoch: server, - epochDuration: cfg.GetUint32("timers.epoch"), + epochDuration: globalConfig.EpochDuration, stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"), stopEstimationDDiv: cfg.GetUint32("timers.stop_estimation.div"), collectBasicIncome: subEpochEventHandler{