-
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 7193/end of epoch sc proc #2219
Conversation
How to join waiting list please? |
epochStart/metachain/systemSCs.go
Outdated
|
||
var activeStorageUpdate *vmcommon.StorageUpdate | ||
for _, storageUpdate := range stakingSCOutput.StorageUpdates { | ||
if len(storageUpdate.Offset) == len(jailedValidator.PublicKey) && |
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.
maybe extract the condition in a small bool variable?
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.
how does a big bool variable look like ? 🍡
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
} | ||
|
||
// NewSystemSCProcessor creates the end of epoch system smart contract processor | ||
func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCProcessor, 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.
Missing unit tests.
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.
wanted to have the first review before writing tests.
|
||
import "github.com/ElrondNetwork/elrond-go/data/state" | ||
|
||
type EpochStartSystemSCStub struct { |
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.
Missing comment
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
@@ -3,6 +3,7 @@ package integrationTests | |||
import ( | |||
"encoding/hex" | |||
"fmt" | |||
"github.com/ElrondNetwork/elrond-go/vm" |
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.
unsorted imports.
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.
new goland does not works as expected. done
process/common.go
Outdated
@@ -4,6 +4,7 @@ import ( | |||
"bytes" | |||
"encoding/hex" | |||
"fmt" | |||
vmcommon "github.com/ElrondNetwork/elrond-vm-common" |
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.
unsorted imports
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
@@ -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 { |
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.
unit tests?
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.
in the smart contract process there are tests directly using this function
|
||
import "github.com/ElrondNetwork/elrond-go/data/state" | ||
|
||
type EpochStartSystemSCStub struct { |
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.
missing comment
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
@@ -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 { |
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.
Maybe extract in a bool var?
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
@@ -5,6 +5,7 @@ import ( | |||
"crypto/rand" | |||
"encoding/hex" | |||
"errors" | |||
"github.com/ElrondNetwork/elrond-go/vm" |
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.
unsorted imports
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
@@ -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 { |
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.
tests?
|
||
// NewSystemSCProcessor creates the end of epoch system smart contract processor | ||
func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCProcessor, error) { | ||
if check.IfNilReflect(args.SystemVM) { |
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.
IfNilReflect ?
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.
yep. systemVM interface does not have isInterfacenil
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
func (s *systemSCProcessor) swapJailedWithWaiting(validatorInfos map[uint32][]*state.ValidatorInfo) error { | ||
jailedValidators := s.getSortedJailedNodes(validatorInfos) | ||
for _, jailedValidator := range jailedValidators { | ||
|
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.
Remove empty line
func (s *systemSCProcessor) processSCOutputAccounts( | ||
vmOutput *vmcommon.VMOutput, | ||
) 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.
Remove empty line
if err != nil { | ||
return err | ||
} | ||
|
||
err = mp.scToProtocol.UpdateProtocol(body, header.Nonce) |
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.
So, this is not needed anymore?
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.
in case of epoch start block is not needed.
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 are no smart contract results in the epoch start block - thus this function did nothing.
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
|
||
outPutAccounts := make([]*vmcommon.OutputAccount, len(vmOutput.OutputAccounts)) | ||
i := 0 | ||
for _, outAcc := range vmOutput.OutputAccounts { |
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 not: index, outAcc and remove line 667 and 670?
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.
output accounts is a map.
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
func GetSortedStorageUpdates(account *vmcommon.OutputAccount) []*vmcommon.StorageUpdate { | ||
storageUpdates := make([]*vmcommon.StorageUpdate, len(account.StorageUpdates)) | ||
i := 0 | ||
for _, update := range account.StorageUpdates { |
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 not: index, update and remove line 683 and 686?
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.
storageUpdates is a map
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
@@ -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 { |
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.
&& stakingData.Staked is enough
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
} | ||
|
||
r.removeFromStakedNodes() | ||
registrationData.Staked = false |
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.
registration data will contain the information related to the waiting or to the jailed node?
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 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 |
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.
... && stakingData.Staked is enough
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.
Unit tests should be added soon as to not forget about them.
…to EN-7193/end-of-epoch-sc-proc
b75a581
@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" |
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.
economics2
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.
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.