From 3919360ef6ab7e2905e2b746c166b3ece7bfe23f Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 3 Sep 2018 17:34:10 -0700 Subject: [PATCH] Wire state block creation and verificaiton into consensus --- blockchain/utxopool.go | 6 ++++++ node/node_handler.go | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/blockchain/utxopool.go b/blockchain/utxopool.go index 184027362..c99644aa9 100644 --- a/blockchain/utxopool.go +++ b/blockchain/utxopool.go @@ -85,6 +85,12 @@ func (utxoPool *UTXOPool) VerifyTransactions(transactions []*Transaction) bool { return true } +// VerifyStateBlock verifies if the given state block matches the current utxo pool. +func (utxoPool *UTXOPool) VerifyStateBlock(stateBlock *Block) bool { + // TODO: implement this + return true +} + // VerifyOneTransaction verifies if a list of transactions valid. func (utxoPool *UTXOPool) VerifyOneTransaction(tx *Transaction, spentTXOs *map[[20]byte]map[string]map[uint32]bool) (valid, crossShard bool) { if len(tx.Proofs) != 0 { diff --git a/node/node_handler.go b/node/node_handler.go index 621fd2a3b..e7a3819ff 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -271,7 +271,11 @@ func (node *Node) BroadcastNewBlock(newBlock *blockchain.Block) { // This is called by consensus participants to verify the block they are running consensus on func (node *Node) VerifyNewBlock(newBlock *blockchain.Block) bool { - return node.UtxoPool.VerifyTransactions(newBlock.Transactions) + if bytes.Equal(newBlock.PrevBlockHash[:], (&[32]byte{})[:]) { + return node.UtxoPool.VerifyStateBlock(newBlock) + } else { + return node.UtxoPool.VerifyTransactions(newBlock.Transactions) + } } // This is called by consensus participants, after consensus is done, to: