diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-28 12:32:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-28 12:32:50 +0800 |
commit | 5fc0efa940c7663a33d0fc501807a2627d2cb573 (patch) | |
tree | 932ef05c2d091bdbe6bc38f0391d45993cc1f42c /simulation/governance.go | |
parent | 189a17a6586cd30ac355bd1165c44da6a2a08569 (diff) | |
download | tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar.gz tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar.bz2 tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar.lz tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar.xz tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.tar.zst tangerine-consensus-5fc0efa940c7663a33d0fc501807a2627d2cb573.zip |
core: hide types.NodeID from full node. (#147)
* Refine core.Governance interface
- Remove types.NodeID from interface declaration.
- All parameter should be round based.
* Add core.NodeSetCache
* Agreement accepts map of nodeID directly.
* test.Transport.Peers method return public keys.
Diffstat (limited to 'simulation/governance.go')
-rw-r--r-- | simulation/governance.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/simulation/governance.go b/simulation/governance.go index eb0f2a2..3290075 100644 --- a/simulation/governance.go +++ b/simulation/governance.go @@ -32,7 +32,7 @@ import ( type simGovernance struct { id types.NodeID lock sync.RWMutex - notarySet map[types.NodeID]struct{} + nodeSet map[types.NodeID]crypto.PublicKey expectedNumNodes int k int phiRatio float32 @@ -52,7 +52,7 @@ func newSimGovernance( numNodes int, consensusConfig config.Consensus) *simGovernance { return &simGovernance{ id: id, - notarySet: make(map[types.NodeID]struct{}), + nodeSet: make(map[types.NodeID]crypto.PublicKey), expectedNumNodes: numNodes, k: consensusConfig.K, phiRatio: consensusConfig.PhiRatio, @@ -71,17 +71,14 @@ func (g *simGovernance) setNetwork(network *network) { } // GetNodeSet returns the current notary set. -func (g *simGovernance) GetNodeSet( - blockHeight uint64) map[types.NodeID]struct{} { +func (g *simGovernance) GetNodeSet(round uint64) (ret []crypto.PublicKey) { g.lock.RLock() defer g.lock.RUnlock() - // Return the cloned notarySet. - ret := make(map[types.NodeID]struct{}) - for k := range g.notarySet { - ret[k] = struct{}{} + for _, pubKey := range g.nodeSet { + ret = append(ret, pubKey) } - return ret + return } // GetConfiguration returns the configuration at a given round. @@ -102,17 +99,19 @@ func (g *simGovernance) GetCRS(round uint64) []byte { } // addNode add a new node into the simulated governance contract. -func (g *simGovernance) addNode(nID types.NodeID) { +func (g *simGovernance) addNode(pubKey crypto.PublicKey) { + nID := types.NewNodeID(pubKey) + g.lock.Lock() defer g.lock.Unlock() - if _, exists := g.notarySet[nID]; exists { + if _, exists := g.nodeSet[nID]; exists { return } - if len(g.notarySet) == g.expectedNumNodes { + if len(g.nodeSet) == g.expectedNumNodes { panic(fmt.Errorf("attempt to add node when ready")) } - g.notarySet[nID] = struct{}{} + g.nodeSet[nID] = pubKey } // ProposeThresholdSignature porposes a ThresholdSignature of round. |