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

feat: limit the number of messages in prepare proposal #3942

Merged
merged 26 commits into from
Oct 15, 2024

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Oct 4, 2024

This PR limits the number of transactions in prepare proposal.

@rach-id rach-id self-assigned this Oct 4, 2024
@rach-id rach-id requested a review from a team as a code owner October 4, 2024 15:33
@rach-id rach-id requested review from cmwaters and ninabarbakadze and removed request for a team October 4, 2024 15:33
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the testing framework and transaction filtering logic within the application. New test functions are introduced to validate transaction limits for different transaction types, while existing functions are modified to enforce caps on specific transactions. Additionally, new constants are added to define these limits, improving the overall configuration of transaction handling.

Changes

File Path Change Summary
app/test/prepare_proposal_test.go Added new test functions TestPrepareProposalCappingNumberOfTransactions and TestPrepareProposalCappingNumberOfMessages for transaction limit tests.
app/validate_txs.go Updated filterStdTxs and filterBlobTxs functions to enforce transaction limits and added countOccurrence helper function.
pkg/appconsts/global_consts.go Added constants NonPFBTransactionCap and PFBTransactionCap for transaction limits.
pkg/appconsts/v3/app_consts.go Introduced constants MsgSendTransactionCap (3200), SdkMsgTransactionCap (200), and PFBTransactionCap (600) for transaction limits.
Makefile Modified test-race target to include a timeout parameter for test execution.

Possibly related PRs

  • feat!: limit the max tx size to 2 MiB #3909: This PR introduces new test cases in app/test/prepare_proposal_test.go that validate the behavior of the PrepareProposal function when handling oversized transactions, which directly relates to the enhancements made in the main PR regarding transaction capping.
  • refactor: cap tx size flups #3967: This PR modifies app/test/prepare_proposal_test.go to update comments and variable names reflecting the shift from "MaxTxBytes" to "MaxTxSize," aligning with the changes in the main PR that also focus on capping transaction sizes.

Suggested labels

testing, WS: Big Blonks 🔭, optimization, WS: Maintenance 🔧

Suggested reviewers

  • evan-forbes
  • ninabarbakadze
  • rootulp
  • cmwaters

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

@celestia-bot celestia-bot requested a review from a team October 4, 2024 15:33
@rach-id rach-id marked this pull request as draft October 4, 2024 15:33
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

LGTM, waiting on others opinions before we merge

left a question about the ability to get past this check by changing the protobuf code that I'm unsure on

app/validate_txs.go Outdated Show resolved Hide resolved
app/validate_txs.go Outdated Show resolved Hide resolved
app/validate_txs.go Outdated Show resolved Hide resolved
test/util/test_app.go Show resolved Hide resolved
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: 5

🧹 Outside diff range and nitpick comments (1)
pkg/appconsts/v3/app_consts.go (1)

9-13: Consider documenting the overall impact of transaction caps and their future adjustments.

The introduction of MsgSendTransactionCap and PFBTransactionCap is a significant change that could impact the system's behavior and performance. To ensure clarity and maintainability, please consider:

  1. Documenting the combined effect of these caps on the overall block size and transaction throughput.
  2. Explaining the rationale behind having separate caps for different transaction types.
  3. Outlining any plans for future adjustments to these caps based on network performance or other factors.
  4. Adding a comment referencing the benchmarks or analysis used to determine these values, as mentioned in the previous review.

This documentation will be crucial for understanding the system's constraints and for future optimizations.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c7f26d6 and 02b2241.

📒 Files selected for processing (4)
  • app/test/prepare_proposal_test.go (2 hunks)
  • app/validate_txs.go (5 hunks)
  • pkg/appconsts/v3/app_consts.go (1 hunks)
  • test/util/test_app.go (4 hunks)
🧰 Additional context used
🔇 Additional comments (8)
pkg/appconsts/v3/app_consts.go (2)

12-13: Please provide more context for the PFBTransactionCap value and clarify the term "PFB".

The introduction of this constant is beneficial for limiting PFB messages per block. However, could you please address the following points:

  1. What does "PFB" stand for in this context?
  2. How was the value of 2700 determined?
  3. What are the implications of this limit on the system's performance and behavior?
  4. Is this limit subject to change based on network conditions or future optimizations?

Adding comments in the code to explain these points and the meaning of "PFB" would greatly improve maintainability and understanding for future developers.

To ensure this constant is used correctly throughout the codebase, let's run a quick check:

#!/bin/bash
# Search for usages of PFBTransactionCap
rg --type go "PFBTransactionCap"

9-10: Please provide more context for the MsgSendTransactionCap value.

The introduction of this constant is a good step towards limiting the number of transactions per block. However, could you please provide more information on:

  1. How was the value of 3200 determined?
  2. What are the implications of this limit on the system's performance and behavior?
  3. Is this limit subject to change based on network conditions or future optimizations?

Adding comments in the code to explain these points would greatly improve maintainability and understanding for future developers.

To ensure this constant is used correctly throughout the codebase, let's run a quick check:

app/test/prepare_proposal_test.go (1)

231-231: ⚠️ Potential issue

Verify the block's MaxBytes setting

Line 231 sets consensusParams.Block.MaxBytes = 128, which seems unusually low given that the test involves a large number of transactions. This small block size may prevent any transactions from being included in the block during testing, potentially causing the test to not function as intended. Please verify if this value is intentional or if it should be increased to accommodate the test transactions.

test/util/test_app.go (5)

67-69: Code refactored for better modularity

The initialiseTestApp function is now used to initialize the test app, promoting code reuse and improving modularity.


71-75: Added function for setting up test app with custom max square size

The new SetupTestAppWithGenesisValSetAndMaxSquareSize function allows specifying a custom maxSquareSize, enhancing the flexibility of the test setup.


Line range hint 77-85: New initialiseTestApp function improves code organization

The initialiseTestApp function encapsulates the app initialization logic, improving code readability and maintainability.


190-192: Updated function to use InitialiseTestAppWithGenesis

The NewTestAppWithGenesisSet function now uses InitialiseTestAppWithGenesis to initialize the app with the genesis state, ensuring consistency across test setups.


Line range hint 209-240: New InitialiseTestAppWithGenesis function centralizes initialization logic

The InitialiseTestAppWithGenesis function centralizes the app initialization with a given genesis state, enhancing code maintainability and reducing duplication.

app/validate_txs.go Show resolved Hide resolved
app/validate_txs.go Outdated Show resolved Hide resolved
app/validate_txs.go Outdated Show resolved Hide resolved
app/test/prepare_proposal_test.go Outdated Show resolved Hide resolved
test/util/test_app.go Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team October 10, 2024 09:21
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)
app/validate_txs.go (2)

4-5: Consider using a more descriptive alias instead of types2

The alias types2 for the imported package github.com/celestiaorg/celestia-app/v3/x/blob/types is not very descriptive and could lead to confusion. Consider renaming it to blobtypes or blobTypes to enhance readability and clarity.


131-136: Rename variable types to avoid confusion with imported packages

Using types as a variable name may cause confusion due to the imported packages named types. Consider renaming the variable to messageTypes or msgTypeList for better clarity and to prevent potential conflicts.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 02b2241 and 54583ae.

📒 Files selected for processing (1)
  • app/validate_txs.go (5 hunks)
🧰 Additional context used

app/validate_txs.go Outdated Show resolved Hide resolved
app/validate_txs.go Outdated Show resolved Hide resolved
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)
pkg/appconsts/v3/app_consts.go (1)

9-13: Consider adding documentation for the chosen values.

While the constants and their purposes are clear, it would be beneficial to add documentation explaining the rationale behind the chosen values (200 for SDK messages and 600 for PFB messages). This will help future maintainers understand the reasoning and implications of these limits.

app/test/prepare_proposal_test.go (1)

250-250: Define magic number 2000 as a constant

Consider defining the value 2000 used for the size of randomBytes as a constant with a meaningful name to improve code readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 54583ae and ba7ae0e.

📒 Files selected for processing (3)
  • app/test/prepare_proposal_test.go (2 hunks)
  • app/validate_txs.go (4 hunks)
  • pkg/appconsts/v3/app_consts.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/validate_txs.go
🧰 Additional context used
🔇 Additional comments (4)
pkg/appconsts/v3/app_consts.go (2)

9-13: LGTM! New constants added for transaction limits.

The addition of SdkMsgTransactionCap and PFBTransactionCap constants aligns with the PR objective of limiting the number of transactions in the prepare proposal phase. The comments for both constants are clear and descriptive.


9-13: Verify the usage of new constants in the codebase.

To ensure these new constants are properly integrated, we should verify their usage throughout the codebase.

Run the following script to check for usage of the new constants:

✅ Verification successful

Usage of new constants verified successfully. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of new constants in the codebase

# Test: Search for SdkMsgTransactionCap usage
echo "Searching for SdkMsgTransactionCap usage:"
rg --type go "SdkMsgTransactionCap"

echo "\nSearching for PFBTransactionCap usage:"
rg --type go "PFBTransactionCap"

Length of output: 1802

app/test/prepare_proposal_test.go (2)

231-231: Verify the appropriateness of Block.MaxBytes value

Setting consensusParams.Block.MaxBytes = 128 may be too low to accommodate the transactions being generated. Please verify if this value is intentional and sufficient for the test scenarios.


217-335: Test function adds valuable coverage

The new TestPrepareProposalCappingNumberOfTransactions function effectively tests the capping logic for transactions. The test cases cover various scenarios, ensuring the caps are correctly enforced for both PFB and MsgSend transactions.

evan-forbes
evan-forbes previously approved these changes Oct 11, 2024
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

LGTM, nice, thanks for pushing this through

…osal

# Conflicts:
#	app/test/prepare_proposal_test.go
#	app/validate_txs.go
#	pkg/appconsts/v3/app_consts.go
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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5a59b88 and 0fdc0ab.

📒 Files selected for processing (2)
  • app/test/prepare_proposal_test.go (2 hunks)
  • app/validate_txs.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/validate_txs.go
🧰 Additional context used
🔇 Additional comments (4)
app/test/prepare_proposal_test.go (4)

4-15: New imports look good

The added imports are necessary for the new test function and there are no unused imports.


297-310: PFB transaction generation looks good

The PFB transaction generation logic is well-implemented:

  • It creates transactions exceeding the cap, which is necessary for testing the capping behavior.
  • Random bytes are used for blob content, which is appropriate for this test.
  • Using a new account for each transaction avoids sequence number complications.

This approach ensures a robust test of the transaction capping mechanism.


312-324: MsgSend transaction generation is well-implemented

The MsgSend transaction generation logic is solid:

  • It creates transactions exceeding the cap, which is necessary for testing the capping behavior.
  • Random addresses are used as recipients, adding variability to the test.
  • Using a new account for each transaction avoids sequence number complications, consistent with the PFB generation approach.

This implementation provides a good basis for testing the transaction capping mechanism.


270-384: Excellent addition of comprehensive test cases

The new TestPrepareProposalCappingNumberOfMessages function significantly enhances the test coverage for transaction capping behavior. It includes a variety of scenarios and thoroughly tests the implementation. The setup is comprehensive, and the test cases are well-structured.

While there are some minor suggestions for improvement, the overall quality of this addition is high. Great work on expanding the test suite!

app/test/prepare_proposal_test.go Outdated Show resolved Hide resolved
app/test/prepare_proposal_test.go Show resolved Hide resolved
rootulp
rootulp previously approved these changes Oct 14, 2024
ninabarbakadze
ninabarbakadze previously approved these changes Oct 14, 2024
Copy link
Member

@ninabarbakadze ninabarbakadze left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

pkg/appconsts/global_consts.go Show resolved Hide resolved
app/test/prepare_proposal_test.go Show resolved Hide resolved
test/util/test_app.go Show resolved Hide resolved
@celestia-bot celestia-bot requested review from a team and evan-forbes and removed request for a team October 14, 2024 17:18
@rach-id rach-id dismissed stale reviews from ninabarbakadze and rootulp via ba58bb8 October 14, 2024 18:38
@celestia-bot celestia-bot requested a review from a team October 14, 2024 18:39
@rach-id
Copy link
Member Author

rach-id commented Oct 14, 2024

One extra test case for transactions with multiple messages

c5071a3

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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0fdc0ab and ca7e282.

📒 Files selected for processing (1)
  • app/test/prepare_proposal_test.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: lint / golangci-lint
app/test/prepare_proposal_test.go

[failure] 323-323:
ineffectual assignment to err (ineffassign)

🔇 Additional comments (2)
app/test/prepare_proposal_test.go (2)

4-17: LGTM: New imports are appropriate for the added functionality.

The new imports are necessary and relevant for the new test function TestPrepareProposalCappingNumberOfMessages. They provide access to required types and functions from the Celestia and Cosmos SDKs, as well as the crypto/rand package for generating random data.


273-298: 🛠️ Refactor suggestion

Consider parameterizing the number of accounts for faster test runs.

The test creates 8000 accounts, which might lead to long test execution times. Consider parameterizing this value and using a smaller number for quicker test runs, while still allowing for thorough testing with a larger number when needed.

-numberOfAccounts := 8000
+numberOfAccounts := 1000 // Adjust this value as needed for different test scenarios

This change would allow for faster test runs during development while still enabling thorough testing with a larger number of accounts when necessary.

Likely invalid or redundant comment.

app/test/prepare_proposal_test.go Show resolved Hide resolved
app/test/prepare_proposal_test.go Show resolved Hide resolved
app/test/prepare_proposal_test.go Outdated Show resolved Hide resolved
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

I'm good with merging this now and handling some testApp tech debt later this week

if we do, let's just create issue for

  • being able to query info and submit txs using the application alone and no rpc
  • use the standard genesis code when building out testapp state

@rach-id
Copy link
Member Author

rach-id commented Oct 14, 2024

#3972

@evan-forbes evan-forbes enabled auto-merge (squash) October 15, 2024 01:12
@evan-forbes evan-forbes merged commit a742bd3 into main Oct 15, 2024
33 checks passed
@evan-forbes evan-forbes deleted the limit-number-of-transactions-in-prepare-proposal branch October 15, 2024 01:17
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.

5 participants