forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 5
feat(consensus): report catching_up when fallen behind peers #40
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e39478b
feat(consensus): report catching_up when fallen behind peers
pratikspatil024 1c7cc68
feat(consensus): derive zero-peer catching_up from sole-validator status
pratikspatil024 c90aa7f
fix(consensus): require a majority of peers to corroborate catching_u…
pratikspatil024 c5e8b23
test(consensus,config): unit-cover catching_up logic to 100% mutation…
pratikspatil024 67da2af
test(consensus): integration-test IsBehind across peer topologies
pratikspatil024 b7ed08e
chore(config): clarify catchup_lag_threshold=1 rejection message
pratikspatil024 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
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,81 @@ | ||
| package consensus | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestEvaluateBehind(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| lagThreshold int64 | ||
| minPeers int | ||
| myHeight int64 | ||
| maxPeerHeight int64 | ||
| nPeers int | ||
| want bool | ||
| }{ | ||
| {"peer far ahead", 5, 0, 100, 110, 3, true}, | ||
| {"peer ahead within threshold", 5, 0, 100, 105, 3, false}, | ||
| {"peer exactly at threshold", 5, 0, 100, 105, 3, false}, | ||
| {"peer one over threshold", 5, 0, 100, 106, 3, true}, | ||
| {"equal height network halt", 5, 0, 100, 100, 3, false}, | ||
| {"round skew peer one ahead", 5, 0, 100, 101, 3, false}, | ||
| {"no peer height learned", 5, 0, 100, 0, 3, false}, | ||
| {"threshold disabled ignores lag", 0, 0, 100, 999, 3, false}, | ||
| {"single node zero peers healthy", 5, 0, 100, 0, 0, false}, | ||
| {"min peers guard off with zero peers", 5, 0, 100, 100, 0, false}, | ||
| {"min peers guard trips below min", 5, 2, 100, 100, 1, true}, | ||
| {"min peers guard satisfied", 5, 2, 100, 100, 2, false}, | ||
| {"min peers guard fires even when lag disabled", 0, 2, 100, 0, 0, true}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| conR := &Reactor{ | ||
| catchUpLagThreshold: tt.lagThreshold, | ||
| minExpectedPeers: tt.minPeers, | ||
| } | ||
| got := conR.evaluateBehind(tt.myHeight, tt.maxPeerHeight, tt.nPeers) | ||
| assert.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyDebounce(t *testing.T) { | ||
| debounce := 10 * time.Second | ||
| t0 := time.Now() | ||
|
|
||
| t.Run("not behind resets and returns false", func(t *testing.T) { | ||
| conR := &Reactor{catchUpDebounce: debounce, behindSince: t0} | ||
| assert.False(t, conR.applyDebounceLocked(false, t0.Add(time.Hour))) | ||
| assert.True(t, conR.behindSince.IsZero()) | ||
| }) | ||
|
|
||
| t.Run("behind but within debounce stays false", func(t *testing.T) { | ||
| conR := &Reactor{catchUpDebounce: debounce} | ||
| assert.False(t, conR.applyDebounceLocked(true, t0)) | ||
| assert.False(t, conR.applyDebounceLocked(true, t0.Add(5*time.Second))) | ||
| }) | ||
|
|
||
| t.Run("behind past debounce flips true", func(t *testing.T) { | ||
| conR := &Reactor{catchUpDebounce: debounce} | ||
| assert.False(t, conR.applyDebounceLocked(true, t0)) | ||
| assert.True(t, conR.applyDebounceLocked(true, t0.Add(debounce))) | ||
| }) | ||
|
|
||
| t.Run("transient blip resets the timer", func(t *testing.T) { | ||
| conR := &Reactor{catchUpDebounce: debounce} | ||
| assert.False(t, conR.applyDebounceLocked(true, t0)) | ||
| assert.False(t, conR.applyDebounceLocked(false, t0.Add(5*time.Second))) | ||
| // timer restarts; not yet past debounce from the new start. | ||
| assert.False(t, conR.applyDebounceLocked(true, t0.Add(6*time.Second))) | ||
| assert.True(t, conR.applyDebounceLocked(true, t0.Add(16*time.Second))) | ||
| }) | ||
|
|
||
| t.Run("zero debounce flips immediately", func(t *testing.T) { | ||
| conR := &Reactor{catchUpDebounce: 0} | ||
| assert.True(t, conR.applyDebounceLocked(true, t0)) | ||
| }) | ||
| } |
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
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.