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

Create ticker on metachain #3363

Merged
merged 11 commits into from
Aug 25, 2021
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
DelegationMgrOps = 50000000
ValidatorToDelegation = 500000000
GetAllNodeStates = 100000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 50000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
RevokeVote = 500000
CloseProposal = 1000000
GetAllNodeStates = 20000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 50000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
GetAllNodeStates = 20000000
UnstakeTokens = 5000000
UnbondTokens = 5000000
LiquidStakingOps = 10000000

[BaseOperationCost]
StorePerByte = 50000
Expand Down
1 change: 1 addition & 0 deletions cmd/node/config/systemSmartContractsConfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[ESDTSystemSCConfig]
BaseIssuingCost = "5000000000000000000" #5 eGLD
OwnerAddress = "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c"
DelegationTicker = "DEL"

[GovernanceSystemSCConfig]
FirstWhitelistedAddress = "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80" #should use a multisign contract instead of a wallet address
Expand Down
5 changes: 3 additions & 2 deletions config/systemSmartContractsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type StakingSystemSCConfig struct {

// ESDTSystemSCConfig defines a set of constant to initialize the esdt system smart contract
type ESDTSystemSCConfig struct {
BaseIssuingCost string
OwnerAddress string
BaseIssuingCost string
OwnerAddress string
DelegationTicker string
}

// GovernanceSystemSCConfigV1 holds the initial set of values that were used to initialise the
Expand Down
3 changes: 3 additions & 0 deletions epochStart/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,6 @@ var ErrEmptyESDTOwnerAddress = errors.New("empty ESDT owner address")

// ErrNilCurrentNetworkEpochSetter signals that a nil current network epoch setter has been provided
var ErrNilCurrentNetworkEpochSetter = errors.New("nil current network epoch setter")

// ErrCouldNotInitLiquidStakingSystemSC signals that liquid staking system sc init failed
var ErrCouldNotInitLiquidStakingSystemSC = errors.New("could not init liquid staking system sc")
87 changes: 87 additions & 0 deletions epochStart/metachain/systemSCs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type systemSCProcessor struct {
esdtEnableEpoch uint32
saveJailedAlwaysEnableEpoch uint32
governanceEnableEpoch uint32
builtInOnMetaEnableEpoch uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

undefined epoch in enableEpochs.toml + print in the /node/nodeRunner.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have it: BuiltInFunctionOnMetaEnableEpoch.

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 was added some PRs before.

maxNodesEnableConfig []config.MaxNodesChangeConfig
maxNodes uint32
flagSwitchJailedWaiting atomic.Flag
Expand All @@ -84,6 +85,7 @@ type systemSCProcessor struct {
flagESDTEnabled atomic.Flag
flagSaveJailedAlwaysEnabled atomic.Flag
flagGovernanceEnabled atomic.Flag
flagBuiltInOnMetaEnabled atomic.Flag
esdtOwnerAddressBytes []byte
mapNumSwitchedPerShard map[uint32]uint32
mapNumSwitchablePerShard map[uint32]uint32
Expand Down Expand Up @@ -179,6 +181,7 @@ func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCPr
esdtOwnerAddressBytes: args.ESDTOwnerAddressBytes,
saveJailedAlwaysEnableEpoch: args.EpochConfig.EnableEpochs.SaveJailedAlwaysEnableEpoch,
governanceEnableEpoch: args.EpochConfig.EnableEpochs.GovernanceEnableEpoch,
builtInOnMetaEnableEpoch: args.EpochConfig.EnableEpochs.BuiltInFunctionOnMetaEnableEpoch,
}

log.Debug("systemSC: enable epoch for switch jail waiting", "epoch", s.switchEnableEpoch)
Expand All @@ -189,6 +192,7 @@ func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCPr
log.Debug("systemSC: enable epoch for correct last unjailed", "epoch", s.correctLastUnJailEpoch)
log.Debug("systemSC: enable epoch for save jailed always", "epoch", s.saveJailedAlwaysEnableEpoch)
log.Debug("systemSC: enable epoch for governanceV2 init", "epoch", s.governanceEnableEpoch)
log.Debug("systemSC: enable epoch for create NFT on meta", "epoch", s.builtInOnMetaEnableEpoch)

s.maxNodesEnableConfig = make([]config.MaxNodesChangeConfig, len(args.MaxNodesEnableConfig))
copy(s.maxNodesEnableConfig, args.MaxNodesEnableConfig)
Expand Down Expand Up @@ -297,6 +301,18 @@ func (s *systemSCProcessor) ProcessSystemSmartContract(
}
}

if s.flagBuiltInOnMetaEnabled.IsSet() {
tokenID, err := s.initTokenOnMeta()
if err != nil {
return err
}

err = s.initLiquidStakingSC(tokenID)
if err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -1101,6 +1117,74 @@ func (s *systemSCProcessor) updateToGovernanceV2() error {
return nil
}

func (s *systemSCProcessor) initTokenOnMeta() ([]byte, error) {
vmInput := &vmcommon.ContractCallInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.ESDTSCAddress,
CallValue: big.NewInt(0),
Arguments: [][]byte{},
GasProvided: math.MaxUint64,
},
RecipientAddr: vm.ESDTSCAddress,
Function: "initDelegationESDTOnMeta",
}
vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput)
if errRun != nil {
return nil, fmt.Errorf("%w when setting up NFTs on metachain", errRun)
}
if vmOutput.ReturnCode != vmcommon.Ok {
return nil, fmt.Errorf("got return code %s, return message %s when setting up NFTs on metachain", vmOutput.ReturnCode, vmOutput.ReturnMessage)
}
if len(vmOutput.ReturnData) != 1 {
return nil, fmt.Errorf("invalid return data on initDelegationESDTOnMeta")
}

