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 Unstake if Bucket is Endorsed #4134

Merged
merged 5 commits into from
Mar 6, 2024

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Feb 6, 2024

Description

After delegate endorsement introduced, we cannot unstake bucket if it's a endorse bucket.

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)

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 Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.38%. Comparing base (e1f0636) to head (a06a141).
Report is 186 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4134      +/-   ##
==========================================
+ Coverage   75.38%   76.38%   +1.00%     
==========================================
  Files         303      340      +37     
  Lines       25923    28973    +3050     
==========================================
+ Hits        19541    22132    +2591     
- Misses       5360     5733     +373     
- Partials     1022     1108      +86     

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

@@ -175,6 +175,10 @@ func (p *Protocol) handleUnstake(ctx context.Context, act *action.Unstake, csm C
failureStatus: iotextypes.ReceiptStatus_ErrUnstakeBeforeMaturity,
}
}
if rErr := validateBucketEndorsement(NewEndorsementStateManager(csm.SM()), bucket, false, blkCtx.BlockHeight); rErr != nil {
return log, rErr
Copy link
Member

Choose a reason for hiding this comment

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

in func validateBucketEndorsement(

case errors.Is(err, state.ErrStateNotExist):
		if isEndorsed {
			return &handleError{
				err:           errors.New("bucket is not endorsed"),
				failureStatus: iotextypes.ReceiptStatus_ErrInvalidBucketType,
			}
		}

should return

				err:           errors.New("bucket is not an endorse bucket"),
				failureStatus: iotextypes.ReceiptStatus_ErrInvalidBucketIndex,

since the bucket is not an endorse bucket

Copy link
Member

Choose a reason for hiding this comment

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

and then if it returns this error, it should be fine to continue?

Copy link
Member Author

Choose a reason for hiding this comment

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

returning error means validation failed, should not continue

Copy link
Member

Choose a reason for hiding this comment

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

ok, fix the error return

@@ -96,7 +96,7 @@ func validateBucketEndorsement(esm *EndorsementStateManager, bucket *VoteBucket,
case errors.Is(err, state.ErrStateNotExist):
if isEndorsed {
return &handleError{
err: errors.New("bucket is not endorsed"),
err: errors.New("bucket is not an endorse bucket"),
Copy link
Contributor

Choose a reason for hiding this comment

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

The error here is the same as the error on line 86 above, and it is best to distinguish 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.

okay

Copy link

sonarcloud bot commented Mar 6, 2024

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarCloud

@envestcc envestcc merged commit 6f8c37d into iotexproject:master Mar 6, 2024
3 of 5 checks passed
@envestcc envestcc deleted the pr-unstake branch March 6, 2024 12:25
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