2021-02-01 16:17:16 +00:00
|
|
|
package basic
|
|
|
|
|
2021-02-02 13:45:13 +00:00
|
|
|
import (
|
2021-02-02 17:23:01 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"math/big"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/settlement/common"
|
2021-02-02 13:45:13 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-02-01 16:17:16 +00:00
|
|
|
func (inc *IncomeSettlementContext) Distribute() {
|
|
|
|
inc.mu.Lock()
|
|
|
|
defer inc.mu.Unlock()
|
2021-02-02 13:45:13 +00:00
|
|
|
|
2023-03-20 17:36:07 +00:00
|
|
|
if inc.noop {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:23:01 +00:00
|
|
|
txTable := common.NewTransferTable()
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
bankBalance, err := inc.balances.Balance(inc.bankOwner)
|
2021-02-02 13:45:13 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
inc.log.Error(logs.BasicCantFetchBalanceOfBankingAccount,
|
2021-02-02 13:45:13 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:23:01 +00:00
|
|
|
total := inc.distributeTable.Total()
|
|
|
|
|
|
|
|
inc.distributeTable.Iterate(func(key []byte, n *big.Int) {
|
|
|
|
nodeOwner, err := inc.accounts.ResolveKey(nodeInfoWrapper(key))
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
inc.log.Warn(logs.BasicCantTransformPublicKeyToOwnerID,
|
2021-02-02 17:23:01 +00:00
|
|
|
zap.String("public_key", hex.EncodeToString(key)),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
txTable.Transfer(&common.TransferTx{
|
2022-05-31 17:00:41 +00:00
|
|
|
From: inc.bankOwner,
|
|
|
|
To: *nodeOwner,
|
2021-02-02 17:23:01 +00:00
|
|
|
Amount: normalizedValue(n, total, bankBalance),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-07 12:12:36 +00:00
|
|
|
common.TransferAssets(inc.exchange, txTable, common.BasicIncomeDistributionDetails(inc.epoch))
|
2021-02-02 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func normalizedValue(n, total, limit *big.Int) *big.Int {
|
|
|
|
if limit.Cmp(bigZero) == 0 {
|
2021-02-03 12:07:37 +00:00
|
|
|
return big.NewInt(0)
|
2021-02-02 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n.Mul(n, limit)
|
|
|
|
return n.Div(n, total)
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|