aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-14 19:55:48 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:58 +0800
commit37b46f3dc966ae578c3a0aedcda2ddb4e1a85444 (patch)
tree3504fbdc62551d7d3a7f931b2a6bed22500e407c
parent691ec7093534274f45dcb939f31807fba8fe5038 (diff)
downloaddexon-37b46f3dc966ae578c3a0aedcda2ddb4e1a85444.tar.gz
dexon-37b46f3dc966ae578c3a0aedcda2ddb4e1a85444.tar.zst
dexon-37b46f3dc966ae578c3a0aedcda2ddb4e1a85444.zip
core: vm: group min gas price with related state variables (#257)
-rw-r--r--core/vm/oracle_contract_abi.go8
-rw-r--r--core/vm/oracle_contracts.go20
-rw-r--r--core/vm/oracle_contracts_test.go4
-rw-r--r--params/config.go16
4 files changed, 24 insertions, 24 deletions
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go
index e06adf633..cd45e2754 100644
--- a/core/vm/oracle_contract_abi.go
+++ b/core/vm/oracle_contract_abi.go
@@ -763,6 +763,10 @@ const GovernanceABIJSON = `
"type": "uint256"
},
{
+ "name": "MinGasPrice",
+ "type": "uint256"
+ },
+ {
"name": "BlockGasLimit",
"type": "uint256"
},
@@ -793,10 +797,6 @@ const GovernanceABIJSON = `
{
"name": "FineValues",
"type": "uint256[]"
- },
- {
- "name": "MinGasPrice",
- "type": "uint256"
}
],
"name": "updateConfiguration",
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index 836489420..37e734a5f 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -84,7 +84,7 @@ const (
minBlockIntervalLoc
fineValuesLoc
finedRecordsLoc
- minGasPriceLoc
+ minGasPriceLoc // TODO(w): reorder this before mainnet
)
func publicKeyToNodeKeyAddress(pkBytes []byte) (common.Address, error) {
@@ -729,6 +729,11 @@ func (s *GovernanceState) MiningHalved() {
s.IncNextHalvingSupply(s.LastHalvedAmount())
}
+// uint256 public minGasPrice;
+func (s *GovernanceState) MinGasPrice() *big.Int {
+ return s.getStateBigInt(big.NewInt(minGasPriceLoc))
+}
+
// uint256 public blockGasLimit;
func (s *GovernanceState) BlockGasLimit() *big.Int {
return s.getStateBigInt(big.NewInt(blockGasLimitLoc))
@@ -803,11 +808,6 @@ func (s *GovernanceState) SetFineRecords(recordHash Bytes32, status bool) {
s.setStateBigInt(loc, big.NewInt(value))
}
-// uint256 public minGasPrice;
-func (s *GovernanceState) MinGasPrice() *big.Int {
- return s.getStateBigInt(big.NewInt(minGasPriceLoc))
-}
-
// Initialize initializes governance contract state.
func (s *GovernanceState) Initialize(config *params.DexconConfig, totalSupply *big.Int) {
if config.NextHalvingSupply.Cmp(totalSupply) <= 0 {
@@ -875,6 +875,7 @@ func (s *GovernanceState) Configuration() *params.DexconConfig {
MiningVelocity: float32(s.getStateBigInt(big.NewInt(miningVelocityLoc)).Uint64()) / decimalMultiplier,
NextHalvingSupply: s.getStateBigInt(big.NewInt(nextHalvingSupplyLoc)),
LastHalvedAmount: s.getStateBigInt(big.NewInt(lastHalvedAmountLoc)),
+ MinGasPrice: s.getStateBigInt(big.NewInt(minGasPriceLoc)),
BlockGasLimit: s.getStateBigInt(big.NewInt(blockGasLimitLoc)).Uint64(),
LambdaBA: s.getStateBigInt(big.NewInt(lambdaBALoc)).Uint64(),
LambdaDKG: s.getStateBigInt(big.NewInt(lambdaDKGLoc)).Uint64(),
@@ -883,7 +884,6 @@ func (s *GovernanceState) Configuration() *params.DexconConfig {
RoundLength: s.getStateBigInt(big.NewInt(roundLengthLoc)).Uint64(),
MinBlockInterval: s.getStateBigInt(big.NewInt(minBlockIntervalLoc)).Uint64(),
FineValues: s.FineValues(),
- MinGasPrice: s.getStateBigInt(big.NewInt(minGasPriceLoc)),
}
}
@@ -894,6 +894,7 @@ func (s *GovernanceState) UpdateConfiguration(cfg *params.DexconConfig) {
s.setStateBigInt(big.NewInt(miningVelocityLoc), big.NewInt(int64(cfg.MiningVelocity*decimalMultiplier)))
s.setStateBigInt(big.NewInt(nextHalvingSupplyLoc), cfg.NextHalvingSupply)
s.setStateBigInt(big.NewInt(lastHalvedAmountLoc), cfg.LastHalvedAmount)
+ s.setStateBigInt(big.NewInt(minGasPriceLoc), cfg.MinGasPrice)
s.setStateBigInt(big.NewInt(blockGasLimitLoc), big.NewInt(int64(cfg.BlockGasLimit)))
s.setStateBigInt(big.NewInt(lambdaBALoc), big.NewInt(int64(cfg.LambdaBA)))
s.setStateBigInt(big.NewInt(lambdaDKGLoc), big.NewInt(int64(cfg.LambdaDKG)))
@@ -902,13 +903,13 @@ func (s *GovernanceState) UpdateConfiguration(cfg *params.DexconConfig) {
s.setStateBigInt(big.NewInt(roundLengthLoc), big.NewInt(int64(cfg.RoundLength)))
s.setStateBigInt(big.NewInt(minBlockIntervalLoc), big.NewInt(int64(cfg.MinBlockInterval)))
s.SetFineValues(cfg.FineValues)
- s.setStateBigInt(big.NewInt(minGasPriceLoc), cfg.MinGasPrice)
}
type rawConfigStruct struct {
MinStake *big.Int
LockupPeriod *big.Int
BlockGasLimit *big.Int
+ MinGasPrice *big.Int
LambdaBA *big.Int
LambdaDKG *big.Int
NotarySetSize *big.Int
@@ -916,13 +917,13 @@ type rawConfigStruct struct {
RoundLength *big.Int
MinBlockInterval *big.Int
FineValues []*big.Int
- MinGasPrice *big.Int
}
// UpdateConfigurationRaw updates system configuration.
func (s *GovernanceState) UpdateConfigurationRaw(cfg *rawConfigStruct) {
s.setStateBigInt(big.NewInt(minStakeLoc), cfg.MinStake)
s.setStateBigInt(big.NewInt(lockupPeriodLoc), cfg.LockupPeriod)
+ s.setStateBigInt(big.NewInt(minGasPriceLoc), cfg.MinGasPrice)
s.setStateBigInt(big.NewInt(blockGasLimitLoc), cfg.BlockGasLimit)
s.setStateBigInt(big.NewInt(lambdaBALoc), cfg.LambdaBA)
s.setStateBigInt(big.NewInt(lambdaDKGLoc), cfg.LambdaDKG)
@@ -931,7 +932,6 @@ func (s *GovernanceState) UpdateConfigurationRaw(cfg *rawConfigStruct) {
s.setStateBigInt(big.NewInt(roundLengthLoc), cfg.RoundLength)
s.setStateBigInt(big.NewInt(minBlockIntervalLoc), cfg.MinBlockInterval)
s.SetFineValues(cfg.FineValues)
- s.setStateBigInt(big.NewInt(minGasPriceLoc), cfg.MinGasPrice)
}
// event ConfigurationChanged();
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index 436923aa3..4539f0864 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -487,6 +487,7 @@ func (g *OracleContractsTestSuite) TestUpdateConfiguration() {
input, err := GovernanceABI.ABI.Pack("updateConfiguration",
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)),
big.NewInt(1000),
+ big.NewInt(2e9),
big.NewInt(8000000),
big.NewInt(250),
big.NewInt(2500),
@@ -494,8 +495,7 @@ func (g *OracleContractsTestSuite) TestUpdateConfiguration() {
big.NewInt(4),
big.NewInt(600),
big.NewInt(900),
- []*big.Int{big.NewInt(1), big.NewInt(1), big.NewInt(1)},
- big.NewInt(2e9))
+ []*big.Int{big.NewInt(1), big.NewInt(1), big.NewInt(1)})
g.Require().NoError(err)
// Call with non-owner.
diff --git a/params/config.go b/params/config.go
index 6ad7fff67..648661bff 100644
--- a/params/config.go
+++ b/params/config.go
@@ -54,6 +54,7 @@ var (
MiningVelocity: 0.1875,
NextHalvingSupply: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2.5e9)),
LastHalvedAmount: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.5e9)),
+ MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
BlockGasLimit: 40000000,
LambdaBA: 250,
LambdaDKG: 2500,
@@ -66,7 +67,6 @@ var (
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)),
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
},
- MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
},
}
@@ -100,6 +100,7 @@ var (
MiningVelocity: 0.1875,
NextHalvingSupply: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.8e8)),
LastHalvedAmount: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.6e7)),
+ MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
BlockGasLimit: 80000000,
LambdaBA: 250,
LambdaDKG: 10000,
@@ -112,7 +113,6 @@ var (
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)),
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
},
- MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
},
}
@@ -137,6 +137,7 @@ var (
MiningVelocity: 0.1875,
NextHalvingSupply: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.8e8)),
LastHalvedAmount: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.6e7)),
+ MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
BlockGasLimit: 21000 * 5000,
LambdaBA: 250,
LambdaDKG: 10000,
@@ -149,7 +150,6 @@ var (
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)),
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
},
- MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
},
}
@@ -182,6 +182,7 @@ var (
MiningVelocity: 0.1875,
NextHalvingSupply: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2e7)),
LastHalvedAmount: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(4e6)),
+ MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
BlockGasLimit: 21000 * 5000,
LambdaBA: 250,
LambdaDKG: 10000,
@@ -194,7 +195,6 @@ var (
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)),
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)),
},
- MinGasPrice: new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1)),
},
}
@@ -324,6 +324,7 @@ type DexconConfig struct {
MiningVelocity float32 `json:"miningVelocity"`
NextHalvingSupply *big.Int `json:"nextHalvingSupply"`
LastHalvedAmount *big.Int `json:"lastHalvedAmount"`
+ MinGasPrice *big.Int `json:"minGasPrice"`
BlockGasLimit uint64 `json:"blockGasLimit"`
LambdaBA uint64 `json:"lambdaBA"`
LambdaDKG uint64 `json:"lambdaDKG"`
@@ -332,20 +333,19 @@ type DexconConfig struct {
RoundLength uint64 `json:"roundLength"`
MinBlockInterval uint64 `json:"minBlockInterval"`
FineValues []*big.Int `json:"fineValues"`
- MinGasPrice *big.Int `json:"minGasPrice"`
}
type dexconConfigSpecMarshaling struct {
MinStake *math.HexOrDecimal256
NextHalvingSupply *math.HexOrDecimal256
LastHalvedAmount *math.HexOrDecimal256
- FineValues []*math.HexOrDecimal256
MinGasPrice *math.HexOrDecimal256
+ FineValues []*math.HexOrDecimal256
}
// String implements the stringer interface, returning the consensus engine details.
func (d *DexconConfig) String() string {
- return fmt.Sprintf("{GenesisCRSText: %v Owner: %v MinStake: %v LockupPeriod: %v MiningVelocity: %v NextHalvingSupply: %v LastHalvedAmount: %v BlockGasLimit: %v LambdaBA: %v LambdaDKG: %v NotarySetSize: %v DKGSetSize: %v RoundLength: %v MinBlockInterval: %v FineValues: %v MinGasPrice: %v}",
+ return fmt.Sprintf("{GenesisCRSText: %v Owner: %v MinStake: %v LockupPeriod: %v MiningVelocity: %v NextHalvingSupply: %v LastHalvedAmount: %v MinGasPrice: %v BlockGasLimit: %v LambdaBA: %v LambdaDKG: %v NotarySetSize: %v DKGSetSize: %v RoundLength: %v MinBlockInterval: %v FineValues: %v}",
d.GenesisCRSText,
d.Owner,
d.MinStake,
@@ -353,6 +353,7 @@ func (d *DexconConfig) String() string {
d.MiningVelocity,
d.NextHalvingSupply,
d.LastHalvedAmount,
+ d.MinGasPrice,
d.BlockGasLimit,
d.LambdaBA,
d.LambdaDKG,
@@ -361,7 +362,6 @@ func (d *DexconConfig) String() string {
d.RoundLength,
d.MinBlockInterval,
d.FineValues,
- d.MinGasPrice,
)
}