frostfs-node/pkg/innerring/processors/settlement/basic/context.go
Pavel Karpy 9cd8f7cea0 [#152] IR: Process empty basic incomes
If network is not configured for basic income earnings, do not distribute
GAS by the Alphabet nodes.

Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
2023-03-21 06:59:33 +00:00

80 lines
2 KiB
Go

package basic
import (
"math/big"
"sync"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/settlement/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"github.com/nspcc-dev/neo-go/pkg/util"
)
type (
EstimationFetcher interface {
Estimations(uint64) ([]*container.Estimations, error)
}
RateFetcher interface {
BasicRate() (uint64, error)
}
// BalanceFetcher uses NEP-17 compatible balance contract.
BalanceFetcher interface {
Balance(id user.ID) (*big.Int, error)
}
IncomeSettlementContext struct {
mu sync.Mutex // lock to prevent collection and distribution in the same time
noop bool
log *logger.Logger
epoch uint64
rate RateFetcher
estimations EstimationFetcher
balances BalanceFetcher
container common.ContainerStorage
placement common.PlacementCalculator
exchange common.Exchanger
accounts common.AccountStorage
bankOwner user.ID
// this table is not thread safe, make sure you use it with mu.Lock()
distributeTable *NodeSizeTable
}
IncomeSettlementContextPrms struct {
Log *logger.Logger
Epoch uint64
Rate RateFetcher
Estimations EstimationFetcher
Balances BalanceFetcher
Container common.ContainerStorage
Placement common.PlacementCalculator
Exchange common.Exchanger
Accounts common.AccountStorage
}
)
func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) *IncomeSettlementContext {
res := &IncomeSettlementContext{
log: p.Log,
epoch: p.Epoch,
rate: p.Rate,
estimations: p.Estimations,
balances: p.Balances,
container: p.Container,
placement: p.Placement,
exchange: p.Exchange,
accounts: p.Accounts,
distributeTable: NewNodeSizeTable(),
}
res.bankOwner.SetScriptHash(util.Uint160{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
return res
}