mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
Remove old CalcTotalDiff function, improve code comments
This commit is contained in:
parent
fee99b3e8d
commit
ff3a891afe
1 changed files with 4 additions and 24 deletions
|
|
@ -74,10 +74,10 @@ type ChainManager struct {
|
||||||
processor types.BlockProcessor
|
processor types.BlockProcessor
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
genesisBlock *types.Block
|
genesisBlock *types.Block
|
||||||
// Last known total difficulty
|
mu sync.RWMutex
|
||||||
mu sync.RWMutex
|
tsmu sync.RWMutex
|
||||||
tsmu sync.RWMutex
|
|
||||||
|
|
||||||
|
// Last known total difficulty
|
||||||
td *big.Int
|
td *big.Int
|
||||||
currentBlock *types.Block
|
currentBlock *types.Block
|
||||||
lastBlockHash common.Hash
|
lastBlockHash common.Hash
|
||||||
|
|
@ -458,26 +458,6 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
|
||||||
bc.td = td
|
bc.td = 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() {
|
func (bc *ChainManager) Stop() {
|
||||||
close(bc.quit)
|
close(bc.quit)
|
||||||
|
|
||||||
|
|
@ -534,7 +514,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
block.Td = new(big.Int)
|
block.Td = new(big.Int)
|
||||||
// Do not penelise on future block. We'll need a block queue eventually that will queue
|
// Do not penalize on future block. We'll need a block queue eventually that will queue
|
||||||
// future block for future use
|
// future block for future use
|
||||||
if err == BlockFutureErr {
|
if err == BlockFutureErr {
|
||||||
block.SetQueued(true)
|
block.SetQueued(true)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue