aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/governance.go20
-rw-r--r--core/vm/oracle_contract_abi.go14
-rw-r--r--core/vm/oracle_contracts.go67
-rw-r--r--core/vm/oracle_contracts_test.go22
4 files changed, 27 insertions, 96 deletions
diff --git a/core/governance.go b/core/governance.go
index bb49efb53..28f0a41fe 100644
--- a/core/governance.go
+++ b/core/governance.go
@@ -146,7 +146,6 @@ func (g *Governance) Configuration(round uint64) *coreTypes.Config {
LambdaBA: time.Duration(c.LambdaBA) * time.Millisecond,
LambdaDKG: time.Duration(c.LambdaDKG) * time.Millisecond,
NotarySetSize: uint32(configHelper.NotarySetSize().Uint64()),
- DKGSetSize: c.DKGSetSize,
RoundLength: c.RoundLength,
MinBlockInterval: time.Duration(c.MinBlockInterval) * time.Millisecond,
}
@@ -199,21 +198,6 @@ func (d *Governance) NotarySetNodeKeyAddresses(round uint64) (map[common.Address
return r, nil
}
-func (d *Governance) DKGSet(round uint64) (map[string]struct{}, error) {
- dkgSet, err := d.nodeSetCache.GetDKGSet(round)
- if err != nil {
- return nil, err
- }
-
- r := make(map[string]struct{}, len(dkgSet))
- for id := range dkgSet {
- if key, exists := d.nodeSetCache.GetPublicKey(id); exists {
- r[hex.EncodeToString(key.Bytes())] = struct{}{}
- }
- }
- return r, nil
-}
-
func (g *Governance) DKGComplaints(round uint64) []*dkgTypes.Complaint {
s := g.GetStateForDKGAtRound(round)
if s == nil {
@@ -245,7 +229,7 @@ func (g *Governance) IsDKGMPKReady(round uint64) bool {
return false
}
config := g.Configuration(round)
- threshold := 2*uint64(config.DKGSetSize)/3 + 1
+ threshold := 2*uint64(config.NotarySetSize)/3 + 1
count := s.DKGMPKReadysCount().Uint64()
return count >= threshold
}
@@ -256,7 +240,7 @@ func (g *Governance) IsDKGFinal(round uint64) bool {
return false
}
config := g.Configuration(round)
- threshold := 2*uint64(config.DKGSetSize)/3 + 1
+ threshold := 2*uint64(config.NotarySetSize)/3 + 1
count := s.DKGFinalizedsCount().Uint64()
return count >= threshold
}
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go
index e42e9266f..3345a8f4c 100644
--- a/core/vm/oracle_contract_abi.go
+++ b/core/vm/oracle_contract_abi.go
@@ -58,20 +58,6 @@ const GovernanceABIJSON = `
{
"constant": true,
"inputs": [],
- "name": "dkgSetSize",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [],
"name": "totalSupply",
"outputs": [
{
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index 12ad4b150..d7c8ffae2 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -88,7 +88,6 @@ const (
notarySetSizeLoc
notaryParamAlphaLoc
notaryParamBetaLoc
- dkgSetSizeLoc
roundLengthLoc
minBlockIntervalLoc
fineValuesLoc
@@ -704,8 +703,8 @@ func (s *GovernanceState) PutDKGMPKReady(addr common.Address, ready bool) {
}
s.setStateBigInt(mapLoc, res)
}
-func (s *GovernanceState) ClearDKGMPKReadys(dkgSet map[coreTypes.NodeID]struct{}) {
- for id := range dkgSet {
+func (s *GovernanceState) ClearDKGMPKReadys(notarySet map[coreTypes.NodeID]struct{}) {
+ for id := range notarySet {
s.PutDKGMPKReady(IdToAddress(id), false)
}
}
@@ -853,22 +852,6 @@ func (s *GovernanceState) NotaryParamBeta() *big.Int {
return s.getStateBigInt(big.NewInt(notaryParamBetaLoc))
}
-// uint256 public dkgSetSize;
-func (s *GovernanceState) DKGSetSize() *big.Int {
- return s.getStateBigInt(big.NewInt(dkgSetSizeLoc))
-}
-func (s *GovernanceState) CalDKGSetSize() {
- nodeSetSize := float64(len(s.QualifiedNodes()))
- setSize := math.Ceil((nodeSetSize*0.6-1)/3)*3 + 1
-
- if nodeSetSize >= 100 {
- alpha := float64(s.NotaryParamAlpha().Uint64()) / decimalMultiplier
- beta := float64(s.NotaryParamBeta().Uint64()) / decimalMultiplier
- setSize = math.Ceil(alpha*math.Log(nodeSetSize) - beta)
- }
- s.setStateBigInt(big.NewInt(dkgSetSizeLoc), big.NewInt(int64(setSize)))
-}
-
// uint256 public roundLength;
func (s *GovernanceState) RoundLength() *big.Int {
return s.getStateBigInt(big.NewInt(roundLengthLoc))
@@ -1038,7 +1021,6 @@ func (s *GovernanceState) UpdateConfiguration(cfg *params.DexconConfig) {
// Calculate set size.
s.CalNotarySetSize()
- s.CalDKGSetSize()
}
type rawConfigStruct struct {
@@ -1070,7 +1052,6 @@ func (s *GovernanceState) UpdateConfigurationRaw(cfg *rawConfigStruct) {
s.SetFineValues(cfg.FineValues)
s.CalNotarySetSize()
- s.CalDKGSetSize()
}
// event ConfigurationChanged();
@@ -1283,15 +1264,15 @@ func (g *GovernanceContract) useGas(gas uint64) ([]byte, error) {
return nil, nil
}
-func (g *GovernanceContract) configDKGSetSize(round *big.Int) *big.Int {
+func (g *GovernanceContract) configNotarySetSize(round *big.Int) *big.Int {
s, err := getConfigState(g.evm, round)
if err != nil {
return big.NewInt(0)
}
- return s.DKGSetSize()
+ return s.NotarySetSize()
}
-func (g *GovernanceContract) getDKGSet(round *big.Int) map[coreTypes.NodeID]struct{} {
+func (g *GovernanceContract) getNotarySet(round *big.Int) map[coreTypes.NodeID]struct{} {
crsRound := g.state.CRSRound()
var crs common.Hash
cmp := round.Cmp(crsRound)
@@ -1316,7 +1297,7 @@ func (g *GovernanceContract) getDKGSet(round *big.Int) map[coreTypes.NodeID]stru
crs = state.CRS()
}
- target := coreTypes.NewDKGSetTarget(coreCommon.Hash(crs))
+ target := coreTypes.NewNotarySetTarget(coreCommon.Hash(crs))
ns := coreTypes.NewNodeSet()
state, err := getConfigState(g.evm, round)
@@ -1330,17 +1311,17 @@ func (g *GovernanceContract) getDKGSet(round *big.Int) map[coreTypes.NodeID]stru
}
ns.Add(coreTypes.NewNodeID(mpk))
}
- return ns.GetSubSet(int(g.configDKGSetSize(round).Uint64()), target)
+ return ns.GetSubSet(int(g.configNotarySetSize(round).Uint64()), target)
}
-func (g *GovernanceContract) inDKGSet(round *big.Int, nodeID coreTypes.NodeID) bool {
- dkgSet := g.getDKGSet(round)
+func (g *GovernanceContract) inNotarySet(round *big.Int, nodeID coreTypes.NodeID) bool {
+ dkgSet := g.getNotarySet(round)
_, ok := dkgSet[nodeID]
return ok
}
func (g *GovernanceContract) clearDKG() {
- dkgSet := g.getDKGSet(g.evm.Round)
+ dkgSet := g.getNotarySet(g.evm.Round)
g.state.ClearDKGMasterPublicKeyProposed()
g.state.ClearDKGMasterPublicKeys()
g.state.ClearDKGComplaintProposed()
@@ -1368,7 +1349,7 @@ func (g *GovernanceContract) addDKGComplaint(comp []byte) ([]byte, error) {
// Calculate 2f
threshold := new(big.Int).Mul(
big.NewInt(2),
- new(big.Int).Div(g.state.DKGSetSize(), big.NewInt(3)))
+ new(big.Int).Div(g.state.NotarySetSize(), big.NewInt(3)))
// If 2f + 1 of DKG set is finalized, one can not propose complaint anymore.
if g.state.DKGFinalizedsCount().Cmp(threshold) > 0 {
@@ -1393,7 +1374,7 @@ func (g *GovernanceContract) addDKGComplaint(comp []byte) ([]byte, error) {
}
// DKGComplaint must belongs to someone in DKG set.
- if !g.inDKGSet(round, dkgComplaint.ProposerID) {
+ if !g.inNotarySet(round, dkgComplaint.ProposerID) {
return nil, errExecutionReverted
}
@@ -1471,7 +1452,7 @@ func (g *GovernanceContract) addDKGMasterPublicKey(mpk []byte) ([]byte, error) {
// Calculate 2f
threshold := new(big.Int).Mul(
big.NewInt(2),
- new(big.Int).Div(g.state.DKGSetSize(), big.NewInt(3)))
+ new(big.Int).Div(g.state.NotarySetSize(), big.NewInt(3)))
// If 2f + 1 of DKG set is mpk ready, one can not propose mpk anymore.
if g.state.DKGMPKReadysCount().Cmp(threshold) > 0 {
@@ -1483,7 +1464,7 @@ func (g *GovernanceContract) addDKGMasterPublicKey(mpk []byte) ([]byte, error) {
}
// DKGMasterPublicKey must belongs to someone in DKG set.
- if !g.inDKGSet(round, dkgMasterPK.ProposerID) {
+ if !g.inNotarySet(round, dkgMasterPK.ProposerID) {
return nil, errExecutionReverted
}
@@ -1514,7 +1495,7 @@ func (g *GovernanceContract) addDKGMPKReady(ready []byte) ([]byte, error) {
}
// DKGFInalize must belongs to someone in DKG set.
- if !g.inDKGSet(round, dkgReady.ProposerID) {
+ if !g.inNotarySet(round, dkgReady.ProposerID) {
return nil, errExecutionReverted
}
@@ -1548,7 +1529,7 @@ func (g *GovernanceContract) addDKGFinalize(finalize []byte) ([]byte, error) {
}
// DKGFInalize must belongs to someone in DKG set.
- if !g.inDKGSet(round, dkgFinalize.ProposerID) {
+ if !g.inNotarySet(round, dkgFinalize.ProposerID) {
return nil, errExecutionReverted
}
@@ -1630,7 +1611,6 @@ func (g *GovernanceContract) register(
g.state.emitStaked(caller, value)
g.state.CalNotarySetSize()
- g.state.CalDKGSetSize()
}
return g.useGas(GovernanceActionGasCost)
}
@@ -1660,7 +1640,6 @@ func (g *GovernanceContract) stake() ([]byte, error) {
g.state.emitStaked(caller, value)
g.state.CalNotarySetSize()
- g.state.CalDKGSetSize()
return g.useGas(GovernanceActionGasCost)
}
@@ -1697,7 +1676,6 @@ func (g *GovernanceContract) unstake(amount *big.Int) ([]byte, error) {
g.state.emitUnstaked(caller, amount)
g.state.CalNotarySetSize()
- g.state.CalDKGSetSize()
return g.useGas(GovernanceActionGasCost)
}
@@ -1778,7 +1756,6 @@ func (g *GovernanceContract) payFine(nodeAddr common.Address) ([]byte, error) {
g.state.emitFinePaid(nodeAddr, g.contract.Value())
g.state.CalNotarySetSize()
- g.state.CalDKGSetSize()
return g.useGas(GovernanceActionGasCost)
}
@@ -1799,7 +1776,7 @@ func (g *GovernanceContract) proposeCRS(nextRound *big.Int, signedCRS []byte) ([
}
threshold := coreUtils.GetDKGThreshold(&coreTypes.Config{
- DKGSetSize: uint32(g.state.DKGSetSize().Uint64())})
+ NotarySetSize: uint32(g.state.NotarySetSize().Uint64())})
dkgGPK, err := g.coreDKGUtils.NewGroupPublicKey(&g.state, nextRound, threshold)
if err != nil {
return nil, errExecutionReverted
@@ -1950,9 +1927,9 @@ func (g *GovernanceContract) resetDKG(newSignedCRS []byte) ([]byte, error) {
// Calculate 2f
threshold := new(big.Int).Mul(
big.NewInt(2),
- new(big.Int).Div(g.state.DKGSetSize(), big.NewInt(3)))
+ new(big.Int).Div(g.state.NotarySetSize(), big.NewInt(3)))
tsigThreshold := coreUtils.GetDKGThreshold(&coreTypes.Config{
- DKGSetSize: uint32(g.state.DKGSetSize().Uint64())})
+ NotarySetSize: uint32(g.state.NotarySetSize().Uint64())})
// If 2f + 1 of DKG set is finalized, check if DKG succeeded.
if g.state.DKGFinalizedsCount().Cmp(threshold) > 0 {
@@ -2248,12 +2225,6 @@ func (g *GovernanceContract) Run(evm *EVM, input []byte, contract *Contract) (re
return nil, errExecutionReverted
}
return res, nil
- case "dkgSetSize":
- res, err := method.Outputs.Pack(g.state.DKGSetSize())
- if err != nil {
- return nil, errExecutionReverted
- }
- return res, nil
case "finedRecords":
record := Bytes32{}
if err := method.Inputs.Unpack(&record, arguments); err != nil {
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index 80bc9a73f..98cc01505 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -189,7 +189,6 @@ func (g *OracleContractsTestSuite) SetupTest() {
config.NextHalvingSupply = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2.5e9))
config.LastHalvedAmount = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1.5e9))
config.MiningVelocity = 0.1875
- config.DKGSetSize = 7
g.config = config
@@ -658,15 +657,6 @@ func (g *OracleContractsTestSuite) TestConfigurationReading() {
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)
- res, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0))
- g.Require().NoError(err)
- err = GovernanceABI.ABI.Unpack(&value, "dkgSetSize", res)
- g.Require().NoError(err)
- g.Require().True(uint32(value.Uint64()) > 0)
-
// RoundLength.
input, err = GovernanceABI.ABI.Pack("roundLength")
g.Require().NoError(err)
@@ -934,18 +924,18 @@ func (v *testTSigVerifierMock) VerifySignature(coreCommon.Hash, coreCrypto.Signa
}
func (g *OracleContractsTestSuite) TestResetDKG() {
- for i := uint32(0); i < g.config.DKGSetSize; i++ {
+ for i := 0; i < 7; i++ {
privKey, addr := newPrefundAccount(g.stateDB)
pk := crypto.FromECDSAPub(&privKey.PublicKey)
// Stake.
amount := new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6))
- input, err := GovernanceABI.ABI.Pack("register", pk, "Test1", "test1@dexon.org", "Taipei", "https://dexon.org")
+ input, err := GovernanceABI.ABI.Pack("register", pk, "Test", "test1@dexon.org", "Taipei", "https://dexon.org")
g.Require().NoError(err)
_, err = g.call(GovernanceContractAddress, addr, input, amount)
g.Require().NoError(err)
}
- g.Require().Len(g.s.QualifiedNodes(), int(g.config.DKGSetSize))
+ g.Require().Len(g.s.QualifiedNodes(), int(g.s.NotarySetSize().Uint64()))
addrs := make(map[int][]common.Address)
dkgSets := make(map[int]map[coreTypes.NodeID]struct{})
@@ -972,7 +962,7 @@ func (g *OracleContractsTestSuite) TestResetDKG() {
}
addrs[round] = []common.Address{}
- target := coreTypes.NewDKGSetTarget(coreCommon.Hash(g.s.CRS()))
+ target := coreTypes.NewNotarySetTarget(coreCommon.Hash(g.s.CRS()))
ns := coreTypes.NewNodeSet()
for _, x := range g.s.QualifiedNodes() {
@@ -982,8 +972,8 @@ func (g *OracleContractsTestSuite) TestResetDKG() {
}
ns.Add(coreTypes.NewNodeID(mpk))
}
- dkgSet := ns.GetSubSet(int(g.s.DKGSetSize().Uint64()), target)
- g.Require().Len(dkgSet, int(g.config.DKGSetSize))
+ dkgSet := ns.GetSubSet(int(g.s.NotarySetSize().Uint64()), target)
+ g.Require().Len(dkgSet, int(g.s.NotarySetSize().Uint64()))
dkgSets[round] = dkgSet
for id := range dkgSet {