Repository navigation
Commit 880848f
perf(autobahn): reject an insert into a full producer mempool before CheckTx (#4451)
An insert into a full producer mempool ran the app CheckTx before it
learned that the mempool had no room. CheckTx does ecrecover and writes
the sender cache, so each such insert paid the full CheckTx cost and
then failed. On a trapped giga-testnet-0 validator, about 4.4x more
CheckTx attempts ran than inserts succeeded (`ok` 797/s, `pending_full`
3,476/s). That wasted CPU keeps a slow validator behind under saturation
load. Linear: PLT-1371 (from PLT-1366).
`State.doInsertTx` now calls `poolCanAdmit` after it gets the session
mempool and before `checkTx`. That function takes the mempool lock once.
It returns the error that the admission loop would return at that moment
for an insert without a ticket. That is `ErrNotProducing` for a closed
session, `errMempoolFull` for `TryInsertTx` when `IsFull()`, and
`errPendingFull` for `InsertTx` when `len(waiters) >=
maxPendingInserts()`. The errors are the same values, so `insertTx`
counts them under the same `producer_inserts{result}` labels. For a
valid tx, RPC callers see the same errors as before. The admission loop
after CheckTx is unchanged and stays authoritative. The check also runs
before the CheckTx permit wait, so a rejected insert does not hold a
`checkTxSem` slot or a `tryInsertSem` slot for the CheckTx duration.
Two points differ from the ticket text. The pending check omits
`IsFull()`: with no ticket and `len(waiters) >= max >= 1`, `isHead` is
false, so the loop rejects with `errPendingFull` whether or not the
mempool is full. The closed check comes first, because the loop also
checks `closed` first; without it, a closed and full session would
report `full` where the loop reports `not_producing`.
Error order. The order changes for a tx that is both invalid and sent to
a full mempool. Before, it got its non-retryable CheckTx rejection, or
`errTooLarge` from the gas checks. Now it gets the retryable
`errMempoolFull` or `errPendingFull`. The client then retries a tx that
can never land, and it learns that only when there is room. Under
saturation this is the intended trade: CheckTx is the cost this change
removes. `TestTryInsertTx_FullRejectsInvalidTxAsFull` pins the new
order.
Race analysis. Each early rejection is exactly the loop's answer at the
moment of the check. After the check, other inserts can fill the
mempool, and a prune can free it by advancing `m.first`. Thus an insert
that the check rejects could have succeeded only if capacity freed
during its own permit wait and CheckTx. One permit wait plus one CheckTx
bounds that window. In that case the caller gets the documented,
retryable mempool-full error, the same answer as with an instantaneous
CheckTx. Under saturation, I expect other in-flight inserts to take the
freed capacity, so throughput does not drop.
A closed session never reopens, so the closed check has no race. The
happy path takes one more short mempool lock (three instead of two). The
`admit` and `check_tx` latency histograms get fewer samples, because
early rejections skip both phases.
Tests: three new tests in `checktx_limit_test.go` use a `countingApp`.
They show that `TryInsertTx` on a full mempool, `InsertTx` with
`MaxPendingInserts` queued, and both calls on a closed session return
the expected result and do not call CheckTx. All three fail on `main`.
The existing producer tests pass with no change.
```
go test -race -count=1 ./sei-tendermint/internal/autobahn/producer/... ok
go test -race -count=20 ./sei-tendermint/internal/autobahn/producer/ ok
gofmt -s -l / goimports -l (changed package) no output
go vet ./sei-tendermint/internal/autobahn/producer/... no output
staticcheck 2026.2.1 (0.8.1) ./sei-tendermint/internal/autobahn/producer/... no output
golangci-lint v2.13.2 run ./sei-tendermint/internal/autobahn/producer/... 0 issues.
golangci-lint v2.13.2 fmt --diff ./sei-tendermint/internal/autobahn/producer/... no output
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent d4853e5 commit 880848f
2 files changed
Lines changed: 127 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
202 | 204 | | |
203 | 205 | | |
204 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
205 | 311 | | |
206 | 312 | | |
207 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
295 | 312 | | |
296 | 313 | | |
297 | 314 | | |
| |||
379 | 396 | | |
380 | 397 | | |
381 | 398 | | |
382 | | - | |
| 399 | + | |
383 | 400 | | |
384 | 401 | | |
385 | 402 | | |
| |||
394 | 411 | | |
395 | 412 | | |
396 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
397 | 417 | | |
398 | 418 | | |
399 | 419 | | |
| |||
0 commit comments