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 msg send and PFBs in prepare proposal #3942

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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 primarily enhance the testing framework and transaction filtering logic within the application. New test cases are added to validate transaction limits for different types, while modifications to existing functions improve transaction filtering by enforcing caps on specific transaction types. Additionally, new constants are introduced to define these limits, and the setup process for test applications is made more flexible through new initialization functions.

Changes

File Path Change Summary
app/test/prepare_proposal_test.go Added new test function TestPrepareProposalCappingNumberOfTransactions with transaction limit tests.
app/validate_txs.go Updated filterStdTxs and filterBlobTxs functions to enforce transaction limits and added countOccurrence helper function.
pkg/appconsts/v3/app_consts.go Introduced constants MsgSendTransactionCap (3200) and PFBTransactionCap (2700) for transaction limits.
test/util/test_app.go Added functions SetupTestAppWithGenesisValSetAndMaxSquareSize, initialiseTestApp, and updated existing setup functions for better initialization.

Possibly related PRs

Suggested labels

required, WS: V3 3️⃣

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
testApp := NewTestApp()
genesisState, valSet, kr := GenesisStateWithSingleValidator(testApp, genAccounts...)

// hacky way of changing the gov max square size without changing the consts
Copy link
Member Author

Choose a reason for hiding this comment

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

@cmwaters I changed the max square size in here in this hacky way. If you think it's fine, I can make this PR ready for review.

@@ -6,4 +6,9 @@ const (
SubtreeRootThreshold int = 64
TxSizeCostPerByte uint64 = 10
GasPerBlobByte uint32 = 8
// MsgSendTransactionCap maximum number of msg send transactions that a block can contain
MsgSendTransactionCap = 3200
Copy link
Member Author

Choose a reason for hiding this comment

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

will be adding couple comments referencing from where we get the numbers and the actual numbers once this PR is merged and the benchmarks one also is.

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

Comment on lines 100 to 101
msgTypes := msgTypes(sdkTx)
if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types2.MsgPayForBlobs{})); count != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if relying on the strings in the msg alone is bullet proof 🤔. Do you know if a msg can be faked and cause the node to do undue execution in process proposal?

Copy link
Member Author

@rach-id rach-id Oct 7, 2024

Choose a reason for hiding this comment

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

if I understand correctly, the msg is taken after casting the sdk transaction so it should have the right value.

Do you mean we manually cast the transaction to a MsgSend and see? casts are often too expensive, that's why I just used the msg type URL

Comment on lines 50 to 64
msgSendTransactionCount := 0
for _, tx := range txs {
sdkTx, err := dec(tx)
if err != nil {
logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err)
continue
}
msgTypes := msgTypes(sdkTx)
if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types.MsgSend{})); count != 0 {
if msgSendTransactionCount+count > v3consts.MsgSendTransactionCap {
logger.Debug("skipping tx because the msg send transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()))
continue
}
msgSendTransactionCount += count
}
Copy link
Member

Choose a reason for hiding this comment

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

for posterity: iirc we're optimizing for simplicity here, and therefore simply counting the number of messages. in the future, we could use a multidimensional gas price model that would account for the savings of only verifying a single signature for multiple msgs

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 148 to 158
// countOccurrence takes a strings slice and counts the number
// of time the provided item exists in that slice.
func countOccurrence(slice []string, item string) int {
count := 0
for _, v := range slice {
if v == item {
count++
}
}
return count
}
Copy link
Member

Choose a reason for hiding this comment

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

very very optional

we might be able to refactor this and msgTypes into a single function that returns all of the different msg types in a map or smth

Copy link
Member Author

Choose a reason for hiding this comment

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

we will need to sequentially go over the message types in all cases, same complexity. Or you mean we make them part of a single function?

Copy link
Member

Choose a reason for hiding this comment

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

Or you mean we make them part of a single function?

yeah, just this. very optional

Copy link
Member Author

Choose a reason for hiding this comment

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

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 Outdated 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 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 Show resolved Hide resolved
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.

2 participants