Skip to content

Don't construct or notify RpcSubscriptions when the RPC is off#6516

Merged
steveluscher merged 5 commits intoanza-xyz:masterfrom
steveluscher:rpc-off-rpc-subscriptions-go-poof
Jul 21, 2025
Merged

Don't construct or notify RpcSubscriptions when the RPC is off#6516
steveluscher merged 5 commits intoanza-xyz:masterfrom
steveluscher:rpc-off-rpc-subscriptions-go-poof

Conversation

@steveluscher
Copy link
Copy Markdown

Problem

It appears as though we unconditionally construct RpcSubscriptions, and push notifications into it, despite the node not having RPC enabled.

Summary of Changes

Turn it into an Option. Only construct it in the block where we set up the rest of the RPC. Don't notify if that Option is None.

Comment thread core/src/validator.rs
Comment on lines -1061 to -1071
let rpc_subscriptions = Arc::new(RpcSubscriptions::new_with_config(
exit.clone(),
max_complete_transaction_status_slot.clone(),
blockstore.clone(),
bank_forks.clone(),
block_commitment_cache.clone(),
optimistically_confirmed_bank.clone(),
&config.pubsub_config,
None,
));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved this…

Comment thread core/src/validator.rs
Comment on lines +1202 to +1211
let rpc_subscriptions = Arc::new(RpcSubscriptions::new_with_config(
exit.clone(),
max_complete_transaction_status_slot,
blockstore.clone(),
bank_forks.clone(),
block_commitment_cache.clone(),
optimistically_confirmed_bank.clone(),
&config.pubsub_config,
None,
));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

…inside here.

@steveluscher steveluscher force-pushed the rpc-off-rpc-subscriptions-go-poof branch from 20aac86 to 6f39b24 Compare June 11, 2025 21:25
@steveluscher steveluscher marked this pull request as ready for review June 11, 2025 22:01
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 99.00990% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.8%. Comparing base (c0bf332) to head (1e0df17).
Report is 139 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #6516     +/-   ##
=========================================
- Coverage    82.8%    82.8%   -0.1%     
=========================================
  Files         851      851             
  Lines      379955   379981     +26     
=========================================
+ Hits       314717   314732     +15     
- Misses      65238    65249     +11     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

The bulk looks good! Mostly some style points and better ways to work with Option<Arc<T>>

Comment thread core/src/cluster_info_vote_listener.rs Outdated
let mut latest_vote_slot_per_validator = HashMap::new();
let mut last_process_root = Instant::now();
let duplicate_confirmed_slot_sender = Some(duplicate_confirmed_slot_sender);
let subscriptions = subscriptions.and_then(|arc| Arc::try_unwrap(arc).ok());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you want to convert from Option<Arc<T>> to Option<&T>, it's better to use as_deref() https://doc.rust-lang.org/std/option/enum.Option.html#method.as_deref

This means changing the &Option<T> to Option<&T> and using as_deref() in all call sites, or you can use &Option<&T>, but I don't think there's any benefit to that.

try_unwrap() will fail if there's other references to the RpcSubscriptions, so we should avoid it: https://doc.rust-lang.org/std/sync/struct.Arc.html#method.try_unwrap

Comment thread core/src/commitment_service.rs Outdated
receiver: &Receiver<CommitmentAggregationData>,
block_commitment_cache: &RwLock<BlockCommitmentCache>,
subscriptions: &Arc<RpcSubscriptions>,
rpc_subscriptions: &Option<Arc<RpcSubscriptions>>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This isn't your fault, but &Arc<T> is an antipattern, and typically should just use &T instead. How about changing this to Option<&RpcSubscriptions>?

Comment thread core/src/replay_stage.rs Outdated
poh_recorder: &Arc<RwLock<PohRecorder>>,
leader_schedule_cache: &Arc<LeaderScheduleCache>,
rpc_subscriptions: &Arc<RpcSubscriptions>,
rpc_subscriptions: &Option<Arc<RpcSubscriptions>>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the flipside, probably not worth changing here for consistency with every other arg 🙃

Comment thread core/src/replay_stage.rs Outdated
&bank_forks,
&leader_schedule_cache,
&rpc_subscriptions,
&Some(rpc_subscriptions.clone()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: These test changes would probably be simpler by doing let rpc_subscriptions = Some(rpc_subscriptions); earlier on, and then passing &rpc_subscriptions as before. Like at line 5193

Comment thread core/src/cluster_info_vote_listener.rs Outdated
&vote_tracker,
&bank3,
&subscriptions,
&Arc::try_unwrap(subscriptions.clone()).ok(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These tests will get much simpler too, since you can just pass subscriptions.as_deref()

@steveluscher
Copy link
Copy Markdown
Author

I'm completely lost.

  • Applied some of your suggestions in f6f669c. Typechecks fine.
  • Kept going to convert &Option<Arc<RpcSubscriptions>> to Option<&RpcSubscriptions> in 999c28f, and couldn't possibly get it to typecheck.

@steveluscher steveluscher requested a review from joncinque June 26, 2025 00:33
@joncinque
Copy link
Copy Markdown

Sorry for leading you astray, the error message in your branch didn't tell the real problem, which was that we were trying to move a reference into a new thread, which is not possible because refs aren't safe to move into new threads. Some nice info at https://users.rust-lang.org/t/question-on-moving-a-reference-to-a-child-thread/47387

I changed some of the callsites back to Arc where needed, and avoided &Arc by cloning the Arc directly into those functions. And I updated some of the tests to look a bit nicer by passing Some(&subscriptions).

Let me know what you think!

@steveluscher
Copy link
Copy Markdown
Author

Thank you! Stamp and I'll ship.

Copy link
Copy Markdown

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

:shipit:

@joncinque
Copy link
Copy Markdown

Ah right, we'll need someone else to approve because I was the last person to push to the branch

Copy link
Copy Markdown

@alannza alannza left a comment

Choose a reason for hiding this comment

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

nice.

@steveluscher steveluscher merged commit a6d8924 into anza-xyz:master Jul 21, 2025
28 checks passed
puhtaytow pushed a commit to puhtaytow/agave that referenced this pull request Jul 24, 2025
…a-xyz#6516)

* Don't construct or notify `RpcSubscriptions` when the RPC is off

* Less dumb Rust

* Keep going? Can't get it to typecheck.

* Revert some places that still need `Arc`s due to threads

* Cleanup tests, avoid a clone in tpu

---------

Co-authored-by: Jon C <me@jonc.dev>
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.

4 participants