Skip to content

Conversation

@taco-paco
Copy link
Contributor

@taco-paco taco-paco commented Oct 17, 2025

⚠️ NOTE: Use notes like this to emphasize something important about the PR.

This could include other PRs this PR is built on top of; API breaking changes; reasons for why the PR is on hold; or anything else you would like to draw attention to.

Status Type ⚠️ Core Change Issue
Ready - No Link

Problem

What problem are you trying to solve?
Some of the tests in validator rely on logs by dlp. Those logs not longer present in fast branch

Solution

How did you solve the problem?
Adding logs back under unit_test_config feature

Before & After Screenshots

Insert screenshots of example code output

BEFORE:
[insert screenshot here]

AFTER:
[insert screenshot here]

Other changes (e.g. bug fixes, small refactors)

Deploy Notes

Notes regarding deployment of the contained body of work. These should note any
new dependencies, new scripts, etc.

New scripts:

  • script : script details

New dependencies:

  • dependency : dependency details

Summary by CodeRabbit

  • Chores
    • Added test configuration logging for debugging specific instruction types under test environments.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 17, 2025

Walkthrough

Adds a feature-gated conditional logging block in fast_process_instruction that logs the discriminator when it matches specific DlpDiscriminator variants (Delegate, CommitState, CommitStateFromBuffer, Finalize, Undelegate). No control flow changes; logging is guarded by #[cfg(feature = "unit_test_config")].

Changes

Cohort / File(s) Summary
Conditional logging for unit tests
src/lib.rs
Adds feature-gated logging block in fast_process_instruction to log discriminator values when they match specific DlpDiscriminator variants; guarded by unit_test_config feature flag

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix: return logs for validator tests" directly and clearly summarizes the main change in the changeset. The raw summary confirms that the change adds conditional logging under the unit_test_config feature to return logs that validator tests depend on, which were previously missing from the fast branch. The title is concise, uses standard commit message conventions (fix: prefix), and accurately represents the primary purpose of the changes without vagueness or misleading information.
Description Check ✅ Passed The pull request description is mostly complete and addresses the required sections. The Problem section clearly identifies the issue: validator tests depend on logs from dlp that are no longer present in the fast branch. The Solution section adequately describes the approach: adding logs back under the unit_test_config feature. While some non-critical sections like Before & After Screenshots and Deploy Notes show only placeholder text, the core sections that explain the purpose and implementation of the change are properly filled out, meeting the threshold for a mostly complete description.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/return-logs-for-tests-pr

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acea6d4 and 75fde9a.

📒 Files selected for processing (1)
  • src/lib.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: install
🔇 Additional comments (1)
src/lib.rs (1)

64-74: Code implementation verified—feature flag is properly configured for validator tests.

The unit_test_config feature is:

  • Defined in Cargo.toml under [features]
  • Enabled in tests/integration/Cargo.toml as a dev-dependency feature: magicblock-delegation-program = { path = ".", features = ["unit_test_config"] }

The feature-gated logging at lines 64-74 in src/lib.rs is correctly implemented and will be active during validator test runs.


Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +64 to +74
#[cfg(feature = "unit_test_config")]
if matches!(
discriminator,
DlpDiscriminator::Delegate
| DlpDiscriminator::CommitState
| DlpDiscriminator::CommitStateFromBuffer
| DlpDiscriminator::Finalize
| DlpDiscriminator::Undelegate
) {
msg!("Processing instruction: {:?}", discriminator);
}
Copy link
Contributor

@snawaz snawaz Oct 18, 2025

Choose a reason for hiding this comment

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

Can we please simplify this by removing the whole if matches!() logic and just writing:

#[cfg(feature = "unit_test_config")]
msg!("Processing instruction: {:?}", discriminator);

And also remove the msg! line from slow_process_instruction(), so it isn’t logged twice.

However, this change will cause 4 tests to fail in this repo, since they ensure that the CU stays within specific limits ... but this innocent-looking change increases the CU by 413 units. 😄

So.. maybe we can introduce a separate feature flag.. like:

#[cfg(feature = "log-discriminator")]
msg!("Processing instruction: {:?}", discriminator);

