-
Notifications
You must be signed in to change notification settings - Fork 204
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 edge case empty waiting list #5061
Fix edge case empty waiting list #5061
Conversation
Codecov Report
📣 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 #5061 +/- ##
==================================================
Coverage ? 70.76%
==================================================
Files ? 681
Lines ? 87805
Branches ? 0
==================================================
Hits ? 62136
Misses ? 21065
Partials ? 4604 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 in Codecov by Sentry. |
|
||
currNodesConfig = node.NodesConfig | ||
require.Len(t, getAllPubKeys(currNodesConfig.eligible), 8) | ||
require.Len(t, getAllPubKeys(currNodesConfig.waiting), 4) |
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.
duplicated code for checking a lot of requires. Make a separate funciton.
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.
Right, should've done this before.
Refactored to reuse functionality with new functions
@@ -2883,22 +2883,6 @@ func (d *delegation) executeStakeAndUpdateStatus( | |||
return vmcommon.Ok | |||
} | |||
|
|||
func (d *delegation) getConfigStatusAndGlobalFund() (*DelegationConfig, *DelegationContractStatus, *GlobalFundData, error) { |
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.
not 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.
Not used, remained here from a rc->feat merge
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.
Not used, I think it was some merging "leftovers" from an rc->feat
// Distribute validators from SHUFFLED OUT -> WAITING | ||
err = arg.distributor.DistributeValidators(newWaiting, shuffledOutMap, arg.randomness, arg.flagBalanceWaitingLists) | ||
if err != nil { | ||
log.Warn("distributeValidators shuffledOut failed", "error", err) |
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.
should return error. why only log.Warn in case of critical errors ?
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.
same for all cases.
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.
Did some digging + tests regarding this and it seems like we could safely return error here and it should also be backwards compatible.
Refactored to return error
@@ -283,6 +285,30 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { | |||
|
|||
shuffledOutMap, newEligible := shuffleOutNodes(newEligible, numToRemove, arg.randomness) | |||
|
|||
numShuffled := getNumPubKeys(shuffledOutMap) |
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.
make a separate function for the new code.
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.
Added separate function with little refactor
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.
We should really continue refactoring shuffleNodes function into a full fedged component.
@@ -285,26 +297,42 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { | |||
|
|||
err = moveMaxNumNodesToMap(newEligible, newWaiting, arg.nodesMeta, arg.nodesPerShard) | |||
if err != nil { | |||
log.Warn("moveNodesToMap failed", "error", err) | |||
return nil, fmt.Errorf("moveNodesToMap failed, error: %w", err) |
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 could be backwards incompatible and is not protected by a flag (before it would just log.warn and now it returns error)
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 is related to my comment from here.
An error here could never happend, that's why it was only treated as a warn;
This case never manifested on mainnet anyway, it's safe to refactor it
// Distribute validators from SHUFFLED OUT -> WAITING | ||
err = arg.distributor.DistributeValidators(newWaiting, shuffledOutMap, arg.randomness, arg.flagBalanceWaitingLists) | ||
if err != nil { | ||
log.Warn("distributeValidators shuffledOut failed", "error", err) | ||
return nil, fmt.Errorf("distributeValidators shuffled out failed, error: %w", err) |
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.
also backwards incompatibility here?
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 is related to my comment from here.
An error here could never happend, that's why it was only treated as a warn;
This case never manifested on mainnet anyway, it's safe to refactor it
Reasoning behind the pull request
nodes in waiting < max waiting list size
, after shuffling out nodes, there is no need to send nodes to auction, since they will be selected anyway. They can be directly sent to waiting list after shuffling, because next epoch they will be selected anyway. This also fixes some edge cases when waiting lists are almost empty and nodes would be forced to spend extra epochs(auction+waiting) before being sent to eligible.Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?