Skip to content

Comments

fix: sync peer ordering#6802

Merged
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_fix_order
Feb 18, 2025
Merged

fix: sync peer ordering#6802
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_fix_order

Conversation

@SWvheerden
Copy link
Collaborator

@SWvheerden SWvheerden commented Feb 18, 2025

Description

Fixes peer sync order.
Currently, the syncing peers are ordered by latency. This is important, but we also need to sync to the highest node tip.
This changes the order for the sync peers to first order by higher, then by latency.

Summary by CodeRabbit

  • New Features

    • Enhanced synchronization by updating peer prioritization to weigh difficulty claims before latency.
    • Introduced a new interface to retrieve each peer's claimed difficulty.
  • Tests

    • Revised the expected outcome for median timestamp calculations to ensure consistency and accuracy.

@SWvheerden SWvheerden requested a review from a team as a code owner February 18, 2025 11:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

The changes modify the peer sorting logic in the header synchronization state by using claimed difficulty as the primary criterion (with a fallback to latency when equal). A new method to retrieve claimed difficulty is added to the sync peer module. Additionally, an update is made to the median timestamp test, correcting the expected value for inputs that include zero.

Changes

File(s) Summary
base_layer/core/.../states/header_sync.rs
base_layer/core/.../sync/sync_peer.rs
In header_sync.rs, updated the sorting logic to prioritize peers by claimed difficulty (with fallback to latency).
In sync_peer.rs, added claimed_difficulty to return the peer's accumulated claimed difficulty.
base_layer/core/.../validation/helpers.rs Modified the test for calc_median_timestamp, updating the expected median from 100.into() to 0.into().

Sequence Diagram(s)

sequenceDiagram
    participant HS as HeaderSyncState::new
    participant Peer1 as SyncPeer (Peer 1)
    participant Peer2 as SyncPeer (Peer 2)

    HS->>Peer1: Retrieve claimed_difficulty()
    HS->>Peer2: Retrieve claimed_difficulty()
    alt Claimed difficulties differ
        HS->>Peer1: Compare claimed_difficulty values
        HS->>Peer2: Order based on claimed_difficulty
    else Claimed difficulties equal
        HS->>Peer1: Compare latency values
        HS->>Peer2: Order based on latency
    end
Loading

Poem

I'm a hopping rabbit, with code so neat,
Sorting peers by difficulty, what a treat!
If equal, latency takes the win,
My little paws rejoice within.
Bound in bytes and joyful leaps,
I cheer the changes—code that peeps!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c89b253 and d4fb774.

📒 Files selected for processing (2)
  • base_layer/core/src/base_node/state_machine_service/states/header_sync.rs (1 hunks)
  • base_layer/core/src/base_node/sync/sync_peer.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • base_layer/core/src/base_node/sync/sync_peer.rs
  • base_layer/core/src/base_node/state_machine_service/states/header_sync.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: clippy

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SWvheerden SWvheerden changed the title fix: Sync peer ordering fix: sync peer ordering Feb 18, 2025
@github-actions
Copy link

Test Results (CI)

    3 files    129 suites   37m 13s ⏱️
1 361 tests 1 361 ✅ 0 💤 0 ❌
4 081 runs  4 081 ✅ 0 💤 0 ❌

Results for commit c89b253.

@github-actions
Copy link

Test Results (Integration tests)

 2 files  + 2  11 suites  +11   32m 57s ⏱️ + 32m 57s
36 tests +36  35 ✅ +35  0 💤 ±0  1 ❌ +1 
37 runs  +37  36 ✅ +36  0 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit c89b253. ± Comparison against base commit 11d9926.

@SWvheerden SWvheerden merged commit e25ac10 into tari-project:development Feb 18, 2025
16 checks passed
@SWvheerden SWvheerden deleted the sw_fix_order branch February 28, 2025 06:48
@coderabbitai coderabbitai bot mentioned this pull request Mar 27, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 28, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants