|
|
@ -331,7 +331,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}) { |
|
|
|
// WaitForConsensusReadyAccount ...
|
|
|
|
// WaitForConsensusReadyAccount ...
|
|
|
|
func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { |
|
|
|
func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { |
|
|
|
node.log.Debug("Waiting for Consensus ready", "node", node) |
|
|
|
node.log.Debug("Waiting for Consensus ready", "node", node) |
|
|
|
time.Sleep(10 * time.Second) |
|
|
|
time.Sleep(15 * time.Second) |
|
|
|
|
|
|
|
|
|
|
|
var newBlock *types.Block |
|
|
|
var newBlock *types.Block |
|
|
|
timeoutCount := 0 |
|
|
|
timeoutCount := 0 |
|
|
@ -349,7 +349,6 @@ func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { |
|
|
|
|
|
|
|
|
|
|
|
if !retry { |
|
|
|
if !retry { |
|
|
|
for { |
|
|
|
for { |
|
|
|
node.log.Debug("Num Pending Txs", "Num", len(node.pendingTransactionsAccount)) |
|
|
|
|
|
|
|
if len(node.pendingTransactionsAccount) >= 1 { |
|
|
|
if len(node.pendingTransactionsAccount) >= 1 { |
|
|
|
// Normal tx block consensus
|
|
|
|
// Normal tx block consensus
|
|
|
|
selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock) |
|
|
|
selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock) |
|
|
@ -438,38 +437,32 @@ func (node *Node) VerifyNewBlockAccount(newBlock *types.Block) bool { |
|
|
|
// 1. add the new block to blockchain
|
|
|
|
// 1. add the new block to blockchain
|
|
|
|
// 2. [leader] move cross shard tx and proof to the list where they wait to be sent to the client
|
|
|
|
// 2. [leader] move cross shard tx and proof to the list where they wait to be sent to the client
|
|
|
|
func (node *Node) PostConsensusProcessing(newBlock *blockchain.Block) { |
|
|
|
func (node *Node) PostConsensusProcessing(newBlock *blockchain.Block) { |
|
|
|
if newBlock.IsStateBlock() { |
|
|
|
//if newBlock.IsStateBlock() {
|
|
|
|
// Clear out old tx blocks and put state block as genesis
|
|
|
|
// // Clear out old tx blocks and put state block as genesis
|
|
|
|
if node.db != nil { |
|
|
|
// if node.db != nil {
|
|
|
|
node.log.Info("Deleting old blocks.") |
|
|
|
// node.log.Info("Deleting old blocks.")
|
|
|
|
for i := 1; i <= len(node.blockchain.Blocks); i++ { |
|
|
|
// for i := 1; i <= len(node.blockchain.Blocks); i++ {
|
|
|
|
blockchain.Delete(node.db, strconv.Itoa(i)) |
|
|
|
// blockchain.Delete(node.db, strconv.Itoa(i))
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
node.blockchain.Blocks = []*blockchain.Block{} |
|
|
|
// node.blockchain.Blocks = []*blockchain.Block{}
|
|
|
|
} |
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if node.Consensus.IsLeader { |
|
|
|
if node.Consensus.IsLeader { |
|
|
|
// Move crossTx-in-consensus into the list to be returned to client
|
|
|
|
// Move crossTx-in-consensus into the list to be returned to client
|
|
|
|
for _, crossTxAndProof := range node.CrossTxsInConsensus { |
|
|
|
//for _, crossTxAndProof := range node.CrossTxsInConsensus {
|
|
|
|
crossTxAndProof.Proof.BlockHash = newBlock.Hash |
|
|
|
// crossTxAndProof.Proof.BlockHash = newBlock.Hash
|
|
|
|
// TODO: fill in the signature proofs
|
|
|
|
// // TODO: fill in the signature proofs
|
|
|
|
} |
|
|
|
//}
|
|
|
|
if len(node.CrossTxsInConsensus) != 0 { |
|
|
|
//if len(node.CrossTxsInConsensus) != 0 {
|
|
|
|
node.addCrossTxsToReturn(node.CrossTxsInConsensus) |
|
|
|
// node.addCrossTxsToReturn(node.CrossTxsInConsensus)
|
|
|
|
node.CrossTxsInConsensus = []*blockchain.CrossShardTxAndProof{} |
|
|
|
// node.CrossTxsInConsensus = []*blockchain.CrossShardTxAndProof{}
|
|
|
|
} |
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
node.SendBackProofOfAcceptOrReject() |
|
|
|
//node.SendBackProofOfAcceptOrReject()
|
|
|
|
node.BroadcastNewBlock(newBlock) |
|
|
|
node.BroadcastNewBlock(newBlock) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
accountBlock := new(types.Block) |
|
|
|
|
|
|
|
err := rlp.DecodeBytes(newBlock.AccountBlock, accountBlock) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
node.log.Error("Failed decoding the block with RLP") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node.AddNewBlock(newBlock) |
|
|
|
node.AddNewBlock(newBlock) |
|
|
|
node.UpdateUtxoAndState(newBlock) |
|
|
|
node.UpdateUtxoAndState(newBlock) |
|
|
|
|
|
|
|
|
|
|
@ -486,7 +479,7 @@ func (node *Node) AddNewBlockAccount(newBlock *types.Block) { |
|
|
|
// AddNewBlock is usedd to add new block into the utxo-based blockchain.
|
|
|
|
// AddNewBlock is usedd to add new block into the utxo-based blockchain.
|
|
|
|
func (node *Node) AddNewBlock(newBlock *blockchain.Block) { |
|
|
|
func (node *Node) AddNewBlock(newBlock *blockchain.Block) { |
|
|
|
// Add it to blockchain
|
|
|
|
// Add it to blockchain
|
|
|
|
node.blockchain.Blocks = append(node.blockchain.Blocks, newBlock) |
|
|
|
// node.blockchain.Blocks = append(node.blockchain.Blocks, newBlock)
|
|
|
|
// Store it into leveldb.
|
|
|
|
// Store it into leveldb.
|
|
|
|
if node.db != nil { |
|
|
|
if node.db != nil { |
|
|
|
node.log.Info("Writing new block into disk.") |
|
|
|
node.log.Info("Writing new block into disk.") |
|
|
|