Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jan 22, 2024
1 parent c4685df commit 05515a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions action/protocol/staking/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func (d *Candidate) Validate() error {
return nil
}

// selfStaked checks if the candidate is self staked
func (d *Candidate) selfStaked() bool {
return d.SelfStakeBucketIdx != candidateNoSelfStakeBucketIndex && d.SelfStake.Sign() > 0
// isSelfStakeBucketSettled checks if self stake bucket is settled
func (d *Candidate) isSelfStakeBucketSettled() bool {
return d.SelfStakeBucketIdx != candidateNoSelfStakeBucketIndex
}

// Collision checks collsion of 2 candidates
Expand All @@ -110,7 +110,7 @@ func (d *Candidate) Collision(c *Candidate) error {
if address.Equal(c.Operator, d.Operator) {
return ErrInvalidOperator
}
if c.SelfStakeBucketIdx == d.SelfStakeBucketIdx && c.selfStaked() {
if c.SelfStakeBucketIdx == d.SelfStakeBucketIdx && c.isSelfStakeBucketSettled() {
return ErrInvalidSelfStkIndex
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions action/protocol/staking/candidate_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (cc *candChange) containsOperator(operator address.Address) bool {

func (cc *candChange) containsSelfStakingBucket(index uint64) bool {
for _, d := range cc.dirty {
if d.selfStaked() && index == d.SelfStakeBucketIdx {
if d.isSelfStakeBucketSettled() && index == d.SelfStakeBucketIdx {
return true
}
}
Expand Down Expand Up @@ -398,7 +398,7 @@ func (cc *candChange) getByOwner(owner address.Address) *Candidate {

func (cc *candChange) getBySelfStakingIndex(index uint64) *Candidate {
for _, d := range cc.dirty {
if d.selfStaked() && index == d.SelfStakeBucketIdx {
if d.isSelfStakeBucketSettled() && index == d.SelfStakeBucketIdx {
return d.Clone()
}
}
Expand Down Expand Up @@ -484,7 +484,7 @@ func (cb *candBase) commit(change *candChange, keepAliasBug bool) (int, error) {
cb.ownerMap[d.Owner.String()] = d
cb.nameMap[d.Name] = d
cb.operatorMap[d.Operator.String()] = d
if d.selfStaked() {
if d.isSelfStakeBucketSettled() {
cb.selfStkBucketMap[d.SelfStakeBucketIdx] = d
}
}
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/staking/candidate_center_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func testEqual(m *CandidateCenter, l CandidateList) bool {
}

d = m.GetBySelfStakingIndex(v.SelfStakeBucketIdx)
if d == nil && v.selfStaked() {
if d == nil && v.isSelfStakeBucketSettled() {
return false
}
if d != nil && !v.Equal(d) {
Expand Down

0 comments on commit 05515a7

Please sign in to comment.