tx: reduce function to one parameter (#5493)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
This commit is contained in:
Marko
2020-10-13 17:38:00 +02:00
committed by GitHub
parent 55e8ccab21
commit 741a515f5b
3 changed files with 5 additions and 17 deletions

View File

@@ -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 {

View File

@@ -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",

View File

@@ -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())
}