Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
5c35437
new mempool draft
pompon0 May 15, 2026
e4a1280
WIP
pompon0 May 15, 2026
2623868
Merge remote-tracking branch 'origin/main' into gprusak-mempool
pompon0 May 15, 2026
5a91fa6
WIP
pompon0 May 18, 2026
a6feb77
WIP
pompon0 May 18, 2026
df95cde
removed priority queue
pompon0 May 18, 2026
4635fca
clist
pompon0 May 19, 2026
13254e5
before implementing PopTxs
pompon0 May 19, 2026
750c82a
reap marker
pompon0 May 19, 2026
6bf90a7
prod code compiles
pompon0 May 19, 2026
cd616ce
fixing tests WIP
pompon0 May 19, 2026
c860fe9
WIP
pompon0 May 19, 2026
e295382
mempool tests compile
pompon0 May 19, 2026
c2d3f06
wip
pompon0 May 19, 2026
bdcd0a2
codex WIP
pompon0 May 20, 2026
b7f02dc
codex WIP
pompon0 May 20, 2026
9f0f768
codex WIP
pompon0 May 20, 2026
4bff32e
moved cache
pompon0 May 20, 2026
f51ec39
reaped requires a better handling
pompon0 May 20, 2026
17702a9
no reaped again
pompon0 May 20, 2026
2a7bc71
codex WIP
pompon0 May 20, 2026
6ea4f7a
codex WIP
pompon0 May 20, 2026
97717e7
fmt
pompon0 May 20, 2026
41dcf16
Merge remote-tracking branch 'origin/main' into gprusak-mempool
pompon0 May 20, 2026
0b9bf27
some updates and documentation
pompon0 May 20, 2026
d25b16d
some fixes
pompon0 May 20, 2026
f55487d
test fix
pompon0 May 20, 2026
58778ce
Merge remote-tracking branch 'origin/main' into gprusak-mempool
pompon0 May 20, 2026
81c762c
termination fix
pompon0 May 20, 2026
f83f36f
fmt
pompon0 May 20, 2026
5a41d05
lint
pompon0 May 20, 2026
9029187
fixes
pompon0 May 20, 2026
77e8580
fixes
pompon0 May 20, 2026
7297954
codex WIP
pompon0 May 20, 2026
dc9e820
metric fixes
pompon0 May 20, 2026
fc4a26e
test fix
pompon0 May 20, 2026
cfc0541
codex WIP
pompon0 May 20, 2026
917a739
codex WIP
pompon0 May 20, 2026
cf803e1
CList.Clear and replacement test
pompon0 May 20, 2026
b516f94
applied codex comments
pompon0 May 20, 2026
94bbd6c
applied codex comments
pompon0 May 20, 2026
b18320d
syntax
pompon0 May 21, 2026
ce65730
monotone blockHeight check
pompon0 May 21, 2026
41450a9
style
pompon0 May 21, 2026
616ba41
wip
pompon0 May 21, 2026
be86a25
merged helpers
pompon0 May 21, 2026
36b309d
backward compatibility fix
pompon0 May 21, 2026
45e80c3
compatibility fix
pompon0 May 21, 2026
0fd6a2d
updated caching logic
pompon0 May 21, 2026
7208030
cache compatible
pompon0 May 21, 2026
5e67f49
fixes
pompon0 May 21, 2026
7be9604
more fixes
pompon0 May 21, 2026
d9b1814
removed irrelevant test
pompon0 May 21, 2026
b4d042b
test fix
pompon0 May 21, 2026
b072f49
adjusted priorityReservoir usage
pompon0 May 21, 2026
91eb256
eliminated deviation from main
pompon0 May 21, 2026
38e5109
test triggering compaction in insert
pompon0 May 21, 2026
c56c2cc
comments
pompon0 May 21, 2026
7a8da94
changed utilisation to account all transactions, because gossip dampe…
pompon0 May 21, 2026
de2eda1
applied comments
pompon0 May 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sei-cosmos/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func startInProcess(
}
defer func() {
if tmNode.IsRunning() {
tmNode.Wait()
tmNode.Stop()
}
}()
// Add the tx service to the gRPC router. We only need to register this
Expand Down Expand Up @@ -464,8 +464,6 @@ func startInProcess(
}
}

// Defer cancelling as the last so that it is called first during unwinding.
defer cancel()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed context cancel changes shutdown ordering

Low Severity

Removing the second defer cancel() that was placed at the end of the function changes context cancellation timing during shutdown. Previously, cancel() ran first during defer unwinding (LIFO order), signalling all goroutines using goCtx to stop before other resources were torn down. Now, the remaining defer cancel() near the top of the function runs last, meaning gRPC servers, API servers, and the app are closed while goroutines using goCtx may still be running.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7a8da94. Configure here.

// wait for signal capture and gracefully return
return WaitForQuitSignals(goCtx, restartCh)
}
16 changes: 11 additions & 5 deletions sei-tendermint/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

mempoolcfg "github.com/sei-protocol/sei-chain/sei-tendermint/internal/mempool"
tmos "github.com/sei-protocol/sei-chain/sei-tendermint/libs/os"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils"
"github.com/sei-protocol/sei-chain/sei-tendermint/types"
)

Expand Down Expand Up @@ -860,15 +861,13 @@ type MempoolConfig struct {
}

func (cfg *MempoolConfig) ToMempoolConfig() *mempoolcfg.Config {
return &mempoolcfg.Config{
mcfg := &mempoolcfg.Config{
Size: cfg.Size,
MaxTxsBytes: cfg.MaxTxsBytes,
CacheSize: cfg.CacheSize,
DuplicateTxsCacheSize: cfg.DuplicateTxsCacheSize,
KeepInvalidTxsInCache: cfg.KeepInvalidTxsInCache,
MaxTxBytes: cfg.MaxTxBytes,
TTLDuration: cfg.TTLDuration,
TTLNumBlocks: cfg.TTLNumBlocks,
TxNotifyThreshold: cfg.TxNotifyThreshold,
PendingSize: cfg.PendingSize,
MaxPendingTxsBytes: cfg.MaxPendingTxsBytes,
Expand All @@ -877,6 +876,13 @@ func (cfg *MempoolConfig) ToMempoolConfig() *mempoolcfg.Config {
DropUtilisationThreshold: cfg.DropUtilisationThreshold,
DropPriorityReservoirSize: cfg.DropPriorityReservoirSize,
}
if cfg.TTLDuration != 0 {
mcfg.TTLDuration = utils.Some(cfg.TTLDuration)
}
if cfg.TTLNumBlocks != 0 {
mcfg.TTLNumBlocks = utils.Some(cfg.TTLNumBlocks)
}
return mcfg
}

// DefaultMempoolConfig returns a default configuration for the Tendermint mempool.
Expand All @@ -891,8 +897,8 @@ func DefaultMempoolConfig() *MempoolConfig {
KeepInvalidTxsInCache: cfg.KeepInvalidTxsInCache,
MaxTxBytes: cfg.MaxTxBytes,
MaxBatchBytes: 0,
TTLDuration: cfg.TTLDuration,
TTLNumBlocks: cfg.TTLNumBlocks,
TTLDuration: cfg.TTLDuration.Or(0),
TTLNumBlocks: cfg.TTLNumBlocks.Or(0),
TxNotifyThreshold: cfg.TxNotifyThreshold,
CheckTxErrorBlacklistEnabled: true,
CheckTxErrorThreshold: 50,
Expand Down
13 changes: 5 additions & 8 deletions sei-tendermint/internal/autobahn/producer/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,27 @@ func (s *State) makePayload(ctx context.Context) (*types.Payload, error) {
// Wait for transactions. We give up and produce an empty block if mempool is empty for
// cfg.BlockInterval.
_ = utils.WithTimeout(ctx, s.cfg.BlockInterval, func(ctx context.Context) error {
return s.txMempool.TxStore().WaitForTxs(ctx)
return s.txMempool.WaitForTxs(ctx)
})
// If the context has been cancelled though, we just fail.
if err := ctx.Err(); err != nil {
return nil, err
}

txs, gasEstimated := s.txMempool.PopTxs(mempool.ReapLimits{
txs, gasEstimated := s.txMempool.ReapTxs(mempool.ReapLimits{
MaxTxs: utils.Some(min(types.MaxTxsPerBlock, s.cfg.maxTxsPerBlock())),
MaxBytes: utils.Some(utils.Clamp[int64](types.MaxTxsBytesPerBlock)),
MaxGasWanted: utils.Some(s.cfg.MaxGasPerBlockI64()),
MaxGasEstimated: utils.Some(s.cfg.MaxGasPerBlockI64()),
})
}, true)
payloadTxs := make([][]byte, 0, len(txs))
for _, tx := range txs {
payloadTxs = append(payloadTxs, tx)
}
payload, err := types.PayloadBuilder{
CreatedAt: time.Now(),
// TODO: ReapMaxTxsBytesMaxGas does not handle corner cases correctly rn, which actually
// can produce negative total gas. Fixing it right away might be backward incompatible afaict,
// so we leave it as is for now.
TotalGas: uint64(gasEstimated), // nolint:gosec
Txs: payloadTxs,
TotalGas: uint64(gasEstimated), // nolint:gosec // always non-negative
Txs: payloadTxs,
}.Build()
// This should never happen: we construct the payload from correctly sized data.
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions sei-tendermint/internal/consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func checkTxsRange(ctx context.Context, t *testing.T, cs *testState, start, end
for i := start; i < end; i++ {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
res, err := cs.txMempool.CheckTx(ctx, txBytes, mempool.TxInfo{})
res, err := cs.txMempool.CheckTx(ctx, txBytes)
require.NoError(t, err, "error after checkTx")
require.Equal(t, code.CodeTypeOK, res.Code, "checkTx code is error, txBytes %X, index=%d", txBytes, i)
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) {
for i := range int(numTxs) {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
res, err := cs.txMempool.CheckTx(ctx, txBytes, mempool.TxInfo{})
res, err := cs.txMempool.CheckTx(ctx, txBytes)
require.NoError(t, err, "error after checkTx")
require.Equal(t, code.CodeTypeOK, res.Code, "checkTx code is error, txBytes %X, index=%d", txBytes, i)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestMempoolRmBadTx(t *testing.T) {
// Try to send the tx through the mempool.
// CheckTx should not err, but the app should return a bad abci code
// and the tx should get removed from the pool
res, err := cs.txMempool.CheckTx(ctx, txBytes, mempool.TxInfo{})
res, err := cs.txMempool.CheckTx(ctx, txBytes)
if err != nil {
t.Errorf("error after CheckTx: %v", err)
return
Expand All @@ -247,7 +247,10 @@ func TestMempoolRmBadTx(t *testing.T) {

// check for the tx
for {
txs := cs.txMempool.ReapMaxBytesMaxGas(int64(len(txBytes)), utils.Max[int64](), utils.Max[int64]())
txs, _ := cs.txMempool.ReapTxs(
mempool.ReapLimits{MaxBytes: utils.Some(int64(len(txBytes)))},
false,
)
if len(txs) == 0 {
emptyMempoolCh <- struct{}{}
return
Expand Down
3 changes: 1 addition & 2 deletions sei-tendermint/internal/consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func finalizeTx(
return scope.Run(ctx, func(ctx context.Context, s scope.Scope) error {
for i, sub := range blocksSubs {
s.Spawn(func() error {
if _, err := states[i].txMempool.CheckTx(ctx, tx, mempool.TxInfo{}); err != nil {
if _, err := states[i].txMempool.CheckTx(ctx, tx); err != nil {
return fmt.Errorf("CheckTx(): %w", err)
}
for {
Expand Down Expand Up @@ -367,7 +367,6 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
_, err := states[1].txMempool.CheckTx(
ctx,
[]byte{1, 2, 3},
mempool.TxInfo{},
)
require.NoError(t, err)

Expand Down
29 changes: 13 additions & 16 deletions sei-tendermint/internal/consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func sendTxs(ctx context.Context, cs *testState) error {
return nil
}
tx := []byte{byte(i)}
if _, err := cs.txMempool.CheckTx(ctx, tx, mempool.TxInfo{}); err != nil {
if _, err := cs.txMempool.CheckTx(ctx, tx); err != nil {
return fmt.Errorf("cs.mempool.CheckTx(): %w", err)
}
}
Expand Down Expand Up @@ -271,8 +271,7 @@ type simulatorTestSuite struct {
Commits []*types.Commit
CleanupFunc cleanupFunc

Mempool *mempool.TxMempool
Evpool sm.EvidencePool
Evpool sm.EvidencePool
}

const (
Expand All @@ -292,11 +291,8 @@ var modes = []uint{0, 1, 2, 3}
func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
t.Helper()
cfg := configSetup(t)
proxyApp := kvstore.NewProxy()

sim := &simulatorTestSuite{
Mempool: newReplayTxMempool(proxyApp),
Evpool: sm.EmptyEvidencePool{},
Evpool: sm.EmptyEvidencePool{},
}

nPeers := 7
Expand Down Expand Up @@ -389,7 +385,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
require.NoError(t, err)
valPubKey1ABCI := crypto.PubKeyToProto(newValidatorPubKey1)
newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx1, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx1)
assert.NoError(t, err)

css[0].signAddVotes(ctx, t, tmproto.PrecommitType, sim.Config.ChainID(),
Expand All @@ -408,7 +404,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
require.NoError(t, err)
updatePubKey1ABCI := crypto.PubKeyToProto(updateValidatorPubKey1)
updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
_, err = css[0].txMempool.CheckTx(ctx, updateValidatorTx1, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, updateValidatorTx1)
assert.NoError(t, err)
css[0].signAddVotes(ctx, t, tmproto.PrecommitType, sim.Config.ChainID(),
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
Expand All @@ -426,14 +422,14 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
require.NoError(t, err)
newVal2ABCI := crypto.PubKeyToProto(newValidatorPubKey2)
newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower)
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx2, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx2)
assert.NoError(t, err)
pv, _ = css[nVals+2].privValidator.Get()
newValidatorPubKey3, err := pv.GetPubKey(ctx)
require.NoError(t, err)
newVal3ABCI := crypto.PubKeyToProto(newValidatorPubKey3)
newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx3, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, newValidatorTx3)
assert.NoError(t, err)
css[0].signAddVotes(ctx, t, tmproto.PrecommitType, sim.Config.ChainID(),
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
Expand Down Expand Up @@ -469,7 +465,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
ensureProposalFromCurrentLeader(height, round)
rs = css[0].GetRoundState()
removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0)
_, err = css[0].txMempool.CheckTx(ctx, removeValidatorTx2, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, removeValidatorTx2)
assert.NoError(t, err)

for i := 0; i < nVals+1; i++ {
Expand Down Expand Up @@ -498,7 +494,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
rs = css[0].GetRoundState()

removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
_, err = css[0].txMempool.CheckTx(ctx, removeValidatorTx3, mempool.TxInfo{})
_, err = css[0].txMempool.CheckTx(ctx, removeValidatorTx3)
assert.NoError(t, err)
for i := 0; i < nVals+1; i++ {
if i == selfIndex {
Expand Down Expand Up @@ -655,11 +651,12 @@ func testHandshakeReplay(
store.commits = commits

state := genesisState.Copy()
replayMempool := newReplayTxMempool(kvstore.NewProxy())
// run the chain through state.ApplyBlock to build up the tendermint state
state = buildTMStateFromChain(
ctx,
t,
sim.Mempool,
replayMempool,
Comment thread
pompon0 marked this conversation as resolved.
sim.Evpool,
stateStore,
state,
Expand All @@ -681,7 +678,7 @@ func testHandshakeReplay(
stateStore := sm.NewStore(stateDB1)
err := stateStore.Save(genesisState)
require.NoError(t, err)
buildAppStateFromChain(ctx, t, app, stateStore, sim.Mempool, sim.Evpool, genesisState, chain, eventBus, nBlocks, mode, store)
buildAppStateFromChain(ctx, t, app, stateStore, sim.Evpool, genesisState, chain, eventBus, nBlocks, mode, store)
}

// Prune block store if requested
Expand Down Expand Up @@ -759,7 +756,6 @@ func buildAppStateFromChain(
t *testing.T,
appClient *kvstore.Application,
stateStore sm.Store,
mempool *mempool.TxMempool,
evpool sm.EvidencePool,
state sm.State,
chain []*types.Block,
Expand All @@ -771,6 +767,7 @@ func buildAppStateFromChain(
t.Helper()
// start a new app without handshake, play nBlocks blocks
proxyApp := proxy.New(appClient, proxy.NopMetrics())
mempool := newReplayTxMempool(proxyApp)
state.Version.Consensus.App = kvstore.ProtocolVersion // simulate handshake, receive app version
_, err := appClient.InitChain(ctx, &abci.RequestInitChain{})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion sei-tendermint/internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ func (cs *State) buildProposalBlock(proposal *types.Proposal) *types.Block {
txs, missingTxs := cs.blockExec.SafeGetTxsByHashes(proposal.TxHashes)
if len(missingTxs) > 0 {
cs.metrics.ProposalMissingTxs.Set(float64(len(missingTxs)))
logger.Debug("Missing txs when trying to build block", "missing_txs", cs.blockExec.GetMissingTxs(proposal.TxHashes))
logger.Debug("Missing txs when trying to build block", "missing_txs", missingTxs)
return nil
}
block := cs.state.MakeBlock(proposal.Height, txs, proposal.LastCommit, proposal.Evidence, proposal.ProposerAddress)
Expand Down
5 changes: 2 additions & 3 deletions sei-tendermint/internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/sei-protocol/sei-chain/sei-tendermint/crypto/ed25519"
cstypes "github.com/sei-protocol/sei-chain/sei-tendermint/internal/consensus/types"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/eventbus"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/mempool"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/proxy"
tmpubsub "github.com/sei-protocol/sei-chain/sei-tendermint/internal/pubsub"
tmquery "github.com/sei-protocol/sei-chain/sei-tendermint/internal/pubsub/query"
Expand Down Expand Up @@ -2208,7 +2207,7 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {

ensureNewBlockHeader(t, newBlockHeader, height, blockID.Hash)

_, err := cs1.txMempool.CheckTx(ctx, types.Tx("test-key=test-value"), mempool.TxInfo{})
_, err := cs1.txMempool.CheckTx(ctx, types.Tx("test-key=test-value"))
require.NoError(t, err, "failed to seed the mempool with a transaction")

ensureNewTimeout(t, timeoutProposeCh, height+1, 0)
Expand Down Expand Up @@ -2592,7 +2591,7 @@ func TestTryCreateProposalBlock_PartsMismatch(t *testing.T) {
incrementRound(vss[1:]...)
cs.startTestRound(ctx, height, round)

_, err := cs.txMempool.CheckTx(ctx, types.Tx("test-key=test-value"), mempool.TxInfo{})
_, err := cs.txMempool.CheckTx(ctx, types.Tx("test-key=test-value"))
require.NoError(t, err, "failed to seed the mempool with a transaction")

proposal, block := cs.decideProposal(ctx, t, vss[1], height, round)
Expand Down
1 change: 0 additions & 1 deletion sei-tendermint/internal/evidence/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ func (evpool *Pool) removeEvidenceFromList(
ev := e.Value()
if _, ok := blockEvidenceMap[evMapKey(ev)]; ok {
evpool.evidenceList.Remove(e)
e.DetachPrev()
Comment thread
pompon0 marked this conversation as resolved.
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions sei-tendermint/internal/libs/clist/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ package clist

import "testing"

func BenchmarkDetaching(b *testing.B) {
lst := New[int]()
for i := 0; i < b.N+1; i++ {
lst.PushBack(i)
}
start := lst.Front()
nxt := start.Next()
b.ResetTimer()
for i := 0; i < b.N; i++ {
start.removed = true
start.detachNext()
start.DetachPrev()
tmp := nxt
nxt = nxt.Next()
start = tmp
}
}

// This is used to benchmark the time of RMutex.
func BenchmarkRemoved(b *testing.B) {
lst := New[int]()
Expand Down
Loading
Loading