From 2bca5879cd7fa3d7f09b4aa8210995760f05c68e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 28 Jan 2021 20:05:52 +0300 Subject: [PATCH] [#326] ir/settlement: Move the calculation of the minimum audit fee Move control of the minimum cost of payment for the audit from the implementation of the Exchanger to the place where the amount is calculated. Signed-off-by: Leonard Lyubich --- pkg/innerring/audit.go | 7 +------ pkg/innerring/processors/settlement/audit/calculate.go | 10 +++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/innerring/audit.go b/pkg/innerring/audit.go index f277b0270a..aef897e0c0 100644 --- a/pkg/innerring/audit.go +++ b/pkg/innerring/audit.go @@ -175,13 +175,8 @@ func (a auditSettlementDeps) Transfer(sender, recipient *owner.ID, amount *big.I return } - amount64 := amount.Int64() - if amount64 == 0 { - amount64 = 1 - } - if err := a.balanceClient.TransferX(balanceClient.TransferPrm{ - Amount: amount64, + Amount: amount.Int64(), From: sender, To: recipient, Details: transferAuditDetails, diff --git a/pkg/innerring/processors/settlement/audit/calculate.go b/pkg/innerring/processors/settlement/audit/calculate.go index 6bea99850f..fd498f593d 100644 --- a/pkg/innerring/processors/settlement/audit/calculate.go +++ b/pkg/innerring/processors/settlement/audit/calculate.go @@ -39,7 +39,11 @@ type singleResultCtx struct { sumSGSize *big.Int } -var bigGB = big.NewInt(1 << 30) +var ( + bigGB = big.NewInt(1 << 30) + bigZero = big.NewInt(0) + bigOne = big.NewInt(1) +) // Calculate calculates payments for audit results in a specific epoch of the network. // Wraps the results in a money transfer transaction and sends it to the network. @@ -242,6 +246,10 @@ func (c *Calculator) fillTransferTable(ctx *singleResultCtx) bool { fee := big.NewInt(0).Mul(price, ctx.sumSGSize) fee.Div(fee, bigGB) + if fee.Cmp(bigZero) == 0 { + fee.Add(fee, bigOne) + } + ctx.txTable.transfer(&transferTx{ from: cnrOwner, to: ownerID,