diff options
Diffstat (limited to 'ethchain/state_manager.go')
-rw-r--r-- | ethchain/state_manager.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 93fd1ec58..589b99ac2 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -346,9 +346,6 @@ func (sm *StateManager) CalculateTD(block *Block) bool { // an uncle or anything that isn't on the current block chain. // Validation validates easy over difficult (dagger takes longer time = difficult) func (sm *StateManager) ValidateBlock(block *Block) error { - // TODO - // 2. Check if the difficulty is correct - // Check each uncle's previous hash. In order for it to be valid // is if it has the same block hash as the current parent := sm.bc.GetBlock(block.PrevHash) @@ -360,6 +357,11 @@ func (sm *StateManager) ValidateBlock(block *Block) error { } */ + expd := CalcDifficulty(block, parent) + if expd.Cmp(block.Difficulty) < 0 { + return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd) + } + diff := block.Time - parent.Time if diff < 0 { return ValidationError("Block timestamp less then prev block %v (%v - %v)", diff, block.Time, sm.bc.CurrentBlock.Time) |