-
Notifications
You must be signed in to change notification settings - Fork 195
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
feat(sozo): provider health check #2745
Changes from 3 commits
70f6b8f
e16ab2e
9252ba3
9d757f1
727017d
5bf7646
719de80
d70090a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ pub mod env; | |
pub mod keystore; | ||
|
||
pub mod signal; | ||
pub mod utils; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||
use starknet::core::types::{BlockId, BlockTag}; | ||||||||||||||||||||||||||||||||||||||
use starknet::providers::Provider; | ||||||||||||||||||||||||||||||||||||||
use tracing::trace; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
pub async fn health_check_provider<P: Provider + Sync + std::fmt::Debug + 'static>( | ||||||||||||||||||||||||||||||||||||||
provider: P, | ||||||||||||||||||||||||||||||||||||||
) -> anyhow::Result<(), anyhow::Error> { | ||||||||||||||||||||||||||||||||||||||
match provider.get_block_with_tx_hashes(BlockId::Tag(BlockTag::Latest)).await { | ||||||||||||||||||||||||||||||||||||||
Ok(block) => { | ||||||||||||||||||||||||||||||||||||||
trace!( | ||||||||||||||||||||||||||||||||||||||
latest_block = ?block, | ||||||||||||||||||||||||||||||||||||||
"Provider health check." | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
Ok(()) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Err(_) => { | ||||||||||||||||||||||||||||||||||||||
let error_info = | ||||||||||||||||||||||||||||||||||||||
format!("Unhealthy provider {:?}, please check your configuration.", provider); | ||||||||||||||||||||||||||||||||||||||
Err(anyhow::anyhow!(error_info)) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance error handling with more actionable messages The current error message indicates the provider is unhealthy but could be more helpful to users. Consider providing more specific guidance: Err(_) => {
let error_info =
- format!("Unhealthy provider {:?}, please check your configuration.", provider);
+ format!(
+ "Provider {:?} is not responding. Please ensure:\n\
+ 1. The provider URL is correct in your configuration\n\
+ 2. The provider service is running and accessible\n\
+ 3. Your network connection is stable",
+ provider
+ );
Err(anyhow::anyhow!(error_info))
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider optimizing Arc usage, sensei!
The current implementation wraps and immediately unwraps the provider. Since the health check is the only async operation needing the Arc, we could optimize this.
Consider this more efficient approach:
This approach: