Skip to content
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

Merged
merged 6 commits into from
Apr 16, 2024

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Apr 8, 2024

Reasoning behind the pull request

  • Possible backwards incompatibility issues

@mariusmihaic mariusmihaic self-assigned this Apr 8, 2024
@mariusmihaic mariusmihaic marked this pull request as ready for review April 8, 2024 13:29
Base automatically changed from backward-incompatibility-fix-for-replace to fix-backwards-compatibility-problem-2024.04.03 April 10, 2024 13:44
sasurobert
sasurobert previously approved these changes Apr 11, 2024
@@ -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)
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

epochStart/metachain/legacySystemSCs.go Show resolved Hide resolved
}

// this should never happen, but replace them anyway, as in old legacy code
log.Error("legacySystemSCProcessor.setValidatorsInShard", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err := validatorsInfoMap.SetValidatorsInShard(shardID, validators) is actually the new version

return epochStart.ErrInvalidMaxNumberOfNodes
}
}

if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this flag is needed... on the old version of the systemSC this was not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mandatory to be there, that flag says:

  • if there is still a staking queue (so staking v4 not started)
  • stake nodes from queue
    We don't want to have anything to do with the queue once stakingV4 is started

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after a closer inspection, it looks like the
s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) equals !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)
it could be refactored so that only the StakingV4StartedFlag is used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed StakingQueueFlag

}

_ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId())
return nil
// try with new code which does extra validity checks.
Copy link
Contributor

Choose a reason for hiding this comment

The 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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Replace is used in 2 other places (after stakingV4 is enabled), where we correctly call the functiona and return error if exists, since that is new code and I tried to correctly use the func

epochStart/metachain/legacySystemSCs.go Show resolved Hide resolved
Base automatically changed from fix-backwards-compatibility-problem-2024.04.03 to rc/v1.7.0 April 12, 2024 13:30
@gabi-vuls gabi-vuls dismissed sasurobert’s stale review April 12, 2024 13:30

The base branch was changed.

Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal allin test: v1.6.15-dev-config-eb2e06c06d -> MX-15351-backwards-compat--e1d0f11464

--- Specific errors ---

block hash does not match 368
wrong nonce in block 316
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 0
Nr. of all WARNS: 229
Nr. of new ERRORS: 0
Nr. of new WARNS: 8
Nr. of PANICS: 0

/------/

--- ERRORS ---

/------/

--- WARNINGS ---

/------/

@mariusmihaic mariusmihaic merged commit 560b15b into rc/v1.7.0 Apr 16, 2024
8 checks passed
@mariusmihaic mariusmihaic deleted the MX-15351-backwards-compat-issues branch April 16, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants