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

En 7194/unJail-with-option #2230

Merged
merged 89 commits into from
Sep 16, 2020
Merged

Conversation

sasurobert
Copy link
Contributor

unJail with option.
If the node was jailed for the first time, it will get in to the top of the waiting list.

@sasurobert sasurobert changed the base branch from master to development August 19, 2020 14:28
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

even number

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

@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong number of arguments

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

for _, blsKey := range blsKeys {
vmOutput, err := s.executeOnStakingSC([]byte("unJail@" + hex.EncodeToString(blsKey)))
if err != nil {
s.eei.AddReturnMessage(err.Error())
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no

@@ -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")
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

stakedData.NumJailed++

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

registrationData.JailedRound = r.eei.BlockChainHook().CurrentRound()
registrationData.JailedNonce = r.eei.BlockChainHook().CurrentNonce()
registrationData.Jailed = true
registrationData.NumJailed = registrationData.NumJailed + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

registrationData.NumJailed++

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

@@ -879,6 +809,67 @@ func (r *stakingSC) addToWaitingList(blsKey []byte) error {
return r.saveElementAndList(inWaitingListKey, elementInWaiting, waitingList)
}

func (r *stakingSC) insertAfter(
Copy link
Contributor

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

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

vm/systemSmartContracts/auction.go Outdated Show resolved Hide resolved
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])))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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/auction.go Show resolved Hide resolved
vm/systemSmartContracts/auction.go Outdated Show resolved Hide resolved
vm/systemSmartContracts/auction.go Show resolved Hide resolved
vm/systemSmartContracts/staking.go Outdated Show resolved Hide resolved

err = r.saveStakingData(argument, stakedData)
if args.Arguments[1][0] == 1 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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 Show resolved Hide resolved
registrationData.UnStakedEpoch = r.eei.BlockChainHook().CurrentEpoch()
registrationData.UnStakedNonce = r.eei.BlockChainHook().CurrentNonce()
registrationData.StakedNonce = math.MaxUint64
registrationData.Jailed = true
Copy link
Contributor

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

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

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

unJail instead unBond ?

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

@@ -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"))
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

raduchis
raduchis previously approved these changes Aug 21, 2020
@@ -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 {
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 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

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.

@@ -40,6 +40,9 @@ type systemSCProcessor struct {
validatorInfoCreator epochStart.ValidatorInfoCreator
endOfEpochCallerAddress []byte
stakingSCAddress []byte

mapNumSwitchedPerShard map[uint32]uint32
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not possible.

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 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ok

raduchis
raduchis previously approved these changes Sep 15, 2020
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 0f16068 into development Sep 16, 2020
@LucianMincu LucianMincu deleted the EN-7194/auction-at-end-of-epoch branch September 16, 2020 07:02
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

5 participants