core, eth: verify td of received blocks

This commit is contained in:
obscuren
2015-04-30 13:41:47 +02:00
parent 9b6e8f6195
commit 28b39267d9
2 changed files with 25 additions and 3 deletions

View File

@ -511,6 +511,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
if block == nil {
continue
}
// Setting block.Td regardless of error (known for example) prevents errors down the line
// in the protocol handler
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
logs, err := self.processor.Process(block)
@ -545,8 +549,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
return i, err
}
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
self.mu.Lock()
{
cblock := self.currentBlock