Skip to content

feat: RPC redundancy #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 24, 2025
Merged

feat: RPC redundancy #157

merged 8 commits into from
Apr 24, 2025

Conversation

merolish
Copy link
Contributor

Change rpc_url to rpc_urls and for all calls, cycle through them until first success.

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

I recommend we create a utils crate and have a solana_multiurl_rpc module or something in, and wrap the RpcClient there. Also, you need to update wss_url as well and handle it in subscription.

I'll look again once you've addressed those.

# rate-limited, so a private endpoint should be used in most cases.
rpc_url = "https://api2.pythnet.pyth.network"
# API calls will cycle through each on failure.
rpc_urls = ["https://api2.pythnet.pyth.network"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This breaks backward compatibility, let's bump the version as a major one. (we can ship it with lazer in one go)

#[serde(default = "default_rpc_url")]
pub rpc_url: String,
pub rpc_urls: Vec<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we take our chance here to convert it to Vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the websocket list below, or something else?

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh sorry my bad, i wanted to say to convert it to Vec of Url :D (because we pass string everywhere and it's not great)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. It looks like the solana rpc client can directly take in Urls as of version 2, so I'll make that change in the wrapper struct when I'm able to bump the solana crates.

Comment on lines 162 to 164
let current_slot_future =
self.rpc_clients[0].get_slot_with_commitment(CommitmentConfig::confirmed());
let latest_blockhash_future = self.rpc_clients[0].get_latest_blockhash();
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's important for this to work properly as the data from these two are used in the transactions. Please loop through urls

@merolish merolish marked this pull request as ready for review April 24, 2025 07:37
@@ -83,6 +84,12 @@ where
tracing::warn!(?sleep_time, "Subscriber restarting too quickly. Sleeping");
tokio::time::sleep(sleep_time).await;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe also add a log to say which one failed?

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

Very nice!

@merolish merolish merged commit af91c2f into main Apr 24, 2025
2 checks passed
@merolish merolish deleted the mike/rpc-redundancy branch April 24, 2025 17:26
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