From a9a85fa746c727063015d6e70881426ce8b3a3fb Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Thu, 25 Jul 2019 15:40:17 +0800 Subject: dex: minor refactor --- dex/handler.go | 24 ++++++++++++------------ dex/peer.go | 2 -- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dex/handler.go b/dex/handler.go index 9ad35ed30..ca26bc6e8 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1288,10 +1288,9 @@ func (pm *ProtocolManager) SetReceiveCoreMessage(enabled bool) { // TODO: finish this func (pm *ProtocolManager) peerSetLoop() { round := pm.gov.Round() - resetCount := pm.gov.DKGResetCount(round) + reset := pm.gov.DKGResetCount(round) log.Debug("ProtocolManager: startup round", - "round", round, - "reset", resetCount) + "round", round, "reset", reset) if round < dexCore.DKGDelayRound { for i := round; i <= dexCore.DKGDelayRound; i++ { @@ -1305,7 +1304,7 @@ func (pm *ProtocolManager) peerSetLoop() { if CRSRound > round { pm.peers.BuildConnection(CRSRound) round = CRSRound - resetCount = pm.gov.DKGResetCount(round) + reset = pm.gov.DKGResetCount(round) } ctx, cancel := context.WithCancel(context.Background()) @@ -1334,22 +1333,22 @@ func (pm *ProtocolManager) peerSetLoop() { if newRound == 0 { break } - reset := pm.gov.DKGResetCount(round) + newReset := pm.gov.DKGResetCount(round) - log.Debug("ProtocolManager: new round", - "round", newRound, - "reset", reset) - if newRound <= round && resetCount == reset { + if newRound <= round && reset == newReset { break } + log.Info("ProtocolManager: configuration changed", + "round", newRound, "reset", newReset) + if newRound == round+1 { pm.peers.BuildConnection(newRound) if round >= 1 { pm.peers.ForgetConnection(round - 1) } - } else if newRound == round && resetCount+1 == reset { - pm.peers.ForgetLabelConnection(peerLabel{set: notaryset, round: newRound}) + } else if newRound == round && reset+1 == newReset { + pm.peers.ForgetLabelConnection(peerLabel{set: notaryset, round: round}) pm.gov.PurgeNotarySet(newRound) pm.peers.BuildConnection(newRound) } else { @@ -1361,8 +1360,9 @@ func (pm *ProtocolManager) peerSetLoop() { } pm.peers.BuildConnection(newRound) } + round = newRound - resetCount = reset + reset = newReset case <-pm.chainHeadSub.Err(): return } diff --git a/dex/peer.go b/dex/peer.go index 9b7eb058c..7436c4a19 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -881,8 +881,6 @@ func (ps *peerSet) ForgetLabelConnection(label peerLabel) { log.Debug("Forget label connection", "label", label) ps.forgetDirectConn(label) ps.forgetGroupConn(label) - delete(ps.directConn, label) - delete(ps.groupConnPeers, label) delete(ps.label2Nodes, label) } -- cgit v1.2.3