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: emit events on revert #2466

Merged
merged 9 commits into from
Jul 16, 2024
Merged

fix: emit events on revert #2466

merged 9 commits into from
Jul 16, 2024

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Jul 12, 2024

Description

in progress

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • Bug Fixes

    • Modified transaction and block handling to prevent errors by setting default values for V, R, and S fields to 0 instead of nil.
    • Updated cross-chain gateway logic to properly manage pending statuses before committing.
  • New Features

    • Added a new test configuration for test_dapp in the local.yml file with a specified Ethereum address.
    • Introduced additional logic in message passing tests to validate and check balances for a new EVM address.
  • Documentation

    • Updated documentation for test suite functions to reflect new assertion checks and default value changes.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

The recent updates primarily address changing assertions in test cases to compare with zero values instead of nil for blockchain transaction fields. Additionally, there are adjustments in transaction status checking, handling of failed EVM calls, and a new configuration for a test DApp address. These changes aim to ensure better consistency and accuracy in transaction processing and testing.

Changes

File Change Summary
rpc/backend/blocks_test.go Assert V, R, and S fields to zero instead of nil in TestEthAndSyntheticGetBlockByNumber.
rpc/backend/tx_info_test.go Multiple test functions now assert V, R, S fields to zero instead of nil.
rpc/types/utils.go Set default values for V, R, and S to zero in NewRPCTransactionFromIncompleteMsg function.
x/crosschain/keeper/cctx_gateway_zevm.go Adjust logic in InitiateOutbound function to check transaction statuses before committing.
x/fungible/keeper/evm.go Reposition handling of a failed result in the CallEVMWithData function.
cmd/zetae2e/config/local.yml Updated test_dapp entry in evm contracts section with a new Ethereum address.
e2e/e2etests/test_message_passing_evm_to_zevm_revert.go Added a constant for a fungible module address and included related balance checks in TestMessagePassingEVMtoZEVMRevert.

Poem

In the realm of code so vast,
A rabbit hopped through changes fast,
With nil to zero fields we stride,
Ensuring tests run far and wide.
New DApp addresses take their place,
While EVM calls find better grace.
Commit with logic, status clear,
In blockchain code, there's nothing to fear.


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 15.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 47.19%. Comparing base (d0db41c) to head (cb06367).
Report is 7 commits behind head on develop.

❗ There is a different number of reports uploaded between BASE (d0db41c) and HEAD (cb06367). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (d0db41c) HEAD (cb06367)
2 1
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #2466       +/-   ##
============================================
- Coverage    69.05%   47.19%   -21.86%     
============================================
  Files          308      444      +136     
  Lines        19192    29372    +10180     
============================================
+ Hits         13253    13863      +610     
- Misses        5264    14704     +9440     
- Partials       675      805      +130     
Files Coverage Δ
x/crosschain/keeper/cctx_gateway_zevm.go 100.00% <100.00%> (ø)
x/fungible/keeper/evm.go 88.23% <100.00%> (+0.42%) ⬆️
rpc/types/utils.go 0.00% <0.00%> (ø)
...2etests/test_message_passing_evm_to_zevm_revert.go 0.00% <0.00%> (ø)

... and 174 files with indirect coverage changes

@lumtis
Copy link
Member

lumtis commented Jul 12, 2024

It seems like I have some issue to retrieve the tx with Cast CLI

Reproduce

Run localnet

make start-localnet

Run deposit failure

zetae2e run eth_deposit_and_call_refund:10000000000000000000 --verbose --config cmd/zetae2e/config/local.ym

Get the synthetic tx hash from the cctx

zetacored q crosschain inbound-hash-to-cctx-data <inbound_hash>

Query tx data

cast tx 0xa2d789b54f01d193f3d8312a12863f70b6c3dd02ac77962d3968b6e0b757fff0 --rpc-url http://0.0.0.0:9545
Error:
Deserialization Error: invalid type: null, expected a (both 0x-prefixed or not) hex string or byte array containing between (0; 8] bytes at line 1 column 1206. Response: {"blockHash":"0x3d16e7c77d1edd2fa40b35ee2667f108261ff094829464192d62b24d92db0040","blockNumber":"0x4c","from":"0x735b14bb79463307aacbed86daf3322b1e6226ab","gas":"0x7a120","gasPrice":"0x2540be400","hash":"0xa2d789b54f01d193f3d8312a12863f70b6c3dd02ac77962d3968b6e0b757fff0","input":"0xc39aca3700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000013a0c5930c028511dc02665e7285134b6d11a5f40000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000d97b1de3619ed2c6beb3860147e30ca8a7dc989100000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005390000000000000000000000000000000000000000000000000000000000000014e5c5367b8224807ac2207d350e60e1b6f27a7ecc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d68656c6c6f207361696c6f727300000000000000000000000000000000000000","nonce":"0x8","to":"0x91d18e54daf4f677cb28167158d6dd21f6ab3921","transactionIndex":"0x22b8","value":"0x0","type":"0x58","chainId":"0x65","v":null,"r":null,"s":null}

Wondering if this could be due to cast specifically? There is something queried at least, it doesn't show tx not found

@skosito
Copy link
Contributor Author

skosito commented Jul 12, 2024

It seems like I have some issue to retrieve the tx with Cast CLI

Reproduce

Run localnet

make start-localnet

Run deposit failure

zetae2e run eth_deposit_and_call_refund:10000000000000000000 --verbose --config cmd/zetae2e/config/local.ym

Get the synthetic tx hash from the cctx

zetacored q crosschain inbound-hash-to-cctx-data <inbound_hash>

Query tx data

cast tx 0xa2d789b54f01d193f3d8312a12863f70b6c3dd02ac77962d3968b6e0b757fff0 --rpc-url http://0.0.0.0:9545
Error:
Deserialization Error: invalid type: null, expected a (both 0x-prefixed or not) hex string or byte array containing between (0; 8] bytes at line 1 column 1206. Response: {"blockHash":"0x3d16e7c77d1edd2fa40b35ee2667f108261ff094829464192d62b24d92db0040","blockNumber":"0x4c","from":"0x735b14bb79463307aacbed86daf3322b1e6226ab","gas":"0x7a120","gasPrice":"0x2540be400","hash":"0xa2d789b54f01d193f3d8312a12863f70b6c3dd02ac77962d3968b6e0b757fff0","input":"0xc39aca3700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000013a0c5930c028511dc02665e7285134b6d11a5f40000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000d97b1de3619ed2c6beb3860147e30ca8a7dc989100000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005390000000000000000000000000000000000000000000000000000000000000014e5c5367b8224807ac2207d350e60e1b6f27a7ecc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d68656c6c6f207361696c6f727300000000000000000000000000000000000000","nonce":"0x8","to":"0x91d18e54daf4f677cb28167158d6dd21f6ab3921","transactionIndex":"0x22b8","value":"0x0","type":"0x58","chainId":"0x65","v":null,"r":null,"s":null}

Wondering if this could be due to cast specifically? There is something queried at least, it doesn't show tx not found

i think this should be fixed with 4581257

@skosito skosito marked this pull request as ready for review July 15, 2024 10:25
Copy link

!!!WARNING!!!
nosec detected in the following files: rpc/types/utils.go, x/fungible/keeper/evm.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Jul 15, 2024
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 ce8afec and 944d088.

Files selected for processing (5)
  • rpc/backend/blocks_test.go (1 hunks)
  • rpc/backend/tx_info_test.go (3 hunks)
  • rpc/types/utils.go (1 hunks)
  • x/crosschain/keeper/cctx_gateway_zevm.go (1 hunks)
  • x/fungible/keeper/evm.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • x/fungible/keeper/evm.go
Additional context used
Path-based instructions (4)
x/crosschain/keeper/cctx_gateway_zevm.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

rpc/types/utils.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

rpc/backend/tx_info_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

rpc/backend/blocks_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

GitHub Check: codecov/patch
rpc/types/utils.go

[warning] 259-261: rpc/types/utils.go#L259-L261
Added lines #L259 - L261 were not covered by tests

Additional comments not posted (5)
x/crosschain/keeper/cctx_gateway_zevm.go (1)

36-36: LGTM! Ensure correct handling of all statuses.

The change ensures that transactions are committed unless the new status is CctxStatus_Aborted, which aligns with the goal of emitting events on revert.

However, verify that all statuses are correctly handled and there are no unintended side effects.

Verification successful

LGTM! Ensure correct handling of all statuses.

The change ensures that transactions are committed unless the new status is CctxStatus_Aborted, which aligns with the goal of emitting events on revert. The extensive tests confirm that all statuses are correctly handled, and there are no unintended side effects.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of all statuses in the `InitiateOutbound` function.

# Test: Search for all usages of `InitiateOutbound`. Expect: Proper handling of all statuses.
rg --type go -A 10 'InitiateOutbound'

Length of output: 27692

rpc/backend/tx_info_test.go (3)

62-64: LGTM!

The changes ensure that the V, R, and S fields are compared to (*hexutil.Big)(big.NewInt(0)) instead of being checked for nil, aligning with the updated default values.


130-132: LGTM!

The changes ensure that the V, R, and S fields are compared to (*hexutil.Big)(big.NewInt(0)) instead of being checked for nil, aligning with the updated default values.


163-165: LGTM!

The changes ensure that the V, R, and S fields are compared to (*hexutil.Big)(big.NewInt(0)) instead of being checked for nil, aligning with the updated default values.

rpc/backend/blocks_test.go (1)

1719-1721: LGTM! Ensure consistency across the codebase.

The changes to compare V, R, and S fields to (*hexutil.Big)(big.NewInt(0)) instead of nil are approved.

However, ensure that similar changes are consistently applied across the codebase.

Verification successful

Changes are consistently applied across the codebase.

The new assertions for V, R, and S fields are present in rpc/backend/tx_info_test.go, confirming consistency with the changes in rpc/backend/blocks_test.go.

  • rpc/backend/tx_info_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all assertions for `V`, `R`, and `S` fields are consistent across the codebase.

# Test: Search for the assertions. Expect: Only occurances of the new assertions.
rg --type go $'.Equal((*hexutil.Big)(big.NewInt(0)), res.V)'
rg --type go $'.Equal((*hexutil.Big)(big.NewInt(0)), res.R)'
rg --type go $'.Equal((*hexutil.Big)(big.NewInt(0)), res.S)'

Length of output: 569


Script:

#!/bin/bash
# Description: Verify that all assertions for `V`, `R`, and `S` fields are consistent across the codebase.

# Test: Search for the assertions. Expect: Only occurrences of the new assertions.
rg --type go '\.Equal\(\(\*hexutil\.Big\)\(big\.NewInt\(0\)\), res\.V\)'
rg --type go '\.Equal\(\(\*hexutil\.Big\)\(big\.NewInt\(0\)\), res\.R\)'
rg --type go '\.Equal\(\(\*hexutil\.Big\)\(big\.NewInt\(0\)\), res\.S\)'

Length of output: 1025

rpc/types/utils.go Show resolved Hide resolved
x/fungible/keeper/evm.go Outdated Show resolved Hide resolved
@lumtis lumtis linked an issue Jul 15, 2024 that may be closed by this pull request
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

It looks good to me.

FYI I pushed an additional assertion for ZEVM MP test, I wanted to ensure the commit refactoring didn't allow to mint ZETA into fungible module on revert.
It looks the change doesn't affect the system as the deposit of token and call are atomic into the EVM call

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, codebase verification and nitpick comments (1)
cmd/zetae2e/config/local.yml (1)

34-34: Add a newline at the end of the file.

The file should end with a newline character to adhere to the POSIX standard.

+ 
Tools
yamllint

[error] 34-34: no new line character at the end of file

(new-line-at-end-of-file)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 944d088 and 2cd00e0.

Files selected for processing (2)
  • cmd/zetae2e/config/local.yml (1 hunks)
  • e2e/e2etests/test_message_passing_evm_to_zevm_revert.go (3 hunks)
Additional context used
Path-based instructions (1)
e2e/e2etests/test_message_passing_evm_to_zevm_revert.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

yamllint
cmd/zetae2e/config/local.yml

[error] 34-34: no new line character at the end of file

(new-line-at-end-of-file)

Additional comments not posted (3)
cmd/zetae2e/config/local.yml (1)

34-34: Verify the new test_dapp address.

Ensure that the new test_dapp address under the evm section is correct and consistent with the rest of the configuration.

