From 8e3128f0a5f1ebce5ddda5ae1010268bb78d4691 Mon Sep 17 00:00:00 2001 From: Joel Nordell Date: Wed, 11 Dec 2024 15:06:07 -0600 Subject: [PATCH 1/2] refactor: reduce info-level log verbosity for rewards, governance, and pos like chain and transactions. --- governance/src/main.rs | 22 +++++++++++++------- parameters/src/main.rs | 12 +++++++---- pos/src/main.rs | 19 ++++++++++------- rewards/src/main.rs | 38 +++++++++++++++++++++++++--------- rewards/src/services/namada.rs | 8 +++---- 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/governance/src/main.rs b/governance/src/main.rs index 3c82bb398..00902ceba 100644 --- a/governance/src/main.rs +++ b/governance/src/main.rs @@ -81,20 +81,20 @@ async fn crawling_fn( let timestamp = Utc::now().naive_utc(); update_crawler_timestamp(&conn, timestamp).await?; - tracing::warn!( + tracing::trace!( "Not enough time has passed since last crawl, skipping..." ); return Err(MainError::NoAction); } - tracing::info!("Starting to update proposals..."); + tracing::debug!("Querying governance proposals..."); let epoch = namada_service::query_last_epoch(&client) .await .into_rpc_error()?; - tracing::info!("Fetched epoch is {} ...", epoch); + tracing::debug!("Fetched epoch is {} ...", epoch); let running_governance_proposals = conn .interact(move |conn| { @@ -105,7 +105,7 @@ async fn crawling_fn( .and_then(identity) .into_db_error()?; - tracing::info!( + tracing::debug!( "Got {} proposals to be tallied...", running_governance_proposals.len() ); @@ -117,7 +117,7 @@ async fn crawling_fn( ) .await .map_err(|_| MainError::RpcError)?; - tracing::info!( + tracing::debug!( "Got {} proposals statuses updates...", proposals_statuses.len() ); @@ -209,11 +209,17 @@ async fn crawling_fn( .collect::>() }) .collect::>(); - tracing::info!("Got {} pgf payments...", pgf_payments.len()); + tracing::debug!("Got {} pgf payments...", pgf_payments.len()); let timestamp = DateTimeUtc::now().0.timestamp(); let crawler_state = IntervalCrawlerState { timestamp }; + tracing::info!( + proposals_statuses = proposals_statuses.len(), + pgf_payments = pgf_payments.len(), + "Queried governance proposals successfully" + ); + conn.interact(move |conn| { conn.build_transaction().read_write().run( |transaction_conn: &mut diesel::prelude::PgConnection| { @@ -241,6 +247,8 @@ async fn crawling_fn( .and_then(identity) .into_db_error()?; + tracing::info!(sleep_for = sleep_for, "Inserted governance into database"); + // Once we are done processing, we reset the instant *instant = Instant::now(); @@ -248,8 +256,6 @@ async fn crawling_fn( } fn can_process(instant: &MutexGuard, sleep_for: u64) -> bool { - tracing::info!("Attempting to process goverance data"); - let time_elapsed = instant.elapsed().as_secs(); time_elapsed >= sleep_for } diff --git a/parameters/src/main.rs b/parameters/src/main.rs index ca197d7e0..324a1dbbc 100644 --- a/parameters/src/main.rs +++ b/parameters/src/main.rs @@ -78,13 +78,15 @@ async fn crawling_fn( let timestamp = Utc::now().naive_utc(); update_crawler_timestamp(&conn, timestamp).await?; - tracing::warn!( - "Not enough time has passed since last crawl, skipping..." + tracing::trace!( + "Not enough time has passed since last crawl, waiting..." ); return Err(MainError::NoAction); } + tracing::debug!("Querying parameters..."); + let parameters = namada_service::get_parameters(&client) .await .into_rpc_error()?; @@ -100,6 +102,8 @@ async fn crawling_fn( let timestamp = DateTimeUtc::now().0.timestamp(); let crawler_state = IntervalCrawlerState { timestamp }; + tracing::info!("Queried parameters successfully",); + conn.interact(move |conn| { conn.build_transaction() .read_write() @@ -136,6 +140,8 @@ async fn crawling_fn( .and_then(identity) .into_db_error()?; + tracing::info!(sleep_for = sleep_for, "Inserted parameters into database"); + // Once we are done processing, we reset the instant *instant = Instant::now(); @@ -143,8 +149,6 @@ async fn crawling_fn( } fn can_process(instant: &MutexGuard, sleep_for: u64) -> bool { - tracing::info!("Attempting to process parameters data"); - let time_elapsed = instant.elapsed().as_secs(); time_elapsed >= sleep_for } diff --git a/pos/src/main.rs b/pos/src/main.rs index 76f7842c1..98e774d28 100644 --- a/pos/src/main.rs +++ b/pos/src/main.rs @@ -59,9 +59,9 @@ async fn crawling_fn( let timestamp = Utc::now().naive_utc(); update_crawler_timestamp(&conn, timestamp).await?; - tracing::warn!( - "Epoch {} was not processed, retry...", - epoch_to_process + tracing::trace!( + epoch = epoch_to_process, + "Epoch does not exist yet, waiting...", ); return Err(MainError::NoAction); @@ -73,9 +73,9 @@ async fn crawling_fn( .into_rpc_error()?; tracing::info!( - "Processing epoch {} with {} validators...", - epoch_to_process, - validators_set.validators.len() + epoch = epoch_to_process, + validators = validators_set.validators.len(), + "Queried validators successfully...", ); let timestamp = DateTimeUtc::now().0.timestamp(); @@ -112,14 +112,17 @@ async fn crawling_fn( .await .context_db_interact_error() .and_then(identity) - .into_db_error() + .into_db_error()?; + + tracing::info!(epoch = epoch_to_process, "Updated validators in database"); + + Ok(()) } async fn can_process( epoch: u32, client: Arc, ) -> Result { - tracing::info!("Attempting to process epoch: {}...", epoch); let current_epoch = namada_service::get_current_epoch(&client.clone()) .await .map_err(|e| { diff --git a/rewards/src/main.rs b/rewards/src/main.rs index a28e09f54..cb161d85d 100644 --- a/rewards/src/main.rs +++ b/rewards/src/main.rs @@ -38,7 +38,7 @@ async fn main() -> Result<(), MainError> { .context_db_interact_error() .into_db_error()?; - tracing::info!("Query epoch..."); + tracing::debug!("Querying epoch..."); let mut epoch; loop { @@ -73,31 +73,45 @@ async fn crawling_fn( let timestamp = Utc::now().naive_utc(); update_crawler_timestamp(&conn, timestamp).await?; - tracing::warn!( - "Epoch {} was not processed, retry...", - epoch_to_process + tracing::trace!( + epoch = epoch_to_process, + "Epoch does not exist yet, waiting...", ); return Err(MainError::NoAction); } - tracing::info!("Starting to update proposals..."); - // TODO: change this by querying all the pairs in the database let delegations_pairs = namada_service::query_delegation_pairs(&client) .await .into_rpc_error()?; - let rewards = namada_service::query_rewards(&client, delegations_pairs) + + tracing::info!( + epoch = epoch_to_process, + delegations = delegations_pairs.len(), + "Querying rewards..." + ); + + let rewards = namada_service::query_rewards(&client, &delegations_pairs) .await .into_rpc_error()?; let non_zero_rewards = rewards - .into_iter() + .iter() .filter(|reward| !reward.amount.is_zero()) - .collect(); + .cloned() + .collect::>(); let timestamp = DateTimeUtc::now().0.timestamp(); let crawler_state = IntervalCrawlerState { timestamp }; + tracing::info!( + epoch = epoch_to_process, + delegations = delegations_pairs.len(), + rewards = rewards.len(), + non_zero_rewards = non_zero_rewards.len(), + "Queried rewards successfully", + ); + conn.interact(move |conn| { conn.build_transaction().read_write().run( |transaction_conn: &mut diesel::prelude::PgConnection| { @@ -120,6 +134,11 @@ async fn crawling_fn( .and_then(identity) .into_db_error()?; + tracing::info!( + epoch = epoch_to_process, + "Inserted rewards into database; waiting for next epoch" + ); + Ok(()) } @@ -127,7 +146,6 @@ async fn can_process( epoch: u32, client: Arc, ) -> Result { - tracing::info!("Attempting to process epoch: {}...", epoch); let current_epoch = namada_service::get_current_epoch(&client.clone()) .await .map_err(|e| { diff --git a/rewards/src/services/namada.rs b/rewards/src/services/namada.rs index af020d3fd..6cece767d 100644 --- a/rewards/src/services/namada.rs +++ b/rewards/src/services/namada.rs @@ -35,11 +35,11 @@ pub async fn query_delegation_pairs( pub async fn query_rewards( client: &HttpClient, - delegation_pairs: HashSet, + delegation_pairs: &HashSet, ) -> anyhow::Result> { Ok(futures::stream::iter(delegation_pairs) .filter_map(|delegation| async move { - tracing::info!( + tracing::debug!( "Fetching rewards {} -> {} ...", delegation.validator_address, delegation.delegator_address @@ -55,14 +55,14 @@ pub async fn query_rewards( .await .ok()?; - tracing::info!( + tracing::debug!( "Done fetching reward for {} -> {}!", delegation.validator_address, delegation.delegator_address ); Some(Reward { - delegation_pair: delegation, + delegation_pair: delegation.clone(), amount: Amount::from(reward), }) }) From b252b3631913d5a141c94ca6e83f82c1f5c0580a Mon Sep 17 00:00:00 2001 From: Joel Nordell Date: Tue, 17 Dec 2024 11:28:39 -0600 Subject: [PATCH 2/2] refactor: reduce "Fetching balance change" message to debug instead of info --- chain/src/services/namada.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/src/services/namada.rs b/chain/src/services/namada.rs index abc6a36d1..9b1b1d7cc 100644 --- a/chain/src/services/namada.rs +++ b/chain/src/services/namada.rs @@ -77,7 +77,7 @@ pub async fn query_balance( ) -> anyhow::Result { Ok(futures::stream::iter(balance_changes) .filter_map(|balance_change| async move { - tracing::info!( + tracing::debug!( "Fetching balance change for {} ...", balance_change.address );