qol: div-by-zero fix, minor patch on sync (#155)

This commit is contained in:
Cassandra Heart 2024-04-02 02:13:28 -05:00 committed by GitHub
parent f05bb62d63
commit e92af02122
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View File

@ -269,6 +269,22 @@ func (e *CeremonyDataClockConsensusEngine) collect(
e.logger.Info("no peers available for sync, waiting")
time.Sleep(5 * time.Second)
} else if maxFrame > latest.FrameNumber {
masterHead, err := e.masterTimeReel.Head()
if err != nil {
panic(err)
}
if masterHead.FrameNumber < maxFrame {
e.logger.Info(
"master frame synchronization needed to continue, waiting",
zap.Uint64("master_frame_head", masterHead.FrameNumber),
zap.Uint64("max_data_frame_target", maxFrame),
)
time.Sleep(30 * time.Second)
continue
}
latest, err = e.sync(latest, maxFrame, peerId)
if err == nil {
break

View File

@ -347,6 +347,14 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFrameData(
}
}()
}
e.dataTimeReel.Insert(frame, e.latestFrameReceived < frame.FrameNumber)
head, err := e.dataTimeReel.Head()
if err != nil {
panic(err)
}
if frame.FrameNumber > head.FrameNumber {
e.dataTimeReel.Insert(frame, e.latestFrameReceived < frame.FrameNumber)
}
return nil
}

View File

@ -31,6 +31,12 @@ func (e *CeremonyDataClockConsensusEngine) GetDataFrame(
var err error
if request.FrameNumber == 0 {
frame, err = e.dataTimeReel.Head()
if frame.FrameNumber == 0 {
return nil, errors.Wrap(
errors.New("not currently syncable"),
"get data frame",
)
}
} else {
frame, _, err = e.clockStore.GetDataClockFrame(
e.filter,