Browse Source

tx: reduce function to one parameter (#5493)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
pull/5501/head
Marko 4 years ago
committed by GitHub
parent
commit
741a515f5b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 17 deletions
  1. +1
    -1
      mempool/clist_mempool.go
  2. +1
    -1
      mempool/mempool.go
  3. +3
    -15
      types/tx.go

+ 1
- 1
mempool/clist_mempool.go 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 {


+ 1
- 1
mempool/mempool.go 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",


+ 3
- 15
types/tx.go 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())
}

Loading…
Cancel
Save