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

Keep max num nodes limit #2995

Merged
merged 14 commits into from
Apr 14, 2021
Merged

Keep max num nodes limit #2995

merged 14 commits into from
Apr 14, 2021

Conversation

sasurobert
Copy link
Contributor

Clean waiting list nodes when no nodes are qualified
Keep the maximum number of nodes property always

@codecov
Copy link

codecov bot commented Apr 12, 2021

Codecov Report

Merging #2995 (78a644c) into master (a938341) will decrease coverage by 0.00%.
The diff coverage is 69.44%.

❗ Current head 78a644c differs from pull request most recent head 0bb95c4. Consider uploading reports for the commit 0bb95c4 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2995      +/-   ##
==========================================
- Coverage   75.06%   75.06%   -0.01%     
==========================================
  Files         629      629              
  Lines       60655    60776     +121     
==========================================
+ Hits        45531    45619      +88     
- Misses      11020    11040      +20     
- Partials     4104     4117      +13     
Impacted Files Coverage Δ
vm/systemSmartContracts/staking.go 57.59% <66.32%> (+1.22%) ⬆️
epochStart/metachain/systemSCs.go 69.24% <71.79%> (-0.55%) ⬇️
epochStart/metachain/stakingDataProvider.go 96.08% <100.00%> (+2.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a938341...0bb95c4. Read the comment docs.

@iulianpascalau iulianpascalau self-requested a review April 12, 2021 11:33
@AdoAdoAdo AdoAdoAdo self-requested a review April 12, 2021 11:47
iulianpascalau
iulianpascalau previously approved these changes Apr 12, 2021
epochStart/metachain/systemSCs.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/staking.go Show resolved Hide resolved
}

for i := len(waitingListData.blsKeys) - 1; i >= 0; i-- {
stakedData := waitingListData.stakedDataList[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

just to make sure, is the len(waitingListData.blsKeys) enforced to always be equal or less than len(waitingListData.stakedDataList) ?

If not enforced, I would add a check before the loop that the two are equal and error otherwise, to avoid panics.

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 enforced

Copy link
Contributor

Choose a reason for hiding this comment

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

I would still add a check, just in case, before the loop.

if len(waitingListData.blsKeys) != len(waitingListData.stakedDataList) return an error

if numQualified < numRegisteredKeys {
mapCheckedOwners[string(owner)] = false
return false, nil
if numQualified >= numRegisteredKeys {
Copy link
Contributor

@AdoAdoAdo AdoAdoAdo Apr 13, 2021

Choose a reason for hiding this comment

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

why not numQualified > numRegisteredKeys?
why do we set qualifiedToStake to true if the registered keys are equal to number of qualified nodes?
wouldn't this cause a stake of an aditional node from staking queue in function stakeNodesFromQueue when not needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

can you please add a test to validate that we do not stake an aditional node from staking queue if we already have exactly numQualified nodes active and an aditional node in the staking queue on the first position?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is already added. All the nodes from the additional queue need those 2500eGLD - thus if numQualified == numRegistered - it means the validator has enough funds to have all of its nodes active.

vm/systemSmartContracts/staking.go Show resolved Hide resolved
@@ -1183,12 +1191,57 @@ func (s *systemSCProcessor) updateSystemSCContractsCode(contractMetadata []byte)
return nil
}

func (s *systemSCProcessor) cleanAdditionalQueue() error {
vmInput := &vmcommon.ContractCallInput{
Copy link
Contributor

Choose a reason for hiding this comment

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

please add this:

        sw := core.NewStopWatch()
	sw.Start("systemSCProcessor")
	defer func() {
		sw.Stop("systemSCProcessor")
		log.Info("systemSCProcessor.cleanAdditionalQueue time measurements", sw.GetMeasurements()...)
	}()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -1543,32 +1545,31 @@ func (s *stakingSC) resetLastUnJailedFromQueue(args *vmcommon.ContractCallInput)

func (s *stakingSC) cleanAdditionalQueueNotEnoughFunds(
Copy link
Contributor

Choose a reason for hiding this comment

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

cleanAdditionalQueueNotEnoughFundsReturningUnstaked is a better name now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is too long.

if s.flagCorrectNumNodesToStake.IsSet() {
err := s.cleanAdditionalQueue()
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

should we consider this a critical error? Shouldn't we just log.Error the 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.

it here we have a critical error - the contracts will not work as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, makes sense. Returning error here will avoid of having an inconsistent state. The metachain will halt and we have to do the fixes so it will resume the operation.

@LucianMincu LucianMincu merged commit be74097 into master Apr 14, 2021
@LucianMincu LucianMincu deleted the keep-max-num-limit branch April 14, 2021 15: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

4 participants