Skip to content

Conversation

NumberFour8
Copy link
Contributor

@NumberFour8 NumberFour8 commented Nov 5, 2024

Fixes the following tests

  • test_redeem_must_not_work_for_tickets_of_previous_epoch_being_aggregated_and_being_redeemed

  • test_redeem_must_not_work_for_tickets_of_next_epoch_being_redeemed

  • test_indexer_should_pass_blocks_that_are_finalized

Closes #6597

- test_redeem_must_not_work_for_tickets_of_previous_epoch_being_aggregated_and_being_redeemed

- test_redeem_must_not_work_for_tickets_of_next_epoch_being_redeemed

Closes #6597
@NumberFour8 NumberFour8 added this to the 2.2.0-rc.1 milestone Nov 5, 2024
@NumberFour8 NumberFour8 requested a review from a team November 5, 2024 20:47
@NumberFour8 NumberFour8 self-assigned this Nov 5, 2024
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

📝 Walkthrough

Walkthrough

The pull request introduces updates to the Cargo.toml file for the chain-actions package, adding dependencies to the features section and removing a development dependency. Additionally, modifications to the TicketRedeemActions trait and its implementation in redeem.rs enhance the ticket redemption process by refining epoch handling, state checks, and error handling. These changes ensure stricter eligibility criteria for redeeming tickets and update related tests to reflect the new logic.

Changes

File Path Change Summary
chain/actions/Cargo.toml - Added hopr-chain-rpc to runtime-async-std, runtime-tokio, and prometheus features.
- Removed tracing-test from dev-dependencies.
chain/actions/src/redeem.rs - Modified redeem_ticket and redeem_tickets_in_channel methods to enforce stricter epoch and state checks for ticket redemption.
- Enhanced error handling and updated tests accordingly.
chain/indexer/src/block.rs - Removed Clone trait requirement from type parameter U in Indexer struct.
- Wrapped db_processor in Arc for shared ownership.

Assessment against linked issues

