Repository navigation
revert: remove app mempool & related abci changes - #5790
Conversation
|
The latest Buf updates on your PR. Results from workflow Protobuf Lint / lint (pull_request).
|
Greptile SummaryThis PR re-introduces the app-side mempool feature: a new
Confidence Score: 4/5Mergeable 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)
|
| 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
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
| 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) |
There was a problem hiding this 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.
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.--- 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
--- 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
--- #### 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]>
--- 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
PR checklist
CHANGELOG.mddocs/orspec/) and code comments