mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 06:57:24 +00:00
tx: reduce function to one parameter (#5493)
Co-authored-by: Callum Waters <cmwaters19@gmail.com>
This commit is contained in:
@@ -526,7 +526,7 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
|
||||
for e := mem.txs.Front(); e != nil; e = e.Next() {
|
||||
memTx := e.Value.(*mempoolTx)
|
||||
|
||||
dataSize := types.ComputeProtoSizeForTxs(txs, memTx.tx)
|
||||
dataSize := types.ComputeProtoSizeForTxs(append(txs, memTx.tx))
|
||||
|
||||
// Check total size requirement
|
||||
if maxBytes > -1 && dataSize > maxBytes {
|
||||
|
||||
@@ -105,7 +105,7 @@ type TxInfo struct {
|
||||
// PreCheckMaxBytes checks that the size of the transaction is smaller or equal to the expected maxBytes.
|
||||
func PreCheckMaxBytes(maxBytes int64) PreCheckFunc {
|
||||
return func(tx types.Tx) error {
|
||||
txSize := types.ComputeProtoSizeForTx(tx)
|
||||
txSize := types.ComputeProtoSizeForTxs([]types.Tx{tx})
|
||||
|
||||
if txSize > maxBytes {
|
||||
return fmt.Errorf("tx size is too big: %d, max: %d",
|
||||
|
||||
18
types/tx.go
18
types/tx.go
@@ -138,22 +138,10 @@ func TxProofFromProto(pb tmproto.TxProof) (TxProof, error) {
|
||||
return pbtp, nil
|
||||
}
|
||||
|
||||
// ComputeProtoOverheadForTxs wraps the transactions in tmproto.Data{} and calculates the size.
|
||||
// ComputeProtoSizeForTxs wraps the transactions in tmproto.Data{} and calculates the size.
|
||||
// https://developers.google.com/protocol-buffers/docs/encoding
|
||||
func ComputeProtoSizeForTxs(txs []Tx, tx Tx) int64 {
|
||||
tt := make(Txs, len(txs)+1)
|
||||
|
||||
tt = append(tt, txs...)
|
||||
tt = append(tt, tx)
|
||||
data := Data{Txs: tt}
|
||||
func ComputeProtoSizeForTxs(txs []Tx) int64 {
|
||||
data := Data{Txs: txs}
|
||||
pdData := data.ToProto()
|
||||
return int64(pdData.Size())
|
||||
}
|
||||
|
||||
// ComputeProtoSizeForTx wraps the transaction in tmproto.Data{} and calculates the size.
|
||||
// https://developers.google.com/protocol-buffers/docs/encoding
|
||||
func ComputeProtoSizeForTx(tx Tx) int64 {
|
||||
pbdata := tmproto.Data{Txs: [][]byte{tx}}
|
||||
|
||||
return int64(pbdata.Size())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user