diff options
author | Wei-Ning Huang <w@byzantine-lab.io> | 2019-07-25 15:40:17 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-09-17 16:57:31 +0800 |
commit | a9a85fa746c727063015d6e70881426ce8b3a3fb (patch) | |
tree | c64c47914fe2b0b5af2f9b3c5141bbf0c26a4331 | |
parent | 38ba6a197f6f16e59b27db97e503a782d385a7c8 (diff) | |
download | go-tangerine-a9a85fa746c727063015d6e70881426ce8b3a3fb.tar.gz go-tangerine-a9a85fa746c727063015d6e70881426ce8b3a3fb.tar.zst go-tangerine-a9a85fa746c727063015d6e70881426ce8b3a3fb.zip |
dex: minor refactor
-rw-r--r-- | dex/handler.go | 24 | ||||
-rw-r--r-- | 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) } |