Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: optimize checking the txs size #264

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Test Coverage
env:
GOPRIVATE: "github.com/line/*"
on:
pull_request:
push:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build & Push
# Build & Push rebuilds the ostracon docker image on every push to master and creation of tags
# and pushes the image to https://docker-registry.linecorp.com/link-network/v2/lbm
env:
GOPRIVATE: "github.com/line/*"
on:
pull_request:
push:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Lint
# Lint runs golangci-lint over the entire Tendermint repository
# This workflow is run on every pull request and push to master
# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified.
env:
GOPRIVATE: "github.com/line/*"
on:
pull_request:
push:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Tests
# Tests runs different tests (test_abci_apps, test_abci_cli, test_apps)
# This workflow runs on every push to master or release branch and every pull requests
# All jobs will pass without running if no *{.go, .mod, .sum} files have been modified
env:
GOPRIVATE: "github.com/line/*"
on:
pull_request:
push:
Expand Down
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)
wetcod marked this conversation as resolved.
Show resolved Hide resolved
// Check total size requirement
if maxBytes > -1 && dataSize > maxBytes {
if maxBytes > -1 && int64(protoTxs.Size()) > maxBytes {
return txs
}
// Check total gas requirement.
Expand Down
30 changes: 30 additions & 0 deletions types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,33 @@ func assertBadProof(t *testing.T, root []byte, bad []byte, good TxProof) {
}
}
}

func TestComputeProtoSizeForTxs(t *testing.T) {
tests := []struct {
count int
}{
{1},
{2},
{30},
{450},
{1352},
{2543},
{4000},
}

for _, tt := range tests {
allTxs := make(Txs, tt.count)
for i := 0; i < tt.count; i++ {
size := tmrand.Intn(500)
allTxs[i] = tmrand.Bytes(size)
}

txs := make([]Tx, 0, len(allTxs))
protoTxs := tmproto.Data{}
for _, tx := range allTxs {
protoTxs.Txs = append(protoTxs.Txs, tx)
txs = append(txs, tx)
require.Equal(t, int64(protoTxs.Size()), ComputeProtoSizeForTxs(txs))
}
}
}