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

Throttle related panic cleanup #640

Merged
merged 12 commits into from
Jan 9, 2023
Merged

Throttle related panic cleanup #640

merged 12 commits into from
Jan 9, 2023

Conversation

shaspitz
Copy link
Contributor

@shaspitz shaspitz commented Jan 5, 2023

Description

For every panic in throttle.go or closely related files, this PR either:

  1. Clarifies with comments why the panic is still included
  2. Removes the panic in favor of an error log to prevent undesirable binary behavior

Linked issues

Works toward #621

Type of change

  • Fix: Changes and/or adds code behavior, specifically to fix a bug
  • Docs: Adds documentation

New behavior tests

n/a, fix was small and only related to queries

@shaspitz shaspitz marked this pull request as ready for review January 5, 2023 20:18
Copy link
Contributor

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

Nice work @smarshall-spitzbart. See my comments below. Also, the following throttling methods are called from EndBlock:

k.CheckForSlashMeterReplenishment(ctx)
k.HandleLeadingVSCMaturedPackets(ctx)
k.HandleThrottleQueues(ctx)

Could you add for each one a docstring describing the scenarios when they panic?

x/ccv/provider/keeper/throttle.go Outdated Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Show resolved Hide resolved
Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

Suggestion: prefix every func which calls panic directly with Must
Tiny nit: some of the comments are a bit verbose ('Explanation:', 'Further', 'In this case'). They are very clear though so that's good

Overall good job!

x/ccv/provider/keeper/throttle.go Outdated Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Outdated Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Outdated Show resolved Hide resolved
x/ccv/provider/keeper/throttle.go Show resolved Hide resolved
@mpoke
Copy link
Contributor

mpoke commented Jan 6, 2023

prefix every func which calls panic directly with Must

@danwt Prefixing getters with Must may imply that the key must exist. I think it's okay to go ahead with the pattern that getters and setters panic if marshaling / unmarshaling fails. We just need to make sure that the data for setters is valid.

@shaspitz
Copy link
Contributor Author

shaspitz commented Jan 6, 2023

Nice work @smarshall-spitzbart. See my comments below. Also, the following throttling methods are called from EndBlock:

k.CheckForSlashMeterReplenishment(ctx)
k.HandleLeadingVSCMaturedPackets(ctx)
k.HandleThrottleQueues(ctx)

Could you add for each one a docstring describing the scenarios when they panic?

Yup! See 19f6afa

@shaspitz shaspitz requested review from danwt and mpoke January 6, 2023 21:03
@mpoke mpoke requested a review from MSalopek January 9, 2023 10:07
Copy link
Contributor

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

Nice work @smarshall-spitzbart

@MSalopek
Copy link
Contributor

MSalopek commented Jan 9, 2023

Overall, LGTM!
I am in favor of adding a Must prefix to functions that perform logic other than Get/Set since the pattern of panicking inside Set/Get is widespread in cosmos-sdk.

Maybe we could aggregate errors that happened during queue iteration and return them as part of the query result in another PR?

Besides that, queries should use pagination to avoid dumping large number of records from the throttle queues. Not sure, but that could also be a very easy DoS attack vector. I doubt it would affect validator nodes (provided the validators use sentry nodes) but the RPC/proxy/sentry nodes could be affected.

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

Great work!

@shaspitz
Copy link
Contributor Author

shaspitz commented Jan 9, 2023

Re "must" naming conventions, see #650. We can then address this for the entire repo

Maybe we could aggregate errors that happened during queue iteration and return them as part of the query result in another PR?

Seems like a good idea 👍, thanks for the input @MSalopek. Could you make an issue for this, as you may have more context as to whether this error accumulation pattern could be applied to other queries as well

@MSalopek
Copy link
Contributor

MSalopek commented Jan 9, 2023

Re "must" naming conventions, see #650. We can then address this for the entire repo

Maybe we could aggregate errors that happened during queue iteration and return them as part of the query result in another PR?

Seems like a good idea 👍, thanks for the input @MSalopek. Could you make an issue for this, as you may have more context as to whether this error accumulation pattern could be applied to other queries as well

Issue opened: #651

Thanks!

@shaspitz shaspitz merged commit eded908 into main Jan 9, 2023
@shaspitz shaspitz deleted the throttle-panic-cleanup branch January 9, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants