Skip to content

Add RandomRPC node selection mode#84

Open
poopoothegorilla wants to merge 3 commits intomainfrom
round-robin
Open

Add RandomRPC node selection mode#84
poopoothegorilla wants to merge 3 commits intomainfrom
round-robin

Conversation

@poopoothegorilla
Copy link
Collaborator

Summary

  • Adds a new RandomRPC node selection mode that picks a random healthy RPC on every SelectRPC call, bypassing the sticky activeNode cache
  • Preserves application-layer subscriptions during RPC rotation by not calling UnsubscribeAllExceptAliveLoop when switching nodes
  • Disables lease-based rotation for this mode (same as existing RoundRobin)

Motivation

All existing selection modes are sticky — selectNode() returns the cached active node as long as it's alive. This new mode distributes RPC calls across healthy nodes without tearing down subscriptions on rotation.

Ref: PLEX-2537

Changes

  • node_selector.go: New NodeSelectionModeRandomRPC constant + factory registration
  • node_selector_random_rpc.go: Selector using math/rand/v2 to pick a random alive node
  • multi_node.go: selectRandomRPCNode() path that skips activeNode caching and subscription teardown; lease check disabled for RandomRPC
  • Tests for selector behavior and MultiNode integration (non-sticky, no-unsub, lease-disable, error cases)

@github-actions
Copy link

👋 poopoothegorilla, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

// selectRandomRPCNode picks a random healthy node on every call without caching
// or terminating existing subscriptions on other nodes.
func (c *MultiNode[CHAIN_ID, RPC]) selectRandomRPCNode(ctx context.Context) (Node[CHAIN_ID, RPC], error) {
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

code duplication with lines 220-239

func (s *randomRPCSelector[CHAIN_ID, RPC]) Select() Node[CHAIN_ID, RPC] {
var liveNodes []Node[CHAIN_ID, RPC]
for _, n := range s.nodes {
if n.State() == nodeStateAlive {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the node is not alive, we should terminate all subscriptions exceptthe alive loop UnsubscribeAllExceptAliveLoop()

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

Comments