-
Notifications
You must be signed in to change notification settings - Fork 56
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
base: 2.0-master
Are you sure you want to change the base?
Bridge/watch dog #2481
Conversation
also: update secp256k1 deps close witnet#2418
also: make protocol versioning safer
This method allows to query the stakes of the specified argument. The argument can contain: - A validator and a withdrawer - A validator - A withdrawer - Empty argument, uses the node's address as validator. The type of the argument is an address as a string.
Please enter the commit message for your changes. Lines starting
if let Err(err) = check_wit_connection_status(&wit_jsonrpc_socket).await { | ||
status = err; | ||
} | ||
let wit_client = JsonRpcClient::start(&wit_jsonrpc_socket) |
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.
I'd handle the error with match
instead of using .expect
that could panic.
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())), | |
}; |
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, |
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.
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(); |
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.
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(ð_jsonrpc_url, eth_account).await { | ||
Ok(Some(eth_balance)) => { |
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.
Can this be move inside check_eth_account_balance
?
let (_, drs_pending, drs_finished, _) = | ||
dr_database.send(CountDrsPerState).await.unwrap().unwrap(); | ||
|
||
let mut metrics: String = "{".to_string(); |
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.
I'd move the logic related with the population of metrics
to its own function
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.
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.
d7b2da6
to
26c27e1
Compare
… connection status
26c27e1
to
092ba76
Compare
ebdb81c
to
33a49c4
Compare
52bccd3
to
daa66db
Compare
No description provided.