qol: small fix-ups to make stuck frame nodes move faster (#153)

This commit is contained in:
Cassandra Heart 2024-03-29 02:20:23 -05:00 committed by GitHub
parent 0e089d5899
commit 52a197368e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 19 deletions

View File

@ -15,13 +15,6 @@ import (
func (e *CeremonyDataClockConsensusEngine) handleMessage( func (e *CeremonyDataClockConsensusEngine) handleMessage(
message *pb.Message, message *pb.Message,
) error { ) error {
e.logger.Debug(
"received message",
zap.Binary("data", message.Data),
zap.Binary("from", message.From),
zap.Binary("signature", message.Signature),
)
go func() { go func() {
e.messageProcessorCh <- message e.messageProcessorCh <- message
}() }()

View File

@ -170,12 +170,6 @@ func (e *CeremonyDataClockConsensusEngine) GetMostAheadPeer(
if v.maxFrame > max && if v.maxFrame > max &&
v.timestamp > config.GetMinimumVersionCutoff().UnixMilli() && v.timestamp > config.GetMinimumVersionCutoff().UnixMilli() &&
bytes.Compare(v.version, config.GetMinimumVersion()) >= 0 && !ok { bytes.Compare(v.version, config.GetMinimumVersion()) >= 0 && !ok {
manifest := e.peerInfoManager.GetPeerInfo(v.peerId)
if manifest == nil || manifest.Bandwidth == 0 {
e.logger.Debug("peer manifest not found or bandwidth zero")
continue
}
peer = v.peerId peer = v.peerId
max = v.maxFrame max = v.maxFrame
} }
@ -274,11 +268,9 @@ func (e *CeremonyDataClockConsensusEngine) collect(
if err != nil { if err != nil {
e.logger.Info("no peers available for sync, waiting") e.logger.Info("no peers available for sync, waiting")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} else if maxFrame-2 > latest.FrameNumber { } else if maxFrame > latest.FrameNumber {
latest, err = e.sync(latest, maxFrame, peerId) latest, err = e.sync(latest, maxFrame, peerId)
if err != nil { if err == nil {
time.Sleep(30 * time.Second)
} else {
break break
} }
} }

View File

@ -291,6 +291,10 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFrameData(
return errors.Wrap(err, "handle clock frame data") return errors.Wrap(err, "handle clock frame data")
} }
if e.latestFrameReceived > frame.FrameNumber {
return nil
}
addr, err := poseidon.HashBytes( addr, err := poseidon.HashBytes(
frame.GetPublicKeySignatureEd448().PublicKey.KeyValue, frame.GetPublicKeySignatureEd448().PublicKey.KeyValue,
) )
@ -343,6 +347,6 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFrameData(
} }
}() }()
} }
e.dataTimeReel.Insert(frame, isSync) e.dataTimeReel.Insert(frame, e.latestFrameReceived < frame.FrameNumber)
return nil return nil
} }

View File

@ -164,6 +164,19 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
for { for {
select { select {
case newFrame := <-e.frameValidationCh: case newFrame := <-e.frameValidationCh:
head, err := e.masterTimeReel.Head()
if err != nil {
panic(err)
}
if head.FrameNumber > newFrame.FrameNumber || newFrame.FrameNumber-head.FrameNumber > 128 {
e.logger.Debug(
"frame out of range, ignoring",
zap.Uint64("number", newFrame.FrameNumber),
)
continue
}
if err := e.frameProver.VerifyMasterClockFrame(newFrame); err != nil { if err := e.frameProver.VerifyMasterClockFrame(newFrame); err != nil {
e.logger.Error("could not verify clock frame", zap.Error(err)) e.logger.Error("could not verify clock frame", zap.Error(err))
continue continue

View File

@ -252,6 +252,7 @@ func (m *MasterTimeReel) processPending() {
for pending, ok := m.pending[m.head.FrameNumber+1]; ok; pending, for pending, ok := m.pending[m.head.FrameNumber+1]; ok; pending,
ok = m.pending[m.head.FrameNumber+1] { ok = m.pending[m.head.FrameNumber+1] {
prev := m.head
for _, frame := range pending { for _, frame := range pending {
frame := frame frame := frame
parent := new(big.Int).SetBytes(frame.ParentSelector) parent := new(big.Int).SetBytes(frame.ParentSelector)
@ -295,8 +296,12 @@ func (m *MasterTimeReel) processPending() {
break break
} }
if m.head.FrameNumber != prev.FrameNumber {
delete(m.pending, m.head.FrameNumber)
} else {
delete(m.pending, m.head.FrameNumber+1) delete(m.pending, m.head.FrameNumber+1)
} }
}
deletes := []uint64{} deletes := []uint64{}
for number := range m.pending { for number := range m.pending {
if number < m.head.FrameNumber { if number < m.head.FrameNumber {