Merge pull request #164 from harmony-one/rj_branch

[HAR-20] Fix faucet contract tx related txgen sync problem
pull/165/head
Rongjian Lan 6 years ago committed by GitHub
commit b5ae67c8fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      client/txgen/main.go
  2. 3
      node/node.go
  3. 51
      node/node_handler.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 // This func is used to update the client's utxopool when new blocks are received from the leaders
updateBlocksFunc := func(blocks []*blockchain.Block) { updateBlocksFunc := func(blocks []*blockchain.Block) {
log.Debug("Received new block from leader", "len", len(blocks))
for _, block := range blocks { for _, block := range blocks {
for _, node := range nodes { for _, node := range nodes {
shardID := block.ShardID shardID := block.ShardID
@ -142,23 +141,14 @@ func main() {
shardID = accountBlock.ShardID() shardID = accountBlock.ShardID()
} }
if node.Consensus.ShardID == shardID { if node.Consensus.ShardID == shardID {
log.Debug("Adding block from leader", "shardID", shardID)
// Add it to blockchain // 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) node.AddNewBlock(block)
utxoPoolMutex.Lock() utxoPoolMutex.Lock()
node.UpdateUtxoAndState(block) node.UpdateUtxoAndState(block)
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() node.Worker.UpdateCurrent()
if err != nil { utxoPoolMutex.Unlock()
log.Debug("Failed to add new block to worker", "Error", err)
}
}
} else { } else {
continue continue
} }
@ -182,7 +172,7 @@ func main() {
} }
// Transaction generation process // 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() start := time.Now()
totalTime := float64(*duration) totalTime := float64(*duration)

@ -308,8 +308,6 @@ func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node {
testBankAddress := crypto.PubkeyToAddress(testBankKey.PublicKey) testBankAddress := crypto.PubkeyToAddress(testBankKey.PublicKey)
testBankFunds := big.NewInt(1000) testBankFunds := big.NewInt(1000)
testBankFunds = testBankFunds.Mul(testBankFunds, big.NewInt(params.Ether)) 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} genesisAloc[testBankAddress] = core.GenesisAccount{Balance: testBankFunds}
node.TestBankKeys = append(node.TestBankKeys, testBankKey) 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) 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))) node.ContractAddresses = append(node.ContractAddresses, crypto.CreateAddress(crypto.PubkeyToAddress(priKey.PublicKey), uint64(0)))
fmt.Println(node.ContractAddresses[0].Hex())
node.addPendingTransactionsAccount(types.Transactions{mycontracttx}) node.addPendingTransactionsAccount(types.Transactions{mycontracttx})
} }

@ -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.")

Loading…
Cancel
Save