From 26aa978456f35708e22af0b2cb752016b58840b5 Mon Sep 17 00:00:00 2001 From: bradyjoestar Date: Thu, 20 Sep 2018 01:40:22 +0800 Subject: [PATCH] Make mempool cache a proper LRU (#2407) Closes #2399 --- CHANGELOG_PENDING.md | 1 + mempool/mempool.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 35d776f6..3a881bd2 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -21,6 +21,7 @@ FEATURES: * \#2310 Mempool is now aware of the MaxGas requirement IMPROVEMENTS: +- [mempool] [\#2399](https://github.com/tendermint/tendermint/issues/2399) Make mempool cache a proper LRU (@bradyjoestar) - [types] add Address to GenesisValidator [\#1714](https://github.com/tendermint/tendermint/issues/1714) - [metrics] `consensus.block_interval_metrics` is now gauge, not histogram (you will be able to see spikes, if any) diff --git a/mempool/mempool.go b/mempool/mempool.go index 0e4a9536..87092262 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -577,7 +577,8 @@ func (cache *mapTxCache) Push(tx types.Tx) bool { // Use the tx hash in the cache txHash := sha256.Sum256(tx) - if _, exists := cache.map_[txHash]; exists { + if moved, exists := cache.map_[txHash]; exists { + cache.list.MoveToFront(moved) return false }