diff options
author | Felix Lange <fjl@twurst.com> | 2015-06-26 20:17:36 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-30 00:51:48 +0800 |
commit | fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36 (patch) | |
tree | 4c6f3a04cb1e5f8e28e806be66e3287d8dd19e5e /core/block_processor.go | |
parent | d0bb90c69e5572417128fdb8188f53cc45f76002 (diff) | |
download | go-tangerine-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.gz go-tangerine-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.zst go-tangerine-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.zip |
core: remove superfluous big.Int allocations
With blocks now being immutable, use big.Int values from
accessor functions instead of copying their results.
Diffstat (limited to 'core/block_processor.go')
-rw-r--r-- | core/block_processor.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index 2fd8c04c0..4b27f8797 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -81,9 +81,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated // Update the state with pending changes statedb.Update() - cumulative := new(big.Int).Set(usedGas.Add(usedGas, gas)) - receipt := types.NewReceipt(statedb.Root().Bytes(), cumulative) - + usedGas.Add(usedGas, gas) + receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) logs := statedb.GetLogs(tx.Hash()) receipt.SetLogs(logs) receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) @@ -260,26 +259,28 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st return state.Logs(), nil } +var ( + big8 = big.NewInt(8) + big32 = big.NewInt(32) +) + // AccumulateRewards credits the coinbase of the given block with the // mining reward. The total reward consists of the static block reward -// and rewards for included uncles. +// and rewards for included uncles. The coinbase of each uncle block is +// also rewarded. func AccumulateRewards(statedb *state.StateDB, header *types.Header, uncles []*types.Header) { reward := new(big.Int).Set(BlockReward) - + r := new(big.Int) for _, uncle := range uncles { - num := new(big.Int).Add(big.NewInt(8), uncle.Number) - num.Sub(num, header.Number) - - r := new(big.Int) - r.Mul(BlockReward, num) - r.Div(r, big.NewInt(8)) - + r.Add(uncle.Number, big8) + r.Sub(r, header.Number) + r.Mul(r, BlockReward) + r.Div(r, big8) statedb.AddBalance(uncle.Coinbase, r) - reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32))) + r.Div(BlockReward, big32) + reward.Add(reward, r) } - - // Get the account associated with the coinbase statedb.AddBalance(header.Coinbase, reward) } |