// Or `log-testinfo` if more kinds of info are required by the tests. 

… and enable it only when we actually need discriminator logs. 🤔

Copy link
Contributor

@snawaz snawaz Oct 18, 2025

Choose a reason for hiding this comment

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

If we need this in production code, maybe we can write a more optimized log utility just to print a preformatted-discriminator and pay 114 CU instead of 413 CU.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but this innocent-looking change increases the CU by 413 units. 😄

This shall be only in test mode, or do we deploy dlp compiled with unit_test_config ? I would think not. @GabrielePicco

I think if we can it would be better to avoid adding extra feature, unit_test_config already relates to tests and affects cu usage for example in load_program_upgrade_authority. Since its needed in validator tests only i think unit_test_config usage make sense as well, or we can rename it to test_config to avoid confusion

Copy link
Contributor Author

@taco-paco taco-paco Oct 20, 2025

Choose a reason for hiding this comment

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

And also remove the msg! line from slow_process_instruction(), so it isn’t logged twice.

Then we would lose that log in release, while old dlp had it. Not sure if anyone rely on those logs tho @GabrielePicco.
The reason I made it this way:

  1. keep old(current) implementation intact
  2. avoid double logging
  3. enable only for tests

Copy link
Contributor

@snawaz snawaz Oct 20, 2025

Choose a reason for hiding this comment

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

I think if we can it would be better to avoid adding extra feature, unit_test_config already relates to tests and affects cu usage for example in load_program_upgrade_authority

I suggested introducing a new flag, because otherwise the tests in this repo will continue to fail as they also ensure CUs stays within specific limits. Please check why the CI is failing!

Please see my previous comment again for the details.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, now it's up to you and @GabrielePicco to decide. I guess I have shared my thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no confusion. My point isn’t about optimization level, but about configuration scope and intent. unit_test_config already represents a test-only build variant that enables additional logic specifically for validator and unit tests.

Now, measuring CU on a test build is an invalid measurement by definition. If we want to do things properly, the CU measurement should happen on the production version, which isn’t compiled with unit_test_config. Introducing another flag just to make these measurements work doesn’t fix the underlying issue — it only adds another layer of conditional code that diverges from what’s actually deployed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn’t confuse testing and CU or performance measurements. These serve different purposes.
We should fix an underlying issue - our measurments happen on a test build

Copy link
Contributor

@snawaz snawaz Oct 21, 2025

Choose a reason for hiding this comment

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

We shouldn’t confuse testing and CU or performance measurements.

performance measurements are part of the testing as well.

The testing is not about correctness only, it is also about how quickly something works, which is why I have added this:

    const consumedLog = tx.meta.logMessages.find((m) =>
      m.includes("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh consumed")
    );
    const consumedCU = parseInt(consumedLog.split(" **").at(3));
    
    assert.isAtMost(
      consumedCU,
      18500,
      "delegate instruction must consume less than 18500"
    );

You don't call it a test?

To get better and more accurate CU, we can build it in "released" mode with unit_test_config (that is also why this flag should have minimal code under it). If not that, some other flag — either way we introduce a flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to make a big deal out of such a small detail.
We don’t need logs in production. We can feature-flag all logs with a “logging” feature to have more granular control. This would work for both the validator and CU tests.

I agree that the CU tests aren’t fully accurate; we can switch to something like Mollusk benchmarking
in the future, but it’s good enough for now.

Comment on lines +64 to +74
#[cfg(feature = "unit_test_config")]
if matches!(
discriminator,
DlpDiscriminator::Delegate
| DlpDiscriminator::CommitState
| DlpDiscriminator::CommitStateFromBuffer
| DlpDiscriminator::Finalize
| DlpDiscriminator::Undelegate
) {
msg!("Processing instruction: {:?}", discriminator);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to make a big deal out of such a small detail.
We don’t need logs in production. We can feature-flag all logs with a “logging” feature to have more granular control. This would work for both the validator and CU tests.

I agree that the CU tests aren’t fully accurate; we can switch to something like Mollusk benchmarking
in the future, but it’s good enough for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants