2021-01-28 19:43:32 +00:00
|
|
|
package settlement
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2021-01-28 19:43:32 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HandleAuditEvent catches a new AuditEvent and
|
|
|
|
// adds AuditProcessor call to the execution queue.
|
|
|
|
func (p *Processor) HandleAuditEvent(e event.Event) {
|
|
|
|
ev := e.(AuditEvent)
|
|
|
|
|
|
|
|
epoch := ev.Epoch()
|
|
|
|
|
2023-03-30 15:24:37 +00:00
|
|
|
if !p.state.IsAlphabet() {
|
|
|
|
p.log.Info("non alphabet mode, ignore audit payments")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 07:41:01 +00:00
|
|
|
log := &logger.Logger{Logger: p.log.With(
|
2021-01-28 19:43:32 +00:00
|
|
|
zap.Uint64("epoch", epoch),
|
2022-09-28 07:41:01 +00:00
|
|
|
)}
|
2021-01-28 19:43:32 +00:00
|
|
|
|
|
|
|
log.Info("new audit settlement event")
|
|
|
|
|
|
|
|
if epoch == 0 {
|
|
|
|
log.Debug("ignore genesis epoch")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
handler := &auditEventHandler{
|
|
|
|
log: log,
|
|
|
|
epoch: epoch,
|
|
|
|
proc: p.auditProc,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := p.pool.Submit(handler.handle)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("could not add handler of AuditEvent to queue",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("AuditEvent handling successfully scheduled")
|
|
|
|
}
|
2021-02-01 16:18:34 +00:00
|
|
|
|
|
|
|
func (p *Processor) HandleIncomeCollectionEvent(e event.Event) {
|
|
|
|
ev := e.(BasicIncomeCollectEvent)
|
|
|
|
epoch := ev.Epoch()
|
|
|
|
|
2021-03-23 15:20:44 +00:00
|
|
|
if !p.state.IsAlphabet() {
|
|
|
|
p.log.Info("non alphabet mode, ignore income collection event")
|
2021-02-01 16:18:34 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.log.Info("start basic income collection",
|
|
|
|
zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
p.contextMu.Lock()
|
|
|
|
defer p.contextMu.Unlock()
|
|
|
|
|
|
|
|
if _, ok := p.incomeContexts[epoch]; ok {
|
|
|
|
p.log.Error("income context already exists",
|
|
|
|
zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
incomeCtx, err := p.basicIncome.CreateContext(epoch)
|
|
|
|
if err != nil {
|
|
|
|
p.log.Error("can't create income context",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.incomeContexts[epoch] = incomeCtx
|
|
|
|
|
|
|
|
err = p.pool.Submit(func() {
|
|
|
|
incomeCtx.Collect()
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
p.log.Warn("could not add handler of basic income collection to queue",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 14:17:38 +00:00
|
|
|
|
|
|
|
func (p *Processor) HandleIncomeDistributionEvent(e event.Event) {
|
|
|
|
ev := e.(BasicIncomeDistributeEvent)
|
|
|
|
epoch := ev.Epoch()
|
|
|
|
|
2021-03-23 15:20:44 +00:00
|
|
|
if !p.state.IsAlphabet() {
|
|
|
|
p.log.Info("non alphabet mode, ignore income distribution event")
|
2021-02-02 14:17:38 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.log.Info("start basic income distribution",
|
|
|
|
zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
p.contextMu.Lock()
|
|
|
|
defer p.contextMu.Unlock()
|
|
|
|
|
|
|
|
incomeCtx, ok := p.incomeContexts[epoch]
|
|
|
|
delete(p.incomeContexts, epoch)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
p.log.Warn("income context distribution does not exists",
|
|
|
|
zap.Uint64("epoch", epoch))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err := p.pool.Submit(func() {
|
|
|
|
incomeCtx.Distribute()
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
p.log.Warn("could not add handler of basic income distribution to queue",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|