Skip to content

refactor: simplify trait impl with ambassador#6842

Merged
LesnyRumcajs merged 1 commit intomainfrom
hm/simplify-trait-impl-with-ambassador
Apr 3, 2026
Merged

refactor: simplify trait impl with ambassador#6842
LesnyRumcajs merged 1 commit intomainfrom
hm/simplify-trait-impl-with-ambassador

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Apr 1, 2026

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Chores
    • Added new build dependency for improved code maintainability
    • Refactored trait implementations for message handling to reduce boilerplate code
    • Updated internal trait organization across multiple modules

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

Walkthrough

The pull request adds the ambassador crate as a dependency and refactors trait implementations across message and beacon modules to use ambassador-based delegation instead of manual trait implementations. The message trait hierarchy is restructured, with MessageTrait renamed to MessageReadWrite and message traits marked as delegatable.

Changes

Cohort / File(s) Summary
Dependency Addition
Cargo.toml
Added direct dependency on ambassador version 0.5.
Beacon Abstraction Refactoring
src/beacon/drand.rs
Replaced manual BeaconImpl trait implementations with ambassador::Delegate derive and #[delegate(Beacon)] attribute; added #[delegatable_trait] to the Beacon trait; updated test build paths for MockBeacon.
Message Trait Restructuring
src/message/mod.rs, src/message/chain_message.rs, src/message/signed_message.rs
Renamed MessageTrait to MessageReadWrite; added #[delegatable_trait] to MessageRead; replaced manual trait implementations with ambassador::Delegate delegation in ChainMessage; updated SignedMessage impl block from MessageTrait to MessageReadWrite; changed function signature for valid_for_block_inclusion to accept &Message instead of &ShimMessage.
Message Handler Type Changes
src/chain/store/base_fee.rs
Updated base-fee computation to treat message references as &dyn MessageReadWrite instead of &dyn Message when iterating over message fields.
Import Updates
src/rpc/methods/eth.rs, src/rpc/methods/gas.rs, src/state_manager/mod.rs
Updated module imports to include MessageReadWrite trait alongside existing message-related imports for proper method resolution.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

dependencies, rust

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring work: simplifying trait implementations across multiple files using the ambassador crate delegation approach.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/simplify-trait-impl-with-ambassador
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/simplify-trait-impl-with-ambassador

Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review April 1, 2026 18:41
@hanabi1224 hanabi1224 requested a review from a team as a code owner April 1, 2026 18:41
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team April 1, 2026 18:41
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.85%. Comparing base (0fe81e6) to head (c6b21df).
⚠️ Report is 8 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/chain/store/base_fee.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/beacon/drand.rs 76.31% <ø> (+0.10%) ⬆️
src/message/chain_message.rs 65.51% <ø> (+13.95%) ⬆️
src/message/mod.rs 90.56% <100.00%> (ø)
src/message/signed_message.rs 82.52% <ø> (ø)
src/rpc/methods/eth.rs 65.55% <ø> (ø)
src/rpc/methods/gas.rs 86.66% <ø> (ø)
src/state_manager/mod.rs 66.46% <ø> (ø)
src/chain/store/base_fee.rs 86.19% <0.00%> (ø)

... and 3 files 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 0fe81e6...c6b21df. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/beacon/drand.rs (1)

4-4: Scope the dead_code allowance more narrowly.

Line 4 silences the entire module, so genuinely unused production paths in drand.rs will disappear along with any macro-related noise. Please move this to the specific generated item, or drop it once the delegation change compiles cleanly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/beacon/drand.rs` at line 4, The module-level attribute
#![allow(dead_code)] in drand.rs is too broad; remove that top-level attribute
and either place #[allow(dead_code)] directly on the specific generated item(s)
(the generated function/struct produced by the delegation change) or delete the
attribute entirely once the delegation change compiles cleanly; update the
generated item declaration(s) to carry #[allow(dead_code)] instead of silencing
the whole module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/beacon/drand.rs`:
- Line 4: The module-level attribute #![allow(dead_code)] in drand.rs is too
broad; remove that top-level attribute and either place #[allow(dead_code)]
directly on the specific generated item(s) (the generated function/struct
produced by the delegation change) or delete the attribute entirely once the
delegation change compiles cleanly; update the generated item declaration(s) to
carry #[allow(dead_code)] instead of silencing the whole module.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4ea17874-1580-4a75-93b2-9e94b195b767

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe81e6 and c6b21df.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • Cargo.toml
  • src/beacon/drand.rs
  • src/chain/store/base_fee.rs
  • src/message/chain_message.rs
  • src/message/mod.rs
  • src/message/signed_message.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/gas.rs
  • src/state_manager/mod.rs

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Apr 3, 2026
Merged via the queue into main with commit ad24532 Apr 3, 2026
39 checks passed
@LesnyRumcajs LesnyRumcajs deleted the hm/simplify-trait-impl-with-ambassador branch April 3, 2026 11:37
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