Repository navigation
Commit d17806f
fix(p2p): make the inbound accept rate configurable and raise its default (#3899)
## Problem
`Router` paces its accept loop with a rate limiter, but the limit has
never been reachable from config. `createRouter` sets `MaxDialRate` from
the p2p `dial-interval` key and leaves `MaxAcceptRate` unset, so every
node falls through to the compiled-in default:
```go
func (o *RouterOptions) maxAcceptRate() rate.Limit {
return o.MaxAcceptRate.Or(rate.Every(time.Second)) // 1 accept/s
}
```
`node/setup.go` is the only non-test construction site for
`RouterOptions`; every other site is a test harness that pins
`MaxAcceptRate: rate.Inf`. So the production value is both unreachable
and unexercised.
**One accept per second is too low for a public-facing node.** The
kernel keeps completing three-way handshakes into the listen backlog
while the loop drains it at 1/s. Once the backlog is more than a few
entries deep, an arriving peer waits longer than `handshake-timeout` and
never completes its handshake. The node stops acquiring inbound peers
while continuing to serve its established ones — so it stays at chain
head and reports healthy while inbound is effectively closed. From the
dialer's side this looks like a peer that accepts TCP and then does
nothing.
## Why it is 1/s
Not a decision about inbound behaviour:
- **#2539** (PeerManager rewrite) introduced the limiter at 2/s,
`rate.Every(500ms)`.
- **#2799** — subject *"made the peer dialing less aggressive"*, body
describing `DialRate` — halved `MaxAcceptRate` to 1/s as a secondary
line item, exposed the **dial** knob to config.toml, and left the
**accept** knob compiled in.
## Change
- Add `accept-interval` to `P2PConfig` (struct field + default +
`ValidateBasic`) and **render it in the generated template**.
`dial-interval` stays unrendered, but this key is the reason the PR
exists, so it belongs where an operator looks.
- Wire it: `MaxAcceptRate:
utils.Some(rate.Every(cfg.P2P.AcceptInterval))`.
- Raise the **package default** in `maxAcceptRate()` from 1/s to 10ms
(100/s), so no construction path inherits a rate too low to drain the
backlog, and default `accept-interval` to the same value. Concurrency is
already bounded by `MaxConcurrentAccepts`, which setup sets to
`maxInbound` (`max-connections` minus the outbound reservation) so the
global limiter should be a backstop, not the binding constraint. Note
`max-incoming-connection-attempts` does **not** fill that role:
`connTracker.AddConn` caps *concurrent* connections per source IP at 100
(the 100ms window applies only once a source drops to zero), and 100
exceeds the default inbound pool of 80, so it does not bound a single
source below the pool.
- `rate.Every` returns `rate.Inf` for a non-positive interval, so
`accept-interval = 0` disables the limiter.
## Behavior change: `[p2p]` validation now runs
`Config.ValidateBasic` routed every section except `[p2p]`, so
`P2PConfig.ValidateBasic` had never executed in production — its
`send-rate`, `recv-rate`, `flush-throttle-timeout` and
`max-packet-msg-payload-size` checks were dead for their whole life.
This PR routes the section, which makes them load-bearing.
**Who is affected.** Traced both entry points:
- **seid's normal boot** (`sei-cosmos/server/util.go`
`interceptConfigs`) calls `ValidateBasic` only on the config-*creation*
branch, so an already-deployed node with an existing `config.toml` is
unaffected.
- **`commands.ParseConfig`** does call it, and
`sei-cosmos/server/util.go:342` invokes that from `AddCommands` with
`panic(err)` on failure.
- **`confix`'s `CheckValid`**
(`sei-tendermint/scripts/confix/confix.go:163`) also reaches it. It
unmarshals into a zero-valued `Config` and all `[p2p]` checks are `< 0`,
so it only trips on a file carrying an explicit negative.
Because an already-deployed node never reaches `ValidateBasic`,
`p2pRouterOptions` additionally clamps a negative pacing interval to the
default — `rate.Every` maps any non-positive interval to `rate.Inf`, so
a typo would otherwise disable pacing silently. A configured `0` still
disables the limiter, as documented.
So the realistic worst case is a `seid` command tree that panics at
startup rather than returning a config error, for an operator whose
`config.toml` carries a negative value in one of those four pre-existing
fields — previously tolerated silently. Low likelihood, but it belongs
in release notes, not buried in a pacing PR.
## Tests
- `TestP2PConfigAcceptInterval` — pins the default exactly; the
rationale lives in the doc comment.
- `TestP2PConfigValidateBasic` — `AcceptInterval` added to
`fieldsToTest`; `dial-interval` now gets the same negative check, since
it also becomes `rate.Inf`.
- `TestEnsureRoot`/`checkConfig` — asserts `accept-interval` is
**present** in the rendered template, and `dial-interval` still absent.
- `p2p_compat_test.go` — both keys parse from an existing config.toml; a
template-shaped file without them still yields the defaults.
- `TestP2PRouterOptions_PacingAndBudgetWiring` — asserts the `cfg →
RouterOptions` derivation directly, over non-default `max-connections`
values (50 → 30/20, 30 → 15/15).
Each guard was checked to fail on the defect it targets, not merely to
pass. `./node/` has three failures (`TestNodeStartStop`,
`TestNodeRestartEventAllowsRecreate`, `TestNodeSetPrivValTCP`) that
reproduce on unmodified `origin/main`.
`gofmt -s -l` and `goimports -l` are clean on all four files.
`./node/` has three failures — `TestNodeStartStop`,
`TestNodeRestartEventAllowsRecreate`, `TestNodeSetPrivValTCP` — which
reproduce identically on unmodified `origin/main`. Pre-existing, not
from this change.
## Notes for review
- **Default value is the judgement call.** 10ms/100 per second is argued
above from the surrounding limiters rather than measured; if you want it
more conservative, the knob now exists and only the constant moves.
- **`AGENTS.md` deviation:** the guide prefers `libs/utils/require` over
`testify`, but `sei-tendermint/config` is entirely `testify` with no
`utils/require` usage. I matched the package. Happy to convert if you
would rather the new test lead the migration.
- **Follow-up not in this PR:** the router test harnesses
(`testonly.go`, `router_test.go`, `giga_router_validator_test.go`) all
substitute `rate.Inf`, so no test exercises the production accept rate
end-to-end. That substitution is why a 1/s cap on a mainnet listener
went unnoticed. Worth a dedicated test at the router level.
- `max-connections` reaches the router only through the
`maxInbound`/`maxOutbound` derivation in `p2pRouterOptions`; it is not
itself a `RouterOptions` field. `MaxConcurrentAccepts` is set to
`maxInbound`, so the connection budget does track `max-connections` —
just via that computation rather than directly.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent d9d8a2c commit d17806f
9 files changed
Lines changed: 296 additions & 24 deletions
File tree
- sei-tendermint
- config
- internal/p2p
- node
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| |||
732 | 735 | | |
733 | 736 | | |
734 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
735 | 742 | | |
736 | 743 | | |
737 | 744 | | |
| |||
762 | 769 | | |
763 | 770 | | |
764 | 771 | | |
| 772 | + | |
765 | 773 | | |
766 | 774 | | |
767 | 775 | | |
| |||
782 | 790 | | |
783 | 791 | | |
784 | 792 | | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
785 | 799 | | |
786 | 800 | | |
787 | 801 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
42 | 53 | | |
43 | 54 | | |
44 | 55 | | |
| |||
231 | 242 | | |
232 | 243 | | |
233 | 244 | | |
| 245 | + | |
| 246 | + | |
234 | 247 | | |
235 | 248 | | |
236 | 249 | | |
| |||
240 | 253 | | |
241 | 254 | | |
242 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
243 | 271 | | |
244 | 272 | | |
245 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
355 | 361 | | |
356 | 362 | | |
357 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
102 | 121 | | |
103 | 122 | | |
104 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
478 | 470 | | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
479 | 474 | | |
480 | 475 | | |
481 | 476 | | |
| |||
497 | 492 | | |
498 | 493 | | |
499 | 494 | | |
500 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
501 | 504 | | |
502 | 505 | | |
503 | | - | |
504 | | - | |
| 506 | + | |
| 507 | + | |
505 | 508 | | |
506 | 509 | | |
507 | 510 | | |
| |||
510 | 513 | | |
511 | 514 | | |
512 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
513 | 543 | | |
514 | 544 | | |
515 | 545 | | |
| |||
0 commit comments