diff --git a/node/node_handler.go b/node/node_handler.go index 64ffe3f59..90fc4a3f2 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -403,18 +403,26 @@ func (node *Node) BroadcastNewBlock(newBlock *blockchain.Block) { // VerifyNewBlock is called by consensus participants to verify the block they are running consensus on func (node *Node) VerifyNewBlock(newBlock *blockchain.Block) bool { + // TODO: just a reminder for syncing. we need to check if the new block is fit with the current blockchain. + // The current blockchain can be in the progress of being synced. + var verified bool if newBlock.AccountBlock != nil { accountBlock := new(types.Block) err := rlp.DecodeBytes(newBlock.AccountBlock, accountBlock) if err != nil { node.log.Error("Failed decoding the block with RLP") } - return node.VerifyNewBlockAccount(accountBlock) + verified = node.VerifyNewBlockAccount(accountBlock) + } else if newBlock.IsStateBlock() { + verified = node.UtxoPool.VerifyStateBlock(newBlock) + } else { + verified = node.UtxoPool.VerifyTransactions(newBlock.Transactions) } - if newBlock.IsStateBlock() { - return node.UtxoPool.VerifyStateBlock(newBlock) + if verified { + // Change the syncing state. + node.State = NodeDoingConsensus } - return node.UtxoPool.VerifyTransactions(newBlock.Transactions) + return verified } // VerifyNewBlockAccount is called by consensus participants to verify the block (account model) they are running consensus on