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

[staking] Cannot withdraw endorsement if it is withdrawing #4179

Merged
merged 8 commits into from
Mar 14, 2024

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Mar 12, 2024

Description

PR includes the following changes:

  • refactor endorsement validation
  • cannot withdraw endorsement if it is withdrawing
  • add tests for endorsement feature

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 76.11%. Comparing base (e1f0636) to head (7c41eae).
Report is 202 commits behind head on master.

Files Patch % Lines
action/protocol/staking/endorsement.go 0.00% 10 Missing ⚠️
action/protocol/staking/bucket_validation.go 68.96% 6 Missing and 3 partials ⚠️
...ction/protocol/staking/endorsement_statemanager.go 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4179      +/-   ##
==========================================
+ Coverage   75.38%   76.11%   +0.73%     
==========================================
  Files         303      340      +37     
  Lines       25923    29229    +3306     
==========================================
+ Hits        19541    22248    +2707     
- Misses       5360     5872     +512     
- Partials     1022     1109      +87     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return validateBucketEndorsementByStatus(esm, bucket, status, height)
}

func validateBucketEndorsementByStatus(esm *EndorsementStateManager, bucket *VoteBucket, status EndorsementStatus, height uint64) ReceiptError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Efficiency is not the first thing to consider in this case, thus this refactor is not suggested.

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted

return &handleError{
err: errors.New("bucket is already endorsed"),
err: errors.Errorf("bucket endorsement is not in status %d", status),
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is very confusing especially in this return error.

Copy link
Member Author

Choose a reason for hiding this comment

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

add EndorsementStatus.String() method to improve readability

@@ -118,14 +118,14 @@ func TestValidateBucket(t *testing.T) {
// endorsed bucket
r.NoError(esm.Put(bktIdx, &Endorsement{ExpireHeight: endorsementNotExpireHeight}))
r.Nil(validateBucketEndorsement(esm, bkt, true, blkHeight))
r.ErrorContains(validateBucketEndorsement(esm, bkt, false, blkHeight), "bucket is already endorsed")
r.ErrorContains(validateBucketEndorsement(esm, bkt, false, blkHeight), "bucket endorsement is not in status 9")
Copy link
Collaborator

Choose a reason for hiding this comment

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

for example, 9 is not straightforward to understand

@envestcc envestcc requested a review from CoderZhi March 13, 2024 09:49
failureStatus: iotextypes.ReceiptStatus_ErrUnknown,
}
}
if status != Endorsed && status != UnEndorsing {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified if status == EndorseExpired

Copy link

sonarcloud bot commented Mar 14, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
7.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@envestcc envestcc merged commit a5b7ef8 into iotexproject:master Mar 14, 2024
2 of 5 checks passed
@envestcc envestcc deleted the pr-test branch March 14, 2024 09:27
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.

3 participants