-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(x/auth/tx): Implement UnorderedTxManager
tx validator
#21426
Conversation
WalkthroughWalkthroughThe changes involve significant updates to the transaction handling logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant UnorderedTxDecorator
participant NextHandler
Client->>UnorderedTxDecorator: Submit Transaction
UnorderedTxDecorator->>UnorderedTxDecorator: ValidateTx()
alt If Valid
UnorderedTxDecorator->>NextHandler: Proceed with Transaction
else If Invalid
UnorderedTxDecorator-->>Client: Return nil
end
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
@hieuvubk your pull request is missing a changelog! |
There was a problem hiding this 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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- x/auth/ante/unordered.go (4 hunks)
- x/auth/tx/config/depinject.go (1 hunks)
Additional context used
Path-based instructions (2)
x/auth/ante/unordered.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/auth/tx/config/depinject.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (3)
x/auth/ante/unordered.go (2)
73-77
: LGTM!The
AnteHandle
function correctly calls theValidateTx
method before proceeding to the next handler. This improves the control flow and ensures that invalid transactions are properly handled.The code changes are approved.
Line range hint
79-138
: LGTM!The
ValidateTx
function performs necessary checks to ensure the validity of unordered transactions. It handles errors appropriately and consumes gas for calculating the transaction hash.The code changes are approved.
x/auth/tx/config/depinject.go (1)
156-159
: LGTM!The
ProvideModule
function correctly includes a conditional check forUnorderedTxManager
and appends a new decorator to theExtraTxValidators
slice if the condition is met. This enhances the functionality by incorporating additional transaction validation logic.The code changes are approved.
There was a problem hiding this 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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- x/auth/ante/unordered.go (4 hunks)
- x/auth/tx/config/depinject.go (1 hunks)
- x/auth/tx/config/module.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
- x/auth/ante/unordered.go
- x/auth/tx/config/depinject.go
Additional context used
Path-based instructions (1)
x/auth/tx/config/module.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (5)
x/auth/tx/config/module.go (5)
5-5
: LGTM!The import statement for
fmt
is necessary for error formatting.The code changes are approved.
23-24
: LGTM!The addition of the
unorderTxValidator
field to theAppModule
struct enhances its capability to handle unordered transaction validation.The code changes are approved.
34-40
: LGTM!The
NewAppModule
function is correctly updated to acceptunorderedTxValidator
as a parameter, ensuring proper initialization.The code changes are approved.
58-61
: LGTM!The type assertion to ensure the transaction is of type
sdk.Tx
is necessary for validation.The code changes are approved.
63-67
: LGTM!The conditional check to call
ValidateTx
ofunorderTxValidator
if it is not nil ensures that unordered transaction validation is performed if the validator is available.The code changes are approved.
@hieuvubk can you run |
UnorderedTxManager
tx validator
There was a problem hiding this 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, codebase verification and nitpick comments (1)
x/auth/ante/unordered.go (1)
Line range hint
80-144
: Add comments to explain the logic.The method can benefit from additional comments to explain the logic, making it easier to understand and maintain.
Consider adding comments like this:
func (d *UnorderedTxDecorator) ValidateTx(ctx context.Context, tx transaction.Tx) error { sdkTx, ok := tx.(sdk.Tx) if !ok { // The transaction is not of type sdk.Tx, return an error. return fmt.Errorf("invalid transaction type %T, expected sdk.Tx", tx) } unorderedTx, ok := tx.(sdk.TxWithUnordered) if !ok || !unorderedTx.GetUnordered() { // If the transaction does not implement unordered capabilities or has the // unordered value as false, we bypass. return nil } headerInfo := d.env.HeaderService.HeaderInfo(ctx) timeoutTimestamp := unorderedTx.GetTimeoutTimeStamp() if timeoutTimestamp.IsZero() || timeoutTimestamp.Unix() == 0 { // The unordered transaction must have a timeout_timestamp set. return errorsmod.Wrap( sdkerrors.ErrInvalidRequest, "unordered transaction must have timeout_timestamp set", ) } if timeoutTimestamp.Before(headerInfo.Time) { // The timeout_timestamp has already passed. return errorsmod.Wrap( sdkerrors.ErrInvalidRequest, "unordered transaction has a timeout_timestamp that has already passed", ) } if timeoutTimestamp.After(headerInfo.Time.Add(d.maxTimeoutDuration)) { // The unordered transaction's TTL exceeds the maximum allowed duration. return errorsmod.Wrapf( sdkerrors.ErrInvalidRequest, "unordered tx ttl exceeds %s", d.maxTimeoutDuration.String(), ) } // consume gas in all exec modes to avoid gas estimation discrepancies if err := d.env.GasService.GasMeter(ctx).Consume(d.sha256Cost, "consume gas for calculating tx hash"); err != nil { return errorsmod.Wrap(sdkerrors.ErrOutOfGas, "out of gas") } // Avoid checking for duplicates and creating the identifier in simulation mode // This is done to avoid sha256 computation in simulation mode if d.env.TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate { return nil } // calculate the tx hash txHash, err := TxIdentifier(uint64(timeoutTimestamp.Unix()), sdkTx) if err != nil { return err } // check for duplicates if d.txManager.Contains(txHash) { return errorsmod.Wrap( sdkerrors.ErrInvalidRequest, "tx %X is duplicated", ) } if d.env.TransactionService.ExecMode(ctx) == transaction.ExecModeFinalize { // a new tx included in the block, add the hash to the unordered tx manager d.txManager.Add(txHash, timeoutTimestamp) } return nil }
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- x/auth/ante/unordered.go (4 hunks)
- x/auth/tx/config/depinject.go (2 hunks)
- x/auth/tx/config/module.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- x/auth/tx/config/depinject.go
- x/auth/tx/config/module.go
Additional context used
Path-based instructions (1)
x/auth/ante/unordered.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (1)
x/auth/ante/unordered.go (1)
74-78
: LGTM!The changes ensure that transactions are validated before being processed further, improving the robustness of the transaction handling process.
func (d *UnorderedTxDecorator) ValidateTx(ctx context.Context, tx transaction.Tx) error { | ||
sdkTx, ok := tx.(sdk.Tx) | ||
if !ok { | ||
return fmt.Errorf("invalid tx type %T, expected sdk.Tx", tx) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error message for invalid transaction type.
The error message can be more descriptive to provide better context.
Apply this diff to improve the error message:
- return fmt.Errorf("invalid tx type %T, expected sdk.Tx", tx)
+ return fmt.Errorf("invalid transaction type %T, expected sdk.Tx", tx)
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.
func (d *UnorderedTxDecorator) ValidateTx(ctx context.Context, tx transaction.Tx) error { | |
sdkTx, ok := tx.(sdk.Tx) | |
if !ok { | |
return fmt.Errorf("invalid tx type %T, expected sdk.Tx", tx) | |
} | |
func (d *UnorderedTxDecorator) ValidateTx(ctx context.Context, tx transaction.Tx) error { | |
sdkTx, ok := tx.(sdk.Tx) | |
if !ok { | |
return fmt.Errorf("invalid transaction type %T, expected sdk.Tx", tx) | |
} |
) (cherry picked from commit 17d864f)
Description
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
New Features
Bug Fixes