-
Notifications
You must be signed in to change notification settings - Fork 886
fix(p2p): make the inbound accept rate configurable and raise its default #3899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
edff731
fix(p2p): make the inbound accept rate configurable and raise its def…
bdchatham cb0338f
test(config): pin accept-interval under the hidden-knob convention
bdchatham c704f4d
address review: render accept-interval, pin the default exactly, test…
bdchatham 0ccc3ff
address review round 2: fix the default at the choke point, tighten t…
bdchatham b816df2
address review round 3: correct the connTracker rationale, close the …
bdchatham be9ad90
address review round 4: route [p2p] through Config.ValidateBasic
bdchatham a9607c5
Merge branch 'main' into fix/p2p-accept-rate-configurable
bdchatham e56a479
address review round 5: collapse the duplicated accept default to one…
bdchatham 0c95de0
conform godocs to the AGENTS.md Godoc rules added on main
bdchatham a4b857e
address human review: drop the cross-package default coupling and the…
bdchatham 371b1ee
address review: clamp negative pacing intervals, pin the package defa…
bdchatham d2b60ee
address review: stop documenting the clamp, and stop applying it sile…
bdchatham c2b0acf
address review: refuse a negative pacing interval instead of clamping it
bdchatham 8f5a204
Merge branch 'main' into fix/p2p-accept-rate-configurable
bdchatham 289b6db
Merge branch 'main' into fix/p2p-accept-rate-configurable
bdchatham 6830f19
Merge branch 'main' into fix/p2p-accept-rate-configurable
bdchatham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package config_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/spf13/viper" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| tmconfig "github.com/sei-protocol/sei-chain/sei-tendermint/config" | ||
| ) | ||
|
|
||
| // readP2PConfig decodes a config.toml into a default Config: absent keys keep | ||
| // the value already in the struct. | ||
| func readP2PConfig(t *testing.T, body string) *tmconfig.P2PConfig { | ||
| t.Helper() | ||
|
|
||
| path := filepath.Join(t.TempDir(), "config.toml") | ||
| require.NoError(t, os.WriteFile(path, []byte(body), 0600)) | ||
|
|
||
| v := viper.New() | ||
| v.SetConfigFile(path) | ||
| require.NoError(t, v.ReadInConfig()) | ||
|
|
||
| cfg := tmconfig.DefaultConfig() | ||
| require.NoError(t, v.Unmarshal(cfg)) | ||
| return cfg.P2P | ||
| } | ||
|
|
||
| // dial-interval is absent from the generated template (see checkConfig in | ||
| // toml_test.go), so nothing else shows it is readable at all. | ||
| func TestP2PPacingKnobsParseFromExistingConfig(t *testing.T) { | ||
| p2p := readP2PConfig(t, ` | ||
| [p2p] | ||
| laddr = "tcp://0.0.0.0:26656" | ||
| dial-interval = "5s" | ||
| accept-interval = "20ms" | ||
| `) | ||
|
|
||
| require.Equal(t, 5*time.Second, p2p.DialInterval) | ||
| require.Equal(t, 20*time.Millisecond, p2p.AcceptInterval) | ||
| require.NoError(t, p2p.ValidateBasic()) | ||
| } | ||
|
|
||
| // TestP2PConfigPredatingPacingKnobsKeepsDefaults asserts a config.toml written | ||
| // before these keys existed still parses to the defaults rather than to zero, | ||
| // which rate.Every would read as "no pacing". | ||
| func TestP2PConfigPredatingPacingKnobsKeepsDefaults(t *testing.T) { | ||
| p2p := readP2PConfig(t, ` | ||
| [p2p] | ||
| laddr = "tcp://0.0.0.0:26656" | ||
| `) | ||
|
|
||
| defaults := tmconfig.DefaultP2PConfig() | ||
| require.Equal(t, defaults.AcceptInterval, p2p.AcceptInterval) | ||
| require.Equal(t, defaults.DialInterval, p2p.DialInterval) | ||
| require.NotZero(t, p2p.AcceptInterval, "a zero accept-interval disables accept pacing entirely") | ||
| require.NoError(t, p2p.ValidateBasic()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package p2p | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "golang.org/x/time/rate" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/require" | ||
| ) | ||
|
|
||
| // #3922 removed the package-level pacing fallbacks in favour of requiring both | ||
| // rates from the construction site, so the risk this guards has moved rather | ||
| // than gone: a site that forgets to set them no longer inherits a rate too low | ||
| // to drain the listen backlog, it fails Validate. Every router test harness | ||
| // pins these to rate.Inf and node setup derives them from config, so nothing | ||
| // else exercises the unset case. | ||
| func TestRouterOptionsRequirePacingRates(t *testing.T) { | ||
| var o RouterOptions | ||
| require.Error(t, o.Validate()) | ||
|
|
||
| o.MaxDialRate = rate.Every(10 * time.Second) | ||
| require.Error(t, o.Validate()) | ||
|
|
||
| o.MaxAcceptRate = rate.Every(10 * time.Millisecond) | ||
| require.NoError(t, o.Validate()) | ||
|
|
||
| // The accessors are plain reads now; no fallback may reappear between the | ||
| // field and the limiter. | ||
| require.Equal(t, rate.Every(10*time.Millisecond), o.maxAcceptRate()) | ||
| require.Equal(t, rate.Every(10*time.Second), o.maxDialRate()) | ||
|
|
||
| // accept-interval = 0 is the documented way to disable pacing: rate.Every | ||
| // maps a non-positive interval to rate.Inf, which Validate still accepts. | ||
| o.MaxAcceptRate = rate.Every(0) | ||
| require.Equal(t, rate.Inf, o.maxAcceptRate()) | ||
| require.NoError(t, o.Validate()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.