-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sozo): provider health check (#2745)
* [ISSUES#] 2739 sozo health check. * [ISSUES#] 2739 provider health check for sozo. * [ISSUES#] 2739 provider health check for sozo. * [ISSUES#] 2739 provider health check for sozo fmt. * fix: new utils provider module and minor fixes --------- Co-authored-by: glihm <[email protected]>
- Loading branch information
Showing
8 changed files
with
55 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ pub use tx::*; | |
|
||
pub mod env; | ||
pub mod keystore; | ||
|
||
pub mod provider; | ||
pub mod signal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use starknet::core::types::{BlockId, BlockTag}; | ||
use starknet::providers::Provider; | ||
use tracing::trace; | ||
|
||
/// Check if the provider is healthy. | ||
/// | ||
/// This function will check if the provider is healthy by getting the latest block, | ||
/// and returns an error otherwise. | ||
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)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters