-
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
En 7194/unJail-with-option #2230
Conversation
vm/systemSmartContracts/auction.go
Outdated
if len(args.Arguments) == 0 { | ||
s.eei.AddReturnMessage("invalid number of arguments: expected min 1, got 0") | ||
if len(args.Arguments) == 0 || len(args.Arguments)%2 != 0 { | ||
s.eei.AddReturnMessage("invalid number of arguments: expected paired number") |
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.
even number
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
@@ -342,38 +300,42 @@ func (r *stakingSC) unJail(args *vmcommon.ContractCallInput) vmcommon.ReturnCode | |||
r.eei.AddReturnMessage("unJail function not allowed to be called by address " + string(args.CallerAddr)) | |||
return vmcommon.UserError | |||
} | |||
if len(args.Arguments) != 2 || len(args.Arguments[1]) != 1 { | |||
r.eei.AddReturnMessage("wrong arguments number") |
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.
wrong number of 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.
done
for _, blsKey := range blsKeys { | ||
vmOutput, err := s.executeOnStakingSC([]byte("unJail@" + hex.EncodeToString(blsKey))) | ||
if err != nil { | ||
s.eei.AddReturnMessage(err.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 need to add this message ?
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
vm/systemSmartContracts/staking.go
Outdated
@@ -342,38 +300,42 @@ func (r *stakingSC) unJail(args *vmcommon.ContractCallInput) vmcommon.ReturnCode | |||
r.eei.AddReturnMessage("unJail function not allowed to be called by address " + string(args.CallerAddr)) | |||
return vmcommon.UserError | |||
} | |||
if len(args.Arguments) != 2 || len(args.Arguments[1]) != 1 { | |||
r.eei.AddReturnMessage("wrong number of arguments, wanted 2") |
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.
the message could be not correct if there are 2 arguments but the len of the second one is not 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.
yes. last argument length must be 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.
This is what I said, that the message could be misleading, if the unJail is called with two arguments but the last one has the len different than 1
vm/systemSmartContracts/staking.go
Outdated
@@ -441,6 +407,7 @@ func (r *stakingSC) jail(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { | |||
stakedData.JailedRound = r.eei.BlockChainHook().CurrentRound() | |||
stakedData.JailedNonce = r.eei.BlockChainHook().CurrentNonce() | |||
stakedData.Jailed = true | |||
stakedData.NumJailed = stakedData.NumJailed + 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.
stakedData.NumJailed++
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
registrationData.JailedRound = r.eei.BlockChainHook().CurrentRound() | ||
registrationData.JailedNonce = r.eei.BlockChainHook().CurrentNonce() | ||
registrationData.Jailed = true | ||
registrationData.NumJailed = registrationData.NumJailed + 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.
registrationData.NumJailed++
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
@@ -879,6 +809,67 @@ func (r *stakingSC) addToWaitingList(blsKey []byte) error { | |||
return r.saveElementAndList(inWaitingListKey, elementInWaiting, waitingList) | |||
} | |||
|
|||
func (r *stakingSC) insertAfter( |
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.
Need some unit tests for this method
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/auction.go
Outdated
if err != nil { | ||
s.eei.AddReturnMessage(err.Error()) | ||
for i, blsKey := range blsKeys { | ||
vmOutput, err := s.executeOnStakingSC([]byte("unJail@" + hex.EncodeToString(blsKey) + "@" + hex.EncodeToString(args.Arguments[2*i+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.
what does the"args.Arguments[2*i+1]" represent?
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.
unJial can be called with unJail@blsKey1@0@blsKey2@1 etc. For each blsKey you need to define whether you want to stake / unstake.
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... not really easy to understand...
vm/systemSmartContracts/staking.go
Outdated
|
||
err = r.saveStakingData(argument, stakedData) | ||
if args.Arguments[1][0] == 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.
What does it check 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.
if it is unJail with stake
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.
o...k...
vm/systemSmartContracts/staking.go
Outdated
registrationData.UnStakedEpoch = r.eei.BlockChainHook().CurrentEpoch() | ||
registrationData.UnStakedNonce = r.eei.BlockChainHook().CurrentNonce() | ||
registrationData.StakedNonce = math.MaxUint64 | ||
registrationData.Jailed = true |
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 needed, already set above
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/auction.go
Outdated
s.eei.Finish(blsKey) | ||
s.eei.Finish([]byte{failed}) | ||
continue | ||
} | ||
} | ||
|
||
err = s.eei.Transfer(args.CallerAddr, args.RecipientAddr, transferBack, nil, 0) | ||
if err != nil { | ||
s.eei.AddReturnMessage("transfer error on unBond 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.
unJail instead unBond ?
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
@@ -1150,25 +1150,25 @@ func TestStakingSc_ExecuteStakeStakeStakeJailJailUnJailTwice(t *testing.T) { | |||
callerAddress := []byte("data") | |||
|
|||
// do stake should work | |||
doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firstKey")) | |||
doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firsstKey")) |
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.
Why firsstKey instead firstKey and fifthhKey instead fifthKey ?
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.
to make it easier the key copies. all keys in the contract has the same length.
epochStart/metachain/systemSCs.go
Outdated
@@ -311,6 +366,9 @@ func (s *systemSCProcessor) getSortedJailedNodes(validatorInfos map[uint32][]*st | |||
|
|||
sort.Slice(jailedValidators, func(i, j int) bool { | |||
if jailedValidators[i].TempRating == jailedValidators[i].TempRating { |
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 a wrongly use of "i" instead "j" in the right side of this comparation. Probably an old bug. Please check if there exists other places where these sorts with TempRating are used with this pattern -> i, i
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.
@@ -40,6 +40,9 @@ type systemSCProcessor struct { | |||
validatorInfoCreator epochStart.ValidatorInfoCreator | |||
endOfEpochCallerAddress []byte | |||
stakingSCAddress []byte | |||
|
|||
mapNumSwitchedPerShard map[uint32]uint32 |
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.
These maps are used without mutex protection. Please check if they should be used under the mutex or not.
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 possible.
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.
It is used in serial way only
@@ -238,6 +238,11 @@ func (stp *stakingToPeer) updatePeerState( | |||
if isNewValidator { | |||
account.SetListAndIndex(account.GetShardId(), string(core.NewList), uint32(stakingData.UnJailedNonce)) | |||
} | |||
|
|||
if account.GetList() == string(core.JailedList) { |
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 shouldn't be done on else branch, if is not new validator ? Could be the situation when isNewValidator == true && account.GetList() == string(core.JailedList) ? In this case account.SetListAndIndex will be executed twice here, first time with core.NewList and second time with core.InactiveList.
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.
Agreed. Must add to else branch.
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 to change. It is good as it is. If it is a new validator, it will set to new list. Thus it will not get into this branch.
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
@@ -238,6 +238,11 @@ func (stp *stakingToPeer) updatePeerState( | |||
if isNewValidator { | |||
account.SetListAndIndex(account.GetShardId(), string(core.NewList), uint32(stakingData.UnJailedNonce)) | |||
} | |||
|
|||
if account.GetList() == string(core.JailedList) { |
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
…och - which leads to panic in node.
feceb84
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! 💯 🔥
unJail with option.
If the node was jailed for the first time, it will get in to the top of the waiting list.