diff --git a/aws-code/transaction_generator.go b/aws-code/transaction_generator.go index 3877439a7..e437f2ce5 100644 --- a/aws-code/transaction_generator.go +++ b/aws-code/transaction_generator.go @@ -22,15 +22,21 @@ func main() { ip := flag.String("ip", "127.0.0.1", "IP of the leader") port := flag.String("port", "9000", "port of the leader.") + txToSend := flag.Int("tx_count", 100, "number of transaction") txs := make([]blockchain.Transaction, 10) + txCount := 0 for true { + if txCount >= *txToSend { + break + } for i := range txs { txs[i] = newRandTransaction() } msg := node.ConstructTransactionListMessage(txs) p2p.SendMessage(p2p.Peer{*ip, *port, "n/a"}, msg) + txCount += len(txs) time.Sleep(1 * time.Second) // 10 transactions per second } } diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index 0dff34d8f..b8ecf2f77 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -18,7 +18,6 @@ var mutex = &sync.Mutex{} func (consensus *Consensus) WaitForNewBlock(blockChannel chan blockchain.Block) { for { // keep waiting for new blocks newBlock := <- blockChannel - log.Println("got block.....") // TODO: think about potential race condition if consensus.state == READY { consensus.startConsensus(&newBlock) diff --git a/node/node.go b/node/node.go index 1679d3491..441f9a9a3 100644 --- a/node/node.go +++ b/node/node.go @@ -122,19 +122,23 @@ func (node *Node) NodeHandler(conn net.Conn) { func (node *Node) WaitForConsensusReady(readySignal chan int) { for { // keep waiting for consensus ready <- readySignal - log.Println("got ready signal.....") // create a new block newBlock := new(blockchain.Block) for { if len(node.pendingTransactions) >= 10 { - log.Println("creating new block") - // TODO: package actual transactions - newBlock = blockchain.NewGenesisBlock(blockchain.NewCoinbaseTX("x", "y")) + log.Println("Creating new block") + // TODO (Minh): package actual transactions + // For now, just take out 10 transactions + var txList []*blockchain.Transaction + for _, tx := range node.pendingTransactions[0:10] { + txList = append(txList, &tx) + } + node.pendingTransactions = node.pendingTransactions[10:] + newBlock = blockchain.NewBlock(txList, []byte{}) break } time.Sleep(1 * time.Second) // Periodically check whether we have enough transactions to package into block. } - log.Println("sending new block to consensus") node.BlockChannel <- *newBlock } }