Skip to content

Commit

Permalink
perf: optimize checking the txs size
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangyeop.lee committed Jun 3, 2021
1 parent b6eb70f commit 028b8f0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
tmos "github.com/line/ostracon/libs/os"
tmsync "github.com/line/ostracon/libs/sync"
"github.com/line/ostracon/p2p"
tmproto "github.com/line/ostracon/proto/ostracon/types"
"github.com/line/ostracon/proxy"
"github.com/line/ostracon/types"
)
Expand Down Expand Up @@ -581,13 +582,13 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
// size per tx, and set the initial capacity based off of that.
// txs := make([]types.Tx, 0, tmmath.MinInt(mem.txs.Len(), max/mem.avgTxSize))
txs := make([]types.Tx, 0, mem.txs.Len())
protoTxs := tmproto.Data{}
for e := mem.txs.Front(); e != nil; e = e.Next() {
memTx := e.Value.(*mempoolTx)

dataSize := types.ComputeProtoSizeForTxs(append(txs, memTx.tx))

protoTxs.Txs = append(protoTxs.Txs, memTx.tx)
// Check total size requirement
if maxBytes > -1 && dataSize > maxBytes {
if maxBytes > -1 && int64(protoTxs.Size()) > maxBytes {
return txs
}
// Check total gas requirement.
Expand Down

0 comments on commit 028b8f0

Please sign in to comment.