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

Waiting list length fix #3534

Merged
merged 12 commits into from
Oct 26, 2021
Merged

Waiting list length fix #3534

merged 12 commits into from
Oct 26, 2021

Conversation

iulianpascalau
Copy link
Contributor

@iulianpascalau iulianpascalau commented Oct 25, 2021

  • added a new functionality that will fix the length on the waiting list length.

@iulianpascalau iulianpascalau marked this pull request as draft October 25, 2021 08:29
@@ -1898,15 +1900,90 @@ func (s *stakingSC) getFirstElementsFromWaitingList(numNodes uint32) (*waitingLi
blsKeysToStake = append(blsKeysToStake, element.BLSPublicKey)
stakedDataList = append(stakedDataList, stakedData)
index++
if len(element.NextKey) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

add in one more place

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

Copy link
Contributor

Choose a reason for hiding this comment

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

there is another place Line 1296
where a
for len(nextKey) != 0 && index <= waitingListHead.Length { is used. Should it be also added there?

copy(nextKey, element.NextKey)
}

if len(blsKeysToStake) != int(waitingListHead.Length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if numNodes >= waitingListHead.Length &&

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

if waitingListHead.Length == 0 {
waitingListHead.Length = 0

return s.saveWaitingListReturningErrorCode(waitingListHead)
Copy link
Contributor

Choose a reason for hiding this comment

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

just return here. without save.

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

return s.saveWaitingListReturningErrorCode(waitingListHead)
}

func (s *stakingSC) saveWaitingListReturningErrorCode(waitingList *WaitingList) vmcommon.ReturnCode {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for this 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, removed

sasurobert
sasurobert previously approved these changes Oct 25, 2021
return vmcommon.UserError
}

if waitingListHead.Length == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

<= 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor

Choose a reason for hiding this comment

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

could we have length = 0 but still have something on the FirstKey? Could there be a case where the Length is smaller than the actual length.

- added unit test
sasurobert
sasurobert previously approved these changes Oct 25, 2021
vm/systemSmartContracts/staking.go Outdated Show resolved Hide resolved
return vmcommon.UserError
}

if waitingListHead.Length == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we have length = 0 but still have something on the FirstKey? Could there be a case where the Length is smaller than the actual length.

@@ -1898,15 +1900,90 @@ func (s *stakingSC) getFirstElementsFromWaitingList(numNodes uint32) (*waitingLi
blsKeysToStake = append(blsKeysToStake, element.BLSPublicKey)
stakedDataList = append(stakedDataList, stakedData)
index++
if len(element.NextKey) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is another place Line 1296
where a
for len(nextKey) != 0 && index <= waitingListHead.Length { is used. Should it be also added there?

- added more unit tests
raduchis
raduchis previously approved these changes Oct 25, 2021
vm/systemSmartContracts/staking.go Show resolved Hide resolved
sasurobert
sasurobert previously approved these changes Oct 25, 2021
@iulianpascalau iulianpascalau marked this pull request as ready for review October 25, 2021 10:45
raduchis
raduchis previously approved these changes Oct 25, 2021
@codecov
Copy link

codecov bot commented Oct 25, 2021

Codecov Report

Merging #3534 (bc9efa4) into master (356fc93) will increase coverage by 0.00%.
The diff coverage is 76.99%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #3534    +/-   ##
========================================
  Coverage   73.88%   73.88%            
========================================
  Files         581      581            
  Lines       74603    74706   +103     
========================================
+ Hits        55119    55197    +78     
- Misses      15079    15095    +16     
- Partials     4405     4414     +9     
Impacted Files Coverage Δ
vm/systemSmartContracts/staking.go 63.12% <76.99%> (+0.97%) ⬆️
p2p/libp2p/netMessenger.go 74.72% <0.00%> (+0.13%) ⬆️

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 356fc93...bc9efa4. Read the comment docs.

return vmcommon.OutOfGas
}
if len(args.Arguments) != 1 {
s.eei.AddReturnMessage("not enough arguments")
Copy link
Contributor

Choose a reason for hiding this comment

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

s.eei.AddReturnMessage(fmt.Sprintf("invalid number of arguments: expected %d, got %d", 1, len(args.Arguments)))

Copy link
Contributor

Choose a reason for hiding this comment

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

would leave as it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but != 1 could be 2,3 ... 100. Not enough arguments doesn't match in these cases

index := uint32(1)
nextKey := make([]byte, len(waitingListHead.FirstKey))
copy(nextKey, waitingListHead.FirstKey)
for len(nextKey) != 0 && index <= waitingListHead.Length {
element, errGet := s.getWaitingListElement(nextKey)
if errGet != nil {
s.eei.AddReturnMessage(err.Error())
s.eei.AddReturnMessage(errGet.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.

👍

_, errGet = s.getOrCreateRegisteredData(element.BLSPublicKey)
if errGet != nil {
s.eei.AddReturnMessage(err.Error())
s.eei.AddReturnMessage(errGet.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.

👍

vm/systemSmartContracts/staking.go Show resolved Hide resolved
return vmcommon.Ok
}

foundLastJailedKey := len(waitingListHead.LastJailedKey) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

this gives true if there is no jailed element, but flag is called foundLastJailed
shouldn't you change to
foundLastJailedKey := len(waitingListHead.LastJailedKey) != 0

Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

@LucianMincu LucianMincu merged commit 2ef5218 into master Oct 26, 2021
@LucianMincu LucianMincu deleted the fix-waiting-list-queue-size branch October 26, 2021 13:25
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

6 participants