calculate amino overhead on the fly
This commit is contained in:
parent
e957f322c7
commit
e873fed815
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"container/list"
|
"container/list"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -385,6 +386,8 @@ func (mem *Mempool) notifyTxsAvailable() {
|
||||||
// If max is negative, there is no cap on the size of all returned
|
// If max is negative, there is no cap on the size of all returned
|
||||||
// transactions (~ all available transactions).
|
// transactions (~ all available transactions).
|
||||||
func (mem *Mempool) ReapMaxBytes(max int) types.Txs {
|
func (mem *Mempool) ReapMaxBytes(max int) types.Txs {
|
||||||
|
var buf [binary.MaxVarintLen64]byte
|
||||||
|
|
||||||
mem.proxyMtx.Lock()
|
mem.proxyMtx.Lock()
|
||||||
defer mem.proxyMtx.Unlock()
|
defer mem.proxyMtx.Unlock()
|
||||||
|
|
||||||
|
@ -400,10 +403,12 @@ func (mem *Mempool) ReapMaxBytes(max int) types.Txs {
|
||||||
txs := make([]types.Tx, 0, mem.txs.Len())
|
txs := make([]types.Tx, 0, mem.txs.Len())
|
||||||
for e := mem.txs.Front(); e != nil; e = e.Next() {
|
for e := mem.txs.Front(); e != nil; e = e.Next() {
|
||||||
memTx := e.Value.(*mempoolTx)
|
memTx := e.Value.(*mempoolTx)
|
||||||
if max > 0 && cur+len(memTx.tx)+types.MaxAminoOverheadForTx > max {
|
// amino.UvarintSize is not used here because it won't be possible to reuse buf
|
||||||
|
aminoOverhead := binary.PutUvarint(buf[:], uint64(len(memTx.tx)))
|
||||||
|
if max > 0 && cur+len(memTx.tx)+aminoOverhead > max {
|
||||||
return txs
|
return txs
|
||||||
}
|
}
|
||||||
cur += len(memTx.tx) + types.MaxAminoOverheadForTx
|
cur += len(memTx.tx) + aminoOverhead
|
||||||
txs = append(txs, memTx.tx)
|
txs = append(txs, memTx.tx)
|
||||||
}
|
}
|
||||||
return txs
|
return txs
|
||||||
|
|
|
@ -11,12 +11,6 @@ import (
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// MaxAminoOverheadForTx - maximum amino overhead to encode a transaction
|
|
||||||
// (ranges from 1 to 4 bytes).
|
|
||||||
MaxAminoOverheadForTx = 4
|
|
||||||
)
|
|
||||||
|
|
||||||
// Tx is an arbitrary byte array.
|
// Tx is an arbitrary byte array.
|
||||||
// NOTE: Tx has no types at this level, so when wire encoded it's just length-prefixed.
|
// NOTE: Tx has no types at this level, so when wire encoded it's just length-prefixed.
|
||||||
// Might we want types here ?
|
// Might we want types here ?
|
||||||
|
|
Loading…
Reference in New Issue