Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Aug 1, 2025

With a single resolver, it is much easier to reason about rate limits.


This pull request refactors the resolver logic in the consensus/src/marshal/actor.rs file to simplify the handling of backfill requests and improve code maintainability. It also updates the test suite in consensus/src/marshal/mod.rs to enhance test coverage and flexibility by introducing parameterized link configurations.

Refactoring of Resolver Logic:

  1. Unified Resolver Handling:

    • Consolidated multiple resolvers (backfill_by_digest, backfill_by_height, backfill_by_view) into a single backfill resolver, simplifying the code and reducing duplication. [1] [2]
    • Updated resolver initialization to use a unified Request type for all backfill operations.
  2. Streamlined Request Handling:

    • Replaced specific fetch and retain calls (e.g., notarization_resolver_by_view.fetch) with generalized resolver.fetch and resolver.retain calls using the Request type. [1] [2] [3]
  3. Simplified Message Processing:

    • Merged separate message handlers for different resolvers into a single handler, improving maintainability. [1] [2]

Test Suite Enhancements:

  1. Parameterized Link Configurations:

    • Introduced Link configuration for latency, jitter, and success rate to test scenarios with varying network conditions. [1] [2]
    • Added test_finalize_good_links and test_finalize_bad_links to validate behavior under different link conditions. [1] [2]
  2. Improved Test Determinism:

    • Ensured deterministic results by running tests with fixed seeds and comparing outcomes. [1] [2]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug in main

+ Debug
+ Hash
+ Display
+ AsRef<[u8]>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, not requiring Span to readily provide a [u8] representation makes it much easier to work with (particularly enums because we must serve an as_ref() -> requires a struct).

@patrick-ogrady patrick-ogrady marked this pull request as ready for review August 1, 2025 01:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the marshal resolver system to use a single unified resolver instead of multiple specialized resolvers. The change simplifies the architecture by consolidating three separate resolvers (for blocks by digest, finalizations by height, and notarizations by view) into one resolver that handles all request types.

  • Replaced Array trait with Span trait across resolver components
  • Introduced a unified Request<B: Block> enum to handle different types of backfill requests
  • Consolidated three separate resolver instances into a single resolver in the marshal actor

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
utils/src/sequence/mod.rs Moved AsRef<[u8]> and Deref<Target = [u8]> bounds from Span to Array trait
resolver/src/p2p/wire.rs Changed generic bounds from Array to Span and updated encoding logic
resolver/src/p2p/ingress.rs Updated trait bounds from Array to Span
resolver/src/p2p/fetcher.rs Updated trait bounds from Array to Span
resolver/src/p2p/engine.rs Updated trait bounds from Array to Span
resolver/src/p2p/config.rs Updated trait bounds from Array to Span
consensus/src/marshal/mod.rs Enhanced test structure with better parametrization and test organization
consensus/src/marshal/ingress/handler.rs Added new Request<B: Block> enum with comprehensive trait implementations and tests
consensus/src/marshal/actor.rs Refactored to use single resolver with Request enum instead of three separate resolvers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up leaving a ton of Array littered over resolver 🤦

BrendanChou
BrendanChou previously approved these changes Aug 1, 2025
@patrick-ogrady patrick-ogrady merged commit 013ed34 into main Aug 1, 2025
34 checks passed
@patrick-ogrady patrick-ogrady deleted the marshal-unify-resolver branch August 1, 2025 02:30
@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 84.72222% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.24%. Comparing base (6b2c76d) to head (cb4f4d6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
consensus/src/marshal/actor.rs 57.14% 36 Missing ⚠️
consensus/src/marshal/ingress/handler.rs 92.20% 18 Missing ⚠️
consensus/src/marshal/mod.rs 97.72% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1340      +/-   ##
==========================================
+ Coverage   91.22%   91.24%   +0.02%     
==========================================
  Files         262      262              
  Lines       65073    65280     +207     
==========================================
+ Hits        59361    59565     +204     
- Misses       5712     5715       +3     
Files with missing lines Coverage Δ
resolver/src/p2p/engine.rs 89.32% <ø> (+0.48%) ⬆️
resolver/src/p2p/fetcher.rs 95.96% <ø> (ø)
resolver/src/p2p/ingress.rs 79.31% <ø> (ø)
resolver/src/p2p/mocks/key.rs 66.66% <ø> (+26.66%) ⬆️
resolver/src/p2p/wire.rs 98.43% <100.00%> (ø)
consensus/src/marshal/mod.rs 99.47% <97.72%> (+0.55%) ⬆️
consensus/src/marshal/ingress/handler.rs 91.98% <92.20%> (+1.35%) ⬆️
consensus/src/marshal/actor.rs 78.20% <57.14%> (+0.91%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b2c76d...cb4f4d6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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