aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-09-18 17:57:36 +0800
committerGitHub <noreply@github.com>2018-09-18 17:57:36 +0800
commit8c33027b943e08de21b7bddb82fecc2b2a5664a2 (patch)
treeeaa282b1238eb609d710e9c45bb0689e7a399039 /core/test
parent476c759f5e2ea3949cf3aaf4e60ccc7e0439ee73 (diff)
downloadtangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar.gz
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar.bz2
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar.lz
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar.xz
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.tar.zst
tangerine-consensus-8c33027b943e08de21b7bddb82fecc2b2a5664a2.zip
core: refine governance interface to reduce Get* methods (#114)
Since we have a bunch of static configurations in the governance contract, instead of using a Get* method for each of them, we instead implement a GetConfiguration() method to return a structure of the configurations.
Diffstat (limited to 'core/test')
-rw-r--r--core/test/governance.go72
1 files changed, 23 insertions, 49 deletions
diff --git a/core/test/governance.go b/core/test/governance.go
index 1658e46..c5746cb 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -24,7 +24,6 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/core/types"
"github.com/dexon-foundation/dexon-consensus-core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
- "github.com/shopspring/decimal"
)
var (
@@ -35,9 +34,9 @@ var (
// Governance is an implementation of Goverance for testing purpose.
type Governance struct {
- Lambda time.Duration
- Validators map[types.ValidatorID]decimal.Decimal
- PrivateKeys map[types.ValidatorID]crypto.PrivateKey
+ lambda time.Duration
+ notarySet map[types.ValidatorID]struct{}
+ privateKeys map[types.ValidatorID]crypto.PrivateKey
DKGComplaint map[uint64][]*types.DKGComplaint
DKGMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
}
@@ -46,9 +45,9 @@ type Governance struct {
func NewGovernance(validatorCount int, lambda time.Duration) (
g *Governance, err error) {
g = &Governance{
- Lambda: lambda,
- Validators: make(map[types.ValidatorID]decimal.Decimal),
- PrivateKeys: make(map[types.ValidatorID]crypto.PrivateKey),
+ lambda: lambda,
+ notarySet: make(map[types.ValidatorID]struct{}),
+ privateKeys: make(map[types.ValidatorID]crypto.PrivateKey),
DKGComplaint: make(map[uint64][]*types.DKGComplaint),
DKGMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
}
@@ -58,53 +57,28 @@ func NewGovernance(validatorCount int, lambda time.Duration) (
return nil, err
}
vID := types.NewValidatorID(prv.PublicKey())
- g.Validators[vID] = decimal.NewFromFloat(0)
- g.PrivateKeys[vID] = prv
+ g.notarySet[vID] = struct{}{}
+ g.privateKeys[vID] = prv
}
return
}
-// GetValidatorSet implements Governance interface to return current
-// validator set.
-func (g *Governance) GetValidatorSet() map[types.ValidatorID]decimal.Decimal {
- return g.Validators
+// GetNotarySet implements Governance interface to return current
+// notary set.
+func (g *Governance) GetNotarySet() map[types.ValidatorID]struct{} {
+ return g.notarySet
}
-// GetTotalOrderingK returns K.
-func (g *Governance) GetTotalOrderingK() int {
- return 0
-}
-
-// GetPhiRatio returns phi ratio.
-func (g *Governance) GetPhiRatio() float32 {
- return 0.667
-}
-
-// GetNumShards returns the number of shards.
-func (g *Governance) GetNumShards() uint32 {
- return 1
-}
-
-// GetNumChains returns the number of chains.
-func (g *Governance) GetNumChains() uint32 {
- return uint32(len(g.Validators))
-}
-
-// GetConfigurationChangeEvent Get configuration change events after a certain
-// epoch.
-func (g *Governance) GetConfigurationChangeEvent(
- epoch int) []types.ConfigurationChangeEvent {
- return nil
-}
-
-// GetGenesisCRS returns the CRS string.
-func (g *Governance) GetGenesisCRS() string {
- return "🆕 DEXON"
-}
-
-// GetLambda returns lambda for BA.
-func (g *Governance) GetLambda() time.Duration {
- return g.Lambda
+// GetConfiguration returns the configuration at a given block height.
+func (g *Governance) GetConfiguration(blockHeight uint64) *types.Config {
+ return &types.Config{
+ NumShards: 1,
+ NumChains: uint32(len(g.notarySet)),
+ GenesisCRS: "__ DEXON",
+ Lambda: g.lambda,
+ K: 0,
+ PhiRatio: 0.667,
+ }
}
// GetPrivateKey return the private key for that validator, this function
@@ -112,7 +86,7 @@ func (g *Governance) GetLambda() time.Duration {
func (g *Governance) GetPrivateKey(
vID types.ValidatorID) (key crypto.PrivateKey, err error) {
- key, exists := g.PrivateKeys[vID]
+ key, exists := g.privateKeys[vID]
if !exists {
err = ErrPrivateKeyNotExists
return