Verification successful

The new test_dapp address is correctly placed and consistent with the rest of the configuration.

  • The address 0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed is correctly located under the evm section in the local.yml file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new test_dapp address in the configuration file.

# Test: Search for the new test_dapp address in the codebase. Expect: Only valid occurrences.
rg --type yaml '0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed'

Length of output: 148


Script:

#!/bin/bash
# Description: Search for the evm section and check the context around the test_dapp entry in the local.yml file.

# Find the evm section and display surrounding lines to verify the context of test_dapp
rg --type yaml -A 10 'evm' cmd/zetae2e/config/local.yml

Length of output: 1357

Tools
yamllint

[error] 34-34: no new line character at the end of file

(new-line-at-end-of-file)

e2e/e2etests/test_message_passing_evm_to_zevm_revert.go (2)

55-57: LGTM! Ensure balance checks are accurate.

The balance checks for the fungible module address enhance the test coverage. Ensure these checks are accurate and consistent with the expected behavior.

Also applies to: 118-129


16-17: Verify the new constant fungibleModuleAddress.

Ensure that the new constant fungibleModuleAddress is correct and used appropriately in the test.

Verification successful

The new constant fungibleModuleAddress is correctly defined and used appropriately in the test.

  • The constant is defined and used within the TestMessagePassingEVMtoZEVMRevert function.
  • It is converted to an Ethereum address and validated, ensuring its correctness.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new constant fungibleModuleAddress in the codebase.

# Test: Search for the new constant in the codebase. Expect: Only valid occurrences.
rg --type go 'const fungibleModuleAddress = "0x735b14BB79463307AAcBED86DAf3322B1e6226aB"'

Length of output: 222


Script:

#!/bin/bash
# Description: Verify the usage of the constant fungibleModuleAddress in the test file.

# Test: Search for all occurrences of fungibleModuleAddress in the test file and include context lines.
rg 'fungibleModuleAddress' -A 5 -B 5 e2e/e2etests/test_message_passing_evm_to_zevm_revert.go

Length of output: 764

@skosito
Copy link
Contributor Author

skosito commented Jul 15, 2024

It looks good to me.

FYI I pushed an additional assertion for ZEVM MP test, I wanted to ensure the commit refactoring didn't allow to mint ZETA into fungible module on revert. It looks the change doesn't affect the system as the deposit of token and call are atomic into the EVM call

thanks!

@skosito skosito requested review from kingpinXD and fbac July 15, 2024 15:46
@fbac fbac enabled auto-merge July 15, 2024 15:48
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2cd00e0 and f048551.

Files selected for processing (2)
  • x/crosschain/keeper/cctx_gateway_zevm.go (1 hunks)
  • x/fungible/keeper/evm.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/crosschain/keeper/cctx_gateway_zevm.go
  • x/fungible/keeper/evm.go

@skosito
Copy link
Contributor Author

skosito commented Jul 16, 2024

@lumtis @fbac just fyi, after your approval, i fixed the issue i introduced here: f048551 that caused e2e tests to fail, with this commit: cb06367

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, codebase verification and nitpick comments (1)
x/crosschain/keeper/cctx_gateway_zevm.go (1)

36-36: Clarify the commit logic in relation to transaction statuses.

The current implementation commits the transaction if the new status is either OutboundMined or PendingRevert. This change aligns with the previous discussion about ensuring that reverted transactions are still committed to allow for event emission and indexing. However, it would be beneficial to add a comment explaining this decision for future maintainability.

It's also important to ensure that all possible statuses where a commit is necessary are covered. The inclusion of PendingRevert is a significant change that should be explicitly documented in the code to avoid confusion.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f048551 and cb06367.

Files selected for processing (1)
  • x/crosschain/keeper/cctx_gateway_zevm.go (1 hunks)
Additional context used
Path-based instructions (1)
x/crosschain/keeper/cctx_gateway_zevm.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

@fbac fbac added this pull request to the merge queue Jul 16, 2024
Merged via the queue into develop with commit 88f37bc Jul 16, 2024
26 of 28 checks passed
@fbac fbac deleted the emit-events-on-revert branch July 16, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emit EVM related event when synthetic EVM tx revert
4 participants