-
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
Changes from 9 commits
5bca1bb
6d4b2f8
26e8245
9712fc0
7217487
c68293a
9f27284
8f7f754
b56b74c
db83ac2
77b331d
1afecd5
c26f690
09be726
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ type shuffleNodesArg struct { | |
nodesPerShard uint32 | ||
nbShards uint32 | ||
maxNodesToSwapPerShard uint32 | ||
maxNumNodes uint32 | ||
flagBalanceWaitingLists bool | ||
flagStakingV4Step2 bool | ||
flagStakingV4Step3 bool | ||
|
@@ -195,6 +196,7 @@ func (rhs *randHashShuffler) UpdateNodeLists(args ArgsUpdateNodes) (*ResUpdateNo | |
flagBalanceWaitingLists: rhs.flagBalanceWaitingLists.IsSet(), | ||
flagStakingV4Step2: rhs.flagStakingV4Step2.IsSet(), | ||
flagStakingV4Step3: rhs.flagStakingV4Step3.IsSet(), | ||
maxNumNodes: rhs.activeNodesConfig.MaxNumNodes, | ||
}) | ||
} | ||
|
||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Added separate function with little refactor |
||
numNewEligible := getNumPubKeys(newEligible) | ||
numNewWaiting := getNumPubKeys(newWaiting) | ||
|
||
numSelectedAuction := uint32(len(arg.auction)) | ||
totalNewWaiting := numNewWaiting + numSelectedAuction | ||
|
||
totalNodes := totalNewWaiting + numNewEligible + numShuffled | ||
maxNumNodes := arg.maxNumNodes | ||
|
||
distributeShuffledToWaitingInStakingV4 := false | ||
if totalNodes <= maxNumNodes { | ||
log.Warn("num of total nodes in waiting is too low after shuffling; will distribute "+ | ||
"shuffled out nodes directly to waiting and skip sending them to auction", | ||
"numShuffled", numShuffled, | ||
"numNewEligible", numNewEligible, | ||
"numSelectedAuction", numSelectedAuction, | ||
"totalNewWaiting", totalNewWaiting, | ||
"totalNodes", totalNodes, | ||
"maxNumNodes", maxNumNodes) | ||
|
||
distributeShuffledToWaitingInStakingV4 = arg.flagStakingV4Step2 | ||
} | ||
|
||
err = moveMaxNumNodesToMap(newEligible, newWaiting, arg.nodesMeta, arg.nodesPerShard) | ||
if err != nil { | ||
log.Warn("moveNodesToMap failed", "error", err) | ||
|
@@ -294,12 +320,27 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { | |
} | ||
|
||
if arg.flagStakingV4Step3 { | ||
log.Debug("distributing selected nodes from auction to waiting", | ||
"num auction nodes", len(arg.auction), "num waiting nodes", numNewWaiting) | ||
|
||
// Distribute selected validators from AUCTION -> WAITING | ||
err = distributeValidators(newWaiting, arg.auction, arg.randomness, false) | ||
if err != nil { | ||
log.Warn("distributeValidators auction list failed", "error", err) | ||
} | ||
} | ||
|
||
if distributeShuffledToWaitingInStakingV4 { | ||
log.Debug("distributing shuffled out nodes to waiting in staking V4", | ||
"num shuffled nodes", numShuffled, "num waiting nodes", numNewWaiting) | ||
|
||
// 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 commentThe 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 commentThe 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 commentThe 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. |
||
} | ||
} | ||
|
||
if !arg.flagStakingV4Step2 { | ||
// Distribute validators from SHUFFLED OUT -> WAITING | ||
err = arg.distributor.DistributeValidators(newWaiting, shuffledOutMap, arg.randomness, arg.flagBalanceWaitingLists) | ||
|
@@ -614,6 +655,16 @@ func moveNodesToMap(destination map[uint32][]Validator, source map[uint32][]Vali | |
return nil | ||
} | ||
|
||
func getNumPubKeys(shardValidatorsMap map[uint32][]Validator) uint32 { | ||
numPubKeys := uint32(0) | ||
|
||
for _, validatorsInShard := range shardValidatorsMap { | ||
numPubKeys += uint32(len(validatorsInShard)) | ||
} | ||
|
||
return numPubKeys | ||
} | ||
|
||
// moveMaxNumNodesToMap moves the validators in the source list to the corresponding destination list | ||
// but adding just enough nodes so that at most the number of nodes is kept in the destination list | ||
// The parameter maxNodesToMove is a limiting factor and should limit the number of nodes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 |
||
dConfig, err := d.getDelegationContractConfig() | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
globalFund, err := d.getGlobalFundData() | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
dStatus, err := d.getDelegationStatus() | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
return dConfig, dStatus, globalFund, nil | ||
} | ||
|
||
func (d *delegation) executeOnValidatorSC(address []byte, function string, args [][]byte, value *big.Int) (*vmcommon.VMOutput, error) { | ||
validatorCall := function | ||
for _, key := range args { | ||
|
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