Skip to content

feat: adds actual parent_blockhash to ReplicaBlockInfoV4#1358

Open
0xzrf wants to merge 2 commits into
magicblock-labs:masterfrom
0xzrf:include_par_bh
Open

feat: adds actual parent_blockhash to ReplicaBlockInfoV4#1358
0xzrf wants to merge 2 commits into
magicblock-labs:masterfrom
0xzrf:include_par_bh

Conversation

@0xzrf

@0xzrf 0xzrf commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds actual parent_blockhash in ReplicaBlockInfoV4 in stead of a dummy value

Changes

  • Added a new LatestBlockInner::new_with_parent() that takes a parent_blockhash(to avoid breaking existing tests) and a new field LatestBlockInner::parent_blockhash
  • Supply the parent_blockhash from apply_replayed_block and prepare_block_as_primary before it's updated to the latest blockhash
  • uses the applied parent_blockhash inside notify_block instead of a dummy placeholder

Breaking Changes

  • None

Test Plan

Extended existing tests and added new tests to verify the changes. You can run the new tests using:

cargo test -p magicblock-ledger --test get_block test_write_block_stores_parent_blockhash
cargo test -p magicblock-processor --test replica_ordering test_replay_block
cargo test -p magicblock-processor --test scheduling test_primary_slot_transition_sets_parent_blockhash

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Block metadata now correctly includes parent block information instead of placeholder values, ensuring proper block linkage and chain integrity.
  • Tests

    • Added tests to verify parent block hash persistence and correctness during block transitions.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@0xzrf, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 28 minutes and 21 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 30b86a3d-18b0-4b82-9e62-dd8f0b033d55

📥 Commits

Reviewing files that changed from the base of the PR and between 4e6c79c and 00fa35f.

📒 Files selected for processing (6)
  • magicblock-aperture/src/geyser.rs
  • magicblock-ledger/src/lib.rs
  • magicblock-ledger/tests/get_block.rs
  • magicblock-processor/src/scheduler/mod.rs
  • magicblock-processor/tests/replica_ordering.rs
  • magicblock-processor/tests/scheduling.rs
📝 Walkthrough

Walkthrough

The PR propagates real parent block hashes through the validator stack. LatestBlockInner in magicblock-ledger gains a parent_blockhash: Hash field; its existing new constructor initializes it to Hash::default(), and a new new_with_parent constructor accepts an explicit parent hash. Both the replica replay path (apply_replayed_block) and the primary production path (prepare_block_as_primary) in TransactionScheduler now read the current ledger block's hash before creating the next block, passing it as parent_blockhash via new_with_parent. In magicblock-aperture, notify_block replaces the hardcoded "11111111111111111111111111111111" placeholder with the real parent_blockhash from the block. Tests cover ledger persistence, replica ordering invariants, and primary slot transitions.

Suggested reviewers

  • thlorenz
  • lucacillario
  • GabrielePicco
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
magicblock-processor/src/scheduler/mod.rs (1)

589-592: 🩺 Stability & Availability | 🟠 Major

Remove panic-on-time-source failure from production block preparation.

Using .unwrap() on duration_since(UNIX_EPOCH) can crash the scheduler thread. Replace with explicit error handling or a safe fallback. Per coding guidelines, .unwrap() in production Rust code within this file path is a major issue that requires proper error handling with logging or a sensible fallback for system time failures.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@magicblock-processor/src/scheduler/mod.rs` around lines 589 - 592, The
`.unwrap()` call on `duration_since(UNIX_EPOCH)` in the timestamp assignment can
cause the scheduler thread to panic if system time is before UNIX_EPOCH. Replace
the unwrap() with proper error handling by either using a match statement or
unwrap_or() with a sensible fallback value (such as a default timestamp of 0 or
the current system time clamped to UNIX_EPOCH). Include appropriate logging if
an error occurs to help with debugging system time issues.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@magicblock-processor/src/scheduler/mod.rs`:
- Around line 395-396: The parent_blockhash derivation at line 395 uses only
ledger.latest_block().load().blockhash, but this can diverge from the
scheduler's actual chain seed which uses fallback logic to SlotHashes when the
ledger hash is default in initial_blockhash(...). To fix this, refactor the
parent_blockhash assignment to use the same fallback logic pattern as
initial_blockhash(...), checking whether the ledger hash is default and falling
back to SlotHashes accordingly. Apply this same fix to the other occurrence
mentioned at lines 585-586 to ensure consistency across all parent_blockhash
derivations.

---

Outside diff comments:
In `@magicblock-processor/src/scheduler/mod.rs`:
- Around line 589-592: The `.unwrap()` call on `duration_since(UNIX_EPOCH)` in
the timestamp assignment can cause the scheduler thread to panic if system time
is before UNIX_EPOCH. Replace the unwrap() with proper error handling by either
using a match statement or unwrap_or() with a sensible fallback value (such as a
default timestamp of 0 or the current system time clamped to UNIX_EPOCH).
Include appropriate logging if an error occurs to help with debugging system
time issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: db6be923-e6c5-4ea1-802c-45ddcd49a2f4

📥 Commits

Reviewing files that changed from the base of the PR and between f1d9c25 and 4e6c79c.

📒 Files selected for processing (6)
  • magicblock-aperture/src/geyser.rs
  • magicblock-ledger/src/lib.rs
  • magicblock-ledger/tests/get_block.rs
  • magicblock-processor/src/scheduler/mod.rs
  • magicblock-processor/tests/replica_ordering.rs
  • magicblock-processor/tests/scheduling.rs

Comment thread magicblock-processor/src/scheduler/mod.rs Outdated
@GabrielePicco GabrielePicco requested a review from bmuddha June 26, 2026 06:31
@0xzrf

0xzrf commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@GabrielePicco @bmuddha thoughts on the PR?

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.

1 participant