err := s.processSCOutputAccounts(vmOutput)
if err != nil {
return nil, err
}

return vmOutput.ReturnData[0], nil
}

func (s *systemSCProcessor) initLiquidStakingSC(tokenID []byte) error {
codeMetaData := &vmcommon.CodeMetadata{
Upgradeable: false,
Payable: false,
Readable: true,
}

vmInput := &vmcommon.ContractCreateInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.LiquidStakingSCAddress,
Arguments: [][]byte{tokenID},
CallValue: big.NewInt(0),
},
ContractCode: vm.LiquidStakingSCAddress,
ContractCodeMetadata: codeMetaData.ToBytes(),
}

vmOutput, err := s.systemVM.RunSmartContractCreate(vmInput)
if err != nil {
return err
}
if vmOutput.ReturnCode != vmcommon.Ok {
return epochStart.ErrCouldNotInitLiquidStakingSystemSC
}

err = s.processSCOutputAccounts(vmOutput)
if err != nil {
return err
}

err = s.updateSystemSCContractsCode(vmInput.ContractCodeMetadata)
if err != nil {
return err
}

return nil
}

func (s *systemSCProcessor) getValidatorSystemAccount() (state.UserAccountHandler, error) {
validatorAccount, err := s.userAccountsDB.LoadAccount(vm.ValidatorSCAddress)
if err != nil {
Expand Down Expand Up @@ -1494,4 +1578,7 @@ func (s *systemSCProcessor) EpochConfirmed(epoch uint32, _ uint64) {

s.flagGovernanceEnabled.Toggle(epoch == s.governanceEnableEpoch)
log.Debug("systemProcessor: governanceV2", "enabled", s.flagGovernanceEnabled.IsSet())

s.flagBuiltInOnMetaEnabled.Toggle(epoch == s.builtInOnMetaEnableEpoch)
log.Debug("systemProcessor: create NFT on meta", "enabled", s.flagBuiltInOnMetaEnabled.IsSet())
}
27 changes: 20 additions & 7 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
vmFactory "github.com/ElrondNetwork/elrond-go/process/factory"
metaProcess "github.com/ElrondNetwork/elrond-go/process/factory/metachain"
"github.com/ElrondNetwork/elrond-go/process/peer"
"github.com/ElrondNetwork/elrond-go/process/smartContract/builtInFunctions"
"github.com/ElrondNetwork/elrond-go/process/smartContract/hooks"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/state"
Expand All @@ -50,7 +51,6 @@ import (
"github.com/ElrondNetwork/elrond-go/vm/systemSmartContracts"
"github.com/ElrondNetwork/elrond-go/vm/systemSmartContracts/defaults"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
vmcommonBuiltInFunctions "github.com/ElrondNetwork/elrond-vm-common/builtInFunctions"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -898,8 +898,21 @@ func createFullArgumentsForSystemSCProcessing(stakingV2EnableEpoch uint32, trieS
StakingV2EnableEpoch: stakingV2EnableEpoch,
}
vCreator, _ := peer.NewValidatorStatisticsProcessor(argsValidatorsProcessor)

gasSchedule := arwenConfig.MakeGasMapForTests()
gasScheduleNotifier := mock.NewGasScheduleNotifierMock(gasSchedule)
blockChain, _ := blockchain.NewMetaChain(&mock.AppStatusHandlerStub{})
argsBuiltIn := builtInFunctions.ArgsCreateBuiltInFunctionContainer{
GasSchedule: gasScheduleNotifier,
MapDNSAddresses: make(map[string]struct{}),
Marshalizer: marshalizer,
Accounts: userAccountsDB,
ShardCoordinator: &mock.ShardCoordinatorStub{SelfIdCalled: func() uint32 {
return core.MetachainShardId
}},
EpochNotifier: epochNotifier,
}
builtInFuncs, _ := builtInFunctions.CreateBuiltInFunctionContainer(argsBuiltIn)

testDataPool := dataRetrieverMock.NewPoolsHolderMock()
argsHook := hooks.ArgBlockChainHook{
Accounts: userAccountsDB,
Expand All @@ -909,13 +922,12 @@ func createFullArgumentsForSystemSCProcessing(stakingV2EnableEpoch uint32, trieS
ShardCoordinator: &mock.ShardCoordinatorStub{},
Marshalizer: marshalizer,
Uint64Converter: &mock.Uint64ByteSliceConverterMock{},
BuiltInFunctions: vmcommonBuiltInFunctions.NewBuiltInFunctionContainer(),
BuiltInFunctions: builtInFuncs,
DataPool: testDataPool,
CompiledSCPool: testDataPool.SmartContracts(),
NilCompiledSCStore: true,
}

gasSchedule := arwenConfig.MakeGasMapForTests()
defaults.FillGasMapInternal(gasSchedule, 1)
signVerifer, _ := disabled.NewMessageSignVerifier(&cryptoMocks.KeyGenStub{})

Expand All @@ -924,14 +936,15 @@ func createFullArgumentsForSystemSCProcessing(stakingV2EnableEpoch uint32, trieS
ArgBlockChainHook: argsHook,
Economics: createEconomicsData(),
MessageSignVerifier: signVerifer,
GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule),
GasSchedule: gasScheduleNotifier,
NodesConfigProvider: nodesSetup,
Hasher: hasher,
Marshalizer: marshalizer,
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down
6 changes: 4 additions & 2 deletions factory/processComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func getProcessArgs(
ImportStartHandler: &testscommon.ImportStartHandlerStub{},
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c",
BaseIssuingCost: "1000",
OwnerAddress: "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
V1: config.GovernanceSystemSCConfigV1{
Expand Down Expand Up @@ -229,6 +230,7 @@ func FillGasMapMetaChainSystemSCsCosts(value uint64) map[string]uint64 {
gasMap["DelegationMgrOps"] = value
gasMap["GetAllNodeStates"] = value
gasMap["ValidatorToDelegation"] = value
gasMap["LiquidStakingOps"] = value

return gasMap
}
5 changes: 3 additions & 2 deletions genesis/process/genesisBlockCreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ func createMockArgument(
HardForkConfig: config.HardforkConfig{},
SystemSCConfig: config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "5000000000000000000000",
OwnerAddress: "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp",
BaseIssuingCost: "5000000000000000000000",
OwnerAddress: "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down
5 changes: 3 additions & 2 deletions integrationTests/multiShard/hardFork/hardFork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ func hardForkImport(
TrieStorageManagers: node.TrieStorageManagers,
SystemSCConfig: config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down
10 changes: 6 additions & 4 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ func CreateFullGenesisBlocks(
TrieStorageManagers: trieStorageManagers,
SystemSCConfig: config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
FirstWhitelistedAddress: DelegationManagerConfigChangeAddress,
Expand Down Expand Up @@ -693,8 +694,9 @@ func CreateGenesisMetaBlock(
HardForkConfig: config.HardforkConfig{},
SystemSCConfig: config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down
10 changes: 6 additions & 4 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,9 @@ func (tpn *TestProcessorNode) createFullSCQueryService() {
Marshalizer: TestMarshalizer,
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
V1: config.GovernanceSystemSCConfigV1{
Expand Down Expand Up @@ -1589,8 +1590,9 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors() {
Marshalizer: TestMarshalizer,
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "1000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down
5 changes: 3 additions & 2 deletions integrationTests/vm/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ func createEpochConfig() *config.EpochConfig {
func createSystemSCConfig() *config.SystemSmartContractsConfig {
return &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "5000000000000000000",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303233",
BaseIssuingCost: "5000000000000000000",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303233",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
V1: config.GovernanceSystemSCConfigV1{
Expand Down
11 changes: 7 additions & 4 deletions process/factory/metachain/vmContainerFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func createVmContainerMockArgument(gasSchedule core.GasScheduleNotifier) ArgsNew
Marshalizer: &mock.MarshalizerMock{},
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "100000000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "100000000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down Expand Up @@ -301,8 +302,9 @@ func TestVmContainerFactory_Create(t *testing.T) {
Marshalizer: &mock.MarshalizerMock{},
SystemSCConfig: &config.SystemSmartContractsConfig{
ESDTSystemSCConfig: config.ESDTSystemSCConfig{
BaseIssuingCost: "100000000",
OwnerAddress: "aaaaaa",
BaseIssuingCost: "100000000",
OwnerAddress: "aaaaaa",
DelegationTicker: "DEL",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
Active: config.GovernanceSystemSCConfigActive{
Expand Down Expand Up @@ -419,6 +421,7 @@ func FillGasMapMetaChainSystemSCsCosts(value uint64) map[string]uint64 {
gasMap["DelegationMgrOps"] = value
gasMap["GetAllNodeStates"] = value
gasMap["ValidatorToDelegation"] = value
gasMap["LiquidStakingOps"] = value

return gasMap
}