Skip to content

Commit

Permalink
remove invalid transactions from the mempool (#3701)
Browse files Browse the repository at this point in the history
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 #3625

Fixes #3699
  • Loading branch information
melekes authored and ebuchman committed Jun 3, 2019
1 parent 21bfd7f commit 048ac8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
27 changes: 13 additions & 14 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
7 changes: 5 additions & 2 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 048ac8d

Please sign in to comment.