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

QGB State machine error handling #550

Merged

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Jul 20, 2022

Improves error handling in state machine. It follows the following thinking:

  • If the state machine is automatically setting something, example, attestation requests, it should panic if something goes wrong.
  • If the state machine is getting something from store:
    • either panic for the state that necessarily needs to exist, such as LastAttestationNonce.
    • return (value, found, error) in other cases to know if element doesn't exist or some error occurred.
  • If the state machine is receiving requests from users getting/setting stuff, like setting a confirm:
    • The keepers should return (value, found, error) to know if an element doesn't exist or some error occurred.
    • The queries would return RequestResponse{ element: nil }, nil if the element doesn't exit and uses will need to do their checks.

Closes: #437

@rach-id rach-id self-assigned this Jul 20, 2022
@rach-id rach-id added the C: QGB label Jul 20, 2022
@rach-id rach-id marked this pull request as draft July 20, 2022 10:13
@rach-id rach-id changed the title State machine error handling QGB State machine error handling Jul 20, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #550 (ed935b1) into qgb-integration (13347c0) will decrease coverage by 0.05%.
The diff coverage is 18.69%.

@@                Coverage Diff                 @@
##           qgb-integration    #550      +/-   ##
==================================================
- Coverage             9.68%   9.63%   -0.06%     
==================================================
  Files                   55      55              
  Lines                 9379    9408      +29     
==================================================
- Hits                   908     906       -2     
- Misses                8395    8423      +28     
- Partials                76      79       +3     
Impacted Files Coverage Δ
x/qgb/keeper/keeper_attestation.go 22.00% <0.00%> (-4.54%) ⬇️
x/qgb/keeper/keeper_valset.go 27.11% <0.00%> (-4.89%) ⬇️
x/qgb/keeper/msg_server.go 0.00% <0.00%> (ø)
x/qgb/keeper/query_attestation.go 0.00% <0.00%> (ø)
x/qgb/orchestrator/test/mock_querier.go 16.27% <0.00%> (ø)
x/qgb/types/query.pb.go 0.72% <ø> (ø)
x/qgb/keeper/query_valset_confirm.go 76.92% <40.00%> (-23.08%) ⬇️
x/qgb/keeper/query_data_commitment_confirm.go 63.33% <70.00%> (-8.10%) ⬇️
x/qgb/keeper/keeper_valset_confirm.go 83.33% <71.42%> (+16.66%) ⬆️
x/qgb/keeper/keeper_data_commitment_confirm.go 52.63% <80.00%> (+9.77%) ⬆️
... and 6 more

@rach-id rach-id marked this pull request as ready for review July 21, 2022 09:26
@rach-id rach-id requested a review from evan-forbes July 21, 2022 09:26
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

nice! I like this a lot. Really good work as per usual

Comment on lines +49 to +50
// Too heavy, shouldn't mainly be used.
// Returns empty array if no element is found.
Copy link
Member

Choose a reason for hiding this comment

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

do you think we might be able to get rid of this in the future? We inherited this from the gravity bridge module's code iirc, and I think we might be able to design around it.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, definitely, it has to do with indexing. If we start double indexing data using multiple keys, we can define iterators with more specific store ranges, and it would be way faster

Copy link
Member Author

Choose a reason for hiding this comment

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

We should investigate however the storage cost if it is worth it compared to the gained performance

Copy link
Member Author

Choose a reason for hiding this comment

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

opened issue: #552

x/qgb/keeper/keeper_valset.go Outdated Show resolved Hide resolved
if !found {
panic(sdkerrors.Wrap(
types.ErrNilAttestation,
fmt.Sprintf("stumbeled upon nil attestation for nonce %d", i),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf("stumbeled upon nil attestation for nonce %d", i),
fmt.Sprintf("found nil attestation for nonce %d", i),

alternatively this

x/qgb/keeper/keeper_valset.go Outdated Show resolved Hide resolved
rach-id and others added 2 commits July 21, 2022 14:29
Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com>
Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com>
@rach-id rach-id merged commit f2168c7 into celestiaorg:qgb-integration Jul 21, 2022
@rach-id rach-id deleted the state_machine_error_handling branch July 21, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants