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

Fix SubmitEthereumTxConfirmation bug #558

Merged
merged 3 commits into from
Feb 27, 2024
Merged

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Feb 20, 2024

Adds an additional lookup to check if the signature is targeting an already-completed outgoing tx.

I verified manually that this fixes the issue with the following steps:

  1. Start the happy path test
  2. Turn off orchestrator 3 as soon as it is started
  3. Stop the test after the SendToEthereum is submitted
  4. Watch another orchestrator's log until the batch is submitted
  5. Query signatures to confirm there are 3
  6. Turn orchestrator 3 back on
  7. Observe 4th signature submission

Closes #555

Copy link

coderabbitai bot commented Feb 20, 2024

Walkthrough

The changes focus on improving the handling of outgoing transaction signatures within the Gravity module, specifically targeting the issue where validators were unable to retroactively sign completed transactions. This enhancement allows for the inclusion of batches and contract call transactions without Ethereum signatures in the list of unconfirmed transactions, thereby enabling validators to sign these transactions post-completion. Additionally, the update ensures that the SubmitEthereumTxConfirmation function checks for completed transactions, addressing a critical oversight that previously led to the jailing of inactive signers.

Changes

File Path Change Summary
module/x/gravity/keeper/batch.go & contract_call.go Added logic to include batches and contract calls without Ethereum signatures in the list of unconfirmed transactions.
module/x/gravity/keeper/.../batch_test.go & contract_call_test.go Updated unit tests to reflect changes: using SetCompletedOutgoingTx and adjusting assertions.
module/x/gravity/keeper/msg_server.go Updated to check for completed outgoing transactions in SubmitEthereumTxConfirmation.

Assessment against linked issues

Objective Addressed Explanation
SubmitEthereumTxConfirmation does not check CompletedOutgoingTxs (#555) The update to msg_server.go ensures that SubmitEthereumTxConfirmation now checks for completed outgoing transactions, directly addressing the issue.

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Comment on lines +15 to +25
k.IterateCompletedOutgoingTxsByType(ctx, types.ContractCallTxPrefixByte, func(_ []byte, cotx types.OutgoingTx) bool {
sig := k.getEthereumSignature(ctx, cotx.GetStoreIndex(), val)
if len(sig) == 0 {
call, ok := cotx.(*types.ContractCallTx)
if !ok {
panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to contract call for completed tx %s", cotx))
}
unconfirmed = append(unconfirmed, call)
}
return false
})
Copy link

Choose a reason for hiding this comment

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

The addition of iterating over completed outgoing transactions to include them in the list of unconfirmed contract call transactions is a crucial fix for the issue described. However, using panic for error handling (line 20) is generally discouraged in Go unless it's a truly unrecoverable error. Consider returning an error to the caller instead, which allows for more graceful error handling and logging.

Regarding performance, ensure that the iteration over completed transactions does not introduce significant overhead, especially as the number of transactions grows. If performance becomes a concern, consider optimizing the data structure used for storing and querying these transactions.

Comment on lines +166 to +176
k.IterateCompletedOutgoingTxsByType(ctx, types.BatchTxPrefixByte, func(_ []byte, cotx types.OutgoingTx) bool {
sig := k.getEthereumSignature(ctx, cotx.GetStoreIndex(), val)
if len(sig) == 0 {
batch, ok := cotx.(*types.BatchTx)
if !ok {
panic(sdkerrors.Wrapf(types.ErrInvalid, "couldn't cast to batch tx for completed tx %s", cotx))
}
unconfirmed = append(unconfirmed, batch)
}
return false
})
Copy link

Choose a reason for hiding this comment

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

Similar to the changes in contract_call.go, the addition of iterating over completed outgoing transactions in GetUnsignedBatchTxs is essential for the fix. However, the use of panic for error handling (line 171) should be reconsidered for the same reasons mentioned earlier: it's generally discouraged unless for truly unrecoverable errors. Consider returning an error instead.

Also, be mindful of the performance implications of iterating over a potentially large number of transactions. If performance issues arise, exploring optimizations for the data structure or query mechanism might be necessary.

@codecov-commenter
Copy link

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (4abf107) 29.54% compared to head (a9e2276) 29.63%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #558      +/-   ##
==========================================
+ Coverage   29.54%   29.63%   +0.09%     
==========================================
  Files          48       48              
  Lines        7030     7048      +18     
==========================================
+ Hits         2077     2089      +12     
- Misses       4771     4775       +4     
- Partials      182      184       +2     
Files Coverage Δ
module/x/gravity/keeper/batch.go 82.22% <75.00%> (-0.46%) ⬇️
module/x/gravity/keeper/contract_call.go 73.33% <75.00%> (+0.36%) ⬆️
module/x/gravity/keeper/msg_server.go 57.89% <10.00%> (-0.52%) ⬇️

@zmanian
Copy link
Contributor

zmanian commented Feb 23, 2024

Are CompletedOutGoingTxs ever pruned or does the set of transactions growth unbounded?

@cbrit
Copy link
Member Author

cbrit commented Feb 23, 2024

Are CompletedOutGoingTxs ever pruned or does the set of transactions growth unbounded?

@zmanian

They are pruned on the block after slashing applies to them

// pruneCompletedOutgoingTxs deletes all completed txs and their signatures whos block height is below the last slashed
// height. This accounts for the corner case where a tx becomes a CompletedOutgoingTx right after its relevant block height
// has been slashed for, since it's possible for a relayer to submit a tx right before its slashing height.
func pruneCompletedOutgoingTxs(ctx sdk.Context, k keeper.Keeper) {
lastSlashed := k.GetLastSlashedOutgoingTxBlockHeight(ctx)
k.IterateCompletedOutgoingTxs(ctx, func(key []byte, cotx types.OutgoingTx) bool {
if cotx.GetCosmosHeight() <= lastSlashed {
k.DeleteCompletedOutgoingTx(ctx, cotx.GetStoreIndex())
}
return false
})
}

@zmanian
Copy link
Contributor

zmanian commented Feb 24, 2024

this is ready to go IMO

@cbrit cbrit merged commit 2329978 into main Feb 27, 2024
11 of 13 checks passed
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.

SubmitEthereumTxConfirmation does not check CompletedOutgoingTxs
3 participants