Skip to content

Commit

Permalink
Merge branch 'development' into EN-8515-linter-checks-fixes
Browse files Browse the repository at this point in the history
# Conflicts:
#	epochStart/metachain/epochStartData.go
  • Loading branch information
bogdan-rosianu committed Dec 18, 2020
2 parents 73f0104 + 41898dd commit 6840d07
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 272 deletions.
10 changes: 5 additions & 5 deletions epochStart/metachain/epochStartData.go
Expand Up @@ -347,17 +347,17 @@ func getEpochStartDataForShard(epochStartMetaHdr *block.MetaBlock, shardID uint3
return nil, nil
}

for _, epochStartDataRes := range epochStartMetaHdr.EpochStart.LastFinalizedHeaders {
if epochStartDataRes.ShardID != shardID {
for _, header := range epochStartMetaHdr.EpochStart.LastFinalizedHeaders {
if header.ShardID != shardID {
continue
}

mapPendingMiniBlocks := make(map[string]block.MiniBlockHeader, len(epochStartDataRes.PendingMiniBlockHeaders))
for _, mbHdr := range epochStartDataRes.PendingMiniBlockHeaders {
mapPendingMiniBlocks := make(map[string]block.MiniBlockHeader, len(header.PendingMiniBlockHeaders))
for _, mbHdr := range header.PendingMiniBlockHeaders {
mapPendingMiniBlocks[string(mbHdr.Hash)] = mbHdr
}

return epochStartDataRes.FirstPendingMetaBlock, mapPendingMiniBlocks
return header.FirstPendingMetaBlock, mapPendingMiniBlocks
}

return nil, nil
Expand Down
10 changes: 8 additions & 2 deletions epochStart/metachain/stakingDataProvider_test.go
Expand Up @@ -463,7 +463,7 @@ func createStakingDataProviderWithMockArgs(
}

func createStakingDataProviderWithRealArgs(t *testing.T, owner []byte, blsKey []byte, topUpVal *big.Int) *stakingDataProvider {
args, _ := createFullArgumentsForSystemSCProcessing(1000)
args, _ := createFullArgumentsForSystemSCProcessing(1000, createMemUnit())
args.EpochNotifier.CheckEpoch(1000000)
s, _ := NewSystemSCProcessor(args)
require.NotNil(t, s)
Expand All @@ -478,6 +478,9 @@ func createStakingDataProviderWithRealArgs(t *testing.T, owner []byte, blsKey []
func saveOutputAccounts(t *testing.T, accountsDB state.AccountsAdapter, vmOutput *vmcommon.VMOutput) {
for _, outputAccount := range vmOutput.OutputAccounts {
account, errLoad := accountsDB.LoadAccount(outputAccount.Address)
if errLoad != nil {
log.Error(errLoad.Error())
}
require.Nil(t, errLoad)

userAccount, _ := account.(state.UserAccountHandler)
Expand All @@ -486,6 +489,9 @@ func saveOutputAccounts(t *testing.T, accountsDB state.AccountsAdapter, vmOutput
}

err := accountsDB.SaveAccount(account)
if err != nil {
assert.Fail(t, err.Error())
}
require.Nil(t, err)
}

Expand All @@ -494,7 +500,7 @@ func saveOutputAccounts(t *testing.T, accountsDB state.AccountsAdapter, vmOutput
}

func createStakingDataProviderAndUpdateCache(t *testing.T, validatorsInfo map[uint32][]*state.ValidatorInfo, topUpValue *big.Int) *stakingDataProvider {
args, _ := createFullArgumentsForSystemSCProcessing(1)
args, _ := createFullArgumentsForSystemSCProcessing(1, createMemUnit())
args.StakingV2EnableEpoch = 0
args.EpochNotifier.CheckEpoch(1)
sdp, _ := NewStakingDataProvider(args.SystemVM, "2500")
Expand Down
66 changes: 34 additions & 32 deletions epochStart/metachain/systemSCs.go
Expand Up @@ -855,20 +855,26 @@ func (s *systemSCProcessor) updateOwnersForBlsKeys() error {
sw.Start("systemSCProcessor")
defer func() {
sw.Stop("systemSCProcessor")
log.Debug("systemSCProcessor.updateOwnersForBlsKeys time measurements", sw.GetMeasurements()...)
log.Info("systemSCProcessor.updateOwnersForBlsKeys time measurements", sw.GetMeasurements()...)
}()

sw.Start("getValidatorSystemAccount")
userValidatorAccount, err := s.getValidatorSystemAccount()
sw.Stop("getValidatorSystemAccount")
if err != nil {
return err
}

validatorAccounts, err := s.getValidatorUserAccountsKeys(userValidatorAccount)
sw.Start("getArgumentsForSetOwnerFunctionality")
arguments, err := s.getArgumentsForSetOwnerFunctionality(userValidatorAccount)
sw.Stop("getArgumentsForSetOwnerFunctionality")
if err != nil {
return err
}

err = s.callUpdateStakingV2(validatorAccounts)
sw.Start("callSetOwnersOnAddresses")
err = s.callSetOwnersOnAddresses(arguments)
sw.Stop("callSetOwnersOnAddresses")
if err != nil {
return err
}
Expand All @@ -894,8 +900,8 @@ func (s *systemSCProcessor) getValidatorSystemAccount() (state.UserAccountHandle
return userValidatorAccount, nil
}

func (s *systemSCProcessor) getValidatorUserAccountsKeys(userValidatorAccount state.UserAccountHandler) ([][]byte, error) {
validatorAccounts := make([][]byte, 0)
func (s *systemSCProcessor) getArgumentsForSetOwnerFunctionality(userValidatorAccount state.UserAccountHandler) ([][]byte, error) {
arguments := make([][]byte, 0)

rootHash, err := userValidatorAccount.DataTrie().Root()
if err != nil {
Expand All @@ -915,42 +921,38 @@ func (s *systemSCProcessor) getValidatorUserAccountsKeys(userValidatorAccount st
}

err = s.marshalizer.Unmarshal(validatorData, value)
dataIsNotValid := err != nil || len(validatorData.BlsPubKeys) == 0
if dataIsNotValid {
if err != nil {
continue
}
validatorAccounts = append(validatorAccounts, leaf.Key())
for _, blsKey := range validatorData.BlsPubKeys {
arguments = append(arguments, blsKey)
arguments = append(arguments, leaf.Key())
}
}

return validatorAccounts, nil
return arguments, nil
}

func (s *systemSCProcessor) callUpdateStakingV2(validatorAccounts [][]byte) error {
for _, validatorAccountKey := range validatorAccounts {
vmInput := &vmcommon.ContractCallInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.ValidatorSCAddress,
CallValue: big.NewInt(0),
Arguments: [][]byte{validatorAccountKey},
},
RecipientAddr: vm.ValidatorSCAddress,
Function: "updateStakingV2",
}
vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput)
if errRun != nil {
return fmt.Errorf("%w when updating to stakingV2 specs the address %s", errRun, hex.EncodeToString(validatorAccountKey))
}
if vmOutput.ReturnCode != vmcommon.Ok {
return fmt.Errorf("got return code %s when updating to stakingV2 specs the address %s", vmOutput.ReturnCode, hex.EncodeToString(validatorAccountKey))
}
func (s *systemSCProcessor) callSetOwnersOnAddresses(arguments [][]byte) error {
vmInput := &vmcommon.ContractCallInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.EndOfEpochAddress,
CallValue: big.NewInt(0),
Arguments: arguments,
},
RecipientAddr: vm.StakingSCAddress,
Function: "setOwnersOnAddresses",
}

err := s.processSCOutputAccounts(vmOutput)
if err != nil {
return err
}
vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput)
if errRun != nil {
return fmt.Errorf("%w when calling setOwnersOnAddresses function", errRun)
}
if vmOutput.ReturnCode != vmcommon.Ok {
return fmt.Errorf("got return code %s when calling setOwnersOnAddresses", vmOutput.ReturnCode)
}

return nil
return s.processSCOutputAccounts(vmOutput)
}

func (s *systemSCProcessor) initDelegationSystemSC() error {
Expand Down

0 comments on commit 6840d07

Please sign in to comment.