-
Notifications
You must be signed in to change notification settings - Fork 330
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] Handling CandidateEndorsement Action #4020
Conversation
490a9b4
to
d226131
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #4020 +/- ##
==========================================
+ Coverage 75.38% 76.20% +0.81%
==========================================
Files 303 339 +36
Lines 25923 28862 +2939
==========================================
+ Hits 19541 21993 +2452
- Misses 5360 5746 +386
- Partials 1022 1123 +101 ☔ View full report in Codecov by Sentry. |
f369707
to
4285729
Compare
57e706b
to
0241d03
Compare
ab2e5ad
to
494acb0
Compare
if err != nil { | ||
return log, nil, err | ||
} | ||
return log, nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need if
, just return log, nil, err
} | ||
log.AddTopics(byteutil.Uint64ToBytesBigEndian(bucket.Index), bucket.Candidate.Bytes(), []byte{byteutil.BoolToByte(act.Endorse())}) | ||
|
||
var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move esm := NewEndorsementStateManager(csm.SM())
to here
var (
err error
esm = ...
)
if err := esm.Put(bucket.Index, &Endorsement{ | ||
ExpireHeight: endorsementNotExpireHeight, | ||
}); err != nil { | ||
return csmErrorToHandleError(caller.String(), err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for csm to use? i. e., when the value/type of err
is related to candidate error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i mean, it will return a regular err
, not the handleError
you may want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return regular err here, b/c the error returned must be some unknown errors from db
if err := esm.Put(bucket.Index, &Endorsement{ | ||
ExpireHeight: expireHeight, | ||
}); err != nil { | ||
return csmErrorToHandleError(caller.String(), err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
||
var err error | ||
if act.Endorse() { | ||
err = p.endorseCandidate(ctx, csm, esm, actCtx.Caller, bucket, cand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expireHeight = endorsementNotExpireHeight
if err := p.validateEndorsement(ctx, csm, esm, caller, bucket, cand); err != nil {
return err // wrap it
}
if act.Endorse() { | ||
err = p.endorseCandidate(ctx, csm, esm, actCtx.Caller, bucket, cand) | ||
} else { | ||
err = p.unEndorseCandidate(ctx, csm, esm, actCtx.Caller, bucket, cand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := validateWithdrawal(ctx, esm, caller, bucket); err != nil {
return err // wrap it
}
expireHeight = blkCtx.BlockHeight
if csm.ContainsSelfStakingBucket(bucket.Index) {
expireHeight += p.config.UnEndorseWaitingBlocks
}
} else { | ||
err = p.unEndorseCandidate(ctx, csm, esm, actCtx.Caller, bucket, cand) | ||
} | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := esm.Put(bucket.Index, &Endorsement{
ExpireHeight: expireHeight,
}); err != nil {
return log, nil, csmErrorToHandleError(caller.String(), err)
}
return log, nil, nil
|
||
expireHeight := blkCtx.BlockHeight | ||
if csm.ContainsSelfStakingBucket(bucket.Index) { | ||
expireHeight += p.config.UnEndorseWaitingBlocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the case for a regular (not self-stake) endorsed bucket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It expire immediately if the bucket is not self-staked, otherwise, expire after unendorse waiting period. Also added code comments for this
|
||
func (p *Protocol) validateUnEndorse(ctx context.Context, esm *EndorsementStateManager, caller address.Address, bucket *VoteBucket) ReceiptError { | ||
blkCtx := protocol.MustGetBlockCtx(ctx) | ||
if err := validateBucketOwner(bucket, caller); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to check other conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two checks should be enough:
- only bucket owner is authorized
- bucket should be endorsed
// new endorsement with not expire height | ||
if err := esm.Put(bucket.Index, &Endorsement{ | ||
ExpireHeight: endorsementNotExpireHeight, | ||
}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part is the same, can move to common end
uint64 expireHeight
if act.Endorse() {
xxx
expireHeight = endorsementNotExpireHeight,
} else {
xxx
expireHeight := protocol.MustGetBlockCtx(ctx).BlockHeight
if csm.ContainsSelfStakingBucket(bucket.Index) {
expireHeight += p.config.EndorsementWithdrawWaitingBlocks
}
}
esm.Put(bucket.Index, &Endorsement{
ExpireHeight: expireHeight,
}
@@ -31,30 +31,26 @@ func (p *Protocol) handleCandidateEndorsement(ctx context.Context, act *action.C | |||
log.AddTopics(byteutil.Uint64ToBytesBigEndian(bucket.Index), bucket.Candidate.Bytes(), []byte{byteutil.BoolToByte(act.Endorse())}) | |||
|
|||
esm := NewEndorsementStateManager(csm.SM()) | |||
// handle endorsement | |||
expireHeight := uint64(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use
var (
expireHeight uint64
esm = NewEndorsementStateManager(csm.SM())
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not my preference
@@ -31,30 +31,26 @@ func (p *Protocol) handleCandidateEndorsement(ctx context.Context, act *action.C | |||
log.AddTopics(byteutil.Uint64ToBytesBigEndian(bucket.Index), bucket.Candidate.Bytes(), []byte{byteutil.BoolToByte(act.Endorse())}) | |||
|
|||
esm := NewEndorsementStateManager(csm.SM()) | |||
// handle endorsement | |||
expireHeight := uint64(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not my preference
WithdrawWaitingPeriod: 3 * 24 * time.Hour, | ||
MinStakeAmount: unit.ConvertIotxToRau(100).String(), | ||
BootstrapCandidates: []BootstrapCandidate{}, | ||
EndorsementWithdrawWaitingBlocks: 24 * 60 * 60 / 5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the meaning of the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After submitting the endorsement withdraw action, it takes the waiting blocks for it to take effect. During this period, the delegate can continue to participate in consensus, and the bucket is locked, meaning it cannot be unstaked or voted to others.
|
||
esm := NewEndorsementStateManager(csm.SM()) | ||
expireHeight := uint64(0) | ||
if act.Endorse() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if act.IsEndorsed() {}
if err := validateBucketSelfStake(csm, bucket, false); err != nil { | ||
return err | ||
} | ||
return validateBucketEndorsement(esm, bucket, false, protocol.MustGetBlockCtx(ctx).BlockHeight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be as the method of endorsement object
68bfced
to
df180c4
Compare
Quality Gate failedFailed conditions 4.7% Duplication on New Code (required ≤ 3%) |
Description
Implement action handling for
CandidateEndorsement
Fixes #(issue)
Type of change
Please delete options that are not relevant.
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
Test Configuration:
Checklist: