aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-11-16 18:17:51 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commit10697136e876446a2807d9fd4799a0a5b9605e30 (patch)
treeef20521eccc0addde3c377715a08ea8c110ade1a
parentfd188f89845ea16c40c2b6af2ffa67b0f445b854 (diff)
downloadgo-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar.gz
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar.bz2
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar.lz
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar.xz
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.tar.zst
go-tangerine-10697136e876446a2807d9fd4799a0a5b9605e30.zip
core: vm: add minStake to governance contract variable (#31)
-rw-r--r--core/genesis_alloc.go2
-rw-r--r--core/vm/governance.go41
-rw-r--r--params/config.go7
-rw-r--r--params/gen_dexcon_config.go6
-rw-r--r--test/genesis.json17
5 files changed, 63 insertions, 10 deletions
diff --git a/core/genesis_alloc.go b/core/genesis_alloc.go
index ffe360457..b4b2732dd 100644
--- a/core/genesis_alloc.go
+++ b/core/genesis_alloc.go
@@ -21,6 +21,6 @@ package core
// Use mkalloc.go to create/update them.
// nolint: misspell
-const mainnetAllocData = "\xf9\x03+\xe9\x94\x12E\xa8g/\xa8\x81\u03c5\x8e\xf0\x1d4\xc4+U\u0672c\xff\u04ca\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\x80\x80\u0100\x80\x80\x80\xf8\xa9\x946\x1eIX\xbd\x8bM\x03\\h\xc4s\x19>w\xfd\xabj\xea\x9d\xf8\x92\x8965\u026d\xc5\u07a0\x00\x00\x89\x1b\x1a\xe4\xd6\xe2\xefP\x00\x00\x80\xb8A\x04\f/\a\xcf\"\x96n\xba\xa1\x9d\xd8}\xe1\x1d\x04\xf9\xa6\x06\xe8>u\xa5)Utv\nZM\xd8(\a\xe7\xd9\xf2\x8f\x86\xcd8\x98q\u0753\x1aG|\xacd\xe23\xa6\xf0\x98\u0572W\x87\x1d\x81c\xdc\x1b\xdd\xcf\xf88\x86DEXON1\x8fnode1@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xa9\x94\xb6\xa2\xe2p\xb5O\x19\xb4\x00-e5\xa7\x1c\xfd\xd1\xca\x1f_\xc1\xf8\x92\x8965\u026d\xc5\u07a0\x00\x00\x89\x1b\x1a\xe4\xd6\xe2\xefP\x00\x00\x80\xb8A\x04c\xf7\x8d9\x8fk\x04)R\x06*&\xf3U\x1aN)J\x11\bK\x10\x06\xc8\xd67d7\xb7$\x88\xd8\xf3\xafk\x84\x991\xc06$\xad-X\x19\x00\xe9\xad_<\xfe\xee\xd0@\u01d9\xe50\x8c\xd8\x01(S\xfb\xf88\x86DEXON3\x8fnode3@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xa9\x94\xb6\xbb\xbe9\x0311\xe4(\u0563TXV\xa5\x96\xca\xcbx\x10\xf8\x92\x8965\u026d\xc5\u07a0\x00\x00\x89\x1b\x1a\xe4\xd6\xe2\xefP\x00\x00\x80\xb8A\x04\xa1\x11\x8c\x8f\x1c.)=\xe5(\xe5\xb4Z\xc5\xe6Qg\xafL\xb4\xd1\b\x87\x92J\x9f\x83\x92\x87\xd0`\xda&AN\x97\x1c\xabu\x01>V\r\xfe\u01c9{\x19\x83\xea\xa61\xae/\x16\xea@bRS\x10\xed\xd8\xea\xf88\x86DEXON4\x8fnode4@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xa9\x94\xbcq\xc0\xf2\xae\xcaF\xfa\x00\x01\xe7e\x96P)\xb1j\x06\x04\x9e\xf8\x92\x8965\u026d\xc5\u07a0\x00\x00\x89\x1b\x1a\xe4\xd6\xe2\xefP\x00\x00\x80\xb8A\x04\xa1*\x01_'\u064eS\x05I\x8d#\xae\xac\xde(\x1eH\xaa\xd9\x18\xae\x87\xd7\xf6\x17\x84\xabC\x82\x89S\u06d9\xbf\x1fDBb\x94\xcb\xc2\x1e2\xcf:\x99\x12/,\xe8\xa3[\xa7\x18\xa7\xc8\x14\xee\u01fa\xe9\xa3\xea\xf88\x86DEXON2\x8fnode2@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\u953f\x8cH\xa6 \xba\xccF\x90\u007f\x9b\x89s-%\xe4z-|\xf7\u04ca\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\x80\x80\u0100\x80\x80\x80\xea\x94\xe0\xf8Y4\x03S\x85F\x93\xf57\xea3q\x06\xa3>\x9f\xea\xb0\u050bR\xb7\xd2\xdc\xc8\f\xd2\xe4\x00\x00\x00\x80\x80\x80\u0100\x80\x80\x80"
+const mainnetAllocData = "\xf9\x033\xe9\x94\x12E\xa8g/\xa8\x81\u03c5\x8e\xf0\x1d4\xc4+U\u0672c\xff\u04ca\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\x80\x80\u0100\x80\x80\x80\xf8\xab\x946\x1eIX\xbd\x8bM\x03\\h\xc4s\x19>w\xfd\xabj\xea\x9d\xf8\x94\x8a*Z\x05\x8f\u0095\xed\x00\x00\x00\x8a\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\xb8A\x04\f/\a\xcf\"\x96n\xba\xa1\x9d\xd8}\xe1\x1d\x04\xf9\xa6\x06\xe8>u\xa5)Utv\nZM\xd8(\a\xe7\xd9\xf2\x8f\x86\xcd8\x98q\u0753\x1aG|\xacd\xe23\xa6\xf0\x98\u0572W\x87\x1d\x81c\xdc\x1b\xdd\xcf\xf88\x86DEXON1\x8fnode1@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xab\x94\xb6\xa2\xe2p\xb5O\x19\xb4\x00-e5\xa7\x1c\xfd\xd1\xca\x1f_\xc1\xf8\x94\x8a*Z\x05\x8f\u0095\xed\x00\x00\x00\x8a\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\xb8A\x04c\xf7\x8d9\x8fk\x04)R\x06*&\xf3U\x1aN)J\x11\bK\x10\x06\xc8\xd67d7\xb7$\x88\xd8\xf3\xafk\x84\x991\xc06$\xad-X\x19\x00\xe9\xad_<\xfe\xee\xd0@\u01d9\xe50\x8c\xd8\x01(S\xfb\xf88\x86DEXON3\x8fnode3@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xab\x94\xb6\xbb\xbe9\x0311\xe4(\u0563TXV\xa5\x96\xca\xcbx\x10\xf8\x94\x8a*Z\x05\x8f\u0095\xed\x00\x00\x00\x8a\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\xb8A\x04\xa1\x11\x8c\x8f\x1c.)=\xe5(\xe5\xb4Z\xc5\xe6Qg\xafL\xb4\xd1\b\x87\x92J\x9f\x83\x92\x87\xd0`\xda&AN\x97\x1c\xabu\x01>V\r\xfe\u01c9{\x19\x83\xea\xa61\xae/\x16\xea@bRS\x10\xed\xd8\xea\xf88\x86DEXON4\x8fnode4@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\xf8\xab\x94\xbcq\xc0\xf2\xae\xcaF\xfa\x00\x01\xe7e\x96P)\xb1j\x06\x04\x9e\xf8\x94\x8a*Z\x05\x8f\u0095\xed\x00\x00\x00\x8a\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\xb8A\x04\xa1*\x01_'\u064eS\x05I\x8d#\xae\xac\xde(\x1eH\xaa\xd9\x18\xae\x87\xd7\xf6\x17\x84\xabC\x82\x89S\u06d9\xbf\x1fDBb\x94\xcb\xc2\x1e2\xcf:\x99\x12/,\xe8\xa3[\xa7\x18\xa7\xc8\x14\xee\u01fa\xe9\xa3\xea\xf88\x86DEXON2\x8fnode2@dexon.org\x8eTaipei, Taiwan\x91https://dexon.org\u953f\x8cH\xa6 \xba\xccF\x90\u007f\x9b\x89s-%\xe4z-|\xf7\u04ca\x15-\x02\xc7\xe1J\xf6\x80\x00\x00\x80\x80\x80\u0100\x80\x80\x80\xea\x94\xe0\xf8Y4\x03S\x85F\x93\xf57\xea3q\x06\xa3>\x9f\xea\xb0\u050bR\xb7\xd2\xdc\xc8\f\xd2\xe4\x00\x00\x00\x80\x80\x80\u0100\x80\x80\x80"
const testnetAllocData = mainnetAllocData
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 &params.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()
diff --git a/params/config.go b/params/config.go
index d66ee5610..4dbbf6233 100644
--- a/params/config.go
+++ b/params/config.go
@@ -54,6 +54,7 @@ var (
Dexcon: &DexconConfig{
GenesisCRSText: "In DEXON, we trust.",
Owner: common.HexToAddress("BF8C48A620bacc46907f9B89732D25E47A2D7Cf7"),
+ MinStake: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
BlockReward: big.NewInt(1e18),
BlockGasLimit: 80000000,
NumChains: 4,
@@ -92,6 +93,7 @@ var (
Dexcon: &DexconConfig{
GenesisCRSText: "In DEXON, we trust.",
Owner: common.HexToAddress("BF8C48A620bacc46907f9B89732D25E47A2D7Cf7"),
+ MinStake: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
BlockReward: big.NewInt(1e18),
BlockGasLimit: 80000000,
NumChains: 6,
@@ -201,6 +203,7 @@ func (c *CliqueConfig) String() string {
type DexconConfig struct {
GenesisCRSText string `json:"genesisCRSText"`
Owner common.Address `json:"owner"`
+ MinStake *big.Int `json:"minStake"`
BlockReward *big.Int `json:"blockReward"`
BlockGasLimit uint64 `json:"blockGasLimit"`
NumChains uint32 `json:"numChains"`
@@ -215,14 +218,16 @@ type DexconConfig struct {
}
type dexconConfigSpecMarshaling struct {
+ MinStake *math.HexOrDecimal256
BlockReward *math.HexOrDecimal256
}
// String implements the stringer interface, returning the consensus engine details.
func (d *DexconConfig) String() string {
- return fmt.Sprintf("{GenesisCRSText: %v Owner: %v BlockReward: %v BlockGasLimit: %v NumChains: %v LambdaBA: %v LambdaDKG: %v K: %v PhiRatio: %v NotarySetSize: %v DKGSetSize: %v RoundInterval: %v MinBlockInterval: %v}",
+ return fmt.Sprintf("{GenesisCRSText: %v Owner: %v MinStake: %v BlockReward: %v BlockGasLimit: %v NumChains: %v LambdaBA: %v LambdaDKG: %v K: %v PhiRatio: %v NotarySetSize: %v DKGSetSize: %v RoundInterval: %v MinBlockInterval: %v}",
d.GenesisCRSText,
d.Owner,
+ d.MinStake,
d.BlockReward,
d.BlockGasLimit,
d.NumChains,
diff --git a/params/gen_dexcon_config.go b/params/gen_dexcon_config.go
index e1be574c0..6633b38f3 100644
--- a/params/gen_dexcon_config.go
+++ b/params/gen_dexcon_config.go
@@ -17,6 +17,7 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) {
type DexconConfig struct {
GenesisCRSText string `json:"genesisCRSText"`
Owner common.Address `json:"owner"`
+ MinStake *math.HexOrDecimal256 `json:"minStake"`
BlockReward *math.HexOrDecimal256 `json:"blockReward"`
BlockGasLimit uint64 `json:"blockGasLimit"`
NumChains uint32 `json:"numChains"`
@@ -32,6 +33,7 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) {
var enc DexconConfig
enc.GenesisCRSText = d.GenesisCRSText
enc.Owner = d.Owner
+ enc.MinStake = (*math.HexOrDecimal256)(d.MinStake)
enc.BlockReward = (*math.HexOrDecimal256)(d.BlockReward)
enc.BlockGasLimit = d.BlockGasLimit
enc.NumChains = d.NumChains
@@ -51,6 +53,7 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error {
type DexconConfig struct {
GenesisCRSText *string `json:"genesisCRSText"`
Owner *common.Address `json:"owner"`
+ MinStake *math.HexOrDecimal256 `json:"minStake"`
BlockReward *math.HexOrDecimal256 `json:"blockReward"`
BlockGasLimit *uint64 `json:"blockGasLimit"`
NumChains *uint32 `json:"numChains"`
@@ -73,6 +76,9 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error {
if dec.Owner != nil {
d.Owner = *dec.Owner
}
+ if dec.MinStake != nil {
+ d.MinStake = (*big.Int)(dec.MinStake)
+ }
if dec.BlockReward != nil {
d.BlockReward = (*big.Int)(dec.BlockReward)
}
diff --git a/test/genesis.json b/test/genesis.json
index 11ae609a0..cf61e2d45 100644
--- a/test/genesis.json
+++ b/test/genesis.json
@@ -12,6 +12,7 @@
"dexcon": {
"genesisCRSText": "In DEXON, we trust.",
"owner": "0xBF8C48A620bacc46907f9B89732D25E47A2D7Cf7",
+ "minStake": "0x152d02c7e14af6800000",
"blockReward": "0xde0b6b3a7640000",
"blockGasLimit": 80000000,
"numChains": 6,
@@ -46,8 +47,8 @@
"staked": "0"
},
"0x361e4958bd8b4d035C68C473193E77FdAb6aEa9D": {
- "balance": "1000000000000000000000",
- "staked": "500000000000000000000",
+ "balance": "200000000000000000000000",
+ "staked": "100000000000000000000000",
"publicKey": "0x040c2f07cf22966ebaa19dd87de11d04f9a606e83e75a5295574760a5a4dd82807e7d9f28f86cd389871dd931a477cac64e233a6f098d5b257871d8163dc1bddcf",
"info": {
"name": "DEXON1",
@@ -57,8 +58,8 @@
}
},
"0xbC71C0F2aeCa46fa0001e765965029b16a06049E": {
- "balance": "1000000000000000000000",
- "staked": "500000000000000000000",
+ "balance": "200000000000000000000000",
+ "staked": "100000000000000000000000",
"publicKey": "0x04a12a015f27d98e5305498d23aeacde281e48aad918ae87d7f61784ab43828953db99bf1f44426294cbc21e32cf3a99122f2ce8a35ba718a7c814eec7bae9a3ea",
"info": {
"name": "DEXON2",
@@ -68,8 +69,8 @@
}
},
"0xB6a2e270b54F19B4002d6535a71CFDd1CA1f5fC1": {
- "balance": "1000000000000000000000",
- "staked": "500000000000000000000",
+ "balance": "200000000000000000000000",
+ "staked": "100000000000000000000000",
"publicKey": "0x0463f78d398f6b042952062a26f3551a4e294a11084b1006c8d6376437b72488d8f3af6b849931c03624ad2d581900e9ad5f3cfeeed040c799e5308cd8012853fb",
"info": {
"name": "DEXON3",
@@ -79,8 +80,8 @@
}
},
"0xb6bBBE39033131e428d5a3545856a596cacB7810": {
- "balance": "1000000000000000000000",
- "staked": "500000000000000000000",
+ "balance": "200000000000000000000000",
+ "staked": "100000000000000000000000",
"publicKey": "0x04a1118c8f1c2e293de528e5b45ac5e65167af4cb4d10887924a9f839287d060da26414e971cab75013e560dfec7897b1983eaa631ae2f16ea4062525310edd8ea",
"info": {
"name": "DEXON4",