From fd461bdb65ec4f9652300846925cddbdfca3be89 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 2 Feb 2021 17:17:51 +0300 Subject: [PATCH] [#365] innerring: Produce distribute income events Signed-off-by: Alex Vanin --- cmd/neofs-ir/defaults.go | 2 ++ pkg/innerring/blocktimer.go | 33 +++++++++++++++++++++++++++------ pkg/innerring/innerring.go | 27 +++++++++++++++++---------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/cmd/neofs-ir/defaults.go b/cmd/neofs-ir/defaults.go index d90f783a8..13e9c4f52 100644 --- a/cmd/neofs-ir/defaults.go +++ b/cmd/neofs-ir/defaults.go @@ -80,6 +80,8 @@ func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("timers.stop_estimation.div", 1) cfg.SetDefault("timers.collect_basic_income.mul", 1) cfg.SetDefault("timers.collect_basic_income.div", 1) + cfg.SetDefault("timers.distribute_basic_income.mul", 1) + cfg.SetDefault("timers.distribute_basic_income.div", 1) cfg.SetDefault("workers.netmap", "10") cfg.SetDefault("workers.balance", "10") diff --git a/pkg/innerring/blocktimer.go b/pkg/innerring/blocktimer.go index e84990ce4..7828f0f37 100644 --- a/pkg/innerring/blocktimer.go +++ b/pkg/innerring/blocktimer.go @@ -15,6 +15,12 @@ type ( EpochCounter() uint64 } + subEpochEventHandler struct { + handler event.Handler // handle to execute + durationMul uint32 // X: X/Y of epoch in blocks + durationDiv uint32 // Y: X/Y of epoch in blocks + } + epochTimerArgs struct { l *zap.Logger @@ -27,9 +33,8 @@ type ( stopEstimationDMul uint32 // X: X/Y of epoch in blocks stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks - collectBasicIncome event.Handler // handle collect basic income - collectBasicIncomeDMul uint32 // X: X/Y of epoch in blocks - collectBasicIncomeDDiv uint32 // Y: X/Y of epoch in blocks + collectBasicIncome subEpochEventHandler + distributeBasicIncome subEpochEventHandler } emitTimerArgs struct { @@ -87,15 +92,31 @@ func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer { }) epochTimer.OnDelta( - args.collectBasicIncomeDMul, - args.collectBasicIncomeDDiv, + args.collectBasicIncome.durationMul, + args.collectBasicIncome.durationDiv, func() { epochN := args.epoch.EpochCounter() if epochN == 0 { // estimates are invalid in genesis epoch return } - args.collectBasicIncome(settlement.NewBasicIncomeCollectEvent(epochN - 1)) + args.collectBasicIncome.handler( + settlement.NewBasicIncomeCollectEvent(epochN - 1), + ) + }) + + epochTimer.OnDelta( + args.distributeBasicIncome.durationMul, + args.distributeBasicIncome.durationDiv, + func() { + epochN := args.epoch.EpochCounter() + if epochN == 0 { // estimates are invalid in genesis epoch + return + } + + args.distributeBasicIncome.handler( + settlement.NewBasicIncomeDistributeEvent(epochN - 1), + ) }) return epochTimer diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 0126440f2..69900557a 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -442,16 +442,23 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error // initialize epoch timers server.epochTimer = newEpochTimer(&epochTimerArgs{ - l: server.log, - nm: netmapProcessor, - cnrWrapper: cnrClient, - epoch: server, - epochDuration: cfg.GetUint32("timers.epoch"), - stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"), - stopEstimationDDiv: cfg.GetUint32("timers.stop_estimation.div"), - collectBasicIncome: settlementProcessor.HandleIncomeCollectionEvent, - collectBasicIncomeDMul: cfg.GetUint32("timers.collect_basic_income.mul"), - collectBasicIncomeDDiv: cfg.GetUint32("timers.collect_basic_income.div"), + l: server.log, + nm: netmapProcessor, + cnrWrapper: cnrClient, + epoch: server, + epochDuration: cfg.GetUint32("timers.epoch"), + stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"), + stopEstimationDDiv: cfg.GetUint32("timers.stop_estimation.div"), + collectBasicIncome: subEpochEventHandler{ + handler: settlementProcessor.HandleIncomeCollectionEvent, + durationMul: cfg.GetUint32("timers.collect_basic_income.mul"), + durationDiv: cfg.GetUint32("timers.collect_basic_income.div"), + }, + distributeBasicIncome: subEpochEventHandler{ + handler: settlementProcessor.HandleIncomeDistributionEvent, + durationMul: cfg.GetUint32("timers.distribute_basic_income.mul"), + durationDiv: cfg.GetUint32("timers.distribute_basic_income.div"), + }, }) server.addBlockTimer(server.epochTimer)