Commit b242a850 authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

MaxRequestAmount

parent 9f69e02a
...@@ -396,7 +396,7 @@ func FloatRound(f float64, n int) float64 { ...@@ -396,7 +396,7 @@ func FloatRound(f float64, n int) float64 {
type TxParams struct { type TxParams struct {
From string `json:"from,omitempty"` From string `json:"from,omitempty"`
//RequestAmount int64 `json:"request_amount"` RequestAmount int64 `json:"request_amount"`
ToAddrs []string `json:"to_addrs"` ToAddrs []string `json:"to_addrs"`
BatchTxSize int64 `json:"batch_tx_size,omitempty"` BatchTxSize int64 `json:"batch_tx_size,omitempty"`
BatchTxHashSize int64 `json:"batch_tx_hash_size,omitempty"` BatchTxHashSize int64 `json:"batch_tx_hash_size,omitempty"`
...@@ -427,15 +427,30 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -427,15 +427,30 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
atomic.StoreInt32(&Running, 1) atomic.StoreInt32(&Running, 1)
if params.EveryTxAmount*params.TxCount > MaxRequestAmount { if params.RequestAmount > MaxRequestAmount || params.RequestAmount < params.EveryTxAmount*params.TxCount {
http.Error(w, fmt.Sprintf("params.EveryTxAmount*params.TxCount > MaxRequestAmount > %d", MaxRequestAmount), http.StatusBadRequest) http.Error(w, fmt.Sprintf("params.RequestAmount %d > MaxRequestAmount %d|| params.RequestAmount %d < params.EveryTxAmount*params.TxCount %d *%d ", params.RequestAmount, MaxRequestAmount, params.RequestAmount, params.EveryTxAmount, params.TxCount), http.StatusBadRequest)
return return
} }
id := uuid.New() id := uuid.New()
consTxNum := 0
total := int(params.TxCount)
if params.From != systemFromAddr {
total = total + 1
}
consTxNum = total / (batchTxHashSize * batchTxSize)
if total%(batchTxHashSize*batchTxSize) != 0 {
consTxNum = consTxNum + 1
}
SetSendRecord(id, SendRecord{TotalConsTx: int64(consTxNum)})
go func() { go func() {
if err := web.ProduceTxs(params.From, params.ToAddrs, int(params.TxCount), params.EveryTxAmount, id); err != nil { if err := web.ProduceTxs(params.From, params.ToAddrs, int(params.TxCount), params.EveryTxAmount, id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
...@@ -478,24 +493,10 @@ type WebResp struct { ...@@ -478,24 +493,10 @@ type WebResp struct {
} }
func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID) error { func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID) error {
consTxNum := 0
addrsL := len(toAddrs) addrsL := len(toAddrs)
first := true first := true
total := txCount
if fromAddr != systemFromAddr {
total = total + 1
}
consTxNum = total / (batchTxHashSize * batchTxSize)
if total%(batchTxHashSize*batchTxSize) != 0 {
consTxNum = consTxNum + 1
}
SetSendRecord(id, SendRecord{TotalConsTx: int64(consTxNum)})
for { for {
var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize) var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize)
......
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