aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_manager.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-10 05:42:36 +0800
committerobscuren <geffobscura@gmail.com>2015-01-10 05:42:36 +0800
commit491c23a728e4f5cdedfa040aded6a6b136f6bee0 (patch)
tree1fa546abacc60e8c29c43f465485d407777565c4 /core/chain_manager.go
parent351516c57cb5872e849ffca643526da5801564f2 (diff)
downloaddexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar.gz
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar.bz2
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar.lz
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar.xz
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.tar.zst
dexon-491c23a728e4f5cdedfa040aded6a6b136f6bee0.zip
Moved the TD method from block processor.
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r--core/chain_manager.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 90b5692ac..caa2e7b43 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -34,6 +34,20 @@ func CalcDifficulty(block, parent *types.Block) *big.Int {
return diff
}
+func CalculateTD(block, parent *types.Block) *big.Int {
+ uncleDiff := new(big.Int)
+ for _, uncle := range block.Uncles() {
+ uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty)
+ }
+
+ // TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty
+ td := new(big.Int)
+ td = td.Add(parent.Td, uncleDiff)
+ td = td.Add(td, block.Header().Difficulty)
+
+ return td
+}
+
func CalcGasLimit(parent, block *types.Block) *big.Int {
if block.Number().Cmp(big.NewInt(0)) == 0 {
return ethutil.BigPow(10, 6)
@@ -360,7 +374,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
cblock := self.currentBlock
if td.Cmp(self.td) > 0 {
if block.Header().Number.Cmp(new(big.Int).Add(cblock.Header().Number, ethutil.Big1)) < 0 {
- chainlogger.Infof("Split detected. New head #%v (%x), was #%v (%x)\n", block.Header().Number, block.Hash()[:4], cblock.Header().Number, cblock.Hash()[:4])
+ chainlogger.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, block.Hash()[:4], td, cblock.Header().Number, cblock.Hash()[:4], self.td)
}
self.setTotalDifficulty(td)