core: verify transactions in AddBlock()

This commit is contained in:
Roman Khimov 2019-09-30 17:35:11 +03:00
parent 1095abb04c
commit 854fb187a3

View file

@ -207,9 +207,17 @@ func (bc *Blockchain) AddBlock(block *Block) error {
if expectedHeight != block.Index {
return fmt.Errorf("expected block %d, but passed block %d", expectedHeight, block.Index)
}
if bc.verifyBlocks && !block.Verify(false) {
if bc.verifyBlocks {
if !block.Verify(false) {
return fmt.Errorf("block %s is invalid", block.Hash())
}
for _, tx := range block.Transactions {
err := bc.Verify(tx)
if err != nil {
return fmt.Errorf("transaction %s failed to verify: %s", tx.Hash().ReverseString(), err)
}
}
}
headerLen := bc.headerListLen()
if int(block.Index) == headerLen {
err := bc.AddHeaders(block.Header())