aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-18 22:45:54 +0800
committerobscuren <geffobscura@gmail.com>2015-01-18 22:45:54 +0800
commit7394ee7c725a3db2efbe2cd2c01cd16312be6026 (patch)
tree3bf41af0a9b16b3cd9193af1183ae61f989a8f9b /core
parent24613a60dc4f142e55cde68e057221a8b772d64d (diff)
downloadgo-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar.gz
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar.bz2
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar.lz
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar.xz
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.tar.zst
go-tangerine-7394ee7c725a3db2efbe2cd2c01cd16312be6026.zip
Fixed difficulty
Difficulty was broken when refactored.
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go3
-rw-r--r--core/chain_manager.go9
2 files changed, 5 insertions, 7 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 6224d7c59..aa8fcc9e7 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -242,8 +242,7 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
}
expd := CalcDifficulty(block, parent)
- if expd.Cmp(block.Header().Difficulty) < 0 {
- fmt.Println("parent\n", parent)
+ if expd.Cmp(block.Header().Difficulty) != 0 {
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
}
diff --git a/core/chain_manager.go b/core/chain_manager.go
index caa2e7b43..c68b7cfc2 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -23,12 +23,11 @@ type StateQuery interface {
func CalcDifficulty(block, parent *types.Block) *big.Int {
diff := new(big.Int)
- bh, ph := block.Header(), parent.Header()
- adjust := new(big.Int).Rsh(ph.Difficulty, 10)
- if bh.Time >= ph.Time+13 {
- diff.Sub(ph.Difficulty, adjust)
+ adjust := new(big.Int).Rsh(parent.Difficulty(), 10)
+ if block.Time() >= parent.Time()+8 {
+ diff.Sub(parent.Difficulty(), adjust)
} else {
- diff.Add(ph.Difficulty, adjust)
+ diff.Add(parent.Difficulty(), adjust)
}
return diff