diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-16 18:17:51 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | 1677355db643a52843a202529d0a044453b090b6 (patch) | |
tree | f842ba311257f6cbdbac3208806a68f35b68d152 /core/vm/governance.go | |
parent | f1f0e7d0b962c802124b2ed9123d3e9bd9cd9644 (diff) | |
download | dexon-1677355db643a52843a202529d0a044453b090b6.tar.gz dexon-1677355db643a52843a202529d0a044453b090b6.tar.zst dexon-1677355db643a52843a202529d0a044453b090b6.zip |
core: vm: add minStake to governance contract variable (#31)
Diffstat (limited to 'core/vm/governance.go')
-rw-r--r-- | core/vm/governance.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go index f406294d2..cbc7f458f 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -165,6 +165,20 @@ const GovernanceABIJSON = ` }, { "constant": true, + "inputs": [], + "name": "minStake", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, "inputs": [ { "name": "", @@ -438,6 +452,10 @@ const GovernanceABIJSON = ` "constant": false, "inputs": [ { + "name": "MinStake", + "type": "uint256" + }, + { "name": "BlockReward", "type": "uint256" }, @@ -870,6 +888,12 @@ func RunGovernanceContract(evm *EVM, input []byte, contract *Contract) ( return nil, errExecutionReverted } return res, nil + case "minStake": + res, err := method.Outputs.Pack(g.state.MinStake()) + if err != nil { + return nil, errExecutionReverted + } + return res, nil case "numChains": res, err := method.Outputs.Pack(g.state.NumChains()) if err != nil { @@ -948,6 +972,7 @@ const ( dkgFinalizedLoc dkgFinalizedsCountLoc ownerLoc + minStakeLoc blockRewardLoc blockGasLimitLoc numChainsLoc @@ -1320,6 +1345,14 @@ func (s *GovernanceStateHelper) SetOwner(newOwner common.Address) { s.setState(common.BigToHash(big.NewInt(ownerLoc)), newOwner.Hash()) } +// uint256 public minStake; +func (s *GovernanceStateHelper) MinStake() *big.Int { + return s.getStateBigInt(big.NewInt(minStakeLoc)) +} +func (s *GovernanceStateHelper) SetMinStake(stake *big.Int) { + s.setStateBigInt(big.NewInt(minStakeLoc), stake) +} + // uint256 public blockReward; func (s *GovernanceStateHelper) BlockReward() *big.Int { return s.getStateBigInt(big.NewInt(blockRewardLoc)) @@ -1401,6 +1434,7 @@ func (s *GovernanceStateHelper) Stake( // Configuration returns the current configuration. func (s *GovernanceStateHelper) Configuration() *params.DexconConfig { return ¶ms.DexconConfig{ + MinStake: s.getStateBigInt(big.NewInt(minStakeLoc)), BlockReward: s.getStateBigInt(big.NewInt(blockRewardLoc)), BlockGasLimit: uint64(s.getStateBigInt(big.NewInt(blockGasLimitLoc)).Uint64()), NumChains: uint32(s.getStateBigInt(big.NewInt(numChainsLoc)).Uint64()), @@ -1417,6 +1451,7 @@ func (s *GovernanceStateHelper) Configuration() *params.DexconConfig { // UpdateConfiguration updates system configuration. func (s *GovernanceStateHelper) UpdateConfiguration(cfg *params.DexconConfig) { + s.setStateBigInt(big.NewInt(minStakeLoc), cfg.MinStake) s.setStateBigInt(big.NewInt(blockRewardLoc), cfg.BlockReward) s.setStateBigInt(big.NewInt(blockGasLimitLoc), big.NewInt(int64(cfg.BlockGasLimit))) s.setStateBigInt(big.NewInt(numChainsLoc), big.NewInt(int64(cfg.NumChains))) @@ -1643,6 +1678,12 @@ func (g *GovernanceContract) stake( caller := g.contract.Caller() offset := g.state.Offset(caller) + // Need to stake at least minStake. + if g.contract.Value().Cmp(g.state.MinStake()) < 0 { + g.penalize() + return nil, errExecutionReverted + } + // Can not stake if already staked. if offset.Cmp(big.NewInt(0)) >= 0 { g.penalize() |