mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 13:21:20 +00:00
Reap takes maxTxs
This commit is contained in:
@ -877,19 +877,8 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
maxBlockSize := config.GetInt("block_size")
|
|
||||||
|
|
||||||
// Mempool validated transactions
|
// Mempool validated transactions
|
||||||
// if block_size < 0, no txs will be included
|
txs := cs.mempool.Reap(config.GetInt("block_size"))
|
||||||
var txs []types.Tx
|
|
||||||
if maxBlockSize >= 0 {
|
|
||||||
txs = cs.mempool.Reap()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cap the number of txs in a block
|
|
||||||
if maxBlockSize > 0 && maxBlockSize < len(txs) {
|
|
||||||
txs = txs[:maxBlockSize]
|
|
||||||
}
|
|
||||||
|
|
||||||
block = &types.Block{
|
block = &types.Block{
|
||||||
Header: &types.Header{
|
Header: &types.Header{
|
||||||
|
@ -183,7 +183,8 @@ func (mem *Mempool) resCbRecheck(req *tmsp.Request, res *tmsp.Response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the valid transactions remaining
|
// Get the valid transactions remaining
|
||||||
func (mem *Mempool) Reap() []types.Tx {
|
// If maxTxs is 0, there is no cap.
|
||||||
|
func (mem *Mempool) Reap(maxTxs int) []types.Tx {
|
||||||
mem.proxyMtx.Lock()
|
mem.proxyMtx.Lock()
|
||||||
defer mem.proxyMtx.Unlock()
|
defer mem.proxyMtx.Unlock()
|
||||||
|
|
||||||
@ -192,13 +193,17 @@ func (mem *Mempool) Reap() []types.Tx {
|
|||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
txs := mem.collectTxs()
|
txs := mem.collectTxs(maxTxs)
|
||||||
return txs
|
return txs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mem *Mempool) collectTxs() []types.Tx {
|
// maxTxs: 0 means uncapped
|
||||||
txs := make([]types.Tx, 0, mem.txs.Len())
|
func (mem *Mempool) collectTxs(maxTxs int) []types.Tx {
|
||||||
for e := mem.txs.Front(); e != nil; e = e.Next() {
|
if maxTxs == 0 {
|
||||||
|
maxTxs = mem.txs.Len()
|
||||||
|
}
|
||||||
|
txs := make([]types.Tx, 0, MinInt(mem.txs.Len(), maxTxs))
|
||||||
|
for e := mem.txs.Front(); e != nil && len(txs) < maxTxs; e = e.Next() {
|
||||||
memTx := e.Value.(*mempoolTx)
|
memTx := e.Value.(*mempoolTx)
|
||||||
txs = append(txs, memTx.tx)
|
txs = append(txs, memTx.tx)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func TestSerialReap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reapCheck := func(exp int) {
|
reapCheck := func(exp int) {
|
||||||
txs := mempool.Reap()
|
txs := mempool.Reap(0)
|
||||||
if len(txs) != exp {
|
if len(txs) != exp {
|
||||||
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
|
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,6 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
||||||
txs := mempoolReactor.Mempool.Reap()
|
txs := mempoolReactor.Mempool.Reap(0)
|
||||||
return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
|
return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user