Skip to content

Conversation

@envestcc
Copy link
Member

Description

Due to the introduction of CandidateRegister without staking, there will occur candidate which lack staking and updates in self-staking bucket. However, the current CandidateCenter does not support these operations. This PR aims to resolve these issues.

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

@codecov
Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 541 lines in your changes are missing coverage. Please review.

Comparison is base (e1f0636) 75.38% compared to head (7bc3b6d) 76.20%.
Report is 164 commits behind head on master.

Files Patch % Lines
action/protocol/staking/staking_statereader.go 69.76% 35 Missing and 17 partials ⚠️
action/protocol/execution/evm/evm.go 48.38% 47 Missing and 1 partial ⚠️
api/coreservice.go 63.24% 37 Missing and 6 partials ⚠️
api/web3server.go 79.24% 30 Missing and 3 partials ⚠️
action/candidate_endorsement.go 0.00% 31 Missing ⚠️
action/protocol/staking/protocol.go 36.36% 28 Missing ⚠️
action/candidate_activate.go 0.00% 25 Missing ⚠️
...tion/protocol/staking/contractstake_bucket_type.go 0.00% 24 Missing ⚠️
action/protocol/rewarding/fund.go 23.07% 19 Missing and 1 partial ⚠️
api/websocket.go 0.00% 20 Missing ⚠️
... and 43 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4060      +/-   ##
==========================================
+ Coverage   75.38%   76.20%   +0.82%     
==========================================
  Files         303      338      +35     
  Lines       25923    28811    +2888     
==========================================
+ Hits        19541    21956    +2415     
- Misses       5360     5737     +377     
- Partials     1022     1118      +96     

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

@envestcc envestcc force-pushed the pr_collision branch 2 times, most recently from 05515a7 to dd2b789 Compare January 22, 2024 10:30
checkCandidates(candcenter, cands)
// commit
r.NoError(candcenter.Commit())
checkCandidates(candcenter, cands)
Copy link
Contributor

Choose a reason for hiding this comment

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

just use r.True(testEqual(candcenter, CandidateList(cands)))? adding this func does not re-use code or reduce code duplication

// add candidates
r.NoError(candcenter.Upsert(candStaked))
r.NoError(candcenter.Upsert(candNonStaked1))
r.NoError(candcenter.Upsert(candNonStaked2))
Copy link
Contributor

Choose a reason for hiding this comment

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

add more test cases:

  1. adding candidate with candNonStaked1/2's owner, name, operator will lead to collision
  2. move the update candidate test below here, can combine the 2 tests to reduce code duplication

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, but Upsert will not collision on owner, updated instead

r.False(candcenter.ContainsSelfStakingBucket(candStaked.SelfStakeBucketIdx))
t.Run("nonstaked candidate not collision on bucket", func(t *testing.T) {
candcenter, err := NewCandidateCenter(nil)
r.NoError(err)
Copy link
Contributor

@dustinxie dustinxie Jan 26, 2024

Choose a reason for hiding this comment

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

add a valid candidate candStaked to candcenter

candUpdated := candStaked.Clone()
candUpdated.SelfStakeBucketIdx = 2
r.NoError(candcenter.Upsert(candUpdated))
checkCandidates(candcenter, []*Candidate{candUpdated})
Copy link
Contributor

Choose a reason for hiding this comment

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

r.False(candcenter.ContainsSelfStakingBucket(candStaked.SelfStakeBucketIdx))
this is a good test line to keep

})
t.Run("nonstaked candidate collision on operator", func(t *testing.T) {
candcenter, err := NewCandidateCenter(nil)
r.NoError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

add a valid candidate candStaked to candcenter

candcenter, err := NewCandidateCenter(nil)
r.NoError(err)
r.NoError(candcenter.Upsert(candNonStaked1))
r.ErrorIs(candcenter.Upsert(candNonStaked1ColOpt), ErrInvalidOperator)
Copy link
Contributor

Choose a reason for hiding this comment

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

can combine the next test into here by just adding 1 line:
r.ErrorIs(candcenter.Upsert(candNonStaked1ColName), action.ErrInvalidCanName)

r.ErrorIs(candcenter.Upsert(candNonStaked1ColOpt), ErrInvalidOperator)
checkCandidates(candcenter, []*Candidate{candNonStaked1})
})
t.Run("nonstaked candidate collision on name", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

merge into previous test


// isSelfStakeBucketSettled checks if self stake bucket is settled
func (d *Candidate) isSelfStakeBucketSettled() bool {
return d.SelfStakeBucketIdx != candidateNoSelfStakeBucketIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

candidateNoSelfStakeBucketIndex is a special value?

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, it means candidate has not already been self-staked

Copy link
Member

Choose a reason for hiding this comment

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

rename to `_candidateNoSelfStakeBucketIndex``

Copy link
Member

Choose a reason for hiding this comment

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

what does it mean a self stake bucket is settled?

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is used to wrap the code d.SelfStakeBucketIdx != candidateNoSelfStakeBucketIndex to avoid making this judgement in multiple places.

Basically, it returns true in three cases:

  • Candidate Activated: The candidate is in an active state and has a valid SelfStakeBucketIdx(the bucket can be self-owned or endorsed).
  • Candidate Endorsement Expired: The endorsement of the candidate has expired (since the expiration of endorsement takes effect with delay, the SelfStakeBucketIdx will not be cleared before performing other operations on the bucket).
  • Candidate Unstaked: The candidate has been unstaked (currently, the implementation of unstake does not clear the SelfStakeBucketIdx, but it might be more appropriate to clear it).

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

2 New issues
0 Security Hotspots
No data about Coverage
2.9% Duplication on New Code

See analysis details on SonarCloud

@envestcc envestcc merged commit 56eeca0 into iotexproject:master Jan 30, 2024
@envestcc envestcc deleted the pr_collision branch January 30, 2024 12:39
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