Skip to content
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

Bridge/watch dog #2481

Open
wants to merge 6 commits into
base: 2.0-master
Choose a base branch
from
Open

Bridge/watch dog #2481

wants to merge 6 commits into from

Conversation

guidiaz
Copy link
Contributor

@guidiaz guidiaz commented Aug 19, 2024

No description provided.

@guidiaz guidiaz requested a review from Tommytrg August 19, 2024 12:23
if let Err(err) = check_wit_connection_status(&wit_jsonrpc_socket).await {
status = err;
}
let wit_client = JsonRpcClient::start(&wit_jsonrpc_socket)
Copy link
Member

Choose a reason for hiding this comment

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

I'd handle the error with match instead of using .expect that could panic.

Suggested change
let wit_client = JsonRpcClient::start(&wit_jsonrpc_socket)
let wit_client = match JsonRpcClient::start(&wit_jsonrpc_socket) {
Ok(client) => client,
Err(_) => return (None, None, Some("wit-connection-failure".to_string())),
};

Comment on lines 124 to 165
let wit_account = match fetch_wit_account(&wit_client).await {
Ok(pkh) => pkh,
Err(err) => {
if status.eq("up-and-running") {
status = err;
}
None
}
};

let wit_balance = match wit_account.clone() {
Some(pkh) => match fetch_wit_account_balance(&wit_client, pkh.as_str()).await {
Ok(wit_balance) => wit_balance,
Err(err) => {
if status.eq("up-and-running") {
status = err;
}
None
}
},
None => None,
};

let wit_utxos_above_threshold = match wit_account.clone() {
Some(pkh) => {
match fetch_wit_account_count_utxos_above(
&wit_client,
pkh.as_str(),
wit_utxo_min_value_threshold,
)
.await
{
Ok(wit_utxos_above_threshold) => wit_utxos_above_threshold,
Err(err) => {
if status.eq("up-and-running") {
status = err;
}
None
}
}
}
None => None,
Copy link
Member

Choose a reason for hiding this comment

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

We could move this three calls into a fetch_wit_info function that returns (wit_account, wit_balance, wit_utxos_above_threshold)

let running_secs = self.start_ts.unwrap().elapsed().as_secs();

let fut = async move {
let mut status = "up-and-running".to_string();
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about having all the possible values of status in an enum so they are easier to handle and less prone to error using them? Something like this

enum WatchDogStatus {
    // Add all of them here
    UpAndRunning,
    WitSyncing,
    Other(String),
}

impl WatchDogStatus {
    fn to_string(&self) -> String {
        match self {
            WatchDogStatus::UpAndRunning => "up-and-running".to_string(),
            WatchDogStatus::WitSyncing => "wit-syncing".to_string(),
            WatchDogStatus::Other(message) => message.clone(),
        }
    }
}

};

let eth_balance = match check_eth_account_balance(&eth_jsonrpc_url, eth_account).await {
Ok(Some(eth_balance)) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be move inside check_eth_account_balance?

bridges/centralized-ethereum/src/actors/watch_dog.rs Outdated Show resolved Hide resolved
let (_, drs_pending, drs_finished, _) =
dr_database.send(CountDrsPerState).await.unwrap().unwrap();

let mut metrics: String = "{".to_string();
Copy link
Member

Choose a reason for hiding this comment

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

I'd move the logic related with the population of metrics to its own function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i prefer not to, as tracing logs is the ultimate goal of the watch_global_status function itself. Besides, that function would only be called from single point, and it would require passing all metrics by parameter.

@guidiaz guidiaz changed the base branch from 2.0-master to master August 21, 2024 09:27
@guidiaz guidiaz changed the base branch from master to 2.0-master August 21, 2024 09:52
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