Objective Addressed Explanation
Ensure unit tests pass on Rust nightly (#6597)

Possibly related PRs

Suggested labels

status:in-review

Suggested reviewers

  • Teebor-Choka
  • tolbrino

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bb07bff and fb1b2d8.

📒 Files selected for processing (1)
  • chain/indexer/src/block.rs (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • chain/indexer/src/block.rs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NumberFour8 NumberFour8 marked this pull request as ready for review November 5, 2024 20:47
@github-actions github-actions bot added dependencies Pull requests that update a dependency file crate:chain-actions labels Nov 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
chain/actions/src/redeem.rs (2)

597-611: Improve variable naming consistency.

The variable ticket_from_previous_epoch_count is used to track tickets from epoch 3, but the test setup comments refer to "Epoch 4" and "Epoch 3". Consider renaming variables to match the epochs they represent for better clarity.

-let ticket_from_previous_epoch_count = 2;
+let tickets_from_epoch_3_count = 2;

674-674: Fix incorrect comment.

The comment states "Insert another 2 tickets in Epoch 3" but the code actually inserts tickets for Epoch 5.

-// Insert another 2 tickets in Epoch 3
+// Insert another 2 tickets in Epoch 5
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c40f1f0 and 73de52a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • chain/actions/Cargo.toml (1 hunks)
  • chain/actions/src/redeem.rs (2 hunks)
🔇 Additional comments (3)
chain/actions/Cargo.toml (2)

19-19: LGTM: Feature dependencies are well-structured.

The addition of hopr-chain-rpc runtime features maintains consistency with existing runtime dependencies and supports the enhanced ticket redemption logic.

Also applies to: 24-24


Line range hint 1-70: Verify impact of removing tracing-test dependency.

The AI summary indicates that tracing-test was removed from dev-dependencies. Since this PR focuses on fixing tests for nightly builds, we should verify this won't impact test debugging capabilities.

✅ Verification successful

Let me analyze the test files to check for tracing usage in the HOPR codebase specifically.


Let me check the actual tracing usage in the test files and the alternative tracing mechanisms in place.


Let me check how tracing is used in the chain-actions crate files to understand the impact.


Based on the analysis of the codebase, I can now provide the final response:

Removing tracing-test dependency has no impact on test debugging capabilities

The codebase uses the test-log crate for test logging (as seen in session_integration_tests.rs) and the standard tracing crate for instrumentation. The removed tracing-test dependency was not actively used. The codebase has comprehensive tracing through:

  • Standard tracing macros (debug, error, info, warn) used throughout the code
  • Instrumented functions with #[tracing::instrument] for detailed logging
  • Test-specific logging via #[test_log::test] attribute
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if tracing-test is used in any test files
# and if there are alternative tracing mechanisms in place

# Search for tracing-test usage in test files
echo "Checking for tracing-test usage in tests:"
rg -l "use.*tracing_test" $(fd -t f -e rs test)

# Check for alternative tracing mechanisms
echo -e "\nChecking for alternative tracing setups:"
rg -l "use.*tracing" $(fd -t f -e rs test)

Length of output: 79946


Script:

#!/bin/bash
# Check for tracing usage in HOPR test files
echo "Checking tracing usage in HOPR tests:"
rg -A 5 "use.*tracing|tracing::" hopr/hopr-lib/tests/chain_integration_tests.rs hopr/hopr-lib/tests/session_integration_tests.rs hopr-socks/hopr-socks-server/tests/socks_server_tests.rs

# Check if tracing is a dependency in other test-related files
echo -e "\nChecking for tracing in test configuration files:"
rg -l "tracing.*=" $(fd -t f "Cargo.toml")

Length of output: 42041


Script:

#!/bin/bash
# Check for test-log dependency which is commonly used for test tracing
echo "Checking for test-log dependency:"
rg "test-log.*=" chain/actions/Cargo.toml

# Check for test logging setup in the test files
echo -e "\nChecking test logging setup:"
rg -A 5 "#\[test_log|use test_log" hopr/hopr-lib/tests/chain_integration_tests.rs hopr/hopr-lib/tests/session_integration_tests.rs

# Check if tracing is used in other test files in the same crate
echo -e "\nChecking tracing usage in other test files:"
fd -t f -e rs . chain/actions/src chain/actions/tests 2>/dev/null | xargs rg -l "use.*tracing|#\[test_log"

Length of output: 1875


Script:

#!/bin/bash
# Check how tracing is used in the chain-actions crate files
echo "Checking tracing usage in chain-actions files:"
rg -A 2 "use.*tracing|tracing::" chain/actions/src/redeem.rs chain/actions/src/node.rs chain/actions/src/channels.rs chain/actions/src/action_queue.rs chain/actions/src/action_state.rs

# Check for any test-specific tracing setup in the crate
echo -e "\nChecking for test-specific tracing setup:"
rg -l "mod test" chain/actions/src/*.rs | xargs rg -A 5 "use.*tracing|#\[test]"

Length of output: 7533

chain/actions/src/redeem.rs (1)

Line range hint 596-720: LGTM! Test improvements enhance clarity and coverage.

The changes successfully improve the test suite by:

  • Making tests more focused on specific epoch validation scenarios
  • Reducing unnecessary complexity while maintaining coverage
  • Properly testing both previous and next epoch validation

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
chain/actions/src/redeem.rs (3)

597-599: Consider defining constants for epoch numbers and counts

Using named constants for values like 2, 3, and 4u32 can enhance readability and maintainability.


605-607: Avoid reusing the variable name ticket

Reusing the ticket variable can cause confusion. Consider renaming variables to reflect their unique purposes.

Also applies to: 609-611


675-681: Consider defining constants for epoch numbers and counts

As with earlier code, using named constants for 5, 0, and 1 improves code clarity and makes future adjustments easier.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c40f1f0 and 73de52a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • chain/actions/Cargo.toml (1 hunks)
  • chain/actions/src/redeem.rs (2 hunks)
🔇 Additional comments (2)
chain/actions/Cargo.toml (2)

19-19: LGTM: Runtime feature additions are well-structured.

The addition of runtime-specific features from hopr-chain-rpc aligns with the existing pattern of runtime configuration and maintains consistency with other dependencies.

Also applies to: 24-24


Line range hint 1-70: Verify impact of removing tracing-test dependency.

The removal of tracing-test from dev-dependencies could affect test debugging capabilities. Please ensure that all tests still have adequate logging and debugging support.

Consider documenting the preferred approach for test tracing if alternatives are being used.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
chain/actions/src/redeem.rs (2)

604-611: Refactor duplicated ticket insertion code into a helper function.

The code for generating and inserting tickets is duplicated. Extracting this logic into a helper function will improve code maintainability and reduce redundancy.

Consider adding a helper function like this:

async fn insert_tickets(
    db: &HoprDb,
    tickets: &mut Vec<AcknowledgedTicket>,
    counterparty: &ChainKeypair,
    epoch: u32,
    indices: &[u64],
) -> anyhow::Result<()> {
    for &index in indices {
        let ticket = generate_random_ack_ticket(index, counterparty, epoch)?;
        db.upsert_ticket(None, ticket.clone()).await?;
        tickets.insert(0, ticket);
    }
    Ok(())
}

Then replace the duplicated code with:

// Insert another 2 tickets in Epoch 3
insert_tickets(&db, &mut tickets, &BOB, 3, &[0, 1]).await?;

675-681: Refactor duplicated ticket insertion code into a helper function.

Similar to the previous suggestion, the code for generating and inserting tickets is duplicated here as well. Refactor this into a helper function to enhance code reuse and readability.

After adding the helper function, update the code:

// Insert another 2 tickets in Epoch 5
insert_tickets(&db, &mut tickets, &BOB, 5, &[0, 1]).await?;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c40f1f0 and 73de52a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • chain/actions/Cargo.toml (1 hunks)
  • chain/actions/src/redeem.rs (2 hunks)
🔇 Additional comments (3)
chain/actions/Cargo.toml (3)

19-19: LGTM! Runtime feature configuration looks good.

The addition of hopr-chain-rpc with specific runtime features ensures consistent async runtime selection across dependencies, which is crucial for nightly compatibility.

Also applies to: 24-24


Line range hint 27-31: LGTM! Prometheus feature configuration is consistent.

The addition of hopr-chain-rpc/prometheus aligns well with the existing prometheus integrations in other dependencies.


Line range hint 1-100: Verify impact of removing tracing-test dependency.

The AI summary indicates that tracing-test was removed from dev-dependencies. Let's verify if this affects the test fixes mentioned in the PR objectives.

✅ Verification successful

Removal of tracing-test dependency is safe

The git history shows that tracing-test was recently removed from dev-dependencies, and our searches found:

  • No test files currently using tracing-test
  • No remaining references to tracing-test in the codebase
  • The dependency was only added in March 2024 and removed in this PR

Since it was a dev-dependency and there are no usages found, its removal does not impact the codebase or test functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if tracing-test is still used in tests and if there are alternative tracing test utilities

# Test 1: Check for any remaining usage of tracing-test in test files
echo "Checking for tracing-test usage in tests..."
rg -l 'use.*tracing_test' 'chain/actions/src/**/*test*.rs'

# Test 2: Check for alternative tracing test utilities
echo "Checking for alternative tracing test utilities..."
rg -l 'use.*tracing::' 'chain/actions/src/**/*test*.rs'

Length of output: 468


Script:

#!/bin/bash
# Let's first check if test files exist in the correct location
echo "Checking for test files..."
fd -t f ".*test.*\.rs$" chain/actions/src/

# Check for any tracing-test usage in the entire crate
echo "Checking for tracing-test usage in the crate..."
rg -l "tracing.test" chain/actions/

# Check Cargo.toml history for tracing-test
echo "Checking git history for tracing-test..."
git log -p chain/actions/Cargo.toml | grep -A 5 -B 5 "tracing-test"

Length of output: 1669

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
chain/actions/src/redeem.rs (2)

604-605: Improve comment clarity for epoch context

The comment should clarify that these are tickets from a previous epoch, as it's important context for understanding the test's purpose.

-// Insert another 2 tickets in Epoch 3
+// Insert another 2 tickets from previous Epoch (3)

674-675: Improve comment clarity for epoch context

The comment should clarify that these are tickets from a future epoch, as it's important context for understanding the test's purpose.

-// Insert another 2 tickets in Epoch 5
+// Insert another 2 tickets from next Epoch (5)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 73de52a and bb07bff.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • chain/actions/src/redeem.rs (2 hunks)
  • chain/indexer/src/block.rs (3 hunks)
🔇 Additional comments (4)
chain/actions/src/redeem.rs (1)

Line range hint 596-741: LGTM! Test cases properly verify epoch-based ticket redemption

The test cases effectively verify that:

  1. Tickets from previous epochs cannot be redeemed
  2. Tickets from future epochs cannot be redeemed
  3. Only tickets from the current epoch are eligible for redemption

This aligns well with the PR objective of fixing tests to run on Rust nightly.

chain/indexer/src/block.rs (3)

60-60: LGTM! Good improvement in type constraints.

The removal of the Clone trait bound from type parameter U is a positive change that:

  • Simplifies the type constraints
  • Removes unnecessary trait requirements
  • Better aligns with Rust's trait minimization principles

Also applies to: 76-76


117-117: LGTM! Good use of Arc for thread-safe sharing.

Wrapping db_processor in Arc is a good improvement that:

  • Enables safe concurrent access to the processor
  • Provides efficient shared ownership across async tasks
  • Eliminates the need for the Clone trait bound

Line range hint 486-553: Verify test coverage for finalized blocks.

The test test_indexer_should_pass_blocks_that_are_finalized appears to be testing critical functionality. Let's verify that all edge cases are covered.

✅ Verification successful

Let me gather more context about the test implementation and related code.


Let me gather more information about the block finalization logic to better understand the test coverage.


Based on the gathered context, I can now provide a final response about the test coverage for finalized blocks.

Test coverage for block finalization appears adequate

The test test_indexer_should_pass_blocks_that_are_finalized comprehensively verifies the block finalization logic by:

  • Testing block finalization with both finalized and unfinalized blocks
  • Verifying proper handling of block sequences (head block and previous block)
  • Checking event collection for finalized blocks
  • Validating the block processing order

The test covers the core finalization scenarios:

  • Processing of finalized blocks (block_id: head_block - 1)
  • Handling of head blocks that allow finalization
  • Event collection from finalized blocks
  • Block sequence validation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other test cases related to block finalization
# Test: Search for test functions that verify block finalization logic
rg -A 2 "test.*finalized" 

Length of output: 586


Script:

#!/bin/bash
# Get the test implementation and surrounding context
rg -B 5 -A 30 "test_indexer_should_pass_blocks_that_are_finalized"

# Check for other related test functions in the same file
ast-grep --pattern 'async fn test_$_($$$) $$$'

Length of output: 4224


Script:

#!/bin/bash
# Search for block finalization related code
rg -B 3 -A 10 "finalized|finalization" --type rust

# Look for other block-related tests
rg -B 2 -A 5 "async fn test.*block" --type rust

Length of output: 59621

@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
Merged via the queue into master with commit efa963d Nov 7, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:chain-actions crate:chain-indexer dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure that unit tests pass on Rust nightly
3 participants