Skip to content

Commit

Permalink
feat(bpos): check lock time of renewal target
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Oct 26, 2023
1 parent ca1bdf4 commit e61b82d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func GetDefaultParams() *Configuration {
DexStartHeight: math.MaxUint32, // todo complete me
ChangeVoteTargetStartHeight: math.MaxUint32, // todo complete me
RenewalVotingTargetDuration: 14 * 720, // todo complete me
MinRenewalVotingTargetLockTime: 720, // todo complete me
OriginArbiters: []string{
"0248df6705a909432be041e0baa25b8f648741018f70d1911f2ed28778db4b8fe4",
"02771faf0f4d4235744b30972d5f2c470993920846c761e4d08889ecfdc061cddf",
Expand Down Expand Up @@ -391,6 +392,7 @@ func (p *Configuration) TestNet() *Configuration {
p.DPoSConfiguration.DexStartHeight = 1171000
p.DPoSConfiguration.ChangeVoteTargetStartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.RenewalVotingTargetDuration = 14 * 720 // todo complete me
p.DPoSConfiguration.MinRenewalVotingTargetLockTime = 720 // todo complete me

p.HttpInfoPort = 21333
p.HttpRestPort = 21334
Expand Down Expand Up @@ -525,6 +527,7 @@ func (p *Configuration) RegNet() *Configuration {
p.DPoSConfiguration.DexStartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.ChangeVoteTargetStartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.RenewalVotingTargetDuration = 14 * 720 // todo complete me
p.DPoSConfiguration.MinRenewalVotingTargetLockTime = 720 // todo complete me

p.MemoryPoolTxMaximumStayHeight = 10

Expand Down Expand Up @@ -749,7 +752,9 @@ type DPoSConfiguration struct {
// ChangeVoteTargetStartHeight defines the starting height for allowing changes to the voting target.
ChangeVoteTargetStartHeight uint32 `screw:"--changevotetargetstartheight" usage:"the starting height for allowing changes to the voting target"`
// RenewalVotingTargetDuration defines the duration of renewal voting target.
RenewalVotingTargetDuration uint32 `crrew:"--renewalvotingtargetduration" usage:"the duration of renewal voting target"`
RenewalVotingTargetDuration uint32 `crew:"--renewalvotingtargetduration" usage:"the duration of renewal voting target"`
// MinRenewalVotingTargetLockTime defines the min lock time of renewal voting target.
MinRenewalVotingTargetLockTime uint32 `crew:"--minrenewalvotingtargetlocktime" usage:"the min lock time of renewal voting target"`
}

type CRConfiguration struct {
Expand Down
5 changes: 3 additions & 2 deletions core/transaction/voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ func (t *VotingTransaction) SpecialContextCheck() (result elaerr.ELAError, end b
if content.VotesInfo.LockTime-blockHeight > t.parameters.Config.DPoSConfiguration.DPoSV2MaxVotesLockTime {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("invalid lock time > DPoSV2MaxVotesLockTime")), true
}
if content.VotesInfo.LockTime-blockHeight <= t.parameters.Config.DPoSConfiguration.RenewalVotingTargetDuration {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("invalid lock time <= RenewalVotingTargetDuration")), true
if content.VotesInfo.LockTime-blockHeight <= t.parameters.Config.DPoSConfiguration.MinRenewalVotingTargetLockTime+
t.parameters.Config.DPoSConfiguration.RenewalVotingTargetDuration {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("invalid lock time")), true
}
if bytes.Equal(oriVote.Info[0].Candidate, content.VotesInfo.Candidate) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("candidate should not be the same one")), true
Expand Down

0 comments on commit e61b82d

Please sign in to comment.