-
Notifications
You must be signed in to change notification settings - Fork 198
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
Waiting list length fix #3534
Conversation
iulianpascalau
commented
Oct 25, 2021
•
edited
edited
- added a new functionality that will fix the length on the waiting list 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 { |
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.
add in one more place
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.
done
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.
there is another place Line 1296
where a
for len(nextKey) != 0 && index <= waitingListHead.Length {
is used. Should it be also added there?
vm/systemSmartContracts/staking.go
Outdated
copy(nextKey, element.NextKey) | ||
} | ||
|
||
if len(blsKeysToStake) != int(waitingListHead.Length) { |
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.
if numNodes >= waitingListHead.Length &&
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.
done
vm/systemSmartContracts/staking.go
Outdated
if waitingListHead.Length == 0 { | ||
waitingListHead.Length = 0 | ||
|
||
return s.saveWaitingListReturningErrorCode(waitingListHead) |
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.
just return here. without save.
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.
done
vm/systemSmartContracts/staking.go
Outdated
return s.saveWaitingListReturningErrorCode(waitingListHead) | ||
} | ||
|
||
func (s *stakingSC) saveWaitingListReturningErrorCode(waitingList *WaitingList) vmcommon.ReturnCode { |
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.
no need for this function
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, removed
vm/systemSmartContracts/staking.go
Outdated
return vmcommon.UserError | ||
} | ||
|
||
if waitingListHead.Length == 0 { |
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.
<= 1
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.
changed
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.
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.
vm/systemSmartContracts/staking.go
Outdated
return vmcommon.UserError | ||
} | ||
|
||
if waitingListHead.Length == 0 { |
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.
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 { |
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.
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
a47d44c
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
vm/systemSmartContracts/staking.go
Outdated
return vmcommon.OutOfGas | ||
} | ||
if len(args.Arguments) != 1 { | ||
s.eei.AddReturnMessage("not enough arguments") |
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.
s.eei.AddReturnMessage(fmt.Sprintf("invalid number of arguments: expected %d, got %d", 1, len(args.Arguments)))
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.
would leave as it is.
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.
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()) |
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.
👍
_, errGet = s.getOrCreateRegisteredData(element.BLSPublicKey) | ||
if errGet != nil { | ||
s.eei.AddReturnMessage(err.Error()) | ||
s.eei.AddReturnMessage(errGet.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.
👍
return vmcommon.Ok | ||
} | ||
|
||
foundLastJailedKey := len(waitingListHead.LastJailedKey) == 0 |
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 gives true if there is no jailed element, but flag is called foundLastJailed
shouldn't you change to
foundLastJailedKey := len(waitingListHead.LastJailedKey) != 0
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.
System tests passed.