Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/node/config/systemSmartContractsConfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

[GovernanceSystemSCConfig]
OwnerAddress = "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80" #should use a multisign contract instead of a wallet address
MaxVotingDelayPeriodInEpochs = 30
[GovernanceSystemSCConfig.V1]
NumNodes = 500
ProposalCost = "5000000000000000000" #5 eGLD
Expand Down
11 changes: 6 additions & 5 deletions config/systemSmartContractsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ESDTSystemSCConfig struct {
}

// GovernanceSystemSCConfigV1 holds the initial set of values that were used to initialise the
// governance system smart contract at genesis time
// governance system smart contract at genesis time
type GovernanceSystemSCConfigV1 struct {
NumNodes int64
ProposalCost string
Expand All @@ -42,7 +42,7 @@ type GovernanceSystemSCConfigV1 struct {
}

// GovernanceSystemSCConfigActive defines the set of configuration values used by the governance
// system smart contract once it activates
// system smart contract once it activates
type GovernanceSystemSCConfigActive struct {
ProposalCost string
LostProposalFee string
Expand All @@ -53,9 +53,10 @@ type GovernanceSystemSCConfigActive struct {

// GovernanceSystemSCConfig defines the set of constants to initialize the governance system smart contract
type GovernanceSystemSCConfig struct {
V1 GovernanceSystemSCConfigV1
Active GovernanceSystemSCConfigActive
OwnerAddress string
V1 GovernanceSystemSCConfigV1
Active GovernanceSystemSCConfigActive
OwnerAddress string
MaxVotingDelayPeriodInEpochs uint32
}

// DelegationManagerSystemSCConfig defines a set of constants to initialize the delegation manager system smart contract
Expand Down
3 changes: 2 additions & 1 deletion epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
3 changes: 2 additions & 1 deletion factory/processing/processComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func createMockProcessComponentsFactoryArgs() processComp.ProcessComponentsFacto
MinPassThreshold: 0.5,
MinVetoThreshold: 0.5,
},
OwnerAddress: "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80",
OwnerAddress: "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "2500000000000000000000",
Expand Down
3 changes: 2 additions & 1 deletion genesis/process/genesisBlockCreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func createMockArgument(
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: nodePrice.Text(10),
Expand Down
3 changes: 2 additions & 1 deletion integrationTests/multiShard/hardFork/hardFork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ func hardForkImport(
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: integrationTests.DelegationManagerConfigChangeAddress,
OwnerAddress: integrationTests.DelegationManagerConfigChangeAddress,
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
6 changes: 4 additions & 2 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ func CreateFullGenesisBlocks(
OwnerAddress: "aaaaaa",
},
GovernanceSystemSCConfig: config.GovernanceSystemSCConfig{
OwnerAddress: DelegationManagerConfigChangeAddress,
OwnerAddress: DelegationManagerConfigChangeAddress,
MaxVotingDelayPeriodInEpochs: 30,
V1: config.GovernanceSystemSCConfigV1{
ProposalCost: "500",
},
Expand Down Expand Up @@ -808,7 +809,8 @@ func CreateGenesisMetaBlock(
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: DelegationManagerConfigChangeAddress,
OwnerAddress: DelegationManagerConfigChangeAddress,
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
6 changes: 4 additions & 2 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ func (tpn *TestProcessorNode) createFullSCQueryService(gasMap map[string]map[str
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: DelegationManagerConfigChangeAddress,
OwnerAddress: DelegationManagerConfigChangeAddress,
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down Expand Up @@ -1882,7 +1883,8 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: DelegationManagerConfigChangeAddress,
OwnerAddress: DelegationManagerConfigChangeAddress,
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
3 changes: 2 additions & 1 deletion integrationTests/vm/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ func createSystemSCConfig() *config.SystemSmartContractsConfig {
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "2500000000000000000000",
Expand Down
3 changes: 2 additions & 1 deletion process/factory/metachain/vmContainerFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ func TestVmContainerFactory_Create(t *testing.T) {
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
3 changes: 2 additions & 1 deletion testscommon/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ func GetProcessArgs(
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80",
OwnerAddress: "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "2500000000000000000000",
Expand Down
23 changes: 12 additions & 11 deletions vm/factory/systemSCFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,18 @@ func (scf *systemSCFactory) createGovernanceContract() (vm.SystemSmartContract,
}

argsGovernance := systemSmartContracts.ArgsNewGovernanceContract{
Eei: scf.systemEI,
GasCost: scf.gasCost,
GovernanceConfig: scf.systemSCConfig.GovernanceSystemSCConfig,
Marshalizer: scf.marshalizer,
Hasher: scf.hasher,
GovernanceSCAddress: vm.GovernanceSCAddress,
DelegationMgrSCAddress: vm.DelegationManagerSCAddress,
ValidatorSCAddress: vm.ValidatorSCAddress,
EnableEpochsHandler: scf.enableEpochsHandler,
UnBondPeriodInEpochs: scf.systemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs,
OwnerAddress: ownerAddress,
Eei: scf.systemEI,
GasCost: scf.gasCost,
GovernanceConfig: scf.systemSCConfig.GovernanceSystemSCConfig,
Marshalizer: scf.marshalizer,
Hasher: scf.hasher,
GovernanceSCAddress: vm.GovernanceSCAddress,
DelegationMgrSCAddress: vm.DelegationManagerSCAddress,
ValidatorSCAddress: vm.ValidatorSCAddress,
EnableEpochsHandler: scf.enableEpochsHandler,
UnBondPeriodInEpochs: scf.systemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs,
MaxVotingDelayPeriodInEpochs: scf.systemSCConfig.GovernanceSystemSCConfig.MaxVotingDelayPeriodInEpochs,
OwnerAddress: ownerAddress,
}
governance, err := systemSmartContracts.NewGovernanceContract(argsGovernance)
return governance, err
Expand Down
3 changes: 2 additions & 1 deletion vm/factory/systemSCFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func createMockNewSystemScFactoryArgs() ArgsNewSystemSCFactory {
MinVetoThreshold: 0.5,
LostProposalFee: "1",
},
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
OwnerAddress: "3132333435363738393031323334353637383930313233343536373839303234",
MaxVotingDelayPeriodInEpochs: 30,
},
StakingSystemSCConfig: config.StakingSystemSCConfig{
GenesisNodePrice: "1000",
Expand Down
88 changes: 47 additions & 41 deletions vm/systemSmartContracts/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,35 @@ const maxPercentage = float64(10000.0)

// ArgsNewGovernanceContract defines the arguments needed for the on-chain governance contract
type ArgsNewGovernanceContract struct {
Eei vm.SystemEI
GasCost vm.GasCost
GovernanceConfig config.GovernanceSystemSCConfig
Marshalizer marshal.Marshalizer
Hasher hashing.Hasher
GovernanceSCAddress []byte
DelegationMgrSCAddress []byte
ValidatorSCAddress []byte
OwnerAddress []byte
UnBondPeriodInEpochs uint32
EnableEpochsHandler common.EnableEpochsHandler
Eei vm.SystemEI
GasCost vm.GasCost
GovernanceConfig config.GovernanceSystemSCConfig
Marshalizer marshal.Marshalizer
Hasher hashing.Hasher
GovernanceSCAddress []byte
DelegationMgrSCAddress []byte
ValidatorSCAddress []byte
OwnerAddress []byte
UnBondPeriodInEpochs uint32
MaxVotingDelayPeriodInEpochs uint32
EnableEpochsHandler common.EnableEpochsHandler
}

type governanceContract struct {
eei vm.SystemEI
gasCost vm.GasCost
baseProposalCost *big.Int
ownerAddress []byte
governanceSCAddress []byte
delegationMgrSCAddress []byte
validatorSCAddress []byte
marshalizer marshal.Marshalizer
hasher hashing.Hasher
governanceConfig config.GovernanceSystemSCConfig
unBondPeriodInEpochs uint32
enableEpochsHandler common.EnableEpochsHandler
mutExecution sync.RWMutex
eei vm.SystemEI
gasCost vm.GasCost
baseProposalCost *big.Int
ownerAddress []byte
governanceSCAddress []byte
delegationMgrSCAddress []byte
validatorSCAddress []byte
marshalizer marshal.Marshalizer
hasher hashing.Hasher
governanceConfig config.GovernanceSystemSCConfig
unBondPeriodInEpochs uint32
maxVotingDelayPeriodInEpochs uint32
enableEpochsHandler common.EnableEpochsHandler
mutExecution sync.RWMutex
}

// NewGovernanceContract creates a new governance smart contract
Expand Down Expand Up @@ -99,18 +101,19 @@ func NewGovernanceContract(args ArgsNewGovernanceContract) (*governanceContract,
}

g := &governanceContract{
eei: args.Eei,
gasCost: args.GasCost,
baseProposalCost: baseProposalCost,
ownerAddress: args.OwnerAddress,
governanceSCAddress: args.GovernanceSCAddress,
delegationMgrSCAddress: args.DelegationMgrSCAddress,
validatorSCAddress: args.ValidatorSCAddress,
marshalizer: args.Marshalizer,
hasher: args.Hasher,
governanceConfig: args.GovernanceConfig,
enableEpochsHandler: args.EnableEpochsHandler,
unBondPeriodInEpochs: args.UnBondPeriodInEpochs,
eei: args.Eei,
gasCost: args.GasCost,
baseProposalCost: baseProposalCost,
ownerAddress: args.OwnerAddress,
governanceSCAddress: args.GovernanceSCAddress,
delegationMgrSCAddress: args.DelegationMgrSCAddress,
validatorSCAddress: args.ValidatorSCAddress,
marshalizer: args.Marshalizer,
hasher: args.Hasher,
governanceConfig: args.GovernanceConfig,
enableEpochsHandler: args.EnableEpochsHandler,
unBondPeriodInEpochs: args.UnBondPeriodInEpochs,
maxVotingDelayPeriodInEpochs: args.MaxVotingDelayPeriodInEpochs,
}

return g, nil
Expand Down Expand Up @@ -1218,18 +1221,21 @@ func (g *governanceContract) proposalExists(reference []byte) bool {

// startEndEpochFromArguments converts the nonce string arguments to uint64
func (g *governanceContract) startEndEpochFromArguments(argStart []byte, argEnd []byte) (uint64, uint64, error) {
startVoteEpoch := big.NewInt(0).SetBytes(argStart)
endVoteEpoch := big.NewInt(0).SetBytes(argEnd)
startVoteEpoch := big.NewInt(0).SetBytes(argStart).Uint64()
endVoteEpoch := big.NewInt(0).SetBytes(argEnd).Uint64()

currentEpoch := uint64(g.eei.BlockChainHook().CurrentEpoch())
if currentEpoch > startVoteEpoch.Uint64() || startVoteEpoch.Uint64() > endVoteEpoch.Uint64() {
if currentEpoch > startVoteEpoch || startVoteEpoch > endVoteEpoch {
return 0, 0, vm.ErrInvalidStartEndVoteEpoch
}
if endVoteEpoch.Uint64()-startVoteEpoch.Uint64() >= uint64(g.unBondPeriodInEpochs) {
if endVoteEpoch-startVoteEpoch >= uint64(g.unBondPeriodInEpochs) {
return 0, 0, vm.ErrInvalidStartEndVoteEpoch
}
if g.enableEpochsHandler.IsFlagEnabled(common.GovernanceFixesFlag) && startVoteEpoch-currentEpoch >= uint64(g.maxVotingDelayPeriodInEpochs) {
return 0, 0, vm.ErrInvalidStartEndVoteEpoch
}

return startVoteEpoch.Uint64(), endVoteEpoch.Uint64(), nil
return startVoteEpoch, endVoteEpoch, nil
}

// convertV2Config converts the passed config file to the correct V2 typed GovernanceConfig
Expand Down
Loading
Loading