|
|
@ -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
|
|
|
|
// VerifyNewBlock is called by consensus participants to verify the block they are running consensus on
|
|
|
|
func (node *Node) VerifyNewBlock(newBlock *blockchain.Block) bool { |
|
|
|
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 { |
|
|
|
if newBlock.AccountBlock != nil { |
|
|
|
accountBlock := new(types.Block) |
|
|
|
accountBlock := new(types.Block) |
|
|
|
err := rlp.DecodeBytes(newBlock.AccountBlock, accountBlock) |
|
|
|
err := rlp.DecodeBytes(newBlock.AccountBlock, accountBlock) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
node.log.Error("Failed decoding the block with RLP") |
|
|
|
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() { |
|
|
|
if verified { |
|
|
|
return node.UtxoPool.VerifyStateBlock(newBlock) |
|
|
|
// 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
|
|
|
|
// VerifyNewBlockAccount is called by consensus participants to verify the block (account model) they are running consensus on
|
|
|
|