-
Notifications
You must be signed in to change notification settings - Fork 201
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
FIX: Possible backwards incompatibilities fixes #6110
Changes from all commits
760a767
a47a099
c655353
f8151b1
f5e038b
e1d0f11
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 |
---|---|---|
|
@@ -207,7 +207,7 @@ func (s *legacySystemSCProcessor) processLegacy( | |
return err | ||
} | ||
|
||
if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { | ||
if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { | ||
err = s.stakeNodesFromQueue(validatorsInfoMap, numUnStaked, nonce, common.NewList) | ||
if err != nil { | ||
return err | ||
|
@@ -292,8 +292,7 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( | |
stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) | ||
validatorLeaving := validatorInfo.ShallowClone() | ||
validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) | ||
err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) | ||
log.LogIfError(err) | ||
s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) | ||
} | ||
|
||
err = s.updateDelegationContracts(mapOwnersKeys) | ||
|
@@ -430,16 +429,28 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa | |
} | ||
|
||
if deleteCalled { | ||
err := validatorsInfoMap.SetValidatorsInShard(shId, newList) | ||
if err != nil { | ||
return err | ||
} | ||
s.setValidatorsInShard(validatorsInfoMap, shId, newList) | ||
raduchis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *legacySystemSCProcessor) setValidatorsInShard( | ||
validatorsInfoMap state.ShardValidatorsInfoMapHandler, | ||
shardID uint32, | ||
validators []state.ValidatorInfoHandler, | ||
) { | ||
err := validatorsInfoMap.SetValidatorsInShard(shardID, validators) | ||
if err == nil { | ||
return | ||
} | ||
|
||
// this should never happen, but replace them anyway, as in old legacy code | ||
log.Error("legacySystemSCProcessor.setValidatorsInShard", "error", err) | ||
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 there is an error on the validatorsInfoMap.SetValidatorsInShard(shardID, validators) with StakingV4 activated, should not an error be returned, and not try the legacy? 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. I didn't want to return error in that case and block execution. Not a strong opinion if we should return error, though 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. it looks like the new version will be never used here... if it fails for any reason, the old version will be used, and the new checks are 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.
|
||
validatorsInfoMap.SetValidatorsInShardUnsafe(shardID, validators) | ||
} | ||
|
||
func (s *legacySystemSCProcessor) prepareStakingDataForEligibleNodes(validatorsInfoMap state.ShardValidatorsInfoMapHandler) error { | ||
eligibleNodes, err := getEligibleNodeKeys(validatorsInfoMap) | ||
if err != nil { | ||
|
@@ -587,14 +598,21 @@ func (s *legacySystemSCProcessor) updateMaxNodes(validatorsInfoMap state.ShardVa | |
return err | ||
} | ||
|
||
if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { | ||
sw.Start("stakeNodesFromQueue") | ||
err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) | ||
sw.Stop("stakeNodesFromQueue") | ||
if err != nil { | ||
return err | ||
} | ||
if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { | ||
return nil | ||
} | ||
|
||
if maxNumberOfNodes < prevMaxNumberOfNodes { | ||
return epochStart.ErrInvalidMaxNumberOfNodes | ||
} | ||
|
||
sw.Start("stakeNodesFromQueue") | ||
err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) | ||
sw.Stop("stakeNodesFromQueue") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -752,8 +770,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( | |
} | ||
|
||
newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) | ||
err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) | ||
log.LogIfError(err) | ||
s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) | ||
|
||
return blsPubKey, nil | ||
} | ||
|
@@ -762,14 +779,21 @@ func (s *legacySystemSCProcessor) replaceValidators( | |
old state.ValidatorInfoHandler, | ||
new state.ValidatorInfoHandler, | ||
validatorsInfoMap state.ShardValidatorsInfoMapHandler, | ||
) error { | ||
stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) | ||
if stakingV4Enabled { | ||
return validatorsInfoMap.Replace(old, new) | ||
) { | ||
// legacy code | ||
if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { | ||
_ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) | ||
return | ||
} | ||
|
||
_ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) | ||
return nil | ||
// try with new code which does extra validity checks. | ||
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. this should not "try" something... are the new checks used in other places? how is the error handling there? if any new check fails and we revert to the old... we could just do the old... 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 this also fails, do legacy code | ||
if err := validatorsInfoMap.Replace(old, new); err != nil { | ||
log.Error("legacySystemSCProcessor.replaceValidators", "error", err) | ||
|
||
replaced := validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) | ||
log.Debug("legacySystemSCProcessor.replaceValidators", "old", old.GetPublicKey(), "new", new.GetPublicKey(), "was replace successful", replaced) | ||
} | ||
} | ||
|
||
func isValidator(validator state.ValidatorInfoHandler) bool { | ||
|
@@ -1219,11 +1243,6 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( | |
return err | ||
} | ||
|
||
err = peerAcc.SetBLSPublicKey(blsKey) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
peerAcc.SetListAndIndex(peerAcc.GetShardId(), string(list), uint32(nonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) | ||
peerAcc.SetTempRating(s.startRating) | ||
peerAcc.SetUnStakedEpoch(common.DefaultUnstakedEpoch) | ||
|
@@ -1244,22 +1263,32 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( | |
AccumulatedFees: big.NewInt(0), | ||
} | ||
|
||
existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) | ||
// This fix is not be backwards incompatible | ||
if !check.IfNil(existingValidator) && s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { | ||
err = validatorsInfoMap.Delete(existingValidator) | ||
if err != nil { | ||
return err | ||
} | ||
err = s.addNewValidator(validatorsInfoMap, validatorInfo) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *legacySystemSCProcessor) addNewValidator( | ||
validatorsInfoMap state.ShardValidatorsInfoMapHandler, | ||
validatorInfo state.ValidatorInfoHandler, | ||
) error { | ||
if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { | ||
return validatorsInfoMap.Add(validatorInfo) | ||
} | ||
|
||
err = validatorsInfoMap.Add(validatorInfo) | ||
existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) | ||
if !check.IfNil(existingValidator) { | ||
err := validatorsInfoMap.Delete(existingValidator) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
return validatorsInfoMap.Add(validatorInfo) | ||
} | ||
|
||
func (s *legacySystemSCProcessor) initESDT() error { | ||
|
@@ -1277,7 +1306,7 @@ func (s *legacySystemSCProcessor) extractConfigFromESDTContract() ([][]byte, err | |
CallerAddr: s.endOfEpochCallerAddress, | ||
Arguments: [][]byte{}, | ||
CallValue: big.NewInt(0), | ||
GasProvided: math.MaxUint64, | ||
GasProvided: math.MaxInt64, | ||
raduchis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
Function: "getContractConfig", | ||
RecipientAddr: vm.ESDTSCAddress, | ||
|
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 bool stakingV4Enabled should be removed from the SetListAndIndex.
I think it should be called SetListAndIndexUpdatePrevious and should always update the previous list and index.
For the previous/backwards compatible version just the SetList should be called on a different if branch
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.
From my point of view, this would create too much overhead without any noticeable benefit.
This func is already backwards compatible and is better to only have one func, so that it is not mistakenly used after stakingV4, since we rely that previous values are always updated
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 benefit would be a cleaner code: in the future SetListAndIndex will be used always with the updatePrevious. All future calls will get a "legacy" argument always true.
could remain like this and be refactored in the future.