mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 14:25:19 +00:00
remove invalid transactions from the mempool (#3701)
Otherwise, we'll be trying to include them in each consecutive block. The downside is that evil proposers will be able to drop valid transactions (see #3322). Reverts https://github.com/tendermint/tendermint/pull/3625 Fixes #3699
This commit is contained in:
committed by
Ethan Buchman
parent
21bfd7fba9
commit
048ac8d94b
@@ -19,3 +19,5 @@
|
||||
### IMPROVEMENTS:
|
||||
|
||||
### BUG FIXES:
|
||||
- [mempool] \#3699 Revert the change where we only remove valid transactions
|
||||
from the mempool once a block is committed.
|
||||
|
||||
@@ -538,24 +538,23 @@ func (mem *CListMempool) Update(
|
||||
if deliverTxResponses[i].Code == abci.CodeTypeOK {
|
||||
// Add valid committed tx to the cache (if missing).
|
||||
_ = mem.cache.Push(tx)
|
||||
|
||||
// Remove valid committed tx from the mempool.
|
||||
if e, ok := mem.txsMap.Load(txKey(tx)); ok {
|
||||
mem.removeTx(tx, e.(*clist.CElement), false)
|
||||
}
|
||||
} else {
|
||||
// Allow invalid transactions to be resubmitted.
|
||||
mem.cache.Remove(tx)
|
||||
}
|
||||
|
||||
// Don't remove invalid tx from the mempool.
|
||||
// Otherwise evil proposer can drop valid txs.
|
||||
// Example:
|
||||
// 100 -> 101 -> 102
|
||||
// Block, proposed by evil proposer:
|
||||
// 101 -> 102
|
||||
// Mempool (if you remove txs):
|
||||
// 100
|
||||
// https://github.com/tendermint/tendermint/issues/3322.
|
||||
// Remove committed tx from the mempool.
|
||||
//
|
||||
// Note an evil proposer can drop valid txs!
|
||||
// Mempool before:
|
||||
// 100 -> 101 -> 102
|
||||
// Block, proposed by an evil proposer:
|
||||
// 101 -> 102
|
||||
// Mempool after:
|
||||
// 100
|
||||
// https://github.com/tendermint/tendermint/issues/3322.
|
||||
if e, ok := mem.txsMap.Load(txKey(tx)); ok {
|
||||
mem.removeTx(tx, e.(*clist.CElement), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,12 +200,15 @@ func TestMempoolUpdate(t *testing.T) {
|
||||
assert.Zero(t, mempool.Size())
|
||||
}
|
||||
|
||||
// 3. Removes invalid transactions from the cache, but leaves them in the mempool (if present)
|
||||
// 3. Removes invalid transactions from the cache and the mempool (if present)
|
||||
{
|
||||
err := mempool.CheckTx([]byte{0x03}, nil)
|
||||
require.NoError(t, err)
|
||||
mempool.Update(1, []types.Tx{[]byte{0x03}}, abciResponses(1, 1), nil, nil)
|
||||
assert.Equal(t, 1, mempool.Size())
|
||||
assert.Zero(t, mempool.Size())
|
||||
|
||||
err = mempool.CheckTx([]byte{0x03}, nil)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user