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(staking): 😊 tracing telemetry for delegation changes #4009

Merged
merged 4 commits into from
Mar 12, 2024
Merged
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
34 changes: 20 additions & 14 deletions crates/core/component/stake/src/component/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,20 @@ impl Component for Staking {
.expect("should be able to track uptime");
}

/// Writes the delegation changes for this block.
#[instrument(name = "staking", skip(state, end_block))]
async fn end_block<S: StateWrite + 'static>(
state: &mut Arc<S>,
end_block: &abci::request::EndBlock,
) {
let state = Arc::get_mut(state).expect("state should be unique");
// Write the delegation changes for this block.
state
.set_delegation_changes(
end_block
.height
.try_into()
.expect("should be able to convert i64 into block height"),
state.get_delegation_changes_tally().clone(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was also being cloned needlessly, see 838887d

)
.await;
let height = end_block
.height
.try_into()
.expect("should be able to convert i64 into block height");
let changes = state.get_delegation_changes_tally();

state.set_delegation_changes(height, changes).await;
}

#[instrument(name = "staking", skip(state))]
Expand Down Expand Up @@ -463,11 +461,19 @@ pub trait RateDataWrite: StateWrite {
);
}

#[tracing::instrument(
level = "trace",
skip_all,
fields(
%height,
delegations = ?changes.delegations,
undelegations = ?changes.undelegations,
)
)]
async fn set_delegation_changes(&mut self, height: block::Height, changes: DelegationChanges) {
self.put(
state_key::chain::delegation_changes::by_height(height.value()),
changes,
);
let key = state_key::chain::delegation_changes::by_height(height.value());
tracing::trace!(%key, "setting delegation changes");
self.put(key, changes);
}
}

Expand Down
Loading