From 2d525bf2b8267cbcebd5ce3899a78684ddbeeff4 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 19 Nov 2018 16:22:17 +0400 Subject: [PATCH] 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 --- CHANGELOG_PENDING.md | 1 + mempool/mempool.go | 5 +++++ mempool/mempool_test.go | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index b499ab40c..de4930be4 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -26,5 +26,6 @@ program](https://hackerone.com/tendermint). ### IMPROVEMENTS: - [config] \#2877 add blocktime_iota to the config.toml (@ackratos) +- [mempool] \#2855 add txs from Update to cache ### BUG FIXES: diff --git a/mempool/mempool.go b/mempool/mempool.go index 136f7abf8..6f8ee0211 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -545,6 +545,11 @@ func (mem *Mempool) Update( mem.postCheck = postCheck } + // Add committed transactions to cache (if missing). + for _, tx := range txs { + _ = mem.cache.Push(tx) + } + // Remove committed transactions. txsLeft := mem.removeTxs(txs) diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index d7ab82737..15bfaa25b 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -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) { app := kvstore.NewKVStoreApplication() cc := proxy.NewLocalClientCreator(app)