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

refactor: reduce info-level log verbosity for rewards, governance, and pos like chain and transactions. #194

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub async fn query_balance(
) -> anyhow::Result<Balances> {
Ok(futures::stream::iter(balance_changes)
.filter_map(|balance_change| async move {
tracing::info!(
tracing::debug!(
"Fetching balance change for {} ...",
balance_change.address
);
Expand Down
22 changes: 14 additions & 8 deletions governance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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()
);
Expand All @@ -117,7 +117,7 @@ async fn crawling_fn(
)
.await
.map_err(|_| MainError::RpcError)?;
tracing::info!(
tracing::debug!(
"Got {} proposals statuses updates...",
proposals_statuses.len()
);
Expand Down Expand Up @@ -209,11 +209,17 @@ async fn crawling_fn(
.collect::<Vec<PgfPayment>>()
})
.collect::<Vec<_>>();
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| {
Expand Down Expand Up @@ -241,15 +247,15 @@ 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();

Ok(())
}

fn can_process(instant: &MutexGuard<Instant>, sleep_for: u64) -> bool {
tracing::info!("Attempting to process goverance data");

let time_elapsed = instant.elapsed().as_secs();
time_elapsed >= sleep_for
}
Expand Down
12 changes: 8 additions & 4 deletions parameters/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand All @@ -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()
Expand Down Expand Up @@ -136,15 +140,15 @@ 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();

Ok(())
}

fn can_process(instant: &MutexGuard<Instant>, sleep_for: u64) -> bool {
tracing::info!("Attempting to process parameters data");

let time_elapsed = instant.elapsed().as_secs();
time_elapsed >= sleep_for
}
Expand Down
19 changes: 11 additions & 8 deletions pos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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<HttpClient>,
) -> Result<bool, MainError> {
tracing::info!("Attempting to process epoch: {}...", epoch);
let current_epoch = namada_service::get_current_epoch(&client.clone())
.await
.map_err(|e| {
Expand Down
38 changes: 28 additions & 10 deletions rewards/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Vec<_>>();

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| {
Expand All @@ -120,14 +134,18 @@ 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(())
}

async fn can_process(
epoch: u32,
client: Arc<HttpClient>,
) -> Result<bool, MainError> {
tracing::info!("Attempting to process epoch: {}...", epoch);
let current_epoch = namada_service::get_current_epoch(&client.clone())
.await
.map_err(|e| {
Expand Down
8 changes: 4 additions & 4 deletions rewards/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub async fn query_delegation_pairs(

pub async fn query_rewards(
client: &HttpClient,
delegation_pairs: HashSet<DelegationPair>,
delegation_pairs: &HashSet<DelegationPair>,
) -> anyhow::Result<Vec<Reward>> {
Ok(futures::stream::iter(delegation_pairs)
.filter_map(|delegation| async move {
tracing::info!(
tracing::debug!(
"Fetching rewards {} -> {} ...",
delegation.validator_address,
delegation.delegator_address
Expand All @@ -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),
})
})
Expand Down
Loading