fix: resync can happen again if distance is significant

This commit is contained in:
Cassandra Heart 2023-10-05 12:43:43 -05:00
parent b0a755cdc3
commit 53a19f3f23
No known key found for this signature in database
GPG Key ID: 6352152859385958
2 changed files with 8 additions and 1 deletions

View File

@ -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)

View File

@ -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
}
}
}