Browse Source

mempool: add txs from Update to cache

We should add txs that come in from mempool.Update to the mempool's
cache, so that they never hit a potentially expensive check tx.

Originally posted by @ValarDragon in #2846
https://github.com/tendermint/tendermint/issues/2846#issuecomment-439216656

Refs #2855
pull/2808/head
Anton Kaliaev 6 years ago
parent
commit
2d525bf2b8
3 changed files with 17 additions and 0 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -0
      mempool/mempool.go
  3. +11
    -0
      mempool/mempool_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -26,5 +26,6 @@ program](https://hackerone.com/tendermint).
### IMPROVEMENTS: ### IMPROVEMENTS:
- [config] \#2877 add blocktime_iota to the config.toml (@ackratos) - [config] \#2877 add blocktime_iota to the config.toml (@ackratos)
- [mempool] \#2855 add txs from Update to cache
### BUG FIXES: ### BUG FIXES:

+ 5
- 0
mempool/mempool.go View File

@ -545,6 +545,11 @@ func (mem *Mempool) Update(
mem.postCheck = postCheck mem.postCheck = postCheck
} }
// Add committed transactions to cache (if missing).
for _, tx := range txs {
_ = mem.cache.Push(tx)
}
// Remove committed transactions. // Remove committed transactions.
txsLeft := mem.removeTxs(txs) txsLeft := mem.removeTxs(txs)


+ 11
- 0
mempool/mempool_test.go View File

@ -163,6 +163,17 @@ func TestMempoolFilters(t *testing.T) {
} }
} }
func TestMempoolUpdateAddsTxsToCache(t *testing.T) {
app := kvstore.NewKVStoreApplication()
cc := proxy.NewLocalClientCreator(app)
mempool := newMempoolWithApp(cc)
mempool.Update(1, []types.Tx{[]byte{0x01}}, nil, nil)
err := mempool.CheckTx([]byte{0x01}, nil)
if assert.Error(t, err) {
assert.Equal(t, ErrTxInCache, err)
}
}
func TestTxsAvailable(t *testing.T) { func TestTxsAvailable(t *testing.T) {
app := kvstore.NewKVStoreApplication() app := kvstore.NewKVStoreApplication()
cc := proxy.NewLocalClientCreator(app) cc := proxy.NewLocalClientCreator(app)


Loading…
Cancel
Save