core: don't return an error from CalculateClaimable

As it never returns one.
This commit is contained in:
Roman Khimov 2020-06-04 22:33:37 +03:00
parent 1bc6d29c0d
commit 50ed4c5967
6 changed files with 13 additions and 29 deletions

View file

@ -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
}

View file

@ -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)
})

View file

@ -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)

View file

@ -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))))
}

View file

@ -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")
}

View file

@ -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.