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

fix: check latest attestation nonce before getting it #1638

Merged
merged 10 commits into from
Apr 28, 2023

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Apr 20, 2023

Overview

Closes #1637

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@rach-id rach-id added the x/qgb label Apr 20, 2023
@rach-id rach-id self-assigned this Apr 20, 2023
@MSevey MSevey requested review from a team and staheri14 and removed request for a team April 20, 2023 13:34
@MSevey MSevey requested a review from a team April 20, 2023 13:36
evan-forbes
evan-forbes previously approved these changes Apr 24, 2023
x/qgb/keeper/keeper_data_commitment.go Outdated Show resolved Hide resolved
Comment on lines +23 to +25
if !k.CheckLatestAttestationNonce(ctx) {
return nil, types.ErrLatestAttestationNonceStillNotInitialized
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's just a problem with the querier, then why do all the other functions have this check. Can't we just add the check in the query methods only?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's an issue with the querier, yes. But, I figured to add the checks also in other places, even if I think they won't be hit, but still there might be some edge case where the value does not exist and might end up causing a panic in the state machine. Maybe after an upgrade, or a hardfork, etc.
So, I added the checks everywhere for more safety.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to initialise with a random value in the genesis i.e. have a nonce of 0 (which could be invalid but avoids panicking)?

Copy link
Member Author

Choose a reason for hiding this comment

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

The genesis actually initializes the value with 0. However, whichever value is set at genesis, it will be incremented. So, there is no guarantees that the nonces will start at 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, just to clarify where I'm coming from. It's okay if we want to be defensive in our programming but we should also balance that with making the code as easy to read as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, I guess after we audit this implementation and be sure that no panic would occur, we can get rid of the extra checks. I don't want the QGB module to cause a network halt at some point or be a pain to deal with while it's still not audited :D

evan-forbes
evan-forbes previously approved these changes Apr 25, 2023
x/qgb/keeper/query_attestation.go Show resolved Hide resolved
@evan-forbes evan-forbes added this to the Mainnet milestone Apr 27, 2023
rootulp
rootulp previously approved these changes Apr 27, 2023
test/util/common.go Outdated Show resolved Hide resolved
test/util/common.go Outdated Show resolved Hide resolved
test/util/common.go Outdated Show resolved Hide resolved
test/util/common.go Outdated Show resolved Hide resolved
@rach-id rach-id dismissed stale reviews from rootulp and evan-forbes via c164eb4 April 27, 2023 19:55
rach-id and others added 2 commits April 27, 2023 21:55
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
@MSevey MSevey requested a review from a team April 27, 2023 19:55
rach-id and others added 2 commits April 27, 2023 21:56
Co-authored-by: Rootul P <rootulp@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #1638 (607c500) into main (309c650) will increase coverage by 0.80%.
The diff coverage is 72.72%.

@@            Coverage Diff             @@
##             main    #1638      +/-   ##
==========================================
+ Coverage   50.98%   51.79%   +0.80%     
==========================================
  Files          92       95       +3     
  Lines        5749     5976     +227     
==========================================
+ Hits         2931     3095     +164     
- Misses       2519     2567      +48     
- Partials      299      314      +15     
Impacted Files Coverage Δ
pkg/wrapper/nmt_wrapper.go 80.43% <ø> (+3.35%) ⬆️
x/qgb/keeper/keeper_attestation.go 73.58% <ø> (ø)
x/qgb/keeper/query_attestation.go 0.00% <0.00%> (ø)
x/qgb/keeper/keeper_data_commitment.go 65.71% <70.00%> (+12.38%) ⬆️
x/qgb/keeper/keeper_valset.go 33.85% <100.00%> (+6.73%) ⬆️

... and 10 files with indirect coverage changes

@rach-id rach-id merged commit 53e68f3 into celestiaorg:main Apr 28, 2023
24 checks passed
evan-forbes pushed a commit that referenced this pull request May 1, 2023
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

Closes #1637

<!--
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue.
-->

<!--
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [ ] New and updated code has appropriate documentation
- [ ] New and updated code has new and/or updated testing
- [ ] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords

---------

Co-authored-by: Rootul P <rootulp@gmail.com>
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.

QGB check latest attestation nonce existence before getting it
5 participants