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 7193/end of epoch sc proc #2219

Merged
merged 13 commits into from
Aug 15, 2020
Merged

Conversation

sasurobert
Copy link
Contributor

end of epoch system smart contract processing. Jailing in the system smart contract the low rating nodes, removing them from staking list, adding users from the waiting list to active.

Start a testnet with MaxNumberOfNodesForStake = number of nodes you run from first epoch.
Stake a set of new nodes, they will enter the waiting list
Turn off some of the initial nodes - only a few of them in order to keep the block production going.
After those nodes rating decreases to minimum, they are jailed and replaced with the ones from the waiting list.

@nouserboop
Copy link

How to join waiting list please?

@iulianpascalau iulianpascalau self-requested a review August 12, 2020 18:37

var activeStorageUpdate *vmcommon.StorageUpdate
for _, storageUpdate := range stakingSCOutput.StorageUpdates {
if len(storageUpdate.Offset) == len(jailedValidator.PublicKey) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe extract the condition in a small bool variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how does a big bool variable look like ? 🍡

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

}

// NewSystemSCProcessor creates the end of epoch system smart contract processor
func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCProcessor, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wanted to have the first review before writing tests.


import "github.com/ElrondNetwork/elrond-go/data/state"

type EpochStartSystemSCStub struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comment

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

@@ -3,6 +3,7 @@ package integrationTests
import (
"encoding/hex"
"fmt"
"github.com/ElrondNetwork/elrond-go/vm"
Copy link
Contributor

Choose a reason for hiding this comment

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

unsorted imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

new goland does not works as expected. done

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
Copy link
Contributor

Choose a reason for hiding this comment

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

unsorted imports

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

@@ -652,3 +653,42 @@ func IsAllowedToSaveUnderKey(key []byte) bool {
trimmedKey := key[:prefixLen]
return !bytes.Equal(trimmedKey, []byte(core.ElrondProtectedKeyPrefix))
}

// SortVMOutputInsideData returns the output accounts as a sorted list
func SortVMOutputInsideData(vmOutput *vmcommon.VMOutput) []*vmcommon.OutputAccount {
Copy link
Contributor

Choose a reason for hiding this comment

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

unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the smart contract process there are tests directly using this function


import "github.com/ElrondNetwork/elrond-go/data/state"

type EpochStartSystemSCStub struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing comment

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

@@ -227,7 +227,7 @@ func (stp *stakingToPeer) updatePeerState(
account.SetTempRating(stp.unJailRating)
}

if !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch {
if !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch && stakingData.Staked == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe extract in a bool var?

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

@@ -5,6 +5,7 @@ import (
"crypto/rand"
"encoding/hex"
"errors"
"github.com/ElrondNetwork/elrond-go/vm"
Copy link
Contributor

Choose a reason for hiding this comment

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

unsorted imports

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

@@ -999,6 +1008,49 @@ func (r *stakingSC) createWaitingListKey(blsKey []byte) []byte {
return []byte(waitingElementPrefix + string(blsKey))
}

func (r *stakingSC) switchJailedWithWaiting(args *vmcommon.ContractCallInput) 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.

tests?


// NewSystemSCProcessor creates the end of epoch system smart contract processor
func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCProcessor, error) {
if check.IfNilReflect(args.SystemVM) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IfNilReflect ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. systemVM interface does not have isInterfacenil

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

func (s *systemSCProcessor) swapJailedWithWaiting(validatorInfos map[uint32][]*state.ValidatorInfo) error {
jailedValidators := s.getSortedJailedNodes(validatorInfos)
for _, jailedValidator := range jailedValidators {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line

func (s *systemSCProcessor) processSCOutputAccounts(
vmOutput *vmcommon.VMOutput,
) error {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line

if err != nil {
return err
}

err = mp.scToProtocol.UpdateProtocol(body, header.Nonce)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this is not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in case of epoch start block is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are no smart contract results in the epoch start block - thus this function did nothing.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok


outPutAccounts := make([]*vmcommon.OutputAccount, len(vmOutput.OutputAccounts))
i := 0
for _, outAcc := range vmOutput.OutputAccounts {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not: index, outAcc and remove line 667 and 670?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

output accounts is a map.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

func GetSortedStorageUpdates(account *vmcommon.OutputAccount) []*vmcommon.StorageUpdate {
storageUpdates := make([]*vmcommon.StorageUpdate, len(account.StorageUpdates))
i := 0
for _, update := range account.StorageUpdates {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not: index, update and remove line 683 and 686?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

storageUpdates is a map

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

@@ -227,7 +227,7 @@ func (stp *stakingToPeer) updatePeerState(
account.SetTempRating(stp.unJailRating)
}

if !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch {
if !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch && stakingData.Staked == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

&& stakingData.Staked is enough

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

}

r.removeFromStakedNodes()
registrationData.Staked = false
Copy link
Contributor

Choose a reason for hiding this comment

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

registration data will contain the information related to the waiting or to the jailed node?

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 already has.

@@ -227,7 +227,8 @@ func (stp *stakingToPeer) updatePeerState(
account.SetTempRating(stp.unJailRating)
}

if !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch && stakingData.Staked == true {
isNewValidator := !isValidator && account.GetUnStakedEpoch() == core.DefaultUnstakedEpoch && stakingData.Staked == true
Copy link
Contributor

Choose a reason for hiding this comment

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

... && stakingData.Staked is enough

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

iulianpascalau
iulianpascalau previously approved these changes Aug 13, 2020
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

Unit tests should be added soon as to not forget about them.

@LucianMincu
Copy link
Contributor

LucianMincu commented Aug 15, 2020

How to join waiting list please?

@nouserboop Make sure you follow our validator channels. In the following weeks we will deploy the functions to the mainnet and than it will be just a matter of enable-ing the functions for everyone so you'll need to be ready if you want to make sure you'll get one seat in front of everyone. 👍

"github.com/ElrondNetwork/elrond-go/hashing"
"github.com/ElrondNetwork/elrond-go/hashing/sha256"
"github.com/ElrondNetwork/elrond-go/marshal"
economics2 "github.com/ElrondNetwork/elrond-go/process/economics"
Copy link
Contributor

Choose a reason for hiding this comment

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

economics2

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 98c7890 into development Aug 15, 2020
@LucianMincu LucianMincu deleted the EN-7193/end-of-epoch-sc-proc branch August 15, 2020 20:20
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