Fully integrate with tx gen by account model

pull/99/head
Rongjian Lan 6 years ago
parent c40fe757e1
commit a4200bccb1
  1. 14
      client/txgen/main.go
  2. 1
      client/txgen/txgen/account_txs_generator.go
  3. 1
      consensus/consensus_leader.go
  4. 2
      harmony/main.go
  5. 1
      node/node.go
  6. 23
      node/node_handler.go

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/client/txgen/txgen"
"github.com/harmony-one/harmony/core/types"
"os"
@ -103,6 +104,19 @@ func main() {
utxoPoolMutex.Lock()
node.UpdateUtxoAndState(block)
utxoPoolMutex.Unlock()
accountBlock := new(types.Block)
err := rlp.DecodeBytes(block.AccountBlock, accountBlock)
fmt.Println("RECEIVED NEW BLOCK ", len(accountBlock.Transactions()))
if err != nil {
log.Error("Failed decoding the block with RLP")
} else {
err = node.Worker.CommitTransactions(accountBlock.Transactions(), accountBlock.Coinbase())
node.Worker.UpdateCurrent()
if err != nil {
log.Debug("Failed to add new block to worker", "Error", err)
}
}
} else {
continue
}

@ -21,7 +21,6 @@ func GenerateSimulatedTransactionsAccount(shardID int, dataNodes []*node.Node, s
txs := make([]*types.Transaction, 1000)
for i := 0; i < 100; i++ {
baseNonce := node.Worker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(node.TestBankKeys[i].PublicKey))
node.Worker.UpdateCurrent()
for j := 0; j < 10; j++ {
randomUserKey, _ := crypto.GenerateKey()
randomUserAddress := crypto.PubkeyToAddress(randomUserKey.PublicKey)

@ -61,6 +61,7 @@ func (consensus *Consensus) WaitForNewBlockAccount(blockChannel chan *types.Bloc
// time.Sleep(500 * time.Millisecond)
data, err := rlp.EncodeToBytes(newBlock)
if err == nil {
consensus.Log.Debug("Sample tx", "tx", newBlock.Transactions()[0])
consensus.startConsensus(&blockchain.Block{Hash: newBlock.Hash(), AccountBlock: data})
} else {
consensus.Log.Error("Failed encoding the block with RLP")

@ -84,7 +84,6 @@ func main() {
txs := make([]*types.Transaction, 100)
worker := worker.New(params.TestChainConfig, chain, consensus.NewFaker())
fmt.Println(worker.GetCurrentState().GetBalance(testBankAddress))
fmt.Println(worker.Commit().Root())
for i, _ := range txs {
randomUserKey, _ := crypto.GenerateKey()
@ -96,5 +95,4 @@ func main() {
worker.CommitTransactions(txs, crypto.PubkeyToAddress(testBankKey.PublicKey))
fmt.Println(worker.GetCurrentState().GetBalance(testBankAddress))
fmt.Println(worker.Commit().Root())
}

@ -134,6 +134,7 @@ func (node *Node) getTransactionsForNewBlockAccount(maxNumTxs int) (types.Transa
node.log.Debug("Invalid transactions discarded", "number", len(invalid))
node.pendingTransactionsAccount = unselected
node.log.Debug("Remaining pending transactions", "number", len(node.pendingTransactionsAccount))
node.pendingTxMutexAccount.Unlock()
return selected, crossShardTxs //TODO: replace cross-shard proofs for account model
}

@ -394,7 +394,11 @@ func (node *Node) WaitForConsensusReadyAccount(readySignal chan struct{}) {
if len(node.pendingTransactionsAccount) >= 1000 {
// Normal tx block consensus
selectedTxs, _ := node.getTransactionsForNewBlockAccount(MaxNumberOfTransactionsPerBlock)
err := node.Worker.CommitTransactions(selectedTxs, pki.GetAddressFromPublicKey(node.SelfPeer.PubKey))
err := node.Worker.UpdateCurrent()
if err != nil {
node.log.Debug("Failed updating worker's state", "Error", err)
}
err = node.Worker.CommitTransactions(selectedTxs, pki.GetAddressFromPublicKey(node.SelfPeer.PubKey))
if err == nil {
block, err := node.Worker.Commit()
if err != nil {
@ -465,7 +469,7 @@ func (node *Node) VerifyNewBlock(newBlock *blockchain.Block) bool {
func (node *Node) VerifyNewBlockAccount(newBlock *types.Block) bool {
err := node.Chain.ValidateNewBlock(newBlock, pki.GetAddressFromPublicKey(node.SelfPeer.PubKey))
if err != nil {
node.log.Debug("Failed verifying new block", "Error", err)
node.log.Debug("Failed verifying new block", "Error", err, "tx", newBlock.Transactions()[0])
return false
}
return true
@ -506,8 +510,7 @@ func (node *Node) PostConsensusProcessing(newBlock *blockchain.Block) {
if err != nil {
node.log.Error("Failed decoding the block with RLP")
}
node.AddNewBlockAccount(accountBlock)
// For utxo model only
node.AddNewBlock(newBlock)
node.UpdateUtxoAndState(newBlock)
@ -515,11 +518,9 @@ func (node *Node) PostConsensusProcessing(newBlock *blockchain.Block) {
// AddNewBlockAccount is usedd to add new block into the blockchain.
func (node *Node) AddNewBlockAccount(newBlock *types.Block) {
fmt.Println("Adding BLOCK")
fmt.Println(len(newBlock.Transactions()))
num, err := node.Chain.InsertChain([]*types.Block{newBlock})
if err != nil {
fmt.Println("Error adding to chain", "numBlocks", num, "Error", err)
node.log.Debug("Error adding to chain", "numBlocks", num, "Error", err)
}
}
@ -532,6 +533,14 @@ func (node *Node) AddNewBlock(newBlock *blockchain.Block) {
node.log.Info("Writing new block into disk.")
newBlock.Write(node.db, strconv.Itoa(len(node.blockchain.Blocks)))
}
// Account model
accountBlock := new(types.Block)
err := rlp.DecodeBytes(newBlock.AccountBlock, accountBlock)
if err != nil {
node.log.Error("Failed decoding the block with RLP")
}
node.AddNewBlockAccount(accountBlock)
}
// UpdateUtxoAndState updates Utxo and state.

Loading…
Cancel
Save