From 196588cbe6009ed8ee3d9733f0f725c7ebc19e5c Mon Sep 17 00:00:00 2001 From: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:21:16 -0600 Subject: [PATCH] v1.2.3 (#36) --- node/app/db_console.go | 4 +- .../ceremony_data_clock_consensus_engine.go | 11 +++ node/consensus/ceremony/consensus_frames.go | 4 +- node/consensus/consensus_engine.go | 6 +- .../application/ceremony_application.go | 54 ++++++++++++- .../ceremony/ceremony_execution_engine.go | 1 + node/main.go | 2 +- node/p2p/blossomsub.go | 4 +- node/store/clock.go | 77 +++++++++++++++++++ 9 files changed, 151 insertions(+), 12 deletions(-) diff --git a/node/app/db_console.go b/node/app/db_console.go index b04b409..f374837 100644 --- a/node/app/db_console.go +++ b/node/app/db_console.go @@ -818,11 +818,11 @@ func logoVersion(width int) string { out += " ####################################### ########\n" out += " ############################# ##\n" out += " \n" - out += " Quilibrium Node - v1.2.2 – Dawn\n" + out += " Quilibrium Node - v1.2.3 – Dawn\n" out += " \n" out += " DB Console\n" } else { - out = "Quilibrium Node - v1.2.2 – Dawn - DB Console\n" + out = "Quilibrium Node - v1.2.3 – Dawn - DB Console\n" } return out } diff --git a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go index 90a1f94..bd4faca 100644 --- a/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go +++ b/node/consensus/ceremony/ceremony_data_clock_consensus_engine.go @@ -213,6 +213,17 @@ func (e *CeremonyDataClockConsensusEngine) Start() <-chan error { panic(err) } + candidateLatestFrame, err := e.clockStore.GetLatestCandidateDataClockFrame( + e.filter, + ) + if err != nil && !errors.Is(err, store.ErrNotFound) { + panic(err) + } + + if candidateLatestFrame != nil { + latestFrame = candidateLatestFrame + } + if latestFrame != nil { e.setFrame(latestFrame) } else { diff --git a/node/consensus/ceremony/consensus_frames.go b/node/consensus/ceremony/consensus_frames.go index 415b126..e2e0b03 100644 --- a/node/consensus/ceremony/consensus_frames.go +++ b/node/consensus/ceremony/consensus_frames.go @@ -972,7 +972,7 @@ func (e *CeremonyDataClockConsensusEngine) sync( grpc.MaxCallRecvMsgSize(600*1024*1024), ) if err != nil { - e.logger.Error( + e.logger.Debug( "received error from peer", zap.Error(err), ) @@ -1052,7 +1052,7 @@ func (e *CeremonyDataClockConsensusEngine) sync( } } if err != nil && err != io.EOF && !errors.Is(err, ErrNoNewFrames) { - e.logger.Error("error while receiving sync", zap.Error(err)) + e.logger.Debug("error while receiving sync", zap.Error(err)) if err := cc.Close(); err != nil { e.logger.Error("error while closing connection", zap.Error(err)) diff --git a/node/consensus/consensus_engine.go b/node/consensus/consensus_engine.go index ae32cea..8aaf0cb 100644 --- a/node/consensus/consensus_engine.go +++ b/node/consensus/consensus_engine.go @@ -51,13 +51,13 @@ type DataConsensusEngine interface { } func GetMinimumVersionCutoff() time.Time { - return time.Date(2024, time.January, 3, 7, 0, 0, 0, time.UTC) + return time.Date(2024, time.January, 14, 7, 0, 0, 0, time.UTC) } func GetMinimumVersion() []byte { - return []byte{0x01, 0x02, 0x00} + return []byte{0x01, 0x02, 0x03} } func GetVersion() []byte { - return []byte{0x01, 0x02, 0x02} + return []byte{0x01, 0x02, 0x03} } diff --git a/node/execution/ceremony/application/ceremony_application.go b/node/execution/ceremony/application/ceremony_application.go index 85a09ea..78a824d 100644 --- a/node/execution/ceremony/application/ceremony_application.go +++ b/node/execution/ceremony/application/ceremony_application.go @@ -646,8 +646,33 @@ func MaterializeApplicationFromFrame( roundCount-- } + stateCount := uint64(0) + setCount := false + + if len(inProgress.DroppedParticipantAttestations) > 0 { + stateCount = frame.FrameNumber - + inProgress.DroppedParticipantAttestations[len(inProgress.DroppedParticipantAttestations)-1].LastSeenFrame + setCount = true + } + + if len(inProgress.LatestSeenProverAttestations) > 0 { + seenCount := frame.FrameNumber - + inProgress.LatestSeenProverAttestations[len(inProgress.LatestSeenProverAttestations)-1].LastSeenFrame + if !setCount || seenCount < stateCount { + stateCount = seenCount + } + } + + if len(inProgress.ActiveParticipants) > 0 { + lastStateCount := frame.FrameNumber - + inProgress.ActiveParticipants[len(inProgress.ActiveParticipants)-1].FrameNumber + if !setCount || (lastStateCount < stateCount && lastStateCount > 20) { + stateCount = lastStateCount - 20 + } + } + return &CeremonyApplication{ - StateCount: 0, + StateCount: stateCount, RoundCount: uint64(roundCount), LobbyState: CEREMONY_APPLICATION_STATE_IN_PROGRESS, NextRoundPreferredParticipants: inProgress.NextRoundParticipants, @@ -667,8 +692,33 @@ func MaterializeApplicationFromFrame( ) } + stateCount := uint64(0) + setCount := false + + if len(finalizing.DroppedParticipantAttestations) > 0 { + stateCount = frame.FrameNumber - + finalizing.DroppedParticipantAttestations[len(finalizing.DroppedParticipantAttestations)-1].LastSeenFrame + setCount = true + } + + if len(finalizing.LatestSeenProverAttestations) > 0 { + seenCount := frame.FrameNumber - + finalizing.LatestSeenProverAttestations[len(finalizing.LatestSeenProverAttestations)-1].LastSeenFrame + if !setCount || seenCount < stateCount { + stateCount = seenCount + } + } + + if len(finalizing.ActiveParticipants) > 0 { + lastStateCount := frame.FrameNumber - + finalizing.ActiveParticipants[len(finalizing.ActiveParticipants)-1].FrameNumber + if !setCount || (lastStateCount < stateCount && lastStateCount > 200) { + stateCount = lastStateCount - 200 + } + } + return &CeremonyApplication{ - StateCount: 0, + StateCount: stateCount, RoundCount: 0, LobbyState: CEREMONY_APPLICATION_STATE_FINALIZING, ActiveParticipants: finalizing.ActiveParticipants, diff --git a/node/execution/ceremony/ceremony_execution_engine.go b/node/execution/ceremony/ceremony_execution_engine.go index fc41ba3..fd8239b 100644 --- a/node/execution/ceremony/ceremony_execution_engine.go +++ b/node/execution/ceremony/ceremony_execution_engine.go @@ -398,6 +398,7 @@ func (e *CeremonyExecutionEngine) RunWorker() { ), zap.Bool("in_round", inRound), zap.Uint64("current_sub_round", app.RoundCount), + zap.Uint64("stale_state_count", app.StateCount), ) shouldConnect := false diff --git a/node/main.go b/node/main.go index 3f6fb07..4502218 100644 --- a/node/main.go +++ b/node/main.go @@ -249,5 +249,5 @@ func printLogo() { func printVersion() { fmt.Println(" ") - fmt.Println(" Quilibrium Node - v1.2.2 – Dawn") + fmt.Println(" Quilibrium Node - v1.2.3 – Dawn") } diff --git a/node/p2p/blossomsub.go b/node/p2p/blossomsub.go index ac5e929..294ccf0 100644 --- a/node/p2p/blossomsub.go +++ b/node/p2p/blossomsub.go @@ -328,7 +328,7 @@ func initDHT( go func() { defer wg.Done() if err := h.Connect(ctx, *peerinfo); err != nil { - logger.Warn("error while connecting to dht peer", zap.Error(err)) + logger.Debug("error while connecting to dht peer", zap.Error(err)) } logger.Info( "connected to peer", @@ -517,7 +517,7 @@ func discoverPeers( logger.Info("found peer", zap.String("peer_id", peer.ID.Pretty())) err := h.Connect(ctx, peer) if err != nil { - logger.Warn( + logger.Debug( "error while connecting to blossomsub peer", zap.String("peer_id", peer.ID.Pretty()), zap.Error(err), diff --git a/node/store/clock.go b/node/store/clock.go index 073095b..931b04f 100644 --- a/node/store/clock.go +++ b/node/store/clock.go @@ -34,6 +34,9 @@ type ClockStore interface { filter []byte, proverTrie *tries.RollingFrecencyCritbitTrie, ) (*protobufs.ClockFrame, error) + GetLatestCandidateDataClockFrame( + filter []byte, + ) (*protobufs.ClockFrame, error) GetEarliestDataClockFrame(filter []byte) (*protobufs.ClockFrame, error) GetDataClockFrame( filter []byte, @@ -324,6 +327,8 @@ const CLOCK_MASTER_FRAME_INDEX_PARENT = 0x30 | CLOCK_MASTER_FRAME_DATA const CLOCK_DATA_FRAME_INDEX_EARLIEST = 0x10 | CLOCK_DATA_FRAME_DATA const CLOCK_DATA_FRAME_INDEX_LATEST = 0x20 | CLOCK_DATA_FRAME_DATA const CLOCK_DATA_FRAME_INDEX_PARENT = 0x30 | CLOCK_DATA_FRAME_DATA +const CLOCK_DATA_FRAME_CANDIDATE_INDEX_LATEST = 0x20 | + CLOCK_DATA_FRAME_CANDIDATE_DATA // // DB Keys @@ -384,6 +389,10 @@ func clockDataLatestIndex(filter []byte) []byte { return clockLatestIndex(filter, CLOCK_DATA_FRAME_INDEX_LATEST) } +func clockDataCandidateLatestIndex(filter []byte) []byte { + return clockLatestIndex(filter, CLOCK_DATA_FRAME_CANDIDATE_INDEX_LATEST) +} + func clockEarliestIndex(filter []byte, frameType byte) []byte { key := []byte{CLOCK_FRAME, frameType} key = append(key, filter...) @@ -801,6 +810,33 @@ func (p *PebbleClockStore) GetLatestDataClockFrame( return frame, nil } +func (p *PebbleClockStore) GetLatestCandidateDataClockFrame( + filter []byte, +) (*protobufs.ClockFrame, error) { + idxValue, closer, err := p.db.Get(clockDataCandidateLatestIndex(filter)) + if err != nil { + if errors.Is(err, pebble.ErrNotFound) { + return nil, ErrNotFound + } + + return nil, errors.Wrap(err, "get latest candidate data clock frame") + } + + frameNumber := binary.BigEndian.Uint64(idxValue) + frames, err := p.GetCandidateDataClockFrames(filter, frameNumber) + if err != nil { + return nil, errors.Wrap(err, "get latest candidate data clock frame") + } + + closer.Close() + + if len(frames) == 0 { + return nil, ErrNotFound + } + + return frames[0], nil +} + // GetLeadingCandidateDataClockFrame implements ClockStore. func (p *PebbleClockStore) GetLeadingCandidateDataClockFrame( filter []byte, @@ -907,6 +943,29 @@ func (p *PebbleClockStore) PutCandidateDataClockFrame( return errors.Wrap(err, "put candidate data clock frame") } + numberBytes, closer, err := p.db.Get(clockDataCandidateLatestIndex(frame.Filter)) + if err != nil && !errors.Is(err, pebble.ErrNotFound) { + return errors.Wrap(err, "put candidate data clock frame") + } + + existingNumber := uint64(0) + + if numberBytes != nil { + existingNumber = binary.BigEndian.Uint64(numberBytes) + closer.Close() + } + + if frame.FrameNumber > existingNumber { + frameNumberBytes := make([]byte, 8) + binary.BigEndian.PutUint64(frameNumberBytes, frame.FrameNumber) + if err = txn.Set( + clockDataCandidateLatestIndex(frame.Filter), + frameNumberBytes, + ); err != nil { + return errors.Wrap(err, "put candidate data clock frame") + } + } + return nil } @@ -1685,6 +1744,24 @@ func (p *PebbleClockStore) DeleteCandidateDataClockFrameRange( return errors.Wrap(err, "delete candidate data clock frame range") } +func (p *PebbleClockStore) DeleteDataClockFrameRange( + filter []byte, + fromFrameNumber uint64, + toFrameNumber uint64, +) error { + err := p.db.DeleteRange( + clockDataFrameKey( + filter, + fromFrameNumber, + ), + clockDataFrameKey( + filter, + toFrameNumber, + ), + ) + return errors.Wrap(err, "delete data clock frame range") +} + func (p *PebbleClockStore) GetHighestCandidateDataClockFrame( filter []byte, ) (*protobufs.ClockFrame, error) {