From 50ed4c59671ed5bbd9364806a5a0866a0a33f75b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 4 Jun 2020 22:33:37 +0300 Subject: [PATCH] core: don't return an error from CalculateClaimable As it never returns one. --- pkg/core/blockchain.go | 9 +++------ pkg/core/blockchain_test.go | 12 ++++-------- pkg/core/blockchainer/blockchainer.go | 2 +- pkg/core/native/native_neo.go | 10 ++-------- pkg/network/helper_test.go | 2 +- pkg/rpc/server/server.go | 7 ++----- 6 files changed, 13 insertions(+), 29 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 224e335af..6d40dee1f 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1238,7 +1238,7 @@ func (bc *Blockchain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) // CalculateClaimable calculates the amount of GAS which can be claimed for a transaction with value. // First return value is GAS generated between startHeight and endHeight. // Second return value is GAS returned from accumulated SystemFees between startHeight and endHeight. -func (bc *Blockchain) CalculateClaimable(value util.Fixed8, startHeight, endHeight uint32) (util.Fixed8, util.Fixed8, error) { +func (bc *Blockchain) CalculateClaimable(value util.Fixed8, startHeight, endHeight uint32) (util.Fixed8, util.Fixed8) { var amount util.Fixed8 di := uint32(bc.decrementInterval) @@ -1274,7 +1274,7 @@ func (bc *Blockchain) CalculateClaimable(value util.Fixed8, startHeight, endHeig sysFeeTotal := util.Fixed8(feeEnd - feeStart) ratio := value / 100000000 - return amount * ratio, sysFeeTotal * ratio, nil + return amount * ratio, sysFeeTotal * ratio } // References maps transaction's inputs into a slice of InOuts, effectively @@ -1479,10 +1479,7 @@ func (bc *Blockchain) calculateBonus(claims []transaction.Input) (util.Fixed8, e func (bc *Blockchain) calculateBonusInternal(scs []*spentCoin) (util.Fixed8, error) { var claimed util.Fixed8 for _, sc := range scs { - gen, sys, err := bc.CalculateClaimable(sc.Output.Amount, sc.StartHeight, sc.EndHeight) - if err != nil { - return 0, err - } + gen, sys := bc.CalculateClaimable(sc.Output.Amount, sc.StartHeight, sc.EndHeight) claimed += gen + sys } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 77a5d697e..c4df1cec8 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -194,29 +194,25 @@ func TestGetClaimable(t *testing.T) { require.NoError(t, err) t.Run("first generation period", func(t *testing.T) { - amount, sysfee, err := bc.CalculateClaimable(util.Fixed8FromInt64(1), 0, 2) - require.NoError(t, err) + amount, sysfee := bc.CalculateClaimable(util.Fixed8FromInt64(1), 0, 2) require.EqualValues(t, 8, amount) require.EqualValues(t, 0, sysfee) }) t.Run("a number of full periods", func(t *testing.T) { - amount, sysfee, err := bc.CalculateClaimable(util.Fixed8FromInt64(1), 0, 6) - require.NoError(t, err) + amount, sysfee := bc.CalculateClaimable(util.Fixed8FromInt64(1), 0, 6) require.EqualValues(t, 4+4+3+3+2+2, amount) require.EqualValues(t, 0, sysfee) }) t.Run("start from the 2-nd block", func(t *testing.T) { - amount, sysfee, err := bc.CalculateClaimable(util.Fixed8FromInt64(1), 1, 7) - require.NoError(t, err) + amount, sysfee := bc.CalculateClaimable(util.Fixed8FromInt64(1), 1, 7) require.EqualValues(t, 4+3+3+2+2+1, amount) require.EqualValues(t, 0, sysfee) }) t.Run("end height after generation has ended", func(t *testing.T) { - amount, sysfee, err := bc.CalculateClaimable(util.Fixed8FromInt64(1), 1, 10) - require.NoError(t, err) + amount, sysfee := bc.CalculateClaimable(util.Fixed8FromInt64(1), 1, 10) require.EqualValues(t, 4+3+3+2+2+1+1, amount) require.EqualValues(t, 0, sysfee) }) diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index 344dac5ea..1e61d254d 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -19,7 +19,7 @@ type Blockchainer interface { AddHeaders(...*block.Header) error AddBlock(*block.Block) error BlockHeight() uint32 - CalculateClaimable(value util.Fixed8, startHeight, endHeight uint32) (util.Fixed8, util.Fixed8, error) + CalculateClaimable(value util.Fixed8, startHeight, endHeight uint32) (util.Fixed8, util.Fixed8) Close() HeaderHeight() uint32 GetBlock(hash util.Uint256) (*block.Block, error) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index aca59e0fb..fe3391a47 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -188,10 +188,7 @@ func (n *NEO) distributeGas(ic *interop.Context, h util.Uint160, acc *state.NEOB if ic.Block == nil || ic.Block.Index == 0 { return nil } - sys, net, err := ic.Chain.CalculateClaimable(util.Fixed8(acc.Balance.Int64()), acc.BalanceHeight, ic.Block.Index) - if err != nil { - return err - } + sys, net := ic.Chain.CalculateClaimable(util.Fixed8(acc.Balance.Int64()), acc.BalanceHeight, ic.Block.Index) acc.BalanceHeight = ic.Block.Index n.GAS.mint(ic, h, big.NewInt(int64(sys+net))) return nil @@ -206,10 +203,7 @@ func (n *NEO) unclaimedGas(ic *interop.Context, args []vm.StackItem) vm.StackIte } tr := bs.Trackers[n.Hash] - sys, net, err := ic.Chain.CalculateClaimable(util.Fixed8(tr.Balance), tr.LastUpdatedBlock, end) - if err != nil { - panic(err) - } + sys, net := ic.Chain.CalculateClaimable(util.Fixed8(tr.Balance), tr.LastUpdatedBlock, end) return vm.NewBigIntegerItem(big.NewInt(int64(sys.Add(net)))) } diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index b48c4b985..4854f27b0 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -31,7 +31,7 @@ func (chain testChain) ApplyPolicyToTxSet([]mempool.TxWithFee) []mempool.TxWithF func (chain testChain) GetConfig() config.ProtocolConfiguration { panic("TODO") } -func (chain testChain) CalculateClaimable(util.Fixed8, uint32, uint32) (util.Fixed8, util.Fixed8, error) { +func (chain testChain) CalculateClaimable(util.Fixed8, uint32, uint32) (util.Fixed8, util.Fixed8) { panic("TODO") } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index e00369a46..0f5acafcd 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -821,11 +821,8 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro if neo == 0 { return "0", nil } - gasG, gasF, err := s.chain.CalculateClaimable(neo, neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block. - if err != nil { - return nil, response.NewInternalServerError("calculation error", err) - } - return strconv.FormatInt(int64(gasG+gasF), 10), nil // It's not represented as Fixed8 in C#. + gasG, gasF := s.chain.CalculateClaimable(neo, neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block. + return strconv.FormatInt(int64(gasG+gasF), 10), nil // It's not represented as Fixed8 in C#. } // getValidators returns the current NEO consensus nodes information and voting status.