feat(rpc): add shared base-layer blockhash registry#1332
Conversation
|
Warning Review limit reached
More reviews will be available in 54 minutes and 6 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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR introduces a shared Assessment against linked issues
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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-rpc-client/src/lib.rs`:
- Around line 276-285: The get() method returns any cached blockhash value
without checking its age, causing stale blockhashes to persist even after the
refresher fails. Modify the get() method to validate that the cached blockhash
has not exceeded the base-layer blockhash lifetime before returning it. Compare
the fetched_at timestamp in the CachedBlockhash against the current time, and
return None if the cached value is too old, allowing the fallback path to use
RPC instead.
- Around line 259-260: The struct CachedBlockhash is defined as private but the
public method BaseLayerBlockhash::get() returns this private type, which causes
a visibility mismatch that prevents external crates from using the return value.
Either make CachedBlockhash public to expose the metadata fields to external
consumers, or change the visibility of BaseLayerBlockhash::get() to pub(crate)
if the metadata is intended to be internal-only.
🪄 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: da8df474-db34-4843-82e6-6313f351c750
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
magicblock-api/src/domain_registry_manager.rsmagicblock-api/src/magic_validator.rsmagicblock-committor-service/src/committor_processor.rsmagicblock-committor-service/src/config.rsmagicblock-rpc-client/Cargo.tomlmagicblock-rpc-client/src/lib.rsmagicblock-validator-admin/src/claim_fees.rs
5589c64 to
7e93727
Compare
|
@copilot resolve the merge conflicts in this pull request |
thlorenz
left a comment
There was a problem hiding this comment.
I found one blocking freshness issue: the registry can keep serving an expired blockhash indefinitely if the refresher stops succeeding, which would make every registry-backed transaction fail until the process restarts or a retry path invalidates it.
I also noted one small cleanup for an unused variable.
| } | ||
|
|
||
| /// Returns the cached base-layer blockhash, if available. | ||
| pub fn latest_blockhash(&self) -> Option<Hash> { |
There was a problem hiding this comment.
This should apply a freshness check before exposing the registry value.
If refresh_once starts failing after a value has been stored, the old value remains in ArcSwapOption and every caller will keep signing with it forever. That affects both MagicblockRpcClient::get_latest_blockhash() and direct users like claim fees/domain registry, since they treat any registry value as valid and never fall back to RPC.
Once the blockhash ages past Solana's validity window, those transactions can fail continuously until a successful refresh or process restart.
Can we expire the cached value here (or in get()) based on fetched_at, and return None when it is too old so callers fall back to a direct fetch? The TTL should be longer than the 10s refresh interval but comfortably below blockhash expiry.
| @@ -71,22 +71,12 @@ impl CommittorProcessor { | |||
| ); | |||
| let rpc_client = Arc::new(rpc_client); | |||
| let websocket_uri = chain_config.websocket_uri.clone(); | |||
There was a problem hiding this comment.
This local is no longer used after the constructor simplification, and cargo check reports it as an unused variable.
Please remove it to keep the crate warning-free.
warning: unused variable: `websocket_uri`
--> magicblock-committor-service/src/committor_processor.rs:73:13
|
73 | let websocket_uri = chain_config.websocket_uri.clone();
| ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_websocket_uri`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
Summary
Shared
BaseLayerBlockhashregistry refreshed every 10s at validator startup; consumers read lock-free instead of callinggetLatestBlockhashper transaction. Closes #1258. Ephemeral blockhash path unchanged.Changes
magicblock-rpc-client:BaseLayerBlockhash+ background refresher;MagicblockRpcClient::new_with_registry; registry-firstget_latest_blockhash()with legacy fallback;invalidate_cached_blockhash()clears registry too.magicblock-api: spawn refresher intry_from_config; pass registry to committor, claim-fees, domain registry.magicblock-committor-service:ChainConfig.blockhash_registry; singlenew_with_registrycall in committor processor.magicblock-validator-admin: claim-fees reads from registry, RPC fallback on miss.Breaking Changes
No config, CLI, disk, or ephemeral RPC changes. Internal API only:
claim_fees,ClaimFeesTask::start,DomainRegistryManagerconstructors/static helpers, andChainConfiggain an optionalBaseLayerBlockhashparam (defaults toNonein test helpers).Test Plan
No new unit tests — wiring only; stale-blockhash retries still go through existing invalidation paths.
Summary by CodeRabbit