Skip to content

Commit cfc0d0d

Browse files
rootulpclaude
andauthored
chore: remove non-CAT mempool implementations (#2803)
Part 1 of celestiaorg/celestia-app#6573 Closes #1382 Closes #2802 ## Summary - Remove v0 (flood/CListMempool) and v1 (priority) mempool implementations, which have been dead code since celestia-app v6 forcibly overrides any non-CAT mempool configuration - The CAT mempool is now the only supported mempool type (besides nop), reducing user confusion where operators may configure "flood" or "priority" thinking their setting is honored - Migrate all tests (consensus, node, fuzz, e2e) from CListMempool to cat.TxPool ## Test plan - [x] `make build` passes - [x] `go test ./mempool/...` passes - [x] `go test ./config/...` passes - [x] `go test ./consensus/...` passes - [x] `go test ./node/...` passes - [x] `go vet ./test/fuzz/...` passes - [x] `make lint` passes with 0 issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 077961a commit cfc0d0d

31 files changed

+55
-5969
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove non-CAT mempool implementations (v0/flood and v1/priority). The CAT mempool is now the only supported mempool type (besides nop).

config/config.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,8 @@ const (
4040
DefaultNodeKeyName = "node_key.json"
4141
DefaultAddrBookName = "addrbook.json"
4242

43-
MempoolTypeFlood = "flood"
44-
MempoolTypeNop = "nop"
45-
MempoolTypePriority = "priority"
46-
MempoolTypeCAT = "cat"
47-
LegacyMempoolTypeFlood = "v0"
48-
LegacyMempoolTypePriority = "v1"
49-
LegacyMempoolTypeCAT = "v2"
43+
MempoolTypeNop = "nop"
44+
MempoolTypeCAT = "cat"
5045
)
5146

5247
// NOTE: Most of the structs & relevant comments + the
@@ -763,18 +758,12 @@ func DefaultFuzzConnConfig() *FuzzConnConfig {
763758
//-----------------------------------------------------------------------------
764759
// MempoolConfig
765760

766-
// MempoolConfig defines the configuration options for the CometBFT mempool
767-
//
768-
// Note: Until v0.37 there was a `Version` field to select which implementation
769-
// of the mempool to use. Two versions used to exist: the current, default
770-
// implementation (previously called v0), and a prioritized mempool (v1), which
771-
// was removed (see https://github.com/cometbft/cometbft/issues/260).
761+
// MempoolConfig defines the configuration options for the CometBFT mempool.
772762
type MempoolConfig struct {
773763
// The type of mempool for this node to use.
774764
//
775765
// Possible types:
776-
// - "flood" : concurrent linked list mempool with flooding gossip protocol
777-
// (default)
766+
// - "cat" : content addressable mempool (default)
778767
// - "nop" : nop-mempool (short for no operation; the ABCI app is
779768
// responsible for storing, disseminating and proposing txs).
780769
// "create_empty_blocks=false" is not supported.
@@ -914,8 +903,7 @@ func (cfg *MempoolConfig) WalEnabled() bool {
914903
// returns an error if any check fails.
915904
func (cfg *MempoolConfig) ValidateBasic() error {
916905
switch cfg.Type {
917-
case MempoolTypeFlood, MempoolTypeNop, MempoolTypePriority, LegacyMempoolTypePriority, LegacyMempoolTypeFlood, MempoolTypeCAT, LegacyMempoolTypeCAT:
918-
case "": // allow empty string to be backwards compatible
906+
case MempoolTypeCAT, MempoolTypeNop:
919907
default:
920908
return fmt.Errorf("unknown mempool type: %q", cfg.Type)
921909
}

config/toml_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestMempoolTypeNotInTemplate(t *testing.T) {
9696

9797
// The mempool type field should not appear in the generated config.
9898
// Use a specific pattern to avoid matching unrelated fields like trace_type.
99-
for _, mempoolType := range []string{"cat", "flood", "nop", "priority"} {
99+
for _, mempoolType := range []string{"cat", "nop"} {
100100
pattern := fmt.Sprintf("type = \"%s\"", mempoolType)
101101
assert.NotContains(t, configContent, pattern,
102102
"Config should not contain mempool type field")

consensus/byzantine_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/cometbft/cometbft/libs/log"
2323
"github.com/cometbft/cometbft/libs/service"
2424
cmtsync "github.com/cometbft/cometbft/libs/sync"
25-
mempl "github.com/cometbft/cometbft/mempool"
25+
"github.com/cometbft/cometbft/mempool/cat"
2626
"github.com/cometbft/cometbft/proxy"
2727

2828
"github.com/cometbft/cometbft/p2p"
@@ -96,11 +96,14 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
9696
proxyAppConnMem := proxy.NewAppConnMempool(abcicli.NewLocalClient(mtx, app), proxy.NopMetrics())
9797

9898
// Make Mempool
99-
mempool := mempl.NewCListMempool(config.Mempool,
99+
mempool := cat.NewTxPool(
100+
log.TestingLogger(),
101+
config.Mempool,
100102
proxyAppConnMem,
101103
state.LastBlockHeight,
102-
mempl.WithPreCheck(sm.TxPreCheck(state)),
103-
mempl.WithPostCheck(sm.TxPostCheck(state)))
104+
cat.WithPreCheck(sm.TxPreCheck(state)),
105+
cat.WithPostCheck(sm.TxPostCheck(state)),
106+
)
104107

105108
if thisConfig.Consensus.WaitForTxs() {
106109
mempool.EnableTxsAvailable()

consensus/common_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
3333
cmtsync "github.com/cometbft/cometbft/libs/sync"
3434
mempl "github.com/cometbft/cometbft/mempool"
35+
"github.com/cometbft/cometbft/mempool/cat"
3536
"github.com/cometbft/cometbft/p2p"
3637
"github.com/cometbft/cometbft/privval"
3738
cmtstate "github.com/cometbft/cometbft/proto/tendermint/state"
@@ -424,12 +425,15 @@ func newStateWithConfigAndBlockStore(
424425
memplMetrics := mempl.NopMetrics()
425426

426427
// Make Mempool
427-
mempool := mempl.NewCListMempool(config.Mempool,
428+
mempool := cat.NewTxPool(
429+
log.TestingLogger(),
430+
config.Mempool,
428431
proxyAppConnMem,
429432
state.LastBlockHeight,
430-
mempl.WithMetrics(memplMetrics),
431-
mempl.WithPreCheck(sm.TxPreCheck(state)),
432-
mempl.WithPostCheck(sm.TxPostCheck(state)))
433+
cat.WithMetrics(memplMetrics),
434+
cat.WithPreCheck(sm.TxPreCheck(state)),
435+
cat.WithPostCheck(sm.TxPostCheck(state)),
436+
)
433437

434438
if thisConfig.Consensus.WaitForTxs() {
435439
mempool.EnableTxsAvailable()

consensus/reactor_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
cmtrand "github.com/cometbft/cometbft/libs/rand"
3232
cmtsync "github.com/cometbft/cometbft/libs/sync"
3333
mempl "github.com/cometbft/cometbft/mempool"
34+
"github.com/cometbft/cometbft/mempool/cat"
3435
"github.com/cometbft/cometbft/p2p"
3536
p2pmock "github.com/cometbft/cometbft/p2p/mock"
3637
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
@@ -165,12 +166,15 @@ func TestReactorWithEvidence(t *testing.T) {
165166
proxyAppConnMem := proxy.NewAppConnMempool(abcicli.NewLocalClient(mtx, app), proxy.NopMetrics())
166167

167168
// Make Mempool
168-
mempool := mempl.NewCListMempool(config.Mempool,
169+
mempool := cat.NewTxPool(
170+
log.TestingLogger(),
171+
config.Mempool,
169172
proxyAppConnMem,
170173
state.LastBlockHeight,
171-
mempl.WithMetrics(memplMetrics),
172-
mempl.WithPreCheck(sm.TxPreCheck(state)),
173-
mempl.WithPostCheck(sm.TxPostCheck(state)))
174+
cat.WithMetrics(memplMetrics),
175+
cat.WithPreCheck(sm.TxPreCheck(state)),
176+
cat.WithPostCheck(sm.TxPostCheck(state)),
177+
)
174178

175179
if thisConfig.Consensus.WaitForTxs() {
176180
mempool.EnableTxsAvailable()

mempool/bench_test.go

Lines changed: 0 additions & 152 deletions
This file was deleted.

mempool/cache_test.go

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,13 @@ package mempool
22

33
import (
44
"crypto/rand"
5-
"crypto/sha256"
65
"testing"
76

8-
"fmt"
9-
107
"github.com/stretchr/testify/require"
118

12-
"github.com/cometbft/cometbft/abci/example/kvstore"
13-
abci "github.com/cometbft/cometbft/abci/types"
14-
"github.com/cometbft/cometbft/proxy"
159
"github.com/cometbft/cometbft/types"
1610
)
1711

18-
func TestCacheAfterUpdate(t *testing.T) {
19-
app := kvstore.NewInMemoryApplication()
20-
cc := proxy.NewLocalClientCreator(app)
21-
mp, cleanup := newMempoolWithApp(cc)
22-
defer cleanup()
23-
24-
// reAddIndices & txsInCache can have elements > numTxsToCreate
25-
// also assumes max index is 255 for convenience
26-
// txs in cache also checks order of elements
27-
tests := []struct {
28-
numTxsToCreate int
29-
updateIndices []int
30-
reAddIndices []int
31-
txsInCache []int
32-
}{
33-
{1, []int{}, []int{1}, []int{1, 0}}, // adding new txs works
34-
{2, []int{1}, []int{}, []int{1, 0}}, // update doesn't remove tx from cache
35-
{2, []int{2}, []int{}, []int{2, 1, 0}}, // update adds new tx to cache
36-
{2, []int{1}, []int{1}, []int{1, 0}}, // re-adding after update doesn't make dupe
37-
}
38-
for tcIndex, tc := range tests {
39-
for i := 0; i < tc.numTxsToCreate; i++ {
40-
tx := kvstore.NewTx(fmt.Sprintf("%d", i), "value")
41-
err := mp.CheckTx(tx, func(resp *abci.ResponseCheckTx) {
42-
require.False(t, resp.IsErr())
43-
}, TxInfo{})
44-
require.NoError(t, err)
45-
}
46-
47-
updateTxs := []*types.CachedTx{}
48-
for _, v := range tc.updateIndices {
49-
tx := kvstore.NewTx(fmt.Sprintf("%d", v), "value")
50-
updateTxs = append(updateTxs, types.Tx(tx).ToCachedTx())
51-
}
52-
err := mp.Update(int64(tcIndex), updateTxs, abciResponses(len(updateTxs), abci.CodeTypeOK), nil, nil)
53-
require.NoError(t, err)
54-
55-
for _, v := range tc.reAddIndices {
56-
tx := kvstore.NewTx(fmt.Sprintf("%d", v), "value")
57-
_ = mp.CheckTx(tx, func(resp *abci.ResponseCheckTx) {
58-
require.False(t, resp.IsErr())
59-
}, TxInfo{})
60-
}
61-
62-
cache := mp.cache.(*LRUTxCache)
63-
node := cache.GetList().Front()
64-
counter := 0
65-
for node != nil {
66-
require.NotEqual(t, len(tc.txsInCache), counter,
67-
"cache larger than expected on testcase %d", tcIndex)
68-
69-
nodeVal := node.Value.(types.TxKey)
70-
expTx := kvstore.NewTx(fmt.Sprintf("%d", tc.txsInCache[len(tc.txsInCache)-counter-1]), "value")
71-
expectedBz := sha256.Sum256(expTx)
72-
// Reference for reading the errors:
73-
// >>> sha256('\x00').hexdigest()
74-
// '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d'
75-
// >>> sha256('\x01').hexdigest()
76-
// '4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a'
77-
// >>> sha256('\x02').hexdigest()
78-
// 'dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986'
79-
80-
require.EqualValues(t, expectedBz, nodeVal, "Equality failed on index %d, tc %d", counter, tcIndex)
81-
counter++
82-
node = node.Next()
83-
}
84-
require.Equal(t, len(tc.txsInCache), counter,
85-
"cache smaller than expected on testcase %d", tcIndex)
86-
mp.Flush()
87-
}
88-
}
89-
9012
func TestCacheRemove(t *testing.T) {
9113
cache := NewLRUTxCache(100)
9214
numTxs := 10

0 commit comments

Comments
 (0)