Skip to content

refactor: propagate an error if block tree rejects a block#1137

Merged
roberts-pumpurs merged 7 commits into
masterfrom
rob/add-logs
Feb 16, 2026
Merged

refactor: propagate an error if block tree rejects a block#1137
roberts-pumpurs merged 7 commits into
masterfrom
rob/add-logs

Conversation

@roberts-pumpurs

@roberts-pumpurs roberts-pumpurs commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Describe the changes

  • remove silently dropping errors when we fail adding a block to the tree

Related Issue(s)
Please link to the issue(s) that will be closed with this PR.

Checklist

  • Tests have been added/updated for the changes.
  • Documentation has been updated for the changes (if applicable).
  • The code follows Rust's style guidelines.

Additional Context
Add any other context about the pull request here.

Summary by CodeRabbit

  • Improvements
    • Enhanced error reporting and structured logging for block-add failures, now including the block identifier and a clear failure reason to aid diagnostics.
  • Tests
    • Increased wait durations in a multi-node restart test to improve timing stability.
    • Added an explicit synchronization step after mining in a PoA validation test to ensure correct block availability before validation.

@coderabbitai

coderabbitai Bot commented Feb 13, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a new PreValidationError::AddBlockFailed { block_hash: H256, reason: String }, updates block-tree add_block error handling to return that variant with structured logging and preserved success-path scheduling logic, and increases a test wait constant and inserts a wait-for-confirmation step in PoA tests.

Changes

Cohort / File(s) Summary
Error Enum
crates/actors/src/block_validation.rs
Added PreValidationError::AddBlockFailed { block_hash: H256, reason: String } with message describing failed add_block and reason.
Block-tree add_block handling
crates/actors/src/block_tree_service.rs
Replaced prior inline add_block failure path with a map_err producing AddBlockFailed { block_hash, reason }; preserved success-path actions (mark scheduled, record diagnostics, send validation request); updated structured logging on failure.
Tests — timing & sync
crates/chain/tests/multi_node/reth_restart.rs, crates/chain/tests/validation/poa_cases.rs
Increased WAIT_SECS from 2 to 30 in reth_restart.rs; added a wait_until_height_confirmed(...) step after mining in poa_cases.rs to ensure block index/migration before PoA checks. Pay attention to test runtime and potential flakiness.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • DanMacDonald
  • antouhou
  • JesseTheRobot
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (14 files):

⚔️ Cargo.lock (content)
⚔️ crates/actors/src/block_tree_service.rs (content)
⚔️ crates/actors/src/block_validation.rs (content)
⚔️ crates/chain/tests/multi_node/reth_restart.rs (content)
⚔️ crates/chain/tests/validation/poa_cases.rs (content)
⚔️ crates/p2p/Cargo.toml (content)
⚔️ crates/p2p/src/chain_sync.rs (content)
⚔️ crates/p2p/src/gossip_client.rs (content)
⚔️ crates/p2p/src/gossip_data_handler.rs (content)
⚔️ crates/p2p/src/peer_network_service.rs (content)
⚔️ crates/p2p/src/tests/util.rs (content)
⚔️ crates/p2p/src/types.rs (content)
⚔️ crates/utils/utils/Cargo.toml (content)
⚔️ crates/utils/utils/src/lib.rs (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting silent error handling into explicit error propagation when the block tree rejects a block, which aligns with the core refactoring across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rob/add-logs
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch rob/add-logs
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@roberts-pumpurs roberts-pumpurs changed the title Rob/add logs refactor: propagate an error if block tree rejects a block Feb 13, 2026
@roberts-pumpurs roberts-pumpurs self-assigned this Feb 13, 2026
@roberts-pumpurs roberts-pumpurs marked this pull request as ready for review February 13, 2026 18:02

@JesseTheRobot JesseTheRobot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - I'll put this in with the peer ID change into the RC

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/chain/tests/validation/poa_cases.rs`:
- Around line 93-97: Replace the hard-coded literal 20 passed into
genesis_node.wait_until_height_confirmed with the existing seconds_to_wait
variable to avoid divergence if the timeout value changes; update the call using
genesis_node.wait_until_height_confirmed(new_block.height,
seconds_to_wait).await? so it uses seconds_to_wait consistently.

Comment on lines +93 to +97
// Wait for the data block to be confirmed and migrated to the block index,
// so that poa_is_valid can look up block bounds for chunk offsets.
genesis_node
.wait_until_height_confirmed(new_block.height, 20)
.await?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Use the seconds_to_wait variable instead of the magic number 20.

Line 21 defines seconds_to_wait = 20 for exactly this purpose. Using the literal 20 here is inconsistent and will silently diverge if the constant is updated.

Proposed fix
     genesis_node
-        .wait_until_height_confirmed(new_block.height, 20)
+        .wait_until_height_confirmed(new_block.height, seconds_to_wait)
         .await?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Wait for the data block to be confirmed and migrated to the block index,
// so that poa_is_valid can look up block bounds for chunk offsets.
genesis_node
.wait_until_height_confirmed(new_block.height, 20)
.await?;
genesis_node
.wait_until_height_confirmed(new_block.height, seconds_to_wait)
.await?;
🤖 Prompt for AI Agents
In `@crates/chain/tests/validation/poa_cases.rs` around lines 93 - 97, Replace the
hard-coded literal 20 passed into genesis_node.wait_until_height_confirmed with
the existing seconds_to_wait variable to avoid divergence if the timeout value
changes; update the call using
genesis_node.wait_until_height_confirmed(new_block.height,
seconds_to_wait).await? so it uses seconds_to_wait consistently.

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