From ab150879a1e812fe9e6153bc338044373a9b9f59 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sat, 15 Dec 2018 00:57:26 -0800 Subject: [PATCH] Fix faucet contract tx related txgen sync problem --- client/txgen/main.go | 18 ++++------------ node/node.go | 3 --- node/node_handler.go | 51 +++++++++++++++++++------------------------- 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/client/txgen/main.go b/client/txgen/main.go index c5c98d204..1e0d58d00 100644 --- a/client/txgen/main.go +++ b/client/txgen/main.go @@ -131,7 +131,6 @@ func main() { // This func is used to update the client's utxopool when new blocks are received from the leaders updateBlocksFunc := func(blocks []*blockchain.Block) { - log.Debug("Received new block from leader", "len", len(blocks)) for _, block := range blocks { for _, node := range nodes { shardID := block.ShardID @@ -142,23 +141,14 @@ func main() { shardID = accountBlock.ShardID() } if node.Consensus.ShardID == shardID { - log.Debug("Adding block from leader", "shardID", shardID) // Add it to blockchain + log.Info("Current Block", "hash", node.Chain.CurrentBlock().Hash().Hex()) + log.Info("Adding block from leader", "txNum", len(accountBlock.Transactions()), "shardID", shardID, "preHash", accountBlock.ParentHash().Hex()) node.AddNewBlock(block) utxoPoolMutex.Lock() node.UpdateUtxoAndState(block) + node.Worker.UpdateCurrent() utxoPoolMutex.Unlock() - - if err != nil { - log.Error("Failed decoding the block with RLP") - } else { - fmt.Println("RECEIVED NEW BLOCK ", len(accountBlock.Transactions())) - node.AddNewBlockAccount(accountBlock) - node.Worker.UpdateCurrent() - if err != nil { - log.Debug("Failed to add new block to worker", "Error", err) - } - } } else { continue } @@ -182,7 +172,7 @@ func main() { } // Transaction generation process - time.Sleep(10 * time.Second) // wait for nodes to be ready + time.Sleep(5 * time.Second) // wait for nodes to be ready start := time.Now() totalTime := float64(*duration) diff --git a/node/node.go b/node/node.go index fe31e8bc6..eb4f41170 100644 --- a/node/node.go +++ b/node/node.go @@ -308,8 +308,6 @@ func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node { testBankAddress := crypto.PubkeyToAddress(testBankKey.PublicKey) testBankFunds := big.NewInt(1000) testBankFunds = testBankFunds.Mul(testBankFunds, big.NewInt(params.Ether)) - // fmt.Println(crypto.PubkeyToAddress(testBankKey.PublicKey).Hex()) - // fmt.Println(hex.EncodeToString(crypto.FromECDSA(testBankKey))) genesisAloc[testBankAddress] = core.GenesisAccount{Balance: testBankFunds} node.TestBankKeys = append(node.TestBankKeys, testBankKey) } @@ -441,7 +439,6 @@ func (node *Node) AddSmartContractsToPendingTransactions() { mycontracttx, _ := types.SignTx(types.NewContractCreation(uint64(0), node.Consensus.ShardID, contractFunds, params.TxGasContractCreation*10, nil, dataEnc), types.HomesteadSigner{}, priKey) node.ContractAddresses = append(node.ContractAddresses, crypto.CreateAddress(crypto.PubkeyToAddress(priKey.PublicKey), uint64(0))) - fmt.Println(node.ContractAddresses[0].Hex()) node.addPendingTransactionsAccount(types.Transactions{mycontracttx}) } diff --git a/node/node_handler.go b/node/node_handler.go index d61b1d6d5..d8c53c8d1 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -331,7 +331,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}) { // WaitForConsensusReadyAccount ... func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { node.log.Debug("Waiting for Consensus ready", "node", node) - time.Sleep(10 * time.Second) + time.Sleep(15 * time.Second) var newBlock *types.Block timeoutCount := 0 @@ -349,7 +349,6 @@ func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) { if !retry { for { - node.log.Debug("Num Pending Txs", "Num", len(node.pendingTransactionsAccount)) if len(node.pendingTransactionsAccount) >= 1 { // Normal tx block consensus selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock) @@ -438,38 +437,32 @@ func (node *Node) VerifyNewBlockAccount(newBlock *types.Block) bool { // 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 func (node *Node) PostConsensusProcessing(newBlock *blockchain.Block) { - if newBlock.IsStateBlock() { - // Clear out old tx blocks and put state block as genesis - if node.db != nil { - node.log.Info("Deleting old blocks.") - for i := 1; i <= len(node.blockchain.Blocks); i++ { - blockchain.Delete(node.db, strconv.Itoa(i)) - } - } - node.blockchain.Blocks = []*blockchain.Block{} - } + //if newBlock.IsStateBlock() { + // // Clear out old tx blocks and put state block as genesis + // if node.db != nil { + // node.log.Info("Deleting old blocks.") + // for i := 1; i <= len(node.blockchain.Blocks); i++ { + // blockchain.Delete(node.db, strconv.Itoa(i)) + // } + // } + // node.blockchain.Blocks = []*blockchain.Block{} + //} if node.Consensus.IsLeader { // Move crossTx-in-consensus into the list to be returned to client - for _, crossTxAndProof := range node.CrossTxsInConsensus { - crossTxAndProof.Proof.BlockHash = newBlock.Hash - // TODO: fill in the signature proofs - } - if len(node.CrossTxsInConsensus) != 0 { - node.addCrossTxsToReturn(node.CrossTxsInConsensus) - node.CrossTxsInConsensus = []*blockchain.CrossShardTxAndProof{} - } - - node.SendBackProofOfAcceptOrReject() + //for _, crossTxAndProof := range node.CrossTxsInConsensus { + // crossTxAndProof.Proof.BlockHash = newBlock.Hash + // // TODO: fill in the signature proofs + //} + //if len(node.CrossTxsInConsensus) != 0 { + // node.addCrossTxsToReturn(node.CrossTxsInConsensus) + // node.CrossTxsInConsensus = []*blockchain.CrossShardTxAndProof{} + //} + // + //node.SendBackProofOfAcceptOrReject() 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.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. func (node *Node) AddNewBlock(newBlock *blockchain.Block) { // Add it to blockchain - node.blockchain.Blocks = append(node.blockchain.Blocks, newBlock) + // node.blockchain.Blocks = append(node.blockchain.Blocks, newBlock) // Store it into leveldb. if node.db != nil { node.log.Info("Writing new block into disk.")