Fine tune consensus throughput locally: one shard / 300 nodes / 800 tps

pull/10/head
Rongjian Lan 6 years ago
parent 600ad2b5e4
commit 4a16c007e7
  1. 19
      aws-code/transaction_generator.go
  2. 2
      benchmark_main.go
  3. 9
      blockchain/utxopool.go
  4. 4
      consensus/consensus_leader.go
  5. 301
      local_config3.txt
  6. 4
      node/node.go
  7. 9
      node/node_handler.go

@ -49,10 +49,10 @@ func getNewFakeTransactions(dataNode *node.Node, numTxs int) []*blockchain.Trans
}
for index, value := range utxoMap {
countAll++
if rand.Intn(100) <= 50 { // 20% sample rate to select UTXO to use for new transactions
if rand.Intn(100) < 50 { // 50% sample rate to select UTXO to use for new transactions
// Spend the money of current UTXO to a random address in [1 - 1000]
txin := blockchain.TXInput{txId, index, address}
txout := blockchain.TXOutput{value, strconv.Itoa(rand.Intn(1000))}
txout := blockchain.TXOutput{value, strconv.Itoa(rand.Intn(10000))}
tx := blockchain.Transaction{[32]byte{}, []blockchain.TXInput{txin}, []blockchain.TXOutput{txout}}
tx.SetID()
@ -115,32 +115,39 @@ func main() {
log.Root().SetHandler(h)
configFile := flag.String("config_file", "local_config.txt", "file containing all ip addresses and config")
numTxsPerBatch := flag.Int("num_txs_per_batch", 1000, "number of transactions to send per message")
numTxsPerBatch := flag.Int("num_txs_per_batch", 10000, "number of transactions to send per message")
flag.Parse()
config := readConfigFile(*configFile)
leaders := getLeaders(&config)
// Testing node to mirror the node data in consensus
dataNode := node.NewNode(&consensus.Consensus{})
dataNode.AddMoreFakeTransactions(1000)
dataNode.AddMoreFakeTransactions(10000)
time.Sleep(5 * time.Second) // wait for nodes to be ready
start := time.Now()
totalTime := 60.0
time.Sleep(3 * time.Second) // wait for nodes to be ready
for true {
t := time.Now()
if t.Sub(start).Seconds() >= totalTime {
fmt.Println(int(t.Sub(start)), start, totalTime)
break
}
t = time.Now()
txsToSend := getNewFakeTransactions(&dataNode, *numTxsPerBatch)
fmt.Printf("CREATE TX TO LEADER took %s", time.Since(t))
msg := node.ConstructTransactionListMessage(txsToSend)
log.Debug("[Generator] Sending txs...", "numTxs", len(txsToSend))
t = time.Now()
p2p.BroadcastMessage(leaders, msg)
fmt.Printf("SEND TX TO LEADER took %s", time.Since(t))
// Update local utxo pool to mirror the utxo pool of a real node
dataNode.UtxoPool.Update(txsToSend)
time.Sleep(1 * time.Second) // Send a batch of transactions every second
time.Sleep(500 * time.Millisecond) // Send a batch of transactions periodically
}
// Send a stop message to stop the nodes at the end

@ -88,7 +88,7 @@ func main() {
consensus.OnConsensusDone = node.AddNewBlockToBlockchain
// Temporary testing code, to be removed.
node.AddMoreFakeTransactions(1000)
node.AddMoreFakeTransactions(10000)
if consensus.IsLeader {
// Let consensus run

@ -5,11 +5,6 @@ import (
"fmt"
)
const (
// MaxNumberOfTransactions is the max number of transaction per a block.
MaxNumberOfTransactions = 100
)
// UTXOPool stores transactions and balance associated with each address.
type UTXOPool struct {
// Mapping from address to a map of transaction id to a map of the index of output
@ -209,10 +204,10 @@ func CreateUTXOPoolFromGenesisBlockChain(bc *Blockchain) *UTXOPool {
}
// SelectTransactionsForNewBlock returns a list of index of valid transactions for the new block.
func (utxoPool *UTXOPool) SelectTransactionsForNewBlock(transactions []*Transaction) ([]*Transaction, []*Transaction) {
func (utxoPool *UTXOPool) SelectTransactionsForNewBlock(transactions []*Transaction, maxNumTxs int) ([]*Transaction, []*Transaction) {
selected, unselected := []*Transaction{}, []*Transaction{}
for _, tx := range transactions {
if len(selected) < MaxNumberOfTransactions && utxoPool.VerifyOneTransaction(tx) {
if len(selected) < maxNumTxs && utxoPool.VerifyOneTransaction(tx) {
selected = append(selected, tx)
} else {
unselected = append(unselected, tx)

@ -74,7 +74,9 @@ func (consensus *Consensus) startConsensus(newBlock *blockchain.Block) {
msgToSend := consensus.constructAnnounceMessage()
fmt.Printf("BROADCAST ANNOUNCE: %d\n", consensus.consensusId)
t := time.Now()
p2p.BroadcastMessage(consensus.validators, msgToSend)
fmt.Printf("ANNOUNCE took %s", time.Since(t))
fmt.Printf("BROADCAST ANNOUNCE DONE: %d\n", consensus.consensusId)
// Set state to ANNOUNCE_DONE
consensus.state = ANNOUNCE_DONE
@ -177,7 +179,9 @@ func (consensus *Consensus) processCommitMessage(payload []byte) {
// Broadcast challenge
msgToSend := consensus.constructChallengeMessage()
//fmt.Printf("BROADCAST CHALLENGE: %d\n", consensus.consensusId)
t := time.Now()
p2p.BroadcastMessage(consensus.validators, msgToSend)
fmt.Printf("ANNOUNCE took %s", time.Since(t))
//fmt.Printf("BROADCAST CHALLENGE DONE: %d\n", consensus.consensusId)
// Set state to CHALLENGE_DONE
consensus.state = CHALLENGE_DONE

@ -0,0 +1,301 @@
127.0.0.1 9001 validator 0
127.0.0.1 9002 validator 0
127.0.0.1 9003 validator 0
127.0.0.1 9004 validator 0
127.0.0.1 9005 validator 0
127.0.0.1 9006 validator 0
127.0.0.1 9007 validator 0
127.0.0.1 9008 validator 0
127.0.0.1 9009 validator 0
127.0.0.1 9010 validator 0
127.0.0.1 9011 validator 0
127.0.0.1 9012 validator 0
127.0.0.1 9013 validator 0
127.0.0.1 9014 validator 0
127.0.0.1 9015 validator 0
127.0.0.1 9016 validator 0
127.0.0.1 9017 validator 0
127.0.0.1 9018 validator 0
127.0.0.1 9019 validator 0
127.0.0.1 9020 validator 0
127.0.0.1 9021 validator 0
127.0.0.1 9022 validator 0
127.0.0.1 9023 validator 0
127.0.0.1 9024 validator 0
127.0.0.1 9025 validator 0
127.0.0.1 9026 validator 0
127.0.0.1 9027 validator 0
127.0.0.1 9028 validator 0
127.0.0.1 9029 validator 0
127.0.0.1 9030 validator 0
127.0.0.1 9031 validator 0
127.0.0.1 9032 validator 0
127.0.0.1 9033 validator 0
127.0.0.1 9034 validator 0
127.0.0.1 9035 validator 0
127.0.0.1 9036 validator 0
127.0.0.1 9037 validator 0
127.0.0.1 9038 validator 0
127.0.0.1 9039 validator 0
127.0.0.1 9040 validator 0
127.0.0.1 9041 validator 0
127.0.0.1 9042 validator 0
127.0.0.1 9043 validator 0
127.0.0.1 9044 validator 0
127.0.0.1 9045 validator 0
127.0.0.1 9046 validator 0
127.0.0.1 9047 validator 0
127.0.0.1 9048 validator 0
127.0.0.1 9049 validator 0
127.0.0.1 9050 validator 0
127.0.0.1 9051 validator 0
127.0.0.1 9052 validator 0
127.0.0.1 9053 validator 0
127.0.0.1 9054 validator 0
127.0.0.1 9055 validator 0
127.0.0.1 9056 validator 0
127.0.0.1 9057 validator 0
127.0.0.1 9058 validator 0
127.0.0.1 9059 validator 0
127.0.0.1 9060 validator 0
127.0.0.1 9061 validator 0
127.0.0.1 9062 validator 0
127.0.0.1 9063 validator 0
127.0.0.1 9064 validator 0
127.0.0.1 9065 validator 0
127.0.0.1 9066 validator 0
127.0.0.1 9067 validator 0
127.0.0.1 9068 validator 0
127.0.0.1 9069 validator 0
127.0.0.1 9070 validator 0
127.0.0.1 9071 validator 0
127.0.0.1 9072 validator 0
127.0.0.1 9073 validator 0
127.0.0.1 9074 validator 0
127.0.0.1 9075 validator 0
127.0.0.1 9076 validator 0
127.0.0.1 9077 validator 0
127.0.0.1 9078 validator 0
127.0.0.1 9079 validator 0
127.0.0.1 9080 validator 0
127.0.0.1 9081 validator 0
127.0.0.1 9082 validator 0
127.0.0.1 9083 validator 0
127.0.0.1 9084 validator 0
127.0.0.1 9085 validator 0
127.0.0.1 9086 validator 0
127.0.0.1 9087 validator 0
127.0.0.1 9088 validator 0
127.0.0.1 9089 validator 0
127.0.0.1 9090 validator 0
127.0.0.1 9091 validator 0
127.0.0.1 9092 validator 0
127.0.0.1 9093 validator 0
127.0.0.1 9094 validator 0
127.0.0.1 9095 validator 0
127.0.0.1 9096 validator 0
127.0.0.1 9097 validator 0
127.0.0.1 9098 validator 0
127.0.0.1 9099 validator 0
127.0.0.1 9100 validator 0
127.0.0.1 9101 validator 0
127.0.0.1 9102 validator 0
127.0.0.1 9103 validator 0
127.0.0.1 9104 validator 0
127.0.0.1 9105 validator 0
127.0.0.1 9106 validator 0
127.0.0.1 9107 validator 0
127.0.0.1 9108 validator 0
127.0.0.1 9109 validator 0
127.0.0.1 9110 validator 0
127.0.0.1 9111 validator 0
127.0.0.1 9112 validator 0
127.0.0.1 9113 validator 0
127.0.0.1 9114 validator 0
127.0.0.1 9115 validator 0
127.0.0.1 9116 validator 0
127.0.0.1 9117 validator 0
127.0.0.1 9118 validator 0
127.0.0.1 9119 validator 0
127.0.0.1 9120 validator 0
127.0.0.1 9121 validator 0
127.0.0.1 9122 validator 0
127.0.0.1 9123 validator 0
127.0.0.1 9124 validator 0
127.0.0.1 9125 validator 0
127.0.0.1 9126 validator 0
127.0.0.1 9127 validator 0
127.0.0.1 9128 validator 0
127.0.0.1 9129 validator 0
127.0.0.1 9130 validator 0
127.0.0.1 9131 validator 0
127.0.0.1 9132 validator 0
127.0.0.1 9133 validator 0
127.0.0.1 9134 validator 0
127.0.0.1 9135 validator 0
127.0.0.1 9136 validator 0
127.0.0.1 9137 validator 0
127.0.0.1 9138 validator 0
127.0.0.1 9139 validator 0
127.0.0.1 9140 validator 0
127.0.0.1 9141 validator 0
127.0.0.1 9142 validator 0
127.0.0.1 9143 validator 0
127.0.0.1 9144 validator 0
127.0.0.1 9145 validator 0
127.0.0.1 9146 validator 0
127.0.0.1 9147 validator 0
127.0.0.1 9148 validator 0
127.0.0.1 9149 validator 0
127.0.0.1 9150 validator 0
127.0.0.1 9151 validator 0
127.0.0.1 9152 validator 0
127.0.0.1 9153 validator 0
127.0.0.1 9154 validator 0
127.0.0.1 9155 validator 0
127.0.0.1 9156 validator 0
127.0.0.1 9157 validator 0
127.0.0.1 9158 validator 0
127.0.0.1 9159 validator 0
127.0.0.1 9160 validator 0
127.0.0.1 9161 validator 0
127.0.0.1 9162 validator 0
127.0.0.1 9163 validator 0
127.0.0.1 9164 validator 0
127.0.0.1 9165 validator 0
127.0.0.1 9166 validator 0
127.0.0.1 9167 validator 0
127.0.0.1 9168 validator 0
127.0.0.1 9169 validator 0
127.0.0.1 9170 validator 0
127.0.0.1 9171 validator 0
127.0.0.1 9172 validator 0
127.0.0.1 9173 validator 0
127.0.0.1 9174 validator 0
127.0.0.1 9175 validator 0
127.0.0.1 9176 validator 0
127.0.0.1 9177 validator 0
127.0.0.1 9178 validator 0
127.0.0.1 9179 validator 0
127.0.0.1 9180 validator 0
127.0.0.1 9181 validator 0
127.0.0.1 9182 validator 0
127.0.0.1 9183 validator 0
127.0.0.1 9184 validator 0
127.0.0.1 9185 validator 0
127.0.0.1 9186 validator 0
127.0.0.1 9187 validator 0
127.0.0.1 9188 validator 0
127.0.0.1 9189 validator 0
127.0.0.1 9190 validator 0
127.0.0.1 9191 validator 0
127.0.0.1 9192 validator 0
127.0.0.1 9193 validator 0
127.0.0.1 9194 validator 0
127.0.0.1 9195 validator 0
127.0.0.1 9196 validator 0
127.0.0.1 9197 validator 0
127.0.0.1 9198 validator 0
127.0.0.1 9199 validator 0
127.0.0.1 9200 validator 0
127.0.0.1 9201 validator 0
127.0.0.1 9202 validator 0
127.0.0.1 9203 validator 0
127.0.0.1 9204 validator 0
127.0.0.1 9205 validator 0
127.0.0.1 9206 validator 0
127.0.0.1 9207 validator 0
127.0.0.1 9208 validator 0
127.0.0.1 9209 validator 0
127.0.0.1 9210 validator 0
127.0.0.1 9211 validator 0
127.0.0.1 9212 validator 0
127.0.0.1 9213 validator 0
127.0.0.1 9214 validator 0
127.0.0.1 9215 validator 0
127.0.0.1 9216 validator 0
127.0.0.1 9217 validator 0
127.0.0.1 9218 validator 0
127.0.0.1 9219 validator 0
127.0.0.1 9220 validator 0
127.0.0.1 9221 validator 0
127.0.0.1 9222 validator 0
127.0.0.1 9223 validator 0
127.0.0.1 9224 validator 0
127.0.0.1 9225 validator 0
127.0.0.1 9226 validator 0
127.0.0.1 9227 validator 0
127.0.0.1 9228 validator 0
127.0.0.1 9229 validator 0
127.0.0.1 9230 validator 0
127.0.0.1 9231 validator 0
127.0.0.1 9232 validator 0
127.0.0.1 9233 validator 0
127.0.0.1 9234 validator 0
127.0.0.1 9235 validator 0
127.0.0.1 9236 validator 0
127.0.0.1 9237 validator 0
127.0.0.1 9238 validator 0
127.0.0.1 9239 validator 0
127.0.0.1 9240 validator 0
127.0.0.1 9241 validator 0
127.0.0.1 9242 validator 0
127.0.0.1 9243 validator 0
127.0.0.1 9244 validator 0
127.0.0.1 9245 validator 0
127.0.0.1 9246 validator 0
127.0.0.1 9247 validator 0
127.0.0.1 9248 validator 0
127.0.0.1 9249 validator 0
127.0.0.1 9250 validator 0
127.0.0.1 9251 validator 0
127.0.0.1 9252 validator 0
127.0.0.1 9253 validator 0
127.0.0.1 9254 validator 0
127.0.0.1 9255 validator 0
127.0.0.1 9256 validator 0
127.0.0.1 9257 validator 0
127.0.0.1 9258 validator 0
127.0.0.1 9259 validator 0
127.0.0.1 9260 validator 0
127.0.0.1 9261 validator 0
127.0.0.1 9262 validator 0
127.0.0.1 9263 validator 0
127.0.0.1 9264 validator 0
127.0.0.1 9265 validator 0
127.0.0.1 9266 validator 0
127.0.0.1 9267 validator 0
127.0.0.1 9268 validator 0
127.0.0.1 9269 validator 0
127.0.0.1 9270 validator 0
127.0.0.1 9271 validator 0
127.0.0.1 9272 validator 0
127.0.0.1 9273 validator 0
127.0.0.1 9274 validator 0
127.0.0.1 9275 validator 0
127.0.0.1 9276 validator 0
127.0.0.1 9277 validator 0
127.0.0.1 9278 validator 0
127.0.0.1 9279 validator 0
127.0.0.1 9280 validator 0
127.0.0.1 9281 validator 0
127.0.0.1 9282 validator 0
127.0.0.1 9283 validator 0
127.0.0.1 9284 validator 0
127.0.0.1 9285 validator 0
127.0.0.1 9286 validator 0
127.0.0.1 9287 validator 0
127.0.0.1 9288 validator 0
127.0.0.1 9289 validator 0
127.0.0.1 9290 validator 0
127.0.0.1 9291 validator 0
127.0.0.1 9292 validator 0
127.0.0.1 9293 validator 0
127.0.0.1 9294 validator 0
127.0.0.1 9295 validator 0
127.0.0.1 9296 validator 0
127.0.0.1 9297 validator 0
127.0.0.1 9298 validator 0
127.0.0.1 9299 validator 0
127.0.0.1 9300 validator 0
127.0.0.1 9000 leader 0

@ -36,9 +36,9 @@ func (node *Node) addPendingTransactions(newTxs []*blockchain.Transaction) {
// Take out a subset of valid transactions from the pending transaction list
// Note the pending transaction list will then contain the rest of the txs
func (node *Node) getTransactionsForNewBlock() []*blockchain.Transaction {
func (node *Node) getTransactionsForNewBlock(maxNumTxs int) []*blockchain.Transaction {
pendingTxMutex.Lock()
selected, unselected := node.UtxoPool.SelectTransactionsForNewBlock(node.pendingTransactions)
selected, unselected := node.UtxoPool.SelectTransactionsForNewBlock(node.pendingTransactions, maxNumTxs)
node.pendingTransactions = unselected
pendingTxMutex.Unlock()
return selected

@ -11,6 +11,11 @@ import (
"time"
)
const (
// The max number of transaction per a block.
MaxNumberOfTransactionsPerBlock = 3000
)
// NodeHandler handles a new incoming connection.
func (node *Node) NodeHandler(conn net.Conn) {
defer conn.Close()
@ -128,8 +133,8 @@ func (node *Node) WaitForConsensusReady(readySignal chan int) {
if !retry {
for {
// Once we have more than 10 transactions pending we will try creating a new block
if len(node.pendingTransactions) >= 10 {
selectedTxs := node.getTransactionsForNewBlock()
if len(node.pendingTransactions) >= 100 {
selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock)
if len(selectedTxs) == 0 {
node.log.Debug("No valid transactions exist", "pendingTx", len(node.pendingTransactions))

Loading…
Cancel
Save