From 53a19f3f23db7d5dcbe4033e020d35e2069af529 Mon Sep 17 00:00:00 2001 From: Cassandra Heart Date: Thu, 5 Oct 2023 12:43:43 -0500 Subject: [PATCH] fix: resync can happen again if distance is significant --- .../ceremony/ceremony_data_clock_consensus_engine.go | 1 + node/consensus/ceremony/consensus_frames.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go index b7bd0a5..d1ddafb 100644 --- a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go +++ b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go @@ -87,6 +87,7 @@ type CeremonyDataClockConsensusEngine struct { peerAnnounceMap map[string]*protobufs.CeremonyPeerListAnnounce peerMap map[string]*peerInfo activeChannelsMap map[string]ChannelServer + fullResync bool } var _ consensus.DataConsensusEngine = (*CeremonyDataClockConsensusEngine)(nil) diff --git a/node/consensus/ceremony/consensus_frames.go b/node/consensus/ceremony/consensus_frames.go index 20e8824..7d44b02 100644 --- a/node/consensus/ceremony/consensus_frames.go +++ b/node/consensus/ceremony/consensus_frames.go @@ -885,6 +885,7 @@ func (e *CeremonyDataClockConsensusEngine) collect( zap.String("peer_id", peer.ID(peerId).String()), ) + willPerformFullResync := false cc, err := e.pubSub.GetDirectChannel(peerId) if err != nil { e.logger.Error( @@ -895,7 +896,7 @@ func (e *CeremonyDataClockConsensusEngine) collect( from := latest.FrameNumber if from == 0 { from = 1 - } else if maxFrame-from > 32 { + } else if maxFrame-from > 32 && !e.fullResync { // divergence is high, we need to confirm we're not in a fork from = 1 latest, _, err = e.clockStore.GetDataClockFrame(e.filter, 0) @@ -907,6 +908,7 @@ func (e *CeremonyDataClockConsensusEngine) collect( ) panic(err) } + willPerformFullResync = true } client := protobufs.NewCeremonyServiceClient(cc) @@ -946,6 +948,10 @@ func (e *CeremonyDataClockConsensusEngine) collect( if err := cc.Close(); err != nil { e.logger.Error("error while closing connection", zap.Error(err)) } + + if willPerformFullResync { + e.fullResync = true + } } }