Merge pull request #12 from getamis/revert/use-send-batch-txs

Revert "Use send batch txs"
This commit is contained in:
Alan Chen 2017-08-11 17:02:07 +08:00 committed by GitHub
commit 2e23404da4
2 changed files with 6 additions and 16 deletions

View File

@ -10,7 +10,7 @@ import random
ADMIN='c921c91aa4c5f9886bd1e084a848e7e564644d5cc2f265beebb0d51bd251b7e7'
ACCS=100
TX_NUM=120
TX_NUM=100
PERIOD=600
NODES=['http://127.0.0.1:8811', 'http://127.0.0.1:8822', 'http://127.0.0.1:8833', 'http://127.0.0.1:8844']

View File

@ -138,15 +138,6 @@ func sendTx(conn *ethclient.Client, tx *types.Transaction) error {
return nil
}
func sendTxs(conn *ethclient.Client, txs []*types.Transaction) error {
err := conn.SendTransactions(context.Background(), txs)
if err != nil {
return err
}
fmt.Println("txs", len(txs))
return nil
}
func sendEther(prv *ecdsa.PrivateKey, to common.Address, amount *big.Int, nonce uint64) (*types.Transaction, error) {
signer := types.FrontierSigner{}
tx := types.NewTransaction(nonce, to, amount, big.NewInt(GAS_LIMIT), big.NewInt(GAS_PRICE), []byte{})
@ -209,20 +200,19 @@ func batchSend(conn *ethclient.Client, prv *ecdsa.PrivateKey, to common.Address,
return
default:
fmt.Println("round", round)
var txs []*types.Transaction
for i := 0; i < count; i++ {
tx, err := sendEther(prv, to, common.Big1, nonce)
if err != nil {
fmt.Printf("Failed to gen tx, err:%v\n", err)
continue
}
txs = append(txs, tx)
err = sendTx(conn, tx)
if err != nil {
fmt.Printf("Failed to send tx, err:%v\n", err)
continue
}
nonce++
}
err := sendTxs(conn, txs)
if err != nil {
fmt.Printf("Failed to send txs, err:%v\n", err)
}
round++
<-time.After(time.Duration(20+rand.Int()%10) * time.Second)
}