aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-22 13:14:55 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit2354d4aa747616a8fd4fb9482ada8042fd362139 (patch)
tree46fe0953c0258591c2cd415c3760764ff613a5bb /core
parent81193a683d6328b627ee0e5f0f3689b3473e29ea (diff)
downloadgo-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.gz
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.tar.zst
go-tangerine-2354d4aa747616a8fd4fb9482ada8042fd362139.zip
core: Remove K, Phi and NumChains from Governance (#198)
* change default sync_core.sh * vendor: sync to latest core * core: Remove K, Phi and NumChain
Diffstat (limited to 'core')
-rw-r--r--core/blockchain_test.go7
-rw-r--r--core/governance.go14
-rw-r--r--core/vm/oracle_contract_abi.go78
-rw-r--r--core/vm/oracle_contracts.go70
-rw-r--r--core/vm/oracle_contracts_test.go42
5 files changed, 37 insertions, 174 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 1f5197002..f972eb0b2 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -1611,17 +1611,15 @@ type dexconTest struct {
dexcon.Dexcon
blockReward *big.Int
- numChains uint32
}
// Finalize for skip governance access.
func (d *dexconTest) Finalize(chain consensus.ChainReader, header *types.Header,
state *state.StateDB, txs []*types.Transaction, uncles []*types.Header,
receipts []*types.Receipt) (*types.Block, error) {
- reward := new(big.Int).Div(d.blockReward, big.NewInt(int64(d.numChains)))
- state.AddBalance(header.Coinbase, reward)
+ state.AddBalance(header.Coinbase, d.blockReward)
- header.Reward = reward
+ header.Reward = d.blockReward
header.Root = state.IntermediateRoot(true)
return types.NewBlock(header, txs, uncles, receipts), nil
}
@@ -1651,7 +1649,6 @@ func TestProcessBlock(t *testing.T) {
engine := &dexconTest{
blockReward: big.NewInt(1e18),
- numChains: chainConfig.Dexcon.NumChains,
}
chain, err := NewBlockChain(db, nil, chainConfig, engine, vm.Config{}, nil)
if err != nil {
diff --git a/core/governance.go b/core/governance.go
index 538cd2b96..12124760e 100644
--- a/core/governance.go
+++ b/core/governance.go
@@ -91,14 +91,12 @@ func (g *Governance) Configuration(round uint64) *coreTypes.Config {
configHelper := g.GetGovStateHelperAtRound(round)
c := configHelper.Configuration()
return &coreTypes.Config{
- NumChains: c.NumChains,
- LambdaBA: time.Duration(c.LambdaBA) * time.Millisecond,
- LambdaDKG: time.Duration(c.LambdaDKG) * time.Millisecond,
- K: int(c.K),
- PhiRatio: c.PhiRatio,
- NotarySetSize: c.NotarySetSize,
- DKGSetSize: c.DKGSetSize,
- RoundInterval: time.Duration(c.RoundInterval) * time.Millisecond,
+ LambdaBA: time.Duration(c.LambdaBA) * time.Millisecond,
+ LambdaDKG: time.Duration(c.LambdaDKG) * time.Millisecond,
+ NotarySetSize: c.NotarySetSize,
+ DKGSetSize: c.DKGSetSize,
+ // TODO(jimmyhu): remove MinBlockInterval after coreTypes.Config update.
+ RoundInterval: time.Duration(c.RoundLength) * time.Duration(c.MinBlockInterval) * time.Millisecond,
MinBlockInterval: time.Duration(c.MinBlockInterval) * time.Millisecond,
}
}
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go
index 5c6f2a711..fde973203 100644
--- a/core/vm/oracle_contract_abi.go
+++ b/core/vm/oracle_contract_abi.go
@@ -239,20 +239,6 @@ const GovernanceABIJSON = `
},
{
"constant": true,
- "inputs": [],
- "name": "phiRatio",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
"inputs": [
{
"name": "",
@@ -373,12 +359,17 @@ const GovernanceABIJSON = `
},
{
"constant": true,
- "inputs": [],
- "name": "roundInterval",
+ "inputs": [
+ {
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "name": "nodesOffsetByAddress",
"outputs": [
{
"name": "",
- "type": "uint256"
+ "type": "int256"
}
],
"payable": false,
@@ -387,17 +378,12 @@ const GovernanceABIJSON = `
},
{
"constant": true,
- "inputs": [
- {
- "name": "",
- "type": "address"
- }
- ],
- "name": "nodesOffsetByAddress",
+ "inputs": [],
+ "name": "roundLength",
"outputs": [
{
"name": "",
- "type": "int256"
+ "type": "uint256"
}
],
"payable": false,
@@ -533,20 +519,6 @@ const GovernanceABIJSON = `
},
{
"constant": true,
- "inputs": [],
- "name": "k",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
"inputs": [
{
"name": "",
@@ -594,20 +566,6 @@ const GovernanceABIJSON = `
{
"constant": true,
"inputs": [],
- "name": "numChains",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [],
"name": "lockupPeriod",
"outputs": [
{
@@ -871,10 +829,6 @@ const GovernanceABIJSON = `
"type": "uint256"
},
{
- "name": "NumChains",
- "type": "uint256"
- },
- {
"name": "LambdaBA",
"type": "uint256"
},
@@ -883,14 +837,6 @@ const GovernanceABIJSON = `
"type": "uint256"
},
{
- "name": "K",
- "type": "uint256"
- },
- {
- "name": "PhiRatio",
- "type": "uint256"
- },
- {
"name": "NotarySetSize",
"type": "uint256"
},
@@ -899,7 +845,7 @@ const GovernanceABIJSON = `
"type": "uint256"
},
{
- "name": "RoundInterval",
+ "name": "RoundLength",
"type": "uint256"
},
{
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index e060312e5..1eeb57a5a 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -74,14 +74,11 @@ const (
nextHalvingSupplyLoc
lastHalvedAmountLoc
blockGasLimitLoc
- numChainsLoc
lambdaBALoc
lambdaDKGLoc
- kLoc
- phiRatioLoc
notarySetSizeLoc
dkgSetSizeLoc
- roundIntervalLoc
+ roundLengthLoc
minBlockIntervalLoc
fineValuesLoc
finedRecordsLoc
@@ -820,11 +817,6 @@ func (s *GovernanceStateHelper) SetBlockGasLimit(reward *big.Int) {
s.setStateBigInt(big.NewInt(blockGasLimitLoc), reward)
}
-// uint256 public numChains;
-func (s *GovernanceStateHelper) NumChains() *big.Int {
- return s.getStateBigInt(big.NewInt(numChainsLoc))
-}
-
// uint256 public lambdaBA;
func (s *GovernanceStateHelper) LambdaBA() *big.Int {
return s.getStateBigInt(big.NewInt(lambdaBALoc))
@@ -835,16 +827,6 @@ func (s *GovernanceStateHelper) LambdaDKG() *big.Int {
return s.getStateBigInt(big.NewInt(lambdaDKGLoc))
}
-// uint256 public k;
-func (s *GovernanceStateHelper) K() *big.Int {
- return s.getStateBigInt(big.NewInt(kLoc))
-}
-
-// uint256 public phiRatio; // stored as PhiRatio * 10^6
-func (s *GovernanceStateHelper) PhiRatio() *big.Int {
- return s.getStateBigInt(big.NewInt(phiRatioLoc))
-}
-
// uint256 public notarySetSize;
func (s *GovernanceStateHelper) NotarySetSize() *big.Int {
return s.getStateBigInt(big.NewInt(notarySetSizeLoc))
@@ -855,9 +837,9 @@ func (s *GovernanceStateHelper) DKGSetSize() *big.Int {
return s.getStateBigInt(big.NewInt(dkgSetSizeLoc))
}
-// uint256 public roundInterval;
-func (s *GovernanceStateHelper) RoundInterval() *big.Int {
- return s.getStateBigInt(big.NewInt(roundIntervalLoc))
+// uint256 public roundLength;
+func (s *GovernanceStateHelper) RoundLength() *big.Int {
+ return s.getStateBigInt(big.NewInt(roundLengthLoc))
}
// uint256 public minBlockInterval;
@@ -959,14 +941,11 @@ func (s *GovernanceStateHelper) Configuration() *params.DexconConfig {
NextHalvingSupply: s.getStateBigInt(big.NewInt(nextHalvingSupplyLoc)),
LastHalvedAmount: s.getStateBigInt(big.NewInt(lastHalvedAmountLoc)),
BlockGasLimit: s.getStateBigInt(big.NewInt(blockGasLimitLoc)).Uint64(),
- NumChains: uint32(s.getStateBigInt(big.NewInt(numChainsLoc)).Uint64()),
LambdaBA: s.getStateBigInt(big.NewInt(lambdaBALoc)).Uint64(),
LambdaDKG: s.getStateBigInt(big.NewInt(lambdaDKGLoc)).Uint64(),
- K: uint32(s.getStateBigInt(big.NewInt(kLoc)).Uint64()),
- PhiRatio: float32(s.getStateBigInt(big.NewInt(phiRatioLoc)).Uint64()) / decimalMultiplier,
NotarySetSize: uint32(s.getStateBigInt(big.NewInt(notarySetSizeLoc)).Uint64()),
DKGSetSize: uint32(s.getStateBigInt(big.NewInt(dkgSetSizeLoc)).Uint64()),
- RoundInterval: s.getStateBigInt(big.NewInt(roundIntervalLoc)).Uint64(),
+ RoundLength: s.getStateBigInt(big.NewInt(roundLengthLoc)).Uint64(),
MinBlockInterval: s.getStateBigInt(big.NewInt(minBlockIntervalLoc)).Uint64(),
FineValues: s.FineValues(),
}
@@ -980,14 +959,11 @@ func (s *GovernanceStateHelper) UpdateConfiguration(cfg *params.DexconConfig) {
s.setStateBigInt(big.NewInt(nextHalvingSupplyLoc), cfg.NextHalvingSupply)
s.setStateBigInt(big.NewInt(lastHalvedAmountLoc), cfg.LastHalvedAmount)
s.setStateBigInt(big.NewInt(blockGasLimitLoc), big.NewInt(int64(cfg.BlockGasLimit)))
- s.setStateBigInt(big.NewInt(numChainsLoc), big.NewInt(int64(cfg.NumChains)))
s.setStateBigInt(big.NewInt(lambdaBALoc), big.NewInt(int64(cfg.LambdaBA)))
s.setStateBigInt(big.NewInt(lambdaDKGLoc), big.NewInt(int64(cfg.LambdaDKG)))
- s.setStateBigInt(big.NewInt(kLoc), big.NewInt(int64(cfg.K)))
- s.setStateBigInt(big.NewInt(phiRatioLoc), big.NewInt(int64(cfg.PhiRatio*decimalMultiplier)))
s.setStateBigInt(big.NewInt(notarySetSizeLoc), big.NewInt(int64(cfg.NotarySetSize)))
s.setStateBigInt(big.NewInt(dkgSetSizeLoc), big.NewInt(int64(cfg.DKGSetSize)))
- s.setStateBigInt(big.NewInt(roundIntervalLoc), big.NewInt(int64(cfg.RoundInterval)))
+ s.setStateBigInt(big.NewInt(roundLengthLoc), big.NewInt(int64(cfg.RoundLength)))
s.setStateBigInt(big.NewInt(minBlockIntervalLoc), big.NewInt(int64(cfg.MinBlockInterval)))
s.SetFineValues(cfg.FineValues)
}
@@ -996,14 +972,11 @@ type rawConfigStruct struct {
MinStake *big.Int
LockupPeriod *big.Int
BlockGasLimit *big.Int
- NumChains *big.Int
LambdaBA *big.Int
LambdaDKG *big.Int
- K *big.Int
- PhiRatio *big.Int
NotarySetSize *big.Int
DKGSetSize *big.Int
- RoundInterval *big.Int
+ RoundLength *big.Int
MinBlockInterval *big.Int
FineValues []*big.Int
}
@@ -1013,14 +986,11 @@ func (s *GovernanceStateHelper) UpdateConfigurationRaw(cfg *rawConfigStruct) {
s.setStateBigInt(big.NewInt(minStakeLoc), cfg.MinStake)
s.setStateBigInt(big.NewInt(lockupPeriodLoc), cfg.LockupPeriod)
s.setStateBigInt(big.NewInt(blockGasLimitLoc), cfg.BlockGasLimit)
- s.setStateBigInt(big.NewInt(numChainsLoc), cfg.NumChains)
s.setStateBigInt(big.NewInt(lambdaBALoc), cfg.LambdaBA)
s.setStateBigInt(big.NewInt(lambdaDKGLoc), cfg.LambdaDKG)
- s.setStateBigInt(big.NewInt(kLoc), cfg.K)
- s.setStateBigInt(big.NewInt(phiRatioLoc), cfg.PhiRatio)
s.setStateBigInt(big.NewInt(notarySetSizeLoc), cfg.NotarySetSize)
s.setStateBigInt(big.NewInt(dkgSetSizeLoc), cfg.DKGSetSize)
- s.setStateBigInt(big.NewInt(roundIntervalLoc), cfg.RoundInterval)
+ s.setStateBigInt(big.NewInt(roundLengthLoc), cfg.RoundLength)
s.setStateBigInt(big.NewInt(minBlockIntervalLoc), cfg.MinBlockInterval)
s.SetFineValues(cfg.FineValues)
}
@@ -1853,7 +1823,7 @@ func (g *GovernanceContract) resetDKG(newSignedCRS []byte) ([]byte, error) {
}
config := gs.Configuration()
- targetBlockNum := new(big.Int).SetUint64(config.RoundInterval / config.MinBlockInterval)
+ targetBlockNum := new(big.Int).SetUint64(config.RoundLength)
targetBlockNum.Mul(targetBlockNum, target)
targetBlockNum.Quo(targetBlockNum, big.NewInt(100))
targetBlockNum.Add(targetBlockNum, roundHeight)
@@ -2227,12 +2197,6 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
- case "k":
- res, err := method.Outputs.Pack(g.state.K())
- if err != nil {
- return nil, errExecutionReverted
- }
- return res, nil
case "lambdaBA":
res, err := method.Outputs.Pack(g.state.LambdaBA())
if err != nil {
@@ -2281,12 +2245,6 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
- case "numChains":
- res, err := method.Outputs.Pack(g.state.NumChains())
- if err != nil {
- return nil, errExecutionReverted
- }
- return res, nil
case "nodes":
index := new(big.Int)
if err := method.Inputs.Unpack(&index, arguments); err != nil {
@@ -2332,12 +2290,6 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
- case "phiRatio":
- res, err := method.Outputs.Pack(g.state.PhiRatio())
- if err != nil {
- return nil, errExecutionReverted
- }
- return res, nil
case "roundHeight":
round := new(big.Int)
if err := method.Inputs.Unpack(&round, arguments); err != nil {
@@ -2348,8 +2300,8 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
- case "roundInterval":
- res, err := method.Outputs.Pack(g.state.RoundInterval())
+ case "roundLength":
+ res, err := method.Outputs.Pack(g.state.RoundLength())
if err != nil {
return nil, errExecutionReverted
}
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index 654070c57..dd17dddea 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -648,14 +648,11 @@ func (g *OracleContractsTestSuite) TestUpdateConfiguration() {
new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)),
big.NewInt(1000),
big.NewInt(8000000),
- big.NewInt(6),
big.NewInt(250),
big.NewInt(2500),
- big.NewInt(0),
- big.NewInt(667000),
big.NewInt(4),
big.NewInt(4),
- big.NewInt(600000),
+ big.NewInt(600),
big.NewInt(900),
[]*big.Int{big.NewInt(1), big.NewInt(1), big.NewInt(1)})
g.Require().NoError(err)
@@ -720,15 +717,6 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() {
g.Require().NoError(err)
g.Require().Equal(g.config.BlockGasLimit, value.Uint64())
- // NumChains.
- input, err = GovernanceABI.ABI.Pack("numChains")
- g.Require().NoError(err)
- res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
- g.Require().NoError(err)
- err = GovernanceABI.ABI.Unpack(&value, "numChains", res)
- g.Require().NoError(err)
- g.Require().Equal(g.config.NumChains, uint32(value.Uint64()))
-
// LambdaBA.
input, err = GovernanceABI.ABI.Pack("lambdaBA")
g.Require().NoError(err)
@@ -747,24 +735,6 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() {
g.Require().NoError(err)
g.Require().Equal(g.config.LambdaDKG, value.Uint64())
- // K.
- input, err = GovernanceABI.ABI.Pack("k")
- g.Require().NoError(err)
- res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
- g.Require().NoError(err)
- err = GovernanceABI.ABI.Unpack(&value, "k", res)
- g.Require().NoError(err)
- g.Require().Equal(g.config.K, uint32(value.Uint64()))
-
- // PhiRatio.
- input, err = GovernanceABI.ABI.Pack("phiRatio")
- g.Require().NoError(err)
- res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
- g.Require().NoError(err)
- err = GovernanceABI.ABI.Unpack(&value, "phiRatio", res)
- g.Require().NoError(err)
- g.Require().Equal(g.config.PhiRatio, float32(value.Uint64())/decimalMultiplier)
-
// NotarySetSize.
input, err = GovernanceABI.ABI.Pack("notarySetSize")
g.Require().NoError(err)
@@ -783,14 +753,14 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() {
g.Require().NoError(err)
g.Require().Equal(g.config.DKGSetSize, uint32(value.Uint64()))
- // RoundInterval.
- input, err = GovernanceABI.ABI.Pack("roundInterval")
+ // RoundLength.
+ input, err = GovernanceABI.ABI.Pack("roundLength")
g.Require().NoError(err)
res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
g.Require().NoError(err)
- err = GovernanceABI.ABI.Unpack(&value, "roundInterval", res)
+ err = GovernanceABI.ABI.Unpack(&value, "roundLength", res)
g.Require().NoError(err)
- g.Require().Equal(g.config.RoundInterval, value.Uint64())
+ g.Require().Equal(g.config.RoundLength, value.Uint64())
// MinBlockInterval.
input, err = GovernanceABI.ABI.Pack("minBlockInterval")
@@ -1187,7 +1157,7 @@ func (g *OracleContractsTestSuite) TestResetDKG() {
}
// Fill data for previous rounds.
- roundHeight := int64(g.config.RoundInterval / g.config.MinBlockInterval)
+ roundHeight := int64(g.config.RoundLength)
round := 3
for i := 0; i <= round; i++ {
// Prepare CRS.