aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-12 09:36:41 +0800
committerobscuren <geffobscura@gmail.com>2014-01-12 09:36:41 +0800
commit54bce64e3a8e50b6553364f2f01b38382ffbc4df (patch)
tree045ffb9791ee4e2c5050b076be4b6d3a8de99f9f
parentbee05d52bfb9f555b7f9c7b625524594bff97826 (diff)
downloaddexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar.gz
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar.bz2
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar.lz
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar.xz
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.tar.zst
dexon-54bce64e3a8e50b6553364f2f01b38382ffbc4df.zip
Validations reordering & added nonce validation
-rw-r--r--block_manager.go32
1 files changed, 18 insertions, 14 deletions
diff --git a/block_manager.go b/block_manager.go
index 04d45f434..21162f36b 100644
--- a/block_manager.go
+++ b/block_manager.go
@@ -114,30 +114,34 @@ func (bm *BlockManager) CalculateTD(block *ethutil.Block) bool {
}
// Validates the current block. Returns an error if the block was invalid,
-// an uncle or anything that isn't on the current block chain
+// an uncle or anything that isn't on the current block chain.
+// Validation validates easy over difficult (dagger takes longer time = difficult)
func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
// TODO
- // 1. Check if the nonce of the block is valid
// 2. Check if the difficulty is correct
// Check if we have the parent hash, if it isn't known we discard it
// Reasons might be catching up or simply an invalid block
- if bm.bc.HasBlock(block.PrevHash) {
- // Check each uncle's previous hash. In order for it to be valid
- // is if it has the same block hash as the current
- for _, uncle := range block.Uncles {
- if uncle.PrevHash != block.PrevHash {
- if Debug {
- log.Printf("Uncle prvhash mismatch %x %x\n", block.PrevHash, uncle.PrevHash)
- }
-
- return errors.New("Mismatching Prvhash from uncle")
+ if !bm.bc.HasBlock(block.PrevHash) {
+ return errors.New("Block's parent unknown")
+ }
+
+ // Check each uncle's previous hash. In order for it to be valid
+ // is if it has the same block hash as the current
+ for _, uncle := range block.Uncles {
+ if uncle.PrevHash != block.PrevHash {
+ if Debug {
+ log.Printf("Uncle prvhash mismatch %x %x\n", block.PrevHash, uncle.PrevHash)
}
+
+ return errors.New("Mismatching Prvhash from uncle")
}
- } else {
- return errors.New("Block's parent unknown")
}
+ // Verify the nonce of the block. Return an error if it's not valid
+ if !DaggerVerify(block.Hash(), block.Nonce) {
+ return errors.New("Block's nonce is invalid")
+ }
return nil
}