diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-02-25 18:27:34 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | d779f5aead9e91b97c8d05136ddb7a6bd84f4276 (patch) | |
tree | a0f497e1109cc1ad89183f97aee193938bf5306e /core/vm | |
parent | d5e4399839e04f5d85dd3a06fb14d6ad117a79f3 (diff) | |
download | dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar.gz dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar.bz2 dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar.lz dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar.xz dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.tar.zst dexon-d779f5aead9e91b97c8d05136ddb7a6bd84f4276.zip |
core: Fixed gas price (#205)
* core/vm: update abi
* core/vm: add MinGasPrice to gov
* params: Add MinGasPrice to Config
* dex: SuggestPrice from Governance
* test: add minGasPrice to genesis.json
* core: check underpriced tx
* dex: verify with gas price
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/oracle_contract_abi.go | 18 | ||||
-rw-r--r-- | core/vm/oracle_contracts.go | 16 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 12 |
3 files changed, 45 insertions, 1 deletions
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go index fde973203..ff4a94b29 100644 --- a/core/vm/oracle_contract_abi.go +++ b/core/vm/oracle_contract_abi.go @@ -566,6 +566,20 @@ const GovernanceABIJSON = ` { "constant": true, "inputs": [], + "name": "minGasPrice", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], "name": "lockupPeriod", "outputs": [ { @@ -855,6 +869,10 @@ 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 1eeb57a5a..826e0396c 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -83,6 +83,7 @@ const ( fineValuesLoc finedRecordsLoc dkgResetCountLoc + minGasPriceLoc ) func publicKeyToNodeID(pkBytes []byte) (Bytes32, error) { @@ -894,6 +895,11 @@ func (s *GovernanceStateHelper) IncDKGResetCount(round *big.Int) { s.setStateBigInt(loc, new(big.Int).Add(count, big.NewInt(1))) } +// uint256 public minGasPrice; +func (s *GovernanceStateHelper) MinGasPrice() *big.Int { + return s.getStateBigInt(big.NewInt(minGasPriceLoc)) +} + // Stake is a helper function for creating genesis state. func (s *GovernanceStateHelper) Stake( addr common.Address, publicKey []byte, staked *big.Int, @@ -948,6 +954,7 @@ func (s *GovernanceStateHelper) 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)), } } @@ -966,6 +973,7 @@ func (s *GovernanceStateHelper) 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 { @@ -979,6 +987,7 @@ type rawConfigStruct struct { RoundLength *big.Int MinBlockInterval *big.Int FineValues []*big.Int + MinGasPrice *big.Int } // UpdateConfigurationRaw updates system configuration. @@ -993,6 +1002,7 @@ func (s *GovernanceStateHelper) 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(); @@ -2227,6 +2237,12 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re return nil, errExecutionReverted } return res, nil + case "minGasPrice": + res, err := method.Outputs.Pack(g.state.MinGasPrice()) + if err != nil { + return nil, errExecutionReverted + } + return res, nil case "miningVelocity": res, err := method.Outputs.Pack(g.state.MiningVelocity()) if err != nil { diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index dd17dddea..4980d4b77 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -654,7 +654,8 @@ 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.Int{big.NewInt(1), big.NewInt(1), big.NewInt(1)}, + big.NewInt(2e9)) g.Require().NoError(err) // Call with non-owner. @@ -770,6 +771,15 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() { err = GovernanceABI.ABI.Unpack(&value, "minBlockInterval", res) g.Require().NoError(err) g.Require().Equal(g.config.MinBlockInterval, value.Uint64()) + + // MinGasPrice. + input, err = GovernanceABI.ABI.Pack("minGasPrice") + g.Require().NoError(err) + res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) + g.Require().NoError(err) + err = GovernanceABI.ABI.Unpack(&value, "minGasPrice", res) + g.Require().NoError(err) + g.Require().Equal(g.config.MinGasPrice, value) } func (g *OracleContractsTestSuite) TestReportForkVote() { |