Skip to content

Commit

Permalink
[e2e] Fixes prepareProposal not to return oversized set of transactio…
Browse files Browse the repository at this point in the history
…ns (cometbft#1756)

* Fixes prepareProposal not to return oversized set of transactions

* Update test/e2e/app/app.go

* Fix linting error

* add changelog entry

* Avoid marshalling the tx twice

* removing unneeded changelog
  • Loading branch information
lasarojc authored Dec 7, 2023
1 parent bde1111 commit 0bf3f0a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/e2e/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
cryptoenc "github.com/cometbft/cometbft/crypto/encoding"
"github.com/cometbft/cometbft/internal/protoio"
"github.com/cometbft/cometbft/libs/log"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cometbft/cometbft/version"
)

Expand Down Expand Up @@ -434,7 +435,7 @@ func (app *Application) PrepareProposal(
}
extCommitHex := hex.EncodeToString(extCommitBytes)
extTx := []byte(fmt.Sprintf("%s%d|%s", extTxPrefix, sum, extCommitHex))
extTxLen := int64(len(extTx))
extTxLen := cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{extTx})
app.logger.Info("preparing proposal with special transaction from vote extensions", "extTxLen", extTxLen)
if extTxLen > req.MaxTxBytes {
panic(fmt.Errorf("serious problem in the e2e app configuration; "+
Expand All @@ -456,10 +457,11 @@ func (app *Application) PrepareProposal(
app.logger.Error("detected tx that should not come from the mempool", "tx", tx)
continue
}
if totalBytes+int64(len(tx)) > req.MaxTxBytes {
txLen := cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{tx})
if totalBytes+txLen > req.MaxTxBytes {
break
}
totalBytes += int64(len(tx))
totalBytes += txLen
// Coherence: No need to call parseTx, as the check is stateless and has been performed by CheckTx
txs = append(txs, tx)
}
Expand Down

0 comments on commit 0bf3f0a

Please sign in to comment.