diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-10 22:58:33 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:57 +0800 |
commit | a9b1ad951f5cb3d032dca899a595b6c781aefb3e (patch) | |
tree | 63048e13ad19c4ea53c4a3b8372c210d4b1e2409 /core/vm | |
parent | eb7487b9318954404895fbe0d3a0acaabe3558a0 (diff) | |
download | dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar.gz dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar.bz2 dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar.lz dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar.xz dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.tar.zst dexon-a9b1ad951f5cb3d032dca899a595b6c781aefb3e.zip |
core: vm: expose CRSRound and DKGRound and fix consistency (#236)
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/oracle_contract_abi.go | 66 | ||||
-rw-r--r-- | core/vm/oracle_contracts.go | 91 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 21 |
3 files changed, 118 insertions, 60 deletions
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go index 8e931094b..2de3d650f 100644 --- a/core/vm/oracle_contract_abi.go +++ b/core/vm/oracle_contract_abi.go @@ -75,25 +75,6 @@ const GovernanceABIJSON = ` }, { "constant": true, - "inputs": [ - { - "name": "", - "type": "uint256" - } - ], - "name": "DKGResetCount", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, "inputs": [], "name": "totalSupply", "outputs": [ @@ -197,6 +178,20 @@ const GovernanceABIJSON = ` }, { "constant": true, + "inputs": [], + "name": "crsRound", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, "inputs": [ { "name": "", @@ -262,6 +257,20 @@ const GovernanceABIJSON = ` { "constant": true, "inputs": [], + "name": "dkgRound", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], "name": "totalStaked", "outputs": [ { @@ -580,6 +589,25 @@ const GovernanceABIJSON = ` "type": "function" }, { + "constant": true, + "inputs": [ + { + "name": "", + "type": "uint256" + } + ], + "name": "dkgResetCount", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { "anonymous": false, "inputs": [], "name": "ConfigurationChanged", diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index fa5bea54c..5c5a44185 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -64,6 +64,7 @@ const ( crsRoundLoc crsLoc dkgRoundLoc + dkgResetCountLoc dkgMasterPublicKeysLoc dkgComplaintsLoc dkgReadyLoc @@ -85,7 +86,6 @@ const ( minBlockIntervalLoc fineValuesLoc finedRecordsLoc - dkgResetCountLoc minGasPriceLoc ) @@ -614,6 +614,17 @@ func (s *GovernanceState) SetDKGRound(round *big.Int) { s.setStateBigInt(big.NewInt(dkgRoundLoc), round) } +// uint256[] public dkgResetCount; +func (s *GovernanceState) DKGResetCount(round *big.Int) *big.Int { + arrayBaseLoc := s.getSlotLoc(big.NewInt(dkgResetCountLoc)) + return s.getStateBigInt(new(big.Int).Add(arrayBaseLoc, round)) +} +func (s *GovernanceState) IncDKGResetCount(round *big.Int) { + loc := new(big.Int).Add(s.getSlotLoc(big.NewInt(dkgResetCountLoc)), round) + count := s.getStateBigInt(loc) + s.setStateBigInt(loc, new(big.Int).Add(count, big.NewInt(1))) +} + // bytes[] public dkgMasterPublicKeys; func (s *GovernanceState) DKGMasterPublicKeys() [][]byte { return s.read1DByteArray(big.NewInt(dkgMasterPublicKeysLoc)) @@ -857,17 +868,6 @@ func (s *GovernanceState) SetFineRecords(recordHash Bytes32, status bool) { s.setStateBigInt(loc, big.NewInt(value)) } -// uint256[] public DKGResetCount; -func (s *GovernanceState) DKGResetCount(round *big.Int) *big.Int { - arrayBaseLoc := s.getSlotLoc(big.NewInt(dkgResetCountLoc)) - return s.getStateBigInt(new(big.Int).Add(arrayBaseLoc, round)) -} -func (s *GovernanceState) IncDKGResetCount(round *big.Int) { - loc := new(big.Int).Add(s.getSlotLoc(big.NewInt(dkgResetCountLoc)), round) - count := s.getStateBigInt(loc) - s.setStateBigInt(loc, new(big.Int).Add(count, big.NewInt(1))) -} - // uint256 public minGasPrice; func (s *GovernanceState) MinGasPrice() *big.Int { return s.getStateBigInt(big.NewInt(minGasPriceLoc)) @@ -2127,6 +2127,12 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re return nil, errExecutionReverted } return res, nil + case "crsRound": + res, err := method.Outputs.Pack(g.state.CRSRound()) + if err != nil { + return nil, errExecutionReverted + } + return res, nil case "delegators": nodeAddr, index := common.Address{}, new(big.Int) args := []interface{}{&nodeAddr, &index} @@ -2165,54 +2171,69 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re return nil, errExecutionReverted } return res, nil - case "dkgReadys": + case "dkgFinalizeds": addr := common.Address{} if err := method.Inputs.Unpack(&addr, arguments); err != nil { return nil, errExecutionReverted } - ready := g.state.DKGMPKReady(addr) - res, err := method.Outputs.Pack(ready) + finalized := g.state.DKGFinalized(addr) + res, err := method.Outputs.Pack(finalized) if err != nil { return nil, errExecutionReverted } return res, nil - case "dkgReadysCount": - count := g.state.DKGMPKReadysCount() + case "dkgFinalizedsCount": + count := g.state.DKGFinalizedsCount() res, err := method.Outputs.Pack(count) if err != nil { return nil, errExecutionReverted } return res, nil - - case "dkgFinalizeds": + case "dkgMasterPublicKeys": + index := new(big.Int) + if err := method.Inputs.Unpack(&index, arguments); err != nil { + return nil, errExecutionReverted + } + mpks := g.state.DKGMasterPublicKeys() + if int(index.Uint64()) >= len(mpks) { + return nil, errExecutionReverted + } + mpk := mpks[index.Uint64()] + res, err := method.Outputs.Pack(mpk) + if err != nil { + return nil, errExecutionReverted + } + return res, nil + case "dkgReadys": addr := common.Address{} if err := method.Inputs.Unpack(&addr, arguments); err != nil { return nil, errExecutionReverted } - finalized := g.state.DKGFinalized(addr) - res, err := method.Outputs.Pack(finalized) + ready := g.state.DKGMPKReady(addr) + res, err := method.Outputs.Pack(ready) if err != nil { return nil, errExecutionReverted } return res, nil - case "dkgFinalizedsCount": - count := g.state.DKGFinalizedsCount() + case "dkgReadysCount": + count := g.state.DKGMPKReadysCount() res, err := method.Outputs.Pack(count) if err != nil { return nil, errExecutionReverted } return res, nil - case "dkgMasterPublicKeys": - index := new(big.Int) - if err := method.Inputs.Unpack(&index, arguments); err != nil { + case "dkgResetCount": + round := new(big.Int) + if err := method.Inputs.Unpack(&round, arguments); err != nil { return nil, errExecutionReverted } - mpks := g.state.DKGMasterPublicKeys() - if int(index.Uint64()) >= len(mpks) { + res, err := method.Outputs.Pack(g.state.DKGResetCount(round)) + if err != nil { return nil, errExecutionReverted } - mpk := mpks[index.Uint64()] - res, err := method.Outputs.Pack(mpk) + return res, nil + case "dkgRound": + res, err := method.Outputs.Pack(g.state.DKGRound()) if err != nil { return nil, errExecutionReverted } @@ -2372,16 +2393,6 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re return nil, errExecutionReverted } return res, nil - case "DKGResetCount": - round := new(big.Int) - if err := method.Inputs.Unpack(&round, arguments); err != nil { - return nil, errExecutionReverted - } - res, err := method.Outputs.Pack(g.state.DKGResetCount(round)) - if err != nil { - return nil, errExecutionReverted - } - return res, nil } return nil, errExecutionReverted } diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index fb5194d0a..81afe810c 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -676,7 +676,14 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() { var crs0 [32]byte err = GovernanceABI.ABI.Unpack(&crs0, "crs", res) g.Require().NoError(err) - g.Require().Equal(crypto.Keccak256Hash([]byte(g.config.GenesisCRSText)), common.BytesToHash(crs0[:])) + g.Require().Equal(crypto.Keccak256Hash([]byte(g.config.GenesisCRSText)), + common.BytesToHash(crs0[:])) + + // CRSRound. + input, err = GovernanceABI.ABI.Pack("crsRound") + g.Require().NoError(err) + res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) + g.Require().NoError(err) // Owner. input, err = GovernanceABI.ABI.Pack("owner") @@ -743,6 +750,18 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() { g.Require().NoError(err) g.Require().Equal(g.config.NotarySetSize, uint32(value.Uint64())) + // DKGRound. + input, err = GovernanceABI.ABI.Pack("dkgRound") + g.Require().NoError(err) + res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) + g.Require().NoError(err) + + // DKGResetCount. + input, err = GovernanceABI.ABI.Pack("dkgResetCount", big.NewInt(3)) + g.Require().NoError(err) + res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) + g.Require().NoError(err) + // DKGSetSize. input, err = GovernanceABI.ABI.Pack("dkgSetSize") g.Require().NoError(err) |