[#488] reputation/eigentrust/calculator: Implement calc wrapper

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-29 08:30:41 +03:00 committed by Alex Vanin
parent d3c1fc7dda
commit ea781664cf
14 changed files with 294 additions and 53 deletions

View file

@ -9,7 +9,7 @@ import (
// ContinuePrm groups the required parameters of Continue operation.
type ContinuePrm struct {
epoch uint64
Epoch uint64
}
type iterContext struct {
@ -35,20 +35,24 @@ func (c *Controller) Continue(prm ContinuePrm) {
c.mtx.Lock()
{
iterCtx, ok := c.mCtx[prm.epoch]
iterCtx, ok := c.mCtx[prm.Epoch]
if !ok {
iterCtx := new(iterContextCancel)
c.mCtx[prm.epoch] = iterCtx
iterCtx = new(iterContextCancel)
c.mCtx[prm.Epoch] = iterCtx
iterCtx.Context, iterCtx.cancel = context.WithCancel(context.Background())
iterCtx.EpochIteration.SetEpoch(prm.Epoch)
} else {
iterCtx.cancel()
}
iterCtx.last = iterCtx.I() == c.prm.IterationNumber
iterCtx.last = iterCtx.I() == c.iterationNumber-1
err := c.prm.WorkerPool.Submit(func() {
c.prm.DaughtersTrustCalculator.Calculate(iterCtx.iterContext)
// iteration++
iterCtx.Increment()
})
if err != nil {
c.opts.log.Debug("iteration submit failure",
@ -57,11 +61,21 @@ func (c *Controller) Continue(prm ContinuePrm) {
}
if iterCtx.last {
delete(c.mCtx, prm.epoch)
// In this case and worker pool failure we can mark epoch
// number as already processed, but in any case it grows up
// during normal operation of the system. Also, such information
// will only live while the application is alive.
// during normal operation of the system. Also, such information
// number as already processed, but in any case it grows up
// In this case and worker pool failure we can mark epoch
delete(c.mCtx, prm.Epoch)
iterations, err := c.prm.IterationsProvider.EigenTrustIterations()
if err != nil {
c.opts.log.Debug(
"could not get iteration numbers",
zap.String("error", err.Error()),
)
} else {
c.iterationNumber = uint32(iterations)
}
}
}