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

chore: optimize checkTx #3954

Merged
merged 6 commits into from
Oct 10, 2024
Merged

chore: optimize checkTx #3954

merged 6 commits into from
Oct 10, 2024

Conversation

evan-forbes
Copy link
Member

Overview

this PR makes a simple optimization for checkTx

@evan-forbes evan-forbes requested a review from a team as a code owner October 9, 2024 16:33
@evan-forbes evan-forbes requested review from cmwaters and staheri14 and removed request for a team October 9, 2024 16:33
@evan-forbes evan-forbes self-assigned this Oct 9, 2024
@evan-forbes evan-forbes added the optimization item is improves performance resource usage. label Oct 9, 2024
@celestia-bot celestia-bot requested a review from a team October 9, 2024 16:33
@evan-forbes evan-forbes requested review from adlerjohn, rootulp and ninabarbakadze and removed request for staheri14 October 9, 2024 16:34
d.Txs = append(d.Txs, tooManyShareBtx)
},
appVersion: v3.Version,
expectedResult: abci.ResponseProcessProposal_REJECT,
Copy link
Member Author

Choose a reason for hiding this comment

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

this reject isn't new, but it should still be covered by tests

@@ -45,6 +45,7 @@ func FilterTxs(logger log.Logger, ctx sdk.Context, handler sdk.AnteHandler, txCo
func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs [][]byte) ([][]byte, sdk.Context) {
n := 0
for _, tx := range txs {
ctx = ctx.WithTxBytes(tx)
Copy link
Member Author

Choose a reason for hiding this comment

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

this needs to be added for future things anyway, although it has no impact atm

Comment on lines -155 to +154
txBuilder := txConfig.NewTxBuilder()
require.NoError(t, txBuilder.SetMsgs(tc.pfb))
tx := txBuilder.GetTx()
kr, _ := testnode.NewKeyring(testfactory.TestAccName)
signer, err := user.NewSigner(
kr,
ecfg.TxConfig,
testfactory.ChainID,
tc.appVersion,
user.NewAccount(testfactory.TestAccName, 1, 0),
)
require.NoError(t, err)

blobTx := blobfactory.RandBlobTxs(signer, rand, 1, tc.blobsPerPFB, tc.blobSize)

btx, isBlob, err := blobtx.UnmarshalBlobTx([]byte(blobTx[0]))
require.NoError(t, err)
require.True(t, isBlob)
Copy link
Member Author

Choose a reason for hiding this comment

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

made this a much more meaningful test by using actual signed txs instead of mocking a pfb size

@evan-forbes evan-forbes added WS: Maintenance 🔧 includes bugs, refactors, flakes, and tech debt etc backport:v2.x PR will be backported automatically to the v2.x branch upon merging labels Oct 9, 2024
Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant modifications to transaction context handling within the ProcessProposal method. A new variable ctx is utilized in place of sdkCtx, affecting transaction processing and validation. Additionally, tests are enhanced to cover edge cases, particularly involving blob transactions that exceed share limits. The changes also involve updates to the BlobShareDecorator for accurate share calculations based on transaction size. Overall, the updates maintain existing logic while improving context management and test coverage.

Changes

File Change Summary
app/process_proposal.go Modified ProcessProposal method to use ctx instead of sdkCtx for transaction processing and validation. Added a check for transaction bytes with sdkCtx.WithTxBytes(tx) (commented out). Maintained existing transaction logic.
app/test/prepare_proposal_test.go Enhanced TestPrepareProposalFiltering by adding a test for blob transactions exceeding share limits. Introduced utility function repeat for generating slices.
app/test/process_proposal_test.go Updated TestProcessProposal with a new test case for blob transactions that exceed share limits. Added import for v3 application constants.
x/blob/ante/blob_share_decorator.go Altered BlobShareDecorator's AnteHandle method and getSharesNeeded function to include transaction size in share calculations. Updated method signature for getSharesNeeded.
x/blob/ante/blob_share_decorator_test.go Updated TestBlobShareDecorator to use blobsPerPFB and blobSize for clearer test case definitions. Modified test setup to utilize a new signer and adjusted blob transaction handling. Updated repeat function to be generified.

Possibly related PRs

  • test: consistent appHash between commits #3513: This PR's updates to the process_proposal_test.go file align with the main PR's modifications to the ProcessProposal method, indicating a direct relationship in testing transaction proposals.
  • test: consistent app hash on v2 #3879: The updates in app/test/consistent_apphash_test.go involve testing the consistency of application hashes across different versions, which relates to the transaction processing logic refined in the main PR.
  • refactor!: version gas scheduler variables #3735: The changes in app/ante/ante.go and related files introduce version-aware gas scheduling, which could impact transaction processing and validation, linking it to the context management changes in the main PR.
  • test: v3 e2e upgrade #3910: The end-to-end upgrade tests for version 3 involve transaction processing, which is relevant to the changes made in the main PR regarding transaction context management and validation logic.

Suggested reviewers

  • ninabarbakadze
  • rootulp
  • cmwaters
  • staheri14

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc26143 and c2f050d.

📒 Files selected for processing (1)
  • app/process_proposal.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/process_proposal.go

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.

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 (5)
app/validate_txs.go (1)

Line range hint 1-134: Summary: Optimization through context enrichment

The changes in this file focus on enriching the context with transaction bytes before processing in both filterStdTxs and filterBlobTxs functions. This optimization aligns with the PR objective of improving checkTx performance.

While the modifications are minimal, they could potentially enhance logging, error handling, and overall transaction processing by providing immediate access to raw transaction data within the context.

Consider adding a comment explaining the purpose of these changes to improve code readability and maintainability.

x/blob/ante/blob_share_decorator_test.go (2)

43-132: Comprehensive test cases covering various scenarios and edge cases.

The updated test cases provide excellent coverage for different blob sizes, numbers of blobs, and app versions. The inclusion of edge cases, such as blobs that exactly fill or slightly exceed the square capacity, is particularly valuable for ensuring robust behavior.

The explanatory comments for certain test cases are helpful in understanding the expected behavior.

Consider adding a test case for a blob size that is just below the maximum allowed size to ensure there are no off-by-one errors in the size calculation.


136-164: Improved test setup with realistic transaction generation and processing.

The updated test setup provides a more authentic testing environment by using actual signers and generated blob transactions. The use of blobfactory.RandBlobTxs allows for easy creation of test data with specified characteristics, enhancing the flexibility of the tests.

The process of unmarshalling and decoding the blob transaction ensures that the decorator is tested with the correct input format, closely mimicking real-world usage.

Consider extracting the common setup code (keyring creation, signer setup) into a separate helper function to reduce duplication and improve readability.

app/test/process_proposal_test.go (2)

84-96: LGTM: New helper variable for oversized blob transaction

The new tooManyShareBtx variable is well-implemented and serves its purpose of creating a blob transaction that exceeds the allowed number of shares. It uses existing test utilities and follows the pattern of other test data setup.

Consider parameterizing the number of blobs (currently set to 4000) to make the test more flexible and easier to adjust in the future. For example:

-			testfactory.RandomBlobNamespaces(tmrand.NewRand(), 4000),
-			[][]int{repeat(4000, 1)},
+			testfactory.RandomBlobNamespaces(tmrand.NewRand(), maxBlobsPerTx),
+			[][]int{repeat(maxBlobsPerTx, 1)},

Where maxBlobsPerTx could be a constant defined at the package level or a parameter passed to the test function.


317-329: LGTM: New test case for oversized blob transaction

The new test case "blob tx that takes up too many shares" is well-structured and correctly tests the scenario where a transaction exceeds the allowed number of shares. It appropriately uses the v3.Version and expects the proposal to be rejected.

Consider adding a brief comment explaining the significance of this test case for v3. For example:

 		{
+			// This test case ensures that transactions exceeding the maximum allowed shares
+			// are rejected in v3, which introduced or modified this limit.
 			name: "blob tx that takes up too many shares",
 			input: &tmproto.Data{
 				Txs: [][]byte{},
 			},
 			mutator: func(d *tmproto.Data) {
 				// this tx will get filtered out by prepare proposal before this
 				// so we add it here
 				d.Txs = append(d.Txs, tooManyShareBtx)
 			},
 			appVersion:     v3.Version,
 			expectedResult: abci.ResponseProcessProposal_REJECT,
 		},

This comment would help future developers understand the context and importance of this test case.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 72f8549 and ddc9f0b.

📒 Files selected for processing (6)
  • app/process_proposal.go (2 hunks)
  • app/test/prepare_proposal_test.go (3 hunks)
  • app/test/process_proposal_test.go (3 hunks)
  • app/validate_txs.go (2 hunks)
  • x/blob/ante/blob_share_decorator.go (2 hunks)
  • x/blob/ante/blob_share_decorator_test.go (3 hunks)
🧰 Additional context used
🪛 GitHub Check: lint / golangci-lint
app/process_proposal.go

[failure] 98-98:
ineffectual assignment to ctx (ineffassign)

x/blob/ante/blob_share_decorator_test.go

[failure] 175-175:
func repeat is unused (unused)

🔇 Additional comments (15)
app/validate_txs.go (2)

48-48: LGTM: Context enrichment with transaction bytes

The addition of ctx = ctx.WithTxBytes(tx) is a good optimization. It enriches the context with the transaction bytes before decoding, which can be beneficial for logging, error handling, or other operations that might need access to the raw transaction data during processing.


82-82: LGTM: Consistent context enrichment for blob transactions

The addition of ctx = ctx.WithTxBytes(tx.Tx) for blob transactions is consistent with the change made in filterStdTxs. This ensures that the context is uniformly enriched with transaction bytes across different transaction types, maintaining a consistent approach to transaction processing.

x/blob/ante/blob_share_decorator_test.go (4)

10-13: LGTM: Import statements updated appropriately.

The new imports are correctly added to support the changes in the test implementation. They are all being used in the updated test cases and setup.

Also applies to: 17-17, 21-23


33-36: Improved test case structure for better granularity and version testing.

The updated test case structure with blobsPerPFB and blobSize provides more precise control over blob characteristics in test scenarios. The addition of appVersion enables testing across different app versions, which is crucial for ensuring compatibility and correct behavior across versions.


Line range hint 1-181: LGTM: Code style and consistency.

The code adheres to Go style guidelines, uses descriptive and consistent variable names, and is well-formatted. This contributes to the overall readability and maintainability of the test suite.


Line range hint 175-181: Address unused repeat function.

The newly added repeat function is well-implemented and leverages Go's generics feature. However, the static analysis tool indicates that this function is currently unused in the file.

Consider one of the following actions:

  1. If the function is intended for future use or is used in other files, add a comment explaining its purpose and intended usage to suppress the linter warning.
  2. If the function is not needed, remove it to keep the codebase clean.
  3. If the function should be used in the current tests, update the test cases to utilize it where appropriate.

To verify the usage of the repeat function across the codebase, you can run the following command:

This will help determine if the function is used elsewhere in the project.

✅ Verification successful

Verified: repeat function is utilized in multiple test files.

The repeat function is actively used in both blob_share_decorator_test.go and prepare_proposal_test.go. The static analysis tool's indication of it being unused within blob_share_decorator_test.go appears to be a false positive.

  • Ensure that the purpose of the repeat function is documented to clarify its usage within the test suite.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the repeat function across the codebase
rg --type go "repeat\[.+\]" .

Length of output: 188

🧰 Tools
🪛 GitHub Check: lint / golangci-lint

[failure] 175-175:
func repeat is unused (unused)

app/process_proposal.go (3)

70-71: Improved context handling for individual transactions

The introduction of a new ctx variable with transaction bytes for each transaction is a good practice. It ensures that each transaction is processed with its own context, which can improve isolation and potentially help with debugging.


Line range hint 70-98: Verify the impact of context handling changes

The changes introduced to optimize the checkTx function, particularly the new context handling with the ctx variable, are consistent with the PR objectives. These modifications should improve the processing of individual transactions by ensuring each one has its own context.

However, it's crucial to verify that these changes don't inadvertently alter the overall behavior of the ProcessProposal method.

To ensure the changes don't introduce any regressions, please run the following tests:

  1. Unit tests for the ProcessProposal method:
#!/bin/bash
# Run unit tests for ProcessProposal
go test -v -run TestProcessProposal ./app
  1. Integration tests that involve transaction processing:
#!/bin/bash
# Run integration tests related to transaction processing
go test -v -run TestTxProcessing ./integration
  1. Benchmark tests to verify performance improvements:
#!/bin/bash
# Run benchmark tests for ProcessProposal
go test -v -run=^$ -bench=BenchmarkProcessProposal ./app

Please review the results of these tests to ensure that the functionality remains correct and that there are indeed performance improvements as intended by this optimization.


98-98: ⚠️ Potential issue

Potential issue with ineffectual assignment to ctx

The static analysis tool reports an ineffectual assignment to ctx on this line. This means that the result of the handler function is not being used, which could lead to unexpected behavior.

To address this, consider updating the line as follows:

- ctx, err = handler(ctx, sdkTx, false)
+ _, err = handler(ctx, sdkTx, false)

This change acknowledges that we're not using the returned context while still capturing any potential errors.

To ensure this change doesn't impact other parts of the code, please run the following command to check for other usages of the ctx variable after this line:

🧰 Tools
🪛 GitHub Check: lint / golangci-lint

[failure] 98-98:
ineffectual assignment to ctx (ineffassign)

app/test/process_proposal_test.go (1)

23-23: LGTM: New import for v3 constants

The new import for v3 constants is correctly added and follows the existing import style. This import is necessary for using the v3.Version constant in the new test case.

x/blob/ante/blob_share_decorator.go (2)

39-39: Update share calculation to include transaction size

Including uint32(len(ctx.TxBytes())) in the getSharesNeeded function ensures that the transaction's base size is accounted for in the share calculation. This change enhances the accuracy of share requirements.


78-82: Verify all usages of getSharesNeeded are updated to the new signature

With the updated function signature of getSharesNeeded to include the base parameter, ensure that all function calls to getSharesNeeded in the codebase are updated accordingly.

Run the following script to find any calls to getSharesNeeded that may not have been updated:

This script searches for any instances where getSharesNeeded is called with only one argument, which would indicate places in the codebase that have not been updated to the new function signature.

✅ Verification successful

All usages of getSharesNeeded have been successfully updated to the new signature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `getSharesNeeded` with only one argument.

# Test: Search for function calls to `getSharesNeeded` with a single argument.
ast-grep --lang go --pattern 'getSharesNeeded($_)'

Length of output: 52


Script:

#!/bin/bash
# Description: Find all calls to `getSharesNeeded` with only one argument using ripgrep.

# Search for `getSharesNeeded` followed by an opening parenthesis, a single argument, and a closing parenthesis.
rg 'getSharesNeeded\s*\(\s*[^,]+\s*\)'

Length of output: 189

app/test/prepare_proposal_test.go (3)

140-155: Construction of oversized transaction is appropriate

The code correctly constructs a transaction (tooManyShareBtx) intended to exceed the block size limits, which is essential for testing the pruning logic in PrepareProposal. The use of repeat(4000, 1) efficiently creates the necessary blob sizes.


200-206: New test case effectively tests pruning of oversized transactions

The addition of the test case "blob tx with too many shares" enhances the test coverage by ensuring that transactions exceeding the share limit are correctly pruned during proposal preparation.


243-250: Ensure project supports Go generics used in the repeat function

The repeat function utilizes generics ([T any]), a feature introduced in Go 1.18. Verify that the project is configured to use Go 1.18 or higher to prevent any build or compatibility issues.

You can confirm the Go version specified in go.mod using the following command:

Expected result: The output should show go 1.18 or a higher version.

✅ Verification successful

Project is configured to use Go 1.23.1, which supports generics.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check that the project specifies Go 1.18 or newer in go.mod

grep '^go ' go.mod

Length of output: 30

x/blob/ante/blob_share_decorator_test.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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ddc9f0b and 7ed444f.

📒 Files selected for processing (3)
  • app/process_proposal.go (1 hunks)
  • x/blob/ante/blob_share_decorator.go (3 hunks)
  • x/blob/ante/blob_share_decorator_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/process_proposal.go
  • x/blob/ante/blob_share_decorator_test.go
🧰 Additional context used
🔇 Additional comments (1)
x/blob/ante/blob_share_decorator.go (1)

80-84: Inclusion of transaction size in share calculation is appropriate

The updated getSharesNeeded function now accounts for the base transaction size, which enhances the accuracy of the share requirement calculation.

@@ -32,11 +34,11 @@ func (d BlobShareDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool
if ctx.BlockHeader().Version.App == v1.Version {
return next(ctx, tx, simulate)
}

fmt.Println("calling the ante handler lol")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove debug print statement from production code

The fmt.Println("calling the ante handler lol") statement appears to be a leftover debugging statement and should be removed to maintain clean and professional code.

Apply this diff to remove the statement:

-	fmt.Println("calling the ante handler lol")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fmt.Println("calling the ante handler lol")

Comment on lines +41 to 43
if sharesNeeded := getSharesNeeded(uint32(len(ctx.TxBytes())), pfb.BlobSizes); sharesNeeded > maxBlobShares {
return ctx, errors.Wrapf(blobtypes.ErrBlobsTooLarge, "the number of shares occupied by blobs in this MsgPayForBlobs %d exceeds the max number of shares available for blob data %d", sharesNeeded, maxBlobShares)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential integer overflow when casting transaction size to uint32

Casting len(ctx.TxBytes()) to uint32 may cause an integer overflow if the transaction size exceeds the maximum value of uint32. To prevent potential issues, consider using uint64 instead.

Apply this diff to use uint64:

-	if sharesNeeded := getSharesNeeded(uint32(len(ctx.TxBytes())), pfb.BlobSizes); sharesNeeded > maxBlobShares {
+	if sharesNeeded := getSharesNeeded(uint64(len(ctx.TxBytes())), pfb.BlobSizes); sharesNeeded > maxBlobShares {

Also, update the getSharesNeeded function signature:

-func getSharesNeeded(base uint32, blobSizes []uint32) (sum int) {
+func getSharesNeeded(base uint64, blobSizes []uint32) (sum int) {

Ensure that any functions called within getSharesNeeded, such as share.CompactSharesNeeded, accept uint64 parameters.

Committable suggestion was skipped due to low confidence.

rach-id
rach-id previously approved these changes Oct 9, 2024
x/blob/ante/blob_share_decorator.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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7ed444f and 58b9314.

📒 Files selected for processing (1)
  • x/blob/ante/blob_share_decorator.go (3 hunks)
🧰 Additional context used
🪛 GitHub Check: test / test-race
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used


[failure] 4-4:
"fmt" imported and not used

🪛 GitHub Check: test / test-coverage
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used

🪛 GitHub Check: test / test-fuzz
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used

🪛 GitHub Check: test / test
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used


[failure] 4-4:
"fmt" imported and not used

🪛 GitHub Check: test / test-short
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used


[failure] 4-4:
"fmt" imported and not used

🪛 GitHub Check: lint / golangci-lint
x/blob/ante/blob_share_decorator.go

[failure] 4-4:
"fmt" imported and not used (typecheck)

x/blob/ante/blob_share_decorator.go Outdated Show resolved Hide resolved
rootulp
rootulp previously approved these changes Oct 9, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

[follow up] we should improve the docs on blob share decorator in a follow up.

Comment on lines +140 to +141
// create a tx that can't be included in a 64 x 64 when accounting for the
// pfb along with the shares
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional]

Suggested change
// create a tx that can't be included in a 64 x 64 when accounting for the
// pfb along with the shares
// create a tx that can't be included in a 64 x 64 when accounting for the
// PFB shares along with the blob shares.

app/test/prepare_proposal_test.go Show resolved Hide resolved
x/blob/ante/blob_share_decorator.go Outdated Show resolved Hide resolved
x/blob/ante/blob_share_decorator_test.go Outdated Show resolved Hide resolved
@@ -137,6 +137,22 @@ func TestPrepareProposalFiltering(t *testing.T) {
require.NoError(t, err)
noAccountTx := []byte(testutil.SendTxWithManualSequence(t, encConf.TxConfig, kr, nilAccount, accounts[0], 1000, "", 0, 6))

// create a tx that can't be included in a 64 x 64 when accounting for the
// pfb along with the shares
tooManyShareBtx := blobfactory.ManyMultiBlobTx(
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] rename for clarity

Suggested change
tooManyShareBtx := blobfactory.ManyMultiBlobTx(
tooManyShareBlobTx := blobfactory.ManyMultiBlobTx(

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 (1)
x/blob/ante/blob_share_decorator_test.go (1)

43-131: Comprehensive test case coverage with room for one more edge case.

The updated test cases provide excellent coverage of various scenarios, including different blob sizes, numbers of blobs, and app versions. The edge cases are well-represented, aligning with the PR objective of optimizing checkTx.

Consider adding one more test case:

  • A test with multiple blobs of varying sizes within the same transaction, to ensure correct handling of heterogeneous blob sizes.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 58b9314 and bc26143.

📒 Files selected for processing (2)
  • x/blob/ante/blob_share_decorator.go (3 hunks)
  • x/blob/ante/blob_share_decorator_test.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (9)
x/blob/ante/blob_share_decorator_test.go (6)

10-13: LGTM: Import changes are appropriate.

The new imports align well with the updated test structure and blob transaction handling. They provide necessary utilities for improved test setup and execution.

Also applies to: 17-17, 21-23


33-36: Improved test case structure.

The updated test case structure with blobsPerPFB and blobSize provides more granular control over blob characteristics. The addition of appVersion enables testing across different app versions, enhancing compatibility checks.


39-40: LGTM: Enhanced test randomness.

The addition of a random number generator improves test robustness by introducing randomness in blob transaction creation.


135-156: Improved test realism and validity.

The new setup significantly enhances test realism by using actual signed transactions instead of mocks. This change aligns well with the previous suggestion to make the test more meaningful. The process of creating a signer, generating random blob transactions, and then unmarshalling and decoding them ensures that the test is working with valid and realistic blob transactions.


159-163: LGTM: Realistic context setup for decorator testing.

The context setup with specific parameters, including app version and actual transaction bytes, ensures that the BlobShareDecorator is tested under realistic conditions. This approach improves the accuracy and reliability of the test.


Line range hint 1-167: Clarification needed: Missing repeat function.

The AI-generated summary mentioned an update to the repeat function, making it generic. However, this function is not present in the current code. Could you please clarify if this change was reverted or if it's located in a different file?

x/blob/ante/blob_share_decorator.go (3)

39-39: Correct inclusion of transaction size in share calculations

The updated call to getSharesNeeded with txSize ensures that the shares used by the transaction are properly accounted for, enhancing the accuracy of share estimation.


52-53: Simplified calculation of maximum blob shares

Returning totalShares directly is appropriate since transaction shares are now included in getSharesNeeded, ensuring the calculation remains accurate.


75-77: Accurate computation of total shares needed

Including txSize in share.CompactSharesNeeded(txSize) correctly accounts for the transaction's compact shares alongside the blobs' sparse shares, resulting in an accurate total.

rootulp
rootulp previously approved these changes Oct 9, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

nice fix, ty!

Comment on lines +70 to +71
// todo: uncomment once we're sure this isn't consensus breaking
// sdkCtx = sdkCtx.WithTxBytes(tx)
Copy link
Member Author

Choose a reason for hiding this comment

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

sorry for one more review @rootulp

I commented this out as I think there are scenarios where this could be consensus breaking and this is not explicitly tested. It should likely be protected by an if statement for v3

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm this PR targets main so we can technically include consensus breaking things b/c main is the basis for v3.0.0.

IIUC we just can't backport this to v2.x

Copy link
Member

Choose a reason for hiding this comment

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

do we want to remove this for now? and after this is backported to v2 we'll have it for main with version gates

@evan-forbes
Copy link
Member Author

evan-forbes commented Oct 10, 2024

for posterity, this is the PR that is being backported to v2, therefore, its a non-breaking version. ontop of this PR for v3, a breaking change can be made by uncommenting out the ctx change in process proposal

edit: ref #3960

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.

goos stuff

@evan-forbes evan-forbes merged commit ca222a8 into main Oct 10, 2024
33 checks passed
@evan-forbes evan-forbes deleted the evan/minor-bug branch October 10, 2024 23:18
mergify bot pushed a commit that referenced this pull request Oct 10, 2024
## Overview

this PR makes a simple optimization for checkTx

---------

Co-authored-by: Rootul P <[email protected]>
Co-authored-by: CHAMI Rachid <[email protected]>
(cherry picked from commit ca222a8)

# Conflicts:
#	app/test/process_proposal_test.go
#	x/blob/ante/blob_share_decorator_test.go
evan-forbes added a commit that referenced this pull request Oct 15, 2024
## Overview

this PR makes a simple optimization for checkTx 
<hr>This is an automatic backport of pull request #3954 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Evan Forbes <[email protected]>
Co-authored-by: Rootul P <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:v2.x PR will be backported automatically to the v2.x branch upon merging optimization item is improves performance resource usage. WS: Maintenance 🔧 includes bugs, refactors, flakes, and tech debt etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants