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/chain_manager.go | |
parent | d0bb90c69e5572417128fdb8188f53cc45f76002 (diff) | |
download | dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.gz dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.bz2 dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.lz dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.xz dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.zst dexon-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/chain_manager.go')
-rw-r--r-- | core/chain_manager.go | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 8a79e3e8a..8a8078381 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -60,7 +60,9 @@ func CalcTD(block, parent *types.Block) *big.Int { if parent == nil { return block.Difficulty() } - return new(big.Int).Add(parent.Td, block.Header().Difficulty) + d := block.Difficulty() + d.Add(d, parent.Td) + return d } // CalcGasLimit computes the gas limit of the next block after parent. @@ -465,26 +467,6 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) { bc.td = new(big.Int).Set(td) } -func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error) { - parent := self.GetBlock(block.Header().ParentHash) - if parent == nil { - return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.Header().ParentHash) - } - - parentTd := parent.Td - - uncleDiff := new(big.Int) - for _, uncle := range block.Uncles() { - uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty) - } - - td := new(big.Int) - td = td.Add(parentTd, uncleDiff) - td = td.Add(td, block.Header().Difficulty) - - return td, nil -} - func (bc *ChainManager) Stop() { close(bc.quit) atomic.StoreInt32(&bc.procInterrupt, 1) |