aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-10 22:58:33 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit3aa1712606870dc9204ec38ed5eafa1be5d713c8 (patch)
treee5697e80fcdda30ca6afe9e7daa26de9e05e876e
parent763f3e1d551ebf641f747faa478326d6daa7c620 (diff)
downloadgo-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar.gz
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar.bz2
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar.lz
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar.xz
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.tar.zst
go-tangerine-3aa1712606870dc9204ec38ed5eafa1be5d713c8.zip
core: vm: expose CRSRound and DKGRound and fix consistency (#236)
-rw-r--r--core/vm/oracle_contract_abi.go66
-rw-r--r--core/vm/oracle_contracts.go91
-rw-r--r--core/vm/oracle_contracts_test.go21
-rw-r--r--params/config.go6
4 files changed, 121 insertions, 63 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)
diff --git a/params/config.go b/params/config.go
index 29b3b7e50..38e338e37 100644
--- a/params/config.go
+++ b/params/config.go
@@ -26,9 +26,9 @@ import (
// Genesis hashes to enforce below configs on.
var (
- MainnetGenesisHash = common.HexToHash("0x1c7166166a0d5030bce584ecfb153d874be4afb0bfda7c844ff339c85fee5e4a")
- TestnetGenesisHash = common.HexToHash("0x8eeae9be1662831bf98627e7fdd8185c808aa177bdf4e1eed5631d065bf14973")
- YilanGenesisHash = common.HexToHash("0x2c70b276af6c65e18863105f51562571c8c7b710400e31f9c96892d4c0b9699f")
+ MainnetGenesisHash = common.HexToHash("0x0894598473a31c7cd2fa64864c33ded539a8fe0c4535035851ff57c421dbdd16")
+ TestnetGenesisHash = common.HexToHash("0xc5c55f7f0211bab328ce33b3ecbffd115464b70fd019cab1b21aa632d54e83fe")
+ YilanGenesisHash = common.HexToHash("0x523850d25315b5d0fc368b2219236e3e88a9dd544afe699b908d71d5ebd45de3")
)
// TrustedCheckpoints associates each known checkpoint with the genesis hash of