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

Protection check for stakingV4 configs #4983

Merged
merged 6 commits into from Feb 15, 2023

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Feb 13, 2023

Reasoning behind the pull request

  • In case of a wrong epoch configuration for staking v4, there was no protocol sanity check to signal it

Proposed changes

  • Added a config checker for stakingV4, which checks:
  1. StakingV4 steps are in order
  2. MaxNodesChangeEnableEpoch are changed correctly.
  • For "soft configuration mistakes", a warn is thrown

Testing procedure

  • Local testnet scripts

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@mariusmihaic mariusmihaic self-assigned this Feb 13, 2023
@mariusmihaic mariusmihaic changed the title FEAT: Add first version of checking stakingV4 config Protection check for stakingV4 configs Feb 13, 2023
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (feat/staking-v4@99395eb). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head 8e44f81 differs from pull request most recent head 070ac93. Consider uploading reports for the commit 070ac93 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@                Coverage Diff                 @@
##             feat/staking-v4    #4983   +/-   ##
==================================================
  Coverage                   ?   70.90%           
==================================================
  Files                      ?      662           
  Lines                      ?    86491           
  Branches                   ?        0           
==================================================
  Hits                       ?    61323           
  Misses                     ?    20622           
  Partials                   ?     4546           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

DAKI911
DAKI911 previously approved these changes Feb 13, 2023
@mariusmihaic mariusmihaic marked this pull request as ready for review February 14, 2023 11:47

var log = logger.GetOrCreate("configChecker")

func SanityCheckEnableEpochsStakingV4(cfg *Configs) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment to public function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, added it

stakingV4StepsInExpectedOrder := (enableEpochsCfg.StakingV4Step1EnableEpoch == enableEpochsCfg.StakingV4Step2EnableEpoch-1) &&
(enableEpochsCfg.StakingV4Step2EnableEpoch == enableEpochsCfg.StakingV4Step3EnableEpoch-1)
if !stakingV4StepsInExpectedOrder {
log.Warn("staking v4 enable epoch steps should be in cardinal order " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Please return error. Why do you want something like this for playground ? You can have scripts which change to code here in case of playground, it is used in other places.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes let's return the error here as we won't be testing something other than will eventually be on the mainnet. Use fmt.Errorf here and on the other 3 locations to easily pinpoint the error and have a quick fix on the configs

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 was not sure if to consider these "soft errors" or not, so I've decided to let them as they are and fix it after review if necessary.
Thanks for suggestion, I've returned errors for all cases


maxNodesConfigAdaptedForStakingV4 = true
if idx == 0 {
log.Warn(fmt.Sprintf("found config change in MaxNodesChangeEnableEpoch for StakingV4Step3EnableEpoch = %d, ", enableEpochsCfg.StakingV4Step3EnableEpoch) +
Copy link
Contributor

Choose a reason for hiding this comment

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

please return error.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree: return error & remove else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks for suggestion, applied changes


func checkMaxNodesChangedCorrectly(prevMaxNodesChange MaxNodesChangeConfig, currMaxNodesChange MaxNodesChangeConfig, numOfShards uint32) error {
if prevMaxNodesChange.NodesToShufflePerShard != currMaxNodesChange.NodesToShufflePerShard {
log.Warn("previous MaxNodesChangeEnableEpoch.NodesToShufflePerShard != MaxNodesChangeEnableEpoch.NodesToShufflePerShard" +
Copy link
Contributor

Choose a reason for hiding this comment

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

please return error.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree: return error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks for suggestion, applied changes

log.Warn(fmt.Sprintf("found config change in MaxNodesChangeEnableEpoch for StakingV4Step3EnableEpoch = %d, ", enableEpochsCfg.StakingV4Step3EnableEpoch) +
"but no previous config change entry in MaxNodesChangeEnableEpoch, DO NOT use this config in production")
return fmt.Errorf("found config change in MaxNodesChangeEnableEpoch for StakingV4Step3EnableEpoch = %d, but %w ",
enableEpochsCfg.StakingV4Step3EnableEpoch, errNoMaxNodesConfigBeforeStakingV4)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

could have dropped the else branch improving the code readability.

@@ -2,6 +2,12 @@ package config

import "errors"

var errStakingV4StepsNotInOrder = errors.New("staking v4 enable epochs are not in ascending order; expected StakingV4Step1EnableEpoch < StakingV4Step2EnableEpoch < StakingV4Step3EnableEpoch")
var errStakingV4StepsNotInOrder = errors.New("staking v4 enable epoch steps should be in cardinal order(e.g.: StakingV4Step1EnableEpoch = 2, StakingV4Step2EnableEpoch = 3, StakingV4Step3EnableEpoch = 4)")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 good and comprehensive errors.

@mariusmihaic mariusmihaic merged commit 25994dd into feat/staking-v4 Feb 15, 2023
@mariusmihaic mariusmihaic deleted the MX-13669-stakingv4-epochs-protection branch February 15, 2023 11:58
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.

None yet

5 participants