diff --git a/node/consensus/ceremony/broadcast_messaging.go b/node/consensus/ceremony/broadcast_messaging.go index 8331909..4350540 100644 --- a/node/consensus/ceremony/broadcast_messaging.go +++ b/node/consensus/ceremony/broadcast_messaging.go @@ -15,13 +15,6 @@ import ( func (e *CeremonyDataClockConsensusEngine) handleMessage( message *pb.Message, ) error { - e.logger.Debug( - "received message", - zap.Binary("data", message.Data), - zap.Binary("from", message.From), - zap.Binary("signature", message.Signature), - ) - go func() { e.messageProcessorCh <- message }() diff --git a/node/consensus/ceremony/consensus_frames.go b/node/consensus/ceremony/consensus_frames.go index 0f5fa24..a9ca423 100644 --- a/node/consensus/ceremony/consensus_frames.go +++ b/node/consensus/ceremony/consensus_frames.go @@ -170,12 +170,6 @@ func (e *CeremonyDataClockConsensusEngine) GetMostAheadPeer( if v.maxFrame > max && v.timestamp > config.GetMinimumVersionCutoff().UnixMilli() && 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 max = v.maxFrame } @@ -274,11 +268,9 @@ func (e *CeremonyDataClockConsensusEngine) collect( if err != nil { e.logger.Info("no peers available for sync, waiting") time.Sleep(5 * time.Second) - } else if maxFrame-2 > latest.FrameNumber { + } else if maxFrame > latest.FrameNumber { latest, err = e.sync(latest, maxFrame, peerId) - if err != nil { - time.Sleep(30 * time.Second) - } else { + if err == nil { break } } diff --git a/node/consensus/ceremony/message_handler.go b/node/consensus/ceremony/message_handler.go index 1d753f2..891cfd9 100644 --- a/node/consensus/ceremony/message_handler.go +++ b/node/consensus/ceremony/message_handler.go @@ -291,6 +291,10 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFrameData( return errors.Wrap(err, "handle clock frame data") } + if e.latestFrameReceived > frame.FrameNumber { + return nil + } + addr, err := poseidon.HashBytes( 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 } diff --git a/node/consensus/master/master_clock_consensus_engine.go b/node/consensus/master/master_clock_consensus_engine.go index 8cc0b83..d8c6ae8 100644 --- a/node/consensus/master/master_clock_consensus_engine.go +++ b/node/consensus/master/master_clock_consensus_engine.go @@ -164,6 +164,19 @@ func (e *MasterClockConsensusEngine) Start() <-chan error { for { select { 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 { e.logger.Error("could not verify clock frame", zap.Error(err)) continue diff --git a/node/consensus/time/master_time_reel.go b/node/consensus/time/master_time_reel.go index 0c2be08..eed8596 100644 --- a/node/consensus/time/master_time_reel.go +++ b/node/consensus/time/master_time_reel.go @@ -252,6 +252,7 @@ func (m *MasterTimeReel) processPending() { for pending, ok := m.pending[m.head.FrameNumber+1]; ok; pending, ok = m.pending[m.head.FrameNumber+1] { + prev := m.head for _, frame := range pending { frame := frame parent := new(big.Int).SetBytes(frame.ParentSelector) @@ -295,7 +296,11 @@ func (m *MasterTimeReel) processPending() { break } - delete(m.pending, m.head.FrameNumber+1) + if m.head.FrameNumber != prev.FrameNumber { + delete(m.pending, m.head.FrameNumber) + } else { + delete(m.pending, m.head.FrameNumber+1) + } } deletes := []uint64{} for number := range m.pending {