Skip to content
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

network: Ignore invalid tags #4517

Merged
merged 24 commits into from
Feb 1, 2023
Merged

Conversation

cce
Copy link
Contributor

@cce cce commented Sep 8, 2022

Summary

Ignore messages with invalid tags before they hit the readBuffer queue, and add metrics for these occurrences.
Also removes unused message tag UniCatchupReqTag (deprecated by @algonautshant in #1916)

Test Plan

  • Added TestPeerReadLoopSwitchAllTags (checks wsPeer.readLoop switch statement checks all tags in network/wsPeer.go)
  • Added TestTagList (checks TagList matches const Tag declarations in protocol/tags.go)
  • Added TestWebsocketNetworkBasicInvalidTags (sets up two wsNetworks and asserts that messages are dropped without hitting readBuffer)

case protocol.TxnTag:
case protocol.UniCatchupReqTag:
case protocol.UniEnsBlockReqTag:
case protocol.VoteBundleTag:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need that exhaustive switch statement linter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be cool, but these tags are not defined in an enum... idk if there is something to lint switching on const Tag variable assignments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me see if I can put a test together

Copy link
Contributor Author

@cce cce Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this, TestPeerReadLoopSwitchAllTags

winder
winder previously approved these changes Sep 8, 2022
algorandskiy
algorandskiy previously approved these changes Sep 8, 2022
@cce cce dismissed stale reviews from algorandskiy and winder via 1b5595b September 8, 2022 20:48
winder
winder previously approved these changes Sep 8, 2022
@codecov
Copy link

codecov bot commented Sep 8, 2022

Codecov Report

Merging #4517 (4a780fd) into master (149ebb8) will increase coverage by 0.02%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master    #4517      +/-   ##
==========================================
+ Coverage   53.62%   53.65%   +0.02%     
==========================================
  Files         432      432              
  Lines       54057    54063       +6     
==========================================
+ Hits        28990    29005      +15     
+ Misses      22821    22813       -8     
+ Partials     2246     2245       -1     
Impacted Files Coverage Δ
network/wsNetwork.go 64.95% <0.00%> (+0.03%) ⬆️
rpcs/blockService.go 64.62% <ø> (-0.17%) ⬇️
network/wsPeer.go 66.89% <100.00%> (+0.46%) ⬆️
ledger/acctonline.go 79.16% <0.00%> (+0.52%) ⬆️
ledger/tracker.go 75.10% <0.00%> (+0.84%) ⬆️
catchup/service.go 70.53% <0.00%> (+1.20%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

network/wsPeer.go Outdated Show resolved Hide resolved
}

func getProtocolTags(t *testing.T) []string {
file := filepath.Join("../protocol", "tags.go")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does is work for both go test ./network and (cd ./network && go test ./) ?

Copy link
Contributor Author

@cce cce Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read in this blog post that go test sets the working directory to the package where the test is running even in these cases, so you can load up test data from local files/directories that are also in the package directory... it seems to be working from CI which is running from the base go-algorand dir

@winder winder self-requested a review January 27, 2023 13:02
algorandskiy
algorandskiy previously approved these changes Jan 27, 2023
algonautshant
algonautshant previously approved these changes Jan 27, 2023
Copy link
Contributor

@algonautshant algonautshant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
Couple of suggestions.

@@ -53,6 +53,11 @@ import (

const sendBufferLength = 1000

func init() {
// this allows test code to use out-of-protocol message tags and have them go through
allowCustomTags = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we confident that go will never load this test package in production?
Why not keep this false, and whichever test that needs this feature, can set it to true then false, and not run in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code can't be compiled into non-test packages, so it is safe.. but it is true that to parallelize the network tests we'd need to track down which ones needed this flag set. When I did this a while ago I think there were some tests that failed and so I didn't want to track down exactly which ones.

network/wsNetwork_test.go Outdated Show resolved Hide resolved
@cce cce dismissed stale reviews from algonautshant and algorandskiy via 4fbc0f6 January 28, 2023 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants