Skip to content

Commit

Permalink
Add some more tracing to LQT code paths (#5083)
Browse files Browse the repository at this point in the history
## Describe your changes

I found these debug traces very useful when messing around with stuff,
and I think the LQT code paths were a bit light on tracing before.

Testing shouldn't be necessary, just adds tracing.

## Checklist before requesting a review

- [x] I have added guiding text to explain how a reviewer should test
these changes.

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > Just adds more logging
  • Loading branch information
cronokirby authored and conorsch committed Feb 14, 2025
1 parent 73efd09 commit 09e0609
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::event;
/// and credited towards the appropriate destination (i.e. positions or new notes).
pub trait Bank: StateWrite + Sized {
/// Move a fraction of our issuance budget towards an address, by minting a note.
#[tracing::instrument(skip(self))]
async fn reward_to_voter(
&mut self,
unbonded_reward: Amount,
Expand All @@ -34,6 +35,7 @@ pub trait Bank: StateWrite + Sized {
tx_hash: TransactionId,
incentivized_asset_id: asset::Id,
) -> anyhow::Result<()> {
tracing::debug!("rewarding voter");
if unbonded_reward == Amount::zero() {
return Ok(());
}
Expand Down Expand Up @@ -73,7 +75,9 @@ pub trait Bank: StateWrite + Sized {
}

/// Move a fraction of our issuance budget towards a position, increasing its reserves.
#[tracing::instrument(skip(self))]
async fn reward_to_position(&mut self, reward: Amount, lp: position::Id) -> anyhow::Result<()> {
tracing::debug!("rewarding position");
if reward == Amount::default() {
return Ok(());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ async fn relevant_votes_for_asset(
///
/// This will only count votes from the top N voters, as per the params,
/// and only include assets which clear the threshold.
#[tracing::instrument(skip(state))]
async fn asset_totals(
state: &impl StateRead,
params: &LiquidityTournamentParameters,
epoch: u64,
) -> anyhow::Result<Vec<(asset::Id, Amount)>> {
let total_votes = state.total_votes(epoch).await;
tracing::debug!(?total_votes);
// 100 should be ample, but also not a huge amount to allocate.
let mut out = Vec::with_capacity(100);
let mut stream = state.ranked_assets(epoch);
while let Some((_, asset)) = stream.try_next().await? {
let votes = relevant_votes_for_asset(state, params, epoch, asset).await?;
tracing::debug!(?asset, ?votes, "found votes");
// The assets are ranked by descending power, so we can stop here.
if create_share(votes, total_votes) < U128x128::from(params.gauge_threshold) {
break;
Expand Down Expand Up @@ -114,6 +117,7 @@ fn position_shares(
.map_ok(move |(_, lp, volume)| (lp, volume, create_share(volume, total_volume)))
}

#[tracing::instrument(skip(state))]
pub async fn distribute_rewards(mut state: impl StateWrite) -> anyhow::Result<()> {
let current_epoch = state.get_current_epoch().await?.index;
let params = state.get_funding_params().await?;
Expand All @@ -129,6 +133,7 @@ pub async fn distribute_rewards(mut state: impl StateWrite) -> anyhow::Result<()
amount: initial_budget,
})
.await?;
tracing::debug!(?initial_budget);
// Now, we keep a running mutable current budget, because we distribute fractions of
// the initial budget, which should not be modified.
let mut current_budget = initial_budget;
Expand Down

0 comments on commit 09e0609

Please sign in to comment.