forked from TrueCloudLab/frostfs-node
[#365] innerring: Produce distribute income events
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d77d49bd2a
commit
fd461bdb65
3 changed files with 46 additions and 16 deletions
|
@ -80,6 +80,8 @@ func defaultConfiguration(cfg *viper.Viper) {
|
||||||
cfg.SetDefault("timers.stop_estimation.div", 1)
|
cfg.SetDefault("timers.stop_estimation.div", 1)
|
||||||
cfg.SetDefault("timers.collect_basic_income.mul", 1)
|
cfg.SetDefault("timers.collect_basic_income.mul", 1)
|
||||||
cfg.SetDefault("timers.collect_basic_income.div", 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.netmap", "10")
|
||||||
cfg.SetDefault("workers.balance", "10")
|
cfg.SetDefault("workers.balance", "10")
|
||||||
|
|
|
@ -15,6 +15,12 @@ type (
|
||||||
EpochCounter() uint64
|
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 {
|
epochTimerArgs struct {
|
||||||
l *zap.Logger
|
l *zap.Logger
|
||||||
|
|
||||||
|
@ -27,9 +33,8 @@ type (
|
||||||
stopEstimationDMul uint32 // X: X/Y of epoch in blocks
|
stopEstimationDMul uint32 // X: X/Y of epoch in blocks
|
||||||
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
|
stopEstimationDDiv uint32 // Y: X/Y of epoch in blocks
|
||||||
|
|
||||||
collectBasicIncome event.Handler // handle collect basic income
|
collectBasicIncome subEpochEventHandler
|
||||||
collectBasicIncomeDMul uint32 // X: X/Y of epoch in blocks
|
distributeBasicIncome subEpochEventHandler
|
||||||
collectBasicIncomeDDiv uint32 // Y: X/Y of epoch in blocks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emitTimerArgs struct {
|
emitTimerArgs struct {
|
||||||
|
@ -87,15 +92,31 @@ func newEpochTimer(args *epochTimerArgs) *timers.BlockTimer {
|
||||||
})
|
})
|
||||||
|
|
||||||
epochTimer.OnDelta(
|
epochTimer.OnDelta(
|
||||||
args.collectBasicIncomeDMul,
|
args.collectBasicIncome.durationMul,
|
||||||
args.collectBasicIncomeDDiv,
|
args.collectBasicIncome.durationDiv,
|
||||||
func() {
|
func() {
|
||||||
epochN := args.epoch.EpochCounter()
|
epochN := args.epoch.EpochCounter()
|
||||||
if epochN == 0 { // estimates are invalid in genesis epoch
|
if epochN == 0 { // estimates are invalid in genesis epoch
|
||||||
return
|
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
|
return epochTimer
|
||||||
|
|
|
@ -449,9 +449,16 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
epochDuration: cfg.GetUint32("timers.epoch"),
|
epochDuration: cfg.GetUint32("timers.epoch"),
|
||||||
stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"),
|
stopEstimationDMul: cfg.GetUint32("timers.stop_estimation.mul"),
|
||||||
stopEstimationDDiv: cfg.GetUint32("timers.stop_estimation.div"),
|
stopEstimationDDiv: cfg.GetUint32("timers.stop_estimation.div"),
|
||||||
collectBasicIncome: settlementProcessor.HandleIncomeCollectionEvent,
|
collectBasicIncome: subEpochEventHandler{
|
||||||
collectBasicIncomeDMul: cfg.GetUint32("timers.collect_basic_income.mul"),
|
handler: settlementProcessor.HandleIncomeCollectionEvent,
|
||||||
collectBasicIncomeDDiv: cfg.GetUint32("timers.collect_basic_income.div"),
|
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)
|
server.addBlockTimer(server.epochTimer)
|
||||||
|
|
Loading…
Reference in a new issue