forked from TrueCloudLab/frostfs-node
[#365] settlement/basic: Check amount of collected assets
Some transfers from container owners into bank account may fail due to lack of assets, so we have to deal with remaining amount of assets in banking account. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
f85e5f0238
commit
4433448645
4 changed files with 28 additions and 2 deletions
|
@ -18,8 +18,6 @@ func (inc *IncomeSettlementContext) Collect() {
|
||||||
inc.mu.Lock()
|
inc.mu.Lock()
|
||||||
defer inc.mu.Unlock()
|
defer inc.mu.Unlock()
|
||||||
|
|
||||||
// todo: save state of bank wallet
|
|
||||||
|
|
||||||
cachedRate, err := inc.rate.BasicRate()
|
cachedRate, err := inc.rate.BasicRate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
inc.log.Error("can't get basic income rate",
|
inc.log.Error("can't get basic income rate",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package basic
|
package basic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
|
@ -21,6 +22,11 @@ type (
|
||||||
BasicRate() (uint64, error)
|
BasicRate() (uint64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BalanceFetcher uses NEP-17 compatible balance contract
|
||||||
|
BalanceFetcher interface {
|
||||||
|
Balance(id *owner.ID) (*big.Int, error)
|
||||||
|
}
|
||||||
|
|
||||||
IncomeSettlementContext struct {
|
IncomeSettlementContext struct {
|
||||||
mu sync.Mutex // lock to prevent collection and distribution in the same time
|
mu sync.Mutex // lock to prevent collection and distribution in the same time
|
||||||
|
|
||||||
|
@ -29,6 +35,7 @@ type (
|
||||||
|
|
||||||
rate RateFetcher
|
rate RateFetcher
|
||||||
estimations EstimationFetcher
|
estimations EstimationFetcher
|
||||||
|
balances BalanceFetcher
|
||||||
container common.ContainerStorage
|
container common.ContainerStorage
|
||||||
placement common.PlacementCalculator
|
placement common.PlacementCalculator
|
||||||
exchange common.Exchanger
|
exchange common.Exchanger
|
||||||
|
@ -42,6 +49,7 @@ type (
|
||||||
Epoch uint64
|
Epoch uint64
|
||||||
Rate RateFetcher
|
Rate RateFetcher
|
||||||
Estimations EstimationFetcher
|
Estimations EstimationFetcher
|
||||||
|
Balances BalanceFetcher
|
||||||
Container common.ContainerStorage
|
Container common.ContainerStorage
|
||||||
Placement common.PlacementCalculator
|
Placement common.PlacementCalculator
|
||||||
Exchange common.Exchanger
|
Exchange common.Exchanger
|
||||||
|
@ -59,6 +67,7 @@ func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) (*IncomeSettleme
|
||||||
epoch: p.Epoch,
|
epoch: p.Epoch,
|
||||||
rate: p.Rate,
|
rate: p.Rate,
|
||||||
estimations: p.Estimations,
|
estimations: p.Estimations,
|
||||||
|
balances: p.Balances,
|
||||||
container: p.Container,
|
container: p.Container,
|
||||||
placement: p.Placement,
|
placement: p.Placement,
|
||||||
exchange: p.Exchange,
|
exchange: p.Exchange,
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
package basic
|
package basic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
func (inc *IncomeSettlementContext) Distribute() {
|
func (inc *IncomeSettlementContext) Distribute() {
|
||||||
inc.mu.Lock()
|
inc.mu.Lock()
|
||||||
defer inc.mu.Unlock()
|
defer inc.mu.Unlock()
|
||||||
|
|
||||||
|
bankBalance, err := inc.balances.Balance(inc.bankOwner)
|
||||||
|
if err != nil {
|
||||||
|
inc.log.Error("can't fetch balance of banking account",
|
||||||
|
zap.String("error", err.Error()))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = bankBalance
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,10 @@ func (b basicIncomeSettlementDeps) Estimations(epoch uint64) ([]*wrapper.Estimat
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b basicIncomeSettlementDeps) Balance(id *owner.ID) (*big.Int, error) {
|
||||||
|
return b.balanceClient.BalanceOf(id)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *auditSettlementCalculator) ProcessAuditSettlements(epoch uint64) {
|
func (s *auditSettlementCalculator) ProcessAuditSettlements(epoch uint64) {
|
||||||
(*audit.Calculator)(s).Calculate(&audit.CalculatePrm{
|
(*audit.Calculator)(s).Calculate(&audit.CalculatePrm{
|
||||||
Epoch: epoch,
|
Epoch: epoch,
|
||||||
|
@ -271,6 +275,7 @@ func (b *basicSettlementConstructor) CreateContext(epoch uint64) (*basic.IncomeS
|
||||||
Epoch: epoch,
|
Epoch: epoch,
|
||||||
Rate: b.dep,
|
Rate: b.dep,
|
||||||
Estimations: b.dep,
|
Estimations: b.dep,
|
||||||
|
Balances: b.dep,
|
||||||
Container: b.dep,
|
Container: b.dep,
|
||||||
Placement: b.dep,
|
Placement: b.dep,
|
||||||
Exchange: b.dep,
|
Exchange: b.dep,
|
||||||
|
|
Loading…
Reference in a new issue