Skip to content

revert: remove app mempool & related abci changes - #5790

Merged
mattac21 merged 2 commits into
mainfrom
ma/update-main
Apr 17, 2026
Merged

mattac21 merged 2 commits into
mainfrom
ma/update-main

Conversation

@mattac21

@mattac21 mattac21 commented Apr 17, 2026 •

Copy link
Copy Markdown
Collaborator

PR checklist

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

…s from main (#5693)"

This reverts commit b781927.

Discarded files:
- CHANGELOG.md

Edited files:
- libp2p-app-mempool.toml
@mattac21
mattac21 requested a review from a team as a code owner April 17, 2026 15:24
@github-actions

github-actions Bot commented Apr 17, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Protobuf Lint / lint (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 17, 2026, 3:30 PM

@mattac21 mattac21 changed the title Revert "chore(app_mempool)!: remove app mempool & related abci method… revert: remove app mempool & related abci changes Apr 17, 2026
@greptile-apps

greptile-apps Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR re-introduces the app-side mempool feature: a new AppMempool type where the ABCI application owns mempool storage, and CometBFT only proxies InsertTx/ReapTxs ABCI calls and broadcasts transactions. The change adds two new ABCI methods (InsertTx, ReapTxs), a new AppReactor, protobuf definitions, and config options for mempool.type = "app".

  • P1: CheckTx adds the transaction to the seen cache but never removes it on a retry response from CheckTxUnlocked. Any re-attempt by the client (or receipt of the same tx from a peer via InsertTx) will hit ErrSeenTx instead of forwarding to the app, silently dropping the tx until LRU eviction. InsertTx handles this correctly (m.seen.Remove(tx) on retry codes) but CheckTx does not.

Confidence Score: 4/5

Mergeable after fixing the seen-cache retry gap in CheckTx; the remaining issues are P2 style/observability concerns.

One confirmed P1 defect: CheckTx adds a tx to the seen cache but never removes it on CodeTypeRetry, so any retry attempt (from the original client or a peer) hits ErrSeenTx until LRU eviction. InsertTx handles this correctly, making the inconsistency clearly unintentional. The goroutine-leak, dead-channel, SeenCacheSize=0, and e2e unbounded-map issues flagged in prior threads are still unresolved and compound the risk. The remaining new findings (stale comment, metric label) are P2.

mempool/app_mempool.go (CheckTx retry handling), mempool/app_reactor.go (OnStop goroutine leak + waitForSwitchingOnCh), test/e2e/app/app.go (unconditional appMempool insert)

Important Files Changed

Filename Overview
mempool/app_mempool.go New AppMempool type; CheckTx goroutine missing seen-cache removal on retry codes, unlike InsertTx which handles this correctly.
mempool/app_reactor.go New AppReactor for AppMempool broadcasts; OnStop skips cancelCtx when not yet enabled (goroutine leak), and waitForSwitchingOnCh is allocated but never read.
config/config.go New app-mempool config fields (SeenCacheSize, ReapInterval, etc.); MaxBatchBytes comment still says "XXX: Unused" despite now being used by AppReactor; SeenCacheSize=0 allows near-useless LRU.
proxy/app_conn.go Adds InsertTx/ReapTxs to AppConnMempool; CheckTxUnlocked shares metric label with CheckTx making them indistinguishable in dashboards.
abci/types/application.go Adds InsertTx and ReapTxs to the Application interface with BaseApplication default implementations that return OK codes.
abci/client/local_client.go Adds InsertTx, ReapTxs, and CheckTxUnlocked to localClient; unlocked variant skips the mutex as documented.
test/e2e/app/app.go CheckTx unconditionally inserts into appMempool regardless of AppSideMempool flag, causing unbounded map growth when mempool type is flood/nop.
node/setup.go Adds AppMempool and AppReactor wiring in createMempoolAndMemReactor; straightforward case addition.
proto/tendermint/abci/types.proto Adds InsertTx/ReapTxs RPC definitions and message types to the ABCI service; field numbering is consistent (21/22 in Request oneof, 22/23 in Response oneof).

Sequence Diagram

sequenceDiagram
    participant Client as RPC Client
    participant CM as CometBFT Mempool
    participant AM as AppMempool
    participant AR as AppReactor
    participant App as ABCI App
    participant Peer as P2P Peer

    Note over Client,App: CheckTx path (RPC)
    Client->>CM: broadcast_tx
    CM->>AM: CheckTx(tx)
    AM->>AM: guardTx(tx) add to seen cache
    AM-->>CM: nil (async)
    AM->>App: CheckTxUnlocked(tx)
    App-->>AM: ResponseCheckTx{code}
    AM->>Client: callback(response)

    Note over Peer,App: InsertTx path (P2P)
    Peer->>AR: Receive(envelope)
    AR->>AM: InsertTx(tx)
    AM->>AM: guardTx(tx) seen cache check
    AM->>App: InsertTx(tx) via ABCI
    App-->>AM: ResponseInsertTx{code}
    AM-->>AR: nil / error

    Note over AR,App: ReapTxs broadcast path
    AR->>AM: TxStream(ctx)
    loop every ReapInterval
        AM->>App: ReapTxs(maxBytes, maxGas)
        App-->>AM: ResponseReapTxs{txs}
        AM->>AR: chan txs
        AR->>Peer: BroadcastAsync(txs batch)
    end
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: mempool/app_mempool.go
Line: 240-262

Comment:
**`CheckTx` does not remove retry-coded txs from the seen cache**

The goroutine calls `guardTx` (which adds to `seen`) before starting, but never calls `m.seen.Remove(tx)` when `CheckTxUnlocked` returns `CodeTypeRetry`. `InsertTx` handles this correctly at line 106. As a result, any re-submission of the same tx — either from the original client retrying or from a peer arriving via `AppReactor.Receive → AppMempool.InsertTx` — will be rejected with `ErrSeenTx` until the LRU evicts the entry. The tx is silently dropped by every code path.

```go
res, err := m.app.CheckTxUnlocked(m.ctx, &abci.RequestCheckTx{Tx: tx})
if err != nil {
    m.logger.Error("AppMempool.CheckTx: error inserting tx", "error", err, "tx", txHash(tx))
    m.seen.Remove(tx) // allow retry
    return
}

if res != nil && codeRetry(res.Code) {
    m.seen.Remove(tx) // allow retry, same as InsertTx does
}

if callback != nil {
    callback(res)
}
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: config/config.go
Line: 982-984

Comment:
**Stale "XXX: Unused" comment on `MaxBatchBytes`**

`AppReactor.OnStart` now reads `r.config.MaxBatchBytes` to size broadcast batches. The "Unused" comment will mislead operators configuring the app mempool.

```suggestion
	// Maximum size of a batch of transactions to send to a peer
	// Including space needed by encoding (one varint per transaction).
	// Used by the app mempool reactor for batching broadcasts.
	MaxBatchBytes int `mapstructure:"max_batch_bytes"`
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: proxy/app_conn.go
Line: 156-162

Comment:
**`CheckTxUnlocked` emits the same metric label as `CheckTx`**

Both use `"method", "check_tx"`, so dashboards and alerts cannot distinguish regular locked `CheckTx` calls from the unlocked variant used exclusively by `AppMempool`.

```suggestion
func (app *appConnMempool) CheckTxUnlocked(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
	defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "check_tx_unlocked", "type", "sync"))()
	if unlocker, ok := app.appConn.(checkTxUnlocker); ok {
		return unlocker.CheckTxUnlocked(ctx, req)
	}
	return app.appConn.CheckTx(ctx, req)
}
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "changelog" | Re-trigger Greptile

Comment thread mempool/app_reactor.go Resolved
Comment thread test/e2e/app/app.go Resolved
Comment thread mempool/app_reactor.go
Comment on lines +33 to +50
ctx, cancelCtx := context.WithCancel(context.Background())

r := &AppReactor{
config: config,
mempool: mempool,
ctx: ctx,
cancelCtx: cancelCtx,
switchedOn: atomic.Bool{},
waitForSwitchingOnCh: nil,
}

r.BaseReactor = *p2p.NewBaseReactor("Mempool", r)

if waitForSync {
r.switchedOn.Store(false)
r.waitForSwitchingOnCh = make(chan struct{})
} else {
r.switchedOn.Store(true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 waitForSwitchingOnCh is dead code — broadcast runs during sync

waitForSwitchingOnCh is allocated when waitForSync=true and closed in EnableInOutTxs, but it is never read from inside AppReactor. As a result, when waitForSync=true, the broadcast goroutine starts immediately in OnStart and begins polling ReapTxs before sync completes, broadcasting app-mempool transactions to peers while simultaneously dropping all incoming peer transactions in Receive. The channel should gate the broadcast goroutine, or the struct field should be removed if the design intention is to always broadcast during sync.

Prompt To Fix With AI
This is a comment left during a code review.
Path: mempool/app_reactor.go
Line: 33-50

Comment:
**`waitForSwitchingOnCh` is dead code — broadcast runs during sync**

`waitForSwitchingOnCh` is allocated when `waitForSync=true` and closed in `EnableInOutTxs`, but it is never read from inside `AppReactor`. As a result, when `waitForSync=true`, the broadcast goroutine starts immediately in `OnStart` and begins polling `ReapTxs` before sync completes, broadcasting app-mempool transactions to peers while simultaneously dropping all incoming peer transactions in `Receive`. The channel should gate the broadcast goroutine, or the struct field should be removed if the design intention is to always broadcast during sync.

How can I resolve this? If you propose a fix, please make it concise.

@mattac21 mattac21 Apr 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ticket made

Comment thread config/config.go Resolved
Comment thread mempool/app_mempool.go Resolved
@mattac21
mattac21 added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit 766ab92 Apr 17, 2026
53 of 55 checks passed
@mattac21
mattac21 deleted the ma/update-main branch April 17, 2026 15:52
@Eric-Warehime Eric-Warehime mentioned this pull request Apr 20, 2026
2 of 3 tasks
mergify Bot pushed a commit to evanorti/cometbft that referenced this pull request Apr 20, 2026
---

Closes
cometbft#5790 (comment)

#### PR checklist

- [X] Tests written/updated
- [X] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
mattac21 pushed a commit that referenced this pull request May 4, 2026
---

Closes
#5790 (comment)

#### PR checklist

- [X] Tests written/updated
- [X] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: Dmitry S <[email protected]>
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
---

Closes
cometbft#5790 (comment)

#### PR checklist

- [X] Tests written/updated
- [X] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants