Skip to content

Commit

Permalink
Merge d34698a into 6328965
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianMarian authored Aug 19, 2022
2 parents 6328965 + d34698a commit dc6ee6d
Show file tree
Hide file tree
Showing 20 changed files with 744 additions and 1,826 deletions.
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
# MiniBlockPartialExecutionEnableEpoch represents the epoch when mini block partial execution will be enabled
MiniBlockPartialExecutionEnableEpoch = 3

# SetSenderInEeiOutputTransferEnableEpoch represents the epoch when setting the sender in eei output transfers will be enabled
SetSenderInEeiOutputTransferEnableEpoch = 4

# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
{ EpochEnable = 0, MaxNumNodes = 36, NodesToShufflePerShard = 4 },
Expand Down
1 change: 1 addition & 0 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) {
handler.setFlagValue(epoch >= handler.enableEpochsConfig.RefactorContextEnableEpoch, handler.refactorContextFlag, "refactorContextFlag")
handler.setFlagValue(epoch >= handler.enableEpochsConfig.CheckFunctionArgumentEnableEpoch, handler.checkFunctionArgumentFlag, "checkFunctionArgumentFlag")
handler.setFlagValue(epoch >= handler.enableEpochsConfig.CheckExecuteOnReadOnlyEnableEpoch, handler.checkExecuteOnReadOnlyFlag, "checkExecuteOnReadOnlyFlag")
handler.setFlagValue(epoch >= handler.enableEpochsConfig.SetSenderInEeiOutputTransferEnableEpoch, handler.setSenderInEeiOutputTransferFlag, "setSenderInEeiOutputTransferFlag")
}

func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string) {
Expand Down
7 changes: 7 additions & 0 deletions common/enablers/epochFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type epochFlagsHolder struct {
refactorContextFlag *atomic.Flag
checkFunctionArgumentFlag *atomic.Flag
checkExecuteOnReadOnlyFlag *atomic.Flag
setSenderInEeiOutputTransferFlag *atomic.Flag
}

func newEpochFlagsHolder() *epochFlagsHolder {
Expand Down Expand Up @@ -159,6 +160,7 @@ func newEpochFlagsHolder() *epochFlagsHolder {
refactorContextFlag: &atomic.Flag{},
checkFunctionArgumentFlag: &atomic.Flag{},
checkExecuteOnReadOnlyFlag: &atomic.Flag{},
setSenderInEeiOutputTransferFlag: &atomic.Flag{},
}
}

Expand Down Expand Up @@ -547,6 +549,11 @@ func (holder *epochFlagsHolder) IsCheckExecuteOnReadOnlyFlagEnabled() bool {
return holder.checkExecuteOnReadOnlyFlag.IsSet()
}

// IsSetSenderInEeiOutputTransferFlagEnabled returns true if setSenderInEeiOutputTransferFlag is enabled
func (holder *epochFlagsHolder) IsSetSenderInEeiOutputTransferFlagEnabled() bool {
return holder.setSenderInEeiOutputTransferFlag.IsSet()
}

// IsFixAsyncCallbackCheckFlagEnabled returns true if esdtMetadataContinuousCleanupFlag is enabled
// this is a duplicate for ESDTMetadataContinuousCleanupEnableEpoch needed for consistency into vm-common
func (holder *epochFlagsHolder) IsFixAsyncCallbackCheckFlagEnabled() bool {
Expand Down
1 change: 1 addition & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ type EnableEpochsHandler interface {
IsCheckTransferFlagEnabled() bool
IsTransferToMetaFlagEnabled() bool
IsESDTNFTImprovementV1FlagEnabled() bool
IsSetSenderInEeiOutputTransferFlagEnabled() bool

IsInterfaceNil() bool
}
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type EnableEpochs struct {
HeartbeatDisableEpoch uint32
MiniBlockPartialExecutionEnableEpoch uint32
ESDTMetadataContinuousCleanupEnableEpoch uint32
SetSenderInEeiOutputTransferEnableEpoch uint32
}

// GasScheduleByEpochs represents a gas schedule toml entry that will be applied from the provided epoch
Expand Down
4 changes: 4 additions & 0 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ func TestEnableEpochConfig(t *testing.T) {
# ESDTMetadataContinuousCleanupEnableEpoch represents the epoch when esdt metadata is automatically deleted according to inshard liquidity
ESDTMetadataContinuousCleanupEnableEpoch = 56
# SetSenderInEeiOutputTransferEnableEpoch represents the epoch when setting the sender in eei output transfers will be enabled
SetSenderInEeiOutputTransferEnableEpoch = 57
# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
MaxNodesChangeEnableEpoch = [
{ EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 },
Expand Down Expand Up @@ -748,6 +751,7 @@ func TestEnableEpochConfig(t *testing.T) {
ManagedCryptoAPIsEnableEpoch: 54,
HeartbeatDisableEpoch: 55,
ESDTMetadataContinuousCleanupEnableEpoch: 56,
SetSenderInEeiOutputTransferEnableEpoch: 57,
},
GasSchedule: GasScheduleConfig{
GasScheduleByEpochs: []GasScheduleByEpochs{
Expand Down
40 changes: 40 additions & 0 deletions integrationTests/vm/delegation/delegationScenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ import (
"github.com/stretchr/testify/require"
)

func TestDelegationSystemNodesOperationsTest(t *testing.T) {
tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{
MaxShards: 1,
NodeShardId: core.MetachainShardId,
TxSignPrivKeyShardId: 0,
})
tpn.InitDelegationManager()
maxDelegationCap := big.NewInt(5000)
serviceFee := big.NewInt(1000)
value := big.NewInt(1000)

tpn.BlockchainHook.SetCurrentHeader(&block.MetaBlock{Nonce: 1})

tpn.EpochNotifier.CheckEpoch(&testscommon.HeaderHandlerStub{
EpochField: integrationTests.UnreachableEpoch + 1,
})

// create new delegation contract
delegationScAddress := deployNewSc(t, tpn, maxDelegationCap, serviceFee, value, tpn.OwnAccount.Address)

scrsHandler, _ := tpn.InterimProcContainer.Get(block.SmartContractResultBlock)
scrs := scrsHandler.GetAllCurrentFinishedTxs()

numExpectedScrsFound := 0
// we expect the following 2 scrs:
// Delegation Manager -> Delegation Contract Address - 1000 EGLD
// Delegation Contract Address -> Staking Address - 1000 EGLD
for _, scr := range scrs {
if bytes.Equal(scr.GetSndAddr(), vm.DelegationManagerSCAddress) && bytes.Equal(scr.GetRcvAddr(), delegationScAddress) && scr.GetValue().Cmp(value) == 0 {
numExpectedScrsFound++
}

if bytes.Equal(scr.GetSndAddr(), delegationScAddress) && bytes.Equal(scr.GetRcvAddr(), vm.ValidatorSCAddress) && scr.GetValue().Cmp(value) == 0 {
numExpectedScrsFound++
}
}

assert.Equal(t, 2, numExpectedScrsFound)
}

func TestDelegationSystemNodesOperations(t *testing.T) {
tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{
MaxShards: 1,
Expand Down
1 change: 1 addition & 0 deletions node/nodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func printEnableEpochs(configs *config.Configs) {
log.Debug(readEpochFor("refactor contexts"), "epoch", enableEpochs.RefactorContextEnableEpoch)
log.Debug(readEpochFor("disable heartbeat v1"), "epoch", enableEpochs.HeartbeatDisableEpoch)
log.Debug(readEpochFor("mini block partial execution"), "epoch", enableEpochs.MiniBlockPartialExecutionEnableEpoch)
log.Debug(readEpochFor("set sender in eei output transfer"), "epoch", enableEpochs.SetSenderInEeiOutputTransferEnableEpoch)
gasSchedule := configs.EpochConfig.GasSchedule

log.Debug(readEpochFor("gas schedule directories paths"), "epoch", gasSchedule.GasScheduleByEpochs)
Expand Down
16 changes: 9 additions & 7 deletions process/factory/metachain/vmContainerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ func (vmf *vmContainerFactory) CreateForGenesis() (process.VirtualMachinesContai

func (vmf *vmContainerFactory) createSystemVMFactoryAndEEI() (vm.SystemSCContainerFactory, vm.ContextHandler, error) {
atArgumentParser := parsers.NewCallArgsParser()
systemEI, err := systemSmartContracts.NewVMContext(
vmf.blockChainHook,
vmf.cryptoHook,
atArgumentParser,
vmf.validatorAccountsDB,
vmf.chanceComputer,
)
vmContextArgs := systemSmartContracts.VMContextArgs{
BlockChainHook: vmf.blockChainHook,
CryptoHook: vmf.cryptoHook,
InputParser: atArgumentParser,
ValidatorAccountsDB: vmf.validatorAccountsDB,
ChanceComputer: vmf.chanceComputer,
EnableEpochsHandler: vmf.enableEpochsHandler,
}
systemEI, err := systemSmartContracts.NewVMContext(vmContextArgs)
if err != nil {
return nil, nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions sharding/mock/enableEpochsHandlerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ func (mock *EnableEpochsHandlerMock) IsESDTNFTImprovementV1FlagEnabled() bool {
return false
}

// IsSetSenderInEeiOutputTransferFlagEnabled -
func (mock *EnableEpochsHandlerMock) IsSetSenderInEeiOutputTransferFlagEnabled() bool {
return false
}

// IsInterfaceNil returns true if there is no value under the interface
func (mock *EnableEpochsHandlerMock) IsInterfaceNil() bool {
return mock == nil
Expand Down
6 changes: 6 additions & 0 deletions testscommon/enableEpochsHandlerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type EnableEpochsHandlerStub struct {
IsCheckTransferFlagEnabledField bool
IsTransferToMetaFlagEnabledField bool
IsESDTNFTImprovementV1FlagEnabledField bool
IsSetSenderInEeiOutputTransferFlagEnabledField bool
}

// ResetPenalizedTooMuchGasFlag -
Expand Down Expand Up @@ -618,6 +619,11 @@ func (stub *EnableEpochsHandlerStub) IsESDTNFTImprovementV1FlagEnabled() bool {
return stub.IsESDTNFTImprovementV1FlagEnabledField
}

// IsSetSenderInEeiOutputTransferFlagEnabled -
func (stub *EnableEpochsHandlerStub) IsSetSenderInEeiOutputTransferFlagEnabled() bool {
return stub.IsSetSenderInEeiOutputTransferFlagEnabledField
}

// IsInterfaceNil -
func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool {
return stub == nil
Expand Down
6 changes: 0 additions & 6 deletions vm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ var ErrNilValidatorSmartContractAddress = errors.New("nil validator smart contra
// ErrInvalidStakingAccessAddress signals that invalid staking access address was provided
var ErrInvalidStakingAccessAddress = errors.New("invalid staking access address")

// ErrInvalidGovernanceSCAddress signals that invalid governance address was provided
var ErrInvalidGovernanceSCAddress = errors.New("invalid governance smart contract address")

// ErrInvalidJailAccessAddress signals that invalid jailing access address was provided
var ErrInvalidJailAccessAddress = errors.New("invalid jailing access address")

Expand Down Expand Up @@ -185,9 +182,6 @@ var ErrInvalidEndOfEpochAccessAddress = errors.New("invalid end of epoch access
// ErrNilChanceComputer signals that nil chance computer has been provided
var ErrNilChanceComputer = errors.New("nil chance computer")

// ErrNilEpochNotifier signals that the provided EpochNotifier is nil
var ErrNilEpochNotifier = errors.New("nil EpochNotifier")

// ErrNilAddressPubKeyConverter signals that the provided public key converter is nil
var ErrNilAddressPubKeyConverter = errors.New("nil address public key converter")

Expand Down
Loading

0 comments on commit dc6ee6d

Please sign in to comment.