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

staking: 🎁 add additional tracing telemetry #4017

Merged
merged 17 commits into from
Mar 13, 2024

Conversation

cratelyn
Copy link
Contributor

@cratelyn cratelyn commented Mar 13, 2024

this is a group of improvements to the telemetry in the staking component, cherry-picked out of #4001. this improves the logs seen in tests, and additionally takes the time to make some other small gardening tweaks: consolidating imports, adding documentation comments, etc. this is another branch in the spirit of #4009.

the changes here are itemized into distinct, small code transformations to facilitate review, and demonstrate that these are noop changes. you can start here.

  • f331964 - feat(staking): ❗ traces for invalid or missing parameters
  • d33598d - docs(staking): 🤝 add a doc comment
  • f6c60a8 - staking: 🙂 remove needless Ok(_)
  • fd4b8da - feat(staking): 💬 log when delegation changes are not found
  • fe597ff - feat(staking): 🔍 trace-level spans for StateReadExt methods
  • 0447600 - refactor(staking): 🚡 use self:: prefix in reexports
  • 67893c9 - refactor(staking): 🙂 remove import from reexports
  • 043222e - refactor(staking): 🎁 consolidate public submodules
  • 6376796 - refactor(staking): 🎁 consolidate submodules
  • b5bd240 - refactor(staking): 👯 component flag reexports StateWriteExt
  • d57beaa - chore(staking): 🥡 consolidate component reexports
  • aa52f6d - chore(staking): 🧹 tidy epoch_handler imports
  • 765ed75 - refactor(compact-block): 🧹 tidy imports
  • 7cb93f7 - feat(staking): 🌐 log why epoch ended
  • 081d041 - refactor(staking): add context to state.end_epoch call
  • 5701295 - feat(app): 🦠 tracing telemetry for App::end_block
  • f7f78b9 - docs(staking): 📕 add doc comment for end_epoch

cratelyn added 17 commits March 13, 2024 13:33
to disambiguate epochs ending due to chain upgrades, or other natural
causes, include these in the info event.
the changes in `crates/core/component/stake/src/lib.rs` are the
important bit here.

`StateReadExt` and `StateWriteExt` are complimentary traits, and thus
often used together. if we are going to reexport `StateReadExt` in the
top-level namespace, we should include both.

changes in other files adjust imports so that we import both from the
same path, instead of `crate::{StateReadExt, component::StateWriteExt}`,
to clarify their semantic relation.
this is where we are reexporting symbols into our public api.

since there is only one `Lazy` here, let's avoid conflating local
imports and public api surface, and refer to `Lazy` by its whole path.
a nit: let's be extra clear that we are reexporting symbols from this
crate.
these are the core interactions with the cnidarium storage that the app
uses to query various staking parameters.
NB: this is different from logging the error that is propagated back
upwards. at this precise point, it where we will still be in the context
of the various spans that brought us to this point:

this allows to see information like:

```
  2024-03-13T16:47:37.801600Z  INFO penumbra_app::app: ending epoch, is_end_epoch: true, is_chain_upgrade: false, current_height: 718
    at crates/core/app/src/app/mod.rs:485
    in penumbra_app::app::end_block with height: 1
    in penumbra_mock_consensus::abci::end_block
    in penumbra_mock_consensus::block::execute with height: 718, time: 1710348457
    in penumbra_mock_consensus::fast_forward with blocks: 1000, height: 0, fast_forward.blocks: 1000
    in mock_consensus_staking::fast forwarding test node to next epoch

  2024-03-13T16:47:37.802068Z ERROR penumbra_stake::component::stake: could not find delegation changes for block
    at crates/core/component/stake/src/component/stake.rs:262
    in penumbra_stake::component::stake::get_delegation_changes with height: block::Height(2)
    in penumbra_stake::component::epoch_handler::end_epoch with index: 0
    in penumbra_stake::component::stake::staking
    in penumbra_app::app::end_block with height: 1
    in penumbra_mock_consensus::abci::end_block
    in penumbra_mock_consensus::block::execute with height: 718, time: 1710348457
    in penumbra_mock_consensus::fast_forward with blocks: 1000, height: 0, fast_forward.blocks: 1000
    in mock_consensus_staking::fast forwarding test node to next epoch
```
the inner expression is a `Result<T, E>`, we don't need to write
`Ok(expr?)`.
@cratelyn cratelyn added A-staking Area: Design and implementation of staking and delegation C-enhancement Category: an enhancement to the codebase A-telemetry Area: Metrics, logging, and other observability-related features A-mock-consensus Area: Relates to the mock consensus engine C-refactor Category: refactors and other related improvements labels Mar 13, 2024
@cratelyn cratelyn added this to the Sprint 2 milestone Mar 13, 2024
@cratelyn cratelyn self-assigned this Mar 13, 2024
@cratelyn cratelyn requested a review from erwanor March 13, 2024 17:53
Copy link
Member

@erwanor erwanor left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -474,7 +477,7 @@ impl App {
.expect("able to detect upgrade heights");

if is_end_epoch || is_chain_upgrade {
tracing::info!(?current_height, "ending epoch");
tracing::info!(%is_end_epoch, %is_chain_upgrade, ?current_height, "ending epoch");
Copy link
Member

Choose a reason for hiding this comment

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

👍

@cratelyn cratelyn marked this pull request as ready for review March 13, 2024 18:08
@cratelyn cratelyn merged commit dd26138 into main Mar 13, 2024
6 checks passed
@cratelyn cratelyn deleted the kate/staking-debugging-assistance-and-tweaks branch March 13, 2024 18:09
cratelyn added a commit that referenced this pull request Mar 18, 2024
fixes #3966. fixes #3908. fixes _part of_ #3995.

this branch introduces the first steps towards mock consensus (#3588)
testing of the staking component (#3845).

this defines a validator after genesis, and then shows that it does
_not_ enter the consensus set. #3966 is addressed in this branch so that
the existing genesis validator correctly enters the consensus set, and
so that we can successfully progress to the second epoch.

subsequent changes will exercise delegating to this validator in the
`mock_consensus_can_define_and_delegate_to_a_validator`.

#### ✨ changes

* alters `with_penumbra_auto_app_state` so that it adds an allocation of
delegation tokens to the shielded pool component's genesis content.

* extends `generate_penumbra_validator` so that it generates a real
spend key, and returns an `Allocation` for the generated validator.
_(see #3966)_

* adds a new `mock_consensus_can_define_and_delegate_to_a_validator`
test that defines a post-genesis validator. _(see #3908)_

* defines a new `ConsensusIndexRead::get_consensus_set()` method, which
collects all of the identity keys returned by `consensus_set_stream`.

* lowers the events in
`penumbra_mock_consensus::block::Builder::execute()` to trace-level
events.

* `penumbra_mock_consensus::builder::Builder` will now log a warning if
values may be errantly rewritten by the builder methods.

* `TestNode::fast_forward` sets its `i` span field to `1..n`, rather
than `0..n-1`.

---

#### :link: related

* #4009
* #4010
* #4011
* #4017
* #4027
* #4028
* #4029
* #3966
* #3908
* #3588

---------

Co-authored-by: Henry de Valence <hdevalence@penumbralabs.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mock-consensus Area: Relates to the mock consensus engine A-staking Area: Design and implementation of staking and delegation A-telemetry Area: Metrics, logging, and other observability-related features C-enhancement Category: an enhancement to the codebase C-refactor Category: refactors and other related improvements
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants