Commit ce0be510 authored by duanjinfei's avatar duanjinfei

add batch send tx count

parent a5410c05
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
var ( var (
initAcc, initCmp, batchSign, batchRecover, batchRecoverTx, batchVerify bool initAcc, initCmp, batchSign, batchRecover, batchRecoverTx, batchVerify bool
txCount, goRoutineCount, cmpAmount int txCount, goRoutineCount, cmpAmount, batchCount int
cpuProfile string cpuProfile string
cfg *tool.Config cfg *tool.Config
) )
...@@ -25,7 +25,8 @@ func init() { ...@@ -25,7 +25,8 @@ func init() {
startCmd.PersistentFlags().BoolVar(&batchRecoverTx, "batchRecoverTx", false, "test grpc interface -> batchRecoverTx") startCmd.PersistentFlags().BoolVar(&batchRecoverTx, "batchRecoverTx", false, "test grpc interface -> batchRecoverTx")
startCmd.PersistentFlags().BoolVar(&batchVerify, "batchVerify", false, "test grpc interface -> batchVerify") startCmd.PersistentFlags().BoolVar(&batchVerify, "batchVerify", false, "test grpc interface -> batchVerify")
startCmd.PersistentFlags().IntVar(&txCount, "txCount", 1000, "send tran count") startCmd.PersistentFlags().IntVar(&txCount, "txCount", 1000, "send tran count")
startCmd.PersistentFlags().IntVar(&goRoutineCount, "goRoutineCount", 100, "send tran engagement count") startCmd.PersistentFlags().IntVar(&goRoutineCount, "goRoutineCount", 100, "send tran goRoutine count")
startCmd.PersistentFlags().IntVar(&batchCount, "batchCount", 100, "batch send tran count")
startCmd.AddCommand(initCmd) startCmd.AddCommand(initCmd)
} }
......
...@@ -20,6 +20,7 @@ func init() { ...@@ -20,6 +20,7 @@ func init() {
cfg.StorageAccFileName += ".xlsx" cfg.StorageAccFileName += ".xlsx"
cfg.GoRoutineCount = goRoutineCount cfg.GoRoutineCount = goRoutineCount
cfg.SignCount = txCount / 100 cfg.SignCount = txCount / 100
cfg.BatchCount = batchCount
SendTxAccountArr = tool.ReadExcel(cfg.Count, cfg.StorageAccFileName) SendTxAccountArr = tool.ReadExcel(cfg.Count, cfg.StorageAccFileName)
} }
......
...@@ -11,6 +11,7 @@ type Config struct { ...@@ -11,6 +11,7 @@ type Config struct {
ReceiveAddr string `json:"receiveAddr"` ReceiveAddr string `json:"receiveAddr"`
Count int `json:"count"` Count int `json:"count"`
SignCount int `json:"signCount"` SignCount int `json:"signCount"`
BatchCount int `json:"batchCount"`
GoRoutineCount int `json:"goRoutineCount"` GoRoutineCount int `json:"goRoutineCount"`
Type int `json:"type"` Type int `json:"type"`
RpcNode string `json:"rpcNode"` RpcNode string `json:"rpcNode"`
......
...@@ -252,41 +252,18 @@ func BatchRecoverTxHandler(tranArr []*types.Transaction, cfg *tool.Config) error ...@@ -252,41 +252,18 @@ func BatchRecoverTxHandler(tranArr []*types.Transaction, cfg *tool.Config) error
rawTxArr := make([]*v1.MetaTxBase, 0) rawTxArr := make([]*v1.MetaTxBase, 0)
for i := 0; i < int(allSignedTxCount); i++ { for i := 0; i < int(allSignedTxCount); i++ {
tran := tranArr[i] tran := tranArr[i]
v, r, s := tran.RawSignatureValues() rawTx := constructionRawTx(tran)
toAddr := metatypes.BytesToAddress(tran.To().Bytes())
hash := metatypes.HexToHash(tran.Hash().Hex())
nv := metatypes.NewBigInt(0)
nv.Set(v)
nr := metatypes.NewBigInt(0)
nr.Set(r)
ns := metatypes.NewBigInt(0)
ns.Set(s)
rawTx := v1.MetaTxBase{
TxType: uint32(tran.Type()),
ChainId: metatypes.NewBigInt(tran.ChainId().Int64()),
Nonce: tran.Nonce(),
GasPrice: metatypes.NewBigInt(tran.GasPrice().Int64()),
Gas: tran.Gas(),
To: &toAddr,
Value: metatypes.NewBigInt(tran.Value().Int64()),
Data: tran.Data(),
AccessList: nil,
V: nv,
R: nr,
S: ns,
TxHash: &hash,
}
rawTxArr = append(rawTxArr, &rawTx) rawTxArr = append(rawTxArr, &rawTx)
req := crypterv1.BatchRecoverTxRequest{ if len(rawTxArr) == cfg.BatchCount {
RawTx: rawTxArr, req := crypterv1.BatchRecoverTxRequest{
} RawTx: rawTxArr,
if len(rawTxArr) == cfg.SignCount { }
batchRecoverTxRequest <- &req batchRecoverTxRequest <- &req
rawTxArr = make([]*v1.MetaTxBase, 0) rawTxArr = make([]*v1.MetaTxBase, 0)
} }
} }
for { for {
if bathHandleSendCount == allSignedTxCount/int64(cfg.SignCount) { if bathHandleSendCount == allSignedTxCount/int64(cfg.BatchCount) {
log.Infof("Send tran count: %d", bathHandleSendCount) log.Infof("Send tran count: %d", bathHandleSendCount)
log.Infof("Since time: %d ms", time.Since(startTime).Milliseconds()) log.Infof("Since time: %d ms", time.Since(startTime).Milliseconds())
break break
...@@ -294,3 +271,31 @@ func BatchRecoverTxHandler(tranArr []*types.Transaction, cfg *tool.Config) error ...@@ -294,3 +271,31 @@ func BatchRecoverTxHandler(tranArr []*types.Transaction, cfg *tool.Config) error
} }
return nil return nil
} }
func constructionRawTx(tran *types.Transaction) v1.MetaTxBase {
v, r, s := tran.RawSignatureValues()
toAddr := metatypes.BytesToAddress(tran.To().Bytes())
hash := metatypes.HexToHash(tran.Hash().Hex())
nv := metatypes.NewBigInt(0)
nv.Set(v)
nr := metatypes.NewBigInt(0)
nr.Set(r)
ns := metatypes.NewBigInt(0)
ns.Set(s)
rawTx := v1.MetaTxBase{
TxType: uint32(tran.Type()),
ChainId: metatypes.NewBigInt(tran.ChainId().Int64()),
Nonce: tran.Nonce(),
GasPrice: metatypes.NewBigInt(tran.GasPrice().Int64()),
Gas: tran.Gas(),
To: &toAddr,
Value: metatypes.NewBigInt(tran.Value().Int64()),
Data: tran.Data(),
AccessList: nil,
V: nv,
R: nr,
S: ns,
TxHash: &hash,
}
return rawTx
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment