core: remove superfluous big.Int allocations

With blocks now being immutable, use big.Int values from
accessor functions instead of copying their results.
This commit is contained in:
Felix Lange
2015-06-26 14:17:36 +02:00
committed by Jeffrey Wilcke
parent d0bb90c69e
commit fccc7d71eb
3 changed files with 32 additions and 61 deletions

View File

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