-
Notifications
You must be signed in to change notification settings - Fork 197
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
Ignore staking queue #3861
Ignore staking queue #3861
Changes from 11 commits
f9d87f9
36c8648
44677a9
afc619a
fb072e3
97d1d7d
5265146
3a8e998
30d48ca
f6b3a6e
b10b28e
3a59057
30c635d
e8c552c
c6b85c7
d2c6e9c
4fcc03f
6c2ae11
56b33f5
e25a573
4d27010
779733d
5fdc264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,12 @@ type stakingSC struct { | |
flagCorrectLastUnjailed atomic.Flag | ||
flagCorrectFirstQueued atomic.Flag | ||
flagCorrectJailedNotUnstakedEmptyQueue atomic.Flag | ||
flagStakingV4 atomic.Flag | ||
correctJailedNotUnstakedEmptyQueueEpoch uint32 | ||
correctFirstQueuedEpoch uint32 | ||
correctLastUnjailedEpoch uint32 | ||
stakingV2Epoch uint32 | ||
stakingV4Epoch uint32 | ||
walletAddressLen int | ||
mutExecution sync.RWMutex | ||
minNodePrice *big.Int | ||
|
@@ -138,13 +140,15 @@ func NewStakingSmartContract( | |
validatorToDelegationEnableEpoch: args.EpochConfig.EnableEpochs.ValidatorToDelegationEnableEpoch, | ||
correctFirstQueuedEpoch: args.EpochConfig.EnableEpochs.CorrectFirstQueuedEpoch, | ||
correctJailedNotUnstakedEmptyQueueEpoch: args.EpochConfig.EnableEpochs.CorrectJailedNotUnstakedEmptyQueueEpoch, | ||
stakingV4Epoch: args.EpochConfig.EnableEpochs.StakingV4EnableEpoch, | ||
} | ||
log.Debug("staking: enable epoch for stake", "epoch", reg.enableStakingEpoch) | ||
log.Debug("staking: enable epoch for staking v2", "epoch", reg.stakingV2Epoch) | ||
log.Debug("staking: enable epoch for correct last unjailed", "epoch", reg.correctLastUnjailedEpoch) | ||
log.Debug("staking: enable epoch for validator to delegation", "epoch", reg.validatorToDelegationEnableEpoch) | ||
log.Debug("staking: enable epoch for correct first queued", "epoch", reg.correctFirstQueuedEpoch) | ||
log.Debug("staking: enable epoch for correct jailed not unstaked with empty queue", "epoch", reg.correctJailedNotUnstakedEmptyQueueEpoch) | ||
log.Debug("staking: enable epoch for staking v4", "epoch", reg.stakingV4Epoch) | ||
|
||
var conversionOk bool | ||
reg.stakeValue, conversionOk = big.NewInt(0).SetString(args.StakingSCConfig.GenesisNodePrice, conversionBase) | ||
|
@@ -258,6 +262,10 @@ func (s *stakingSC) numSpareNodes() int64 { | |
} | ||
|
||
func (s *stakingSC) canStake() bool { | ||
if s.flagStakingV4.IsSet() { | ||
return true | ||
} | ||
|
||
stakeConfig := s.getConfig() | ||
return stakeConfig.StakedNodes < stakeConfig.MaxNumNodes | ||
} | ||
|
@@ -536,10 +544,12 @@ func (s *stakingSC) processStake(blsKey []byte, registrationData *StakedDataV2_0 | |
return nil | ||
} | ||
|
||
err := s.removeFromWaitingList(blsKey) | ||
if err != nil { | ||
s.eei.AddReturnMessage("error while removing from waiting") | ||
return err | ||
if !s.flagStakingV4.IsSet() { | ||
err := s.removeFromWaitingList(blsKey) | ||
if err != nil { | ||
s.eei.AddReturnMessage("error while removing from waiting") | ||
return err | ||
} | ||
} | ||
s.addToStakedNodes(1) | ||
s.activeStakingFor(registrationData) | ||
|
@@ -588,6 +598,7 @@ func (s *stakingSC) unStakeAtEndOfEpoch(args *vmcommon.ContractCallInput) vmcomm | |
if registrationData.Staked { | ||
s.removeFromStakedNodes() | ||
} | ||
|
||
if registrationData.Waiting { | ||
err = s.removeFromWaitingList(args.Arguments[0]) | ||
if err != nil { | ||
|
@@ -644,6 +655,11 @@ func (s *stakingSC) unStake(args *vmcommon.ContractCallInput) vmcommon.ReturnCod | |
} | ||
|
||
if !registrationData.Staked { | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.ExecutionFailed | ||
} | ||
|
||
registrationData.Waiting = false | ||
err = s.removeFromWaitingList(args.Arguments[0]) | ||
if err != nil { | ||
|
@@ -659,12 +675,14 @@ func (s *stakingSC) unStake(args *vmcommon.ContractCallInput) vmcommon.ReturnCod | |
return vmcommon.Ok | ||
} | ||
|
||
addOneFromQueue := !s.flagCorrectLastUnjailed.IsSet() || s.canStakeIfOneRemoved() | ||
if addOneFromQueue { | ||
_, err = s.moveFirstFromWaitingToStaked() | ||
if err != nil { | ||
s.eei.AddReturnMessage(err.Error()) | ||
return vmcommon.UserError | ||
if !s.flagStakingV4.IsSet() { | ||
addOneFromQueue := !s.flagCorrectLastUnjailed.IsSet() || s.canStakeIfOneRemoved() | ||
if addOneFromQueue { | ||
_, err = s.moveFirstFromWaitingToStaked() | ||
if err != nil { | ||
s.eei.AddReturnMessage(err.Error()) | ||
return vmcommon.UserError | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1147,6 +1165,10 @@ func createWaitingListKey(blsKey []byte) []byte { | |
} | ||
|
||
func (s *stakingSC) switchJailedWithWaiting(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
if !bytes.Equal(args.CallerAddr, s.endOfEpochAccessAddr) { | ||
s.eei.AddReturnMessage("switchJailedWithWaiting function not allowed to be called by address " + string(args.CallerAddr)) | ||
return vmcommon.UserError | ||
|
@@ -1289,6 +1311,12 @@ func (s *stakingSC) isNodeJailedOrWithBadRating(registrationData *StakedDataV2_0 | |
} | ||
|
||
func (s *stakingSC) getWaitingListIndex(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
s.eei.Finish([]byte{0}) | ||
|
||
return vmcommon.Ok | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you have return message than return vmcommon.UserError, and do not add to Finish anything. as it is ignored There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for heads up, refactored it |
||
} | ||
if !bytes.Equal(args.CallerAddr, s.stakeAccessAddr) { | ||
s.eei.AddReturnMessage("this is only a view function") | ||
return vmcommon.UserError | ||
|
@@ -1353,6 +1381,13 @@ func (s *stakingSC) getWaitingListIndex(args *vmcommon.ContractCallInput) vmcomm | |
} | ||
|
||
func (s *stakingSC) getWaitingListSize(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
s.eei.Finish([]byte{0}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you have return message than return vmcommon.UserError, and do not add to Finish anything. as it is ignored There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for heads up, refactored it |
||
|
||
return vmcommon.Ok | ||
} | ||
|
||
if args.CallValue.Cmp(zero) != 0 { | ||
s.eei.AddReturnMessage(vm.TransactionValueMustBeZero) | ||
return vmcommon.UserError | ||
|
@@ -1581,13 +1616,13 @@ func (s *stakingSC) getTotalNumberOfRegisteredNodes(args *vmcommon.ContractCallI | |
return vmcommon.UserError | ||
} | ||
|
||
stakeConfig := s.getConfig() | ||
waitingListHead, err := s.getWaitingListHead() | ||
if err != nil { | ||
s.eei.AddReturnMessage(err.Error()) | ||
return vmcommon.UserError | ||
} | ||
|
||
stakeConfig := s.getConfig() | ||
totalRegistered := stakeConfig.StakedNodes + stakeConfig.JailedNodes + int64(waitingListHead.Length) | ||
s.eei.Finish(big.NewInt(totalRegistered).Bytes()) | ||
return vmcommon.Ok | ||
|
@@ -1598,6 +1633,10 @@ func (s *stakingSC) resetLastUnJailedFromQueue(args *vmcommon.ContractCallInput) | |
// backward compatibility | ||
return vmcommon.UserError | ||
} | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
if !bytes.Equal(args.CallerAddr, s.endOfEpochAccessAddr) { | ||
s.eei.AddReturnMessage("stake nodes from waiting list can be called by endOfEpochAccess address only") | ||
return vmcommon.UserError | ||
|
@@ -1682,6 +1721,10 @@ func (s *stakingSC) stakeNodesFromQueue(args *vmcommon.ContractCallInput) vmcomm | |
s.eei.AddReturnMessage("invalid method to call") | ||
return vmcommon.UserError | ||
} | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
if !bytes.Equal(args.CallerAddr, s.endOfEpochAccessAddr) { | ||
s.eei.AddReturnMessage("stake nodes from waiting list can be called by endOfEpochAccess address only") | ||
return vmcommon.UserError | ||
|
@@ -1754,6 +1797,10 @@ func (s *stakingSC) cleanAdditionalQueue(args *vmcommon.ContractCallInput) vmcom | |
s.eei.AddReturnMessage("invalid method to call") | ||
return vmcommon.UserError | ||
} | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
if !bytes.Equal(args.CallerAddr, s.endOfEpochAccessAddr) { | ||
s.eei.AddReturnMessage("stake nodes from waiting list can be called by endOfEpochAccess address only") | ||
return vmcommon.UserError | ||
|
@@ -1964,6 +2011,10 @@ func (s *stakingSC) fixWaitingListQueueSize(args *vmcommon.ContractCallInput) vm | |
s.eei.AddReturnMessage("invalid method to call") | ||
return vmcommon.UserError | ||
} | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
|
||
if args.CallValue.Cmp(zero) != 0 { | ||
s.eei.AddReturnMessage(vm.TransactionValueMustBeZero) | ||
|
@@ -2035,6 +2086,10 @@ func (s *stakingSC) addMissingNodeToQueue(args *vmcommon.ContractCallInput) vmco | |
s.eei.AddReturnMessage("invalid method to call") | ||
return vmcommon.UserError | ||
} | ||
if s.flagStakingV4.IsSet() { | ||
s.eei.AddReturnMessage(vm.ErrWaitingListDisabled.Error()) | ||
return vmcommon.UserError | ||
} | ||
if args.CallValue.Cmp(zero) != 0 { | ||
s.eei.AddReturnMessage(vm.TransactionValueMustBeZero) | ||
return vmcommon.UserError | ||
|
@@ -2114,6 +2169,9 @@ func (s *stakingSC) EpochConfirmed(epoch uint32, _ uint64) { | |
|
||
s.flagCorrectJailedNotUnstakedEmptyQueue.SetValue(epoch >= s.correctJailedNotUnstakedEmptyQueueEpoch) | ||
log.Debug("stakingSC: correct jailed not unstaked with empty queue", "enabled", s.flagCorrectJailedNotUnstakedEmptyQueue.IsSet()) | ||
|
||
s.flagStakingV4.SetValue(epoch >= s.stakingV4Epoch) | ||
log.Debug("stakingSC: staking v4", "enabled", s.flagStakingV4.IsSet()) | ||
} | ||
|
||
// CanUseContract returns true if contract can be used | ||
|
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 file will need one big cleanup - like stakingV2 separate file and stakingV4 separate. Add a task in JIRA and we will see later.