From 70a20ce031f0e0ff3e57a59fb66284878020aa50 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 15 Feb 2021 19:07:08 +0300 Subject: [PATCH] core: fix system fee calculation It was completely wrong starting from the genesis block. --- pkg/core/blockchain.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 159a5153f..8bb1b0b9a 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1577,11 +1577,44 @@ func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8 { // SystemFee returns system fee. func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8 { - if t.Type == transaction.InvocationType { + switch t.Type { + case transaction.InvocationType: inv := t.Data.(*transaction.InvocationTX) - if inv.Version >= 1 { - return inv.Gas + return inv.Gas + case transaction.IssueType: + if t.Version >= 1 { + return util.Fixed8(0) } + var iszero = true + for i := range t.Outputs { + asset := t.Outputs[i].AssetID + if asset != UtilityTokenID() && asset != GoverningTokenID() { + iszero = false + break + } + } + if iszero { + return util.Fixed8(0) + } + case transaction.RegisterType: + reg := t.Data.(*transaction.RegisterTX) + if reg.AssetType == transaction.GoverningToken || reg.AssetType == transaction.UtilityToken { + return util.Fixed8(0) + } + case transaction.StateType: + res := util.Fixed8(0) + st := t.Data.(*transaction.StateTX) + for _, desc := range st.Descriptors { + if desc.Type == transaction.Validator && desc.Field == "Registered" { + for i := range desc.Value { + if desc.Value[i] != 0 { + res += util.Fixed8FromInt64(1000) + break + } + } + } + } + return res } return bc.GetConfig().SystemFee.TryGetValue(t.Type) }