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

refactor: delete all trackers when finalizing CCTX #2615

Merged
merged 9 commits into from
Aug 6, 2024

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Aug 1, 2024

Description

Closes #2610

  • Try to delete all trackers associated with the cctx when finalizing it. If the tracker doesn't exist, nothing happens
  • Try to update the pending nonce for all nonces associated with the tracker, if the nonce has been previously updated, nothing happens
  • Fixes setting the ballot index properly for cases when a revert is added . (previously the ballot index was getting set to the revert tx instead of the original outbound )

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

  • New Features

    • Added a validation check for outbound transaction trackers in the local end-to-end testing framework.
    • Introduced a new method to set the outbound ballot index within the CrossChainTx structure.
  • Bug Fixes

    • Improved handling of outbound transaction states by simplifying method signatures and enhancing functionality.
  • Documentation

    • Minor formatting adjustments in command-line documentation for clarity.
  • Tests

    • Expanded test coverage for outbound transaction handling and nonce removal functionality.

Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent changes introduce enhancements primarily focused on the management and validation of outbound transaction trackers within the system. A new function, checkTrackers, has been added to ensure that all outbound trackers are cleared when finalizing cross-chain transactions. Additional refinements in method signatures streamline the processes for saving outbound transactions, thereby enhancing code clarity and maintainability. Documentation has also been improved for better readability.

Changes

File Path Change Summary
changelog.md Added a new "Refactor" section documenting a pull request related to the cleanup of outbound trackers.
cmd/zetae2e/local/local.go Introduced checkTrackers, enhancing validation of outbound transaction trackers.
x/crosschain/keeper/msg_server_vote_outbound_tx.go Modified VoteOutbound, removed ballotIndex from several methods to streamline signatures and improve handling of outbound parameters.
x/crosschain/keeper/msg_server_vote_outbound_tx_test.go Updated tests to reflect changes in method signatures and improved readability of test cases for outbound transaction handling.
x/crosschain/types/cctx.go Added SetOutboundBallotIndex method to enhance manipulation of the BallotIndex within CrossChainTx.
x/crosschain/types/cctx_test.go Introduced TestCrossChainTx_SetOutboundBallot to verify the correct setting of the outbound ballot index within a CrossChainTx instance.
x/observer/keeper/pending_nonces_test.go Added test case for RemoveFromPendingNonces to validate nonce removal while ensuring integrity across multiple chains.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LocalE2ETest
    participant CctxClient
    participant TrackerManager
    
    User->>LocalE2ETest: Initiate Local E2E Test
    LocalE2ETest->>CctxClient: Perform Network Report Validation
    LocalE2ETest->>TrackerManager: checkTrackers()
    TrackerManager-->>LocalE2ETest: Validate No Outbound Trackers
    LocalE2ETest-->>User: Test Complete
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove all trackers for a cctx when finalizing (#2610)

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 Configuration 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.

@kingpinXD kingpinXD changed the title refactor tracker cleanup refactor: tracker cleanup Aug 1, 2024
@kingpinXD kingpinXD marked this pull request as ready for review August 1, 2024 16:52
@kingpinXD kingpinXD added the TSS_MIGRATION_TESTS Run TSS migration tests label Aug 1, 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: 4

Outside diff range, codebase verification and nitpick comments (3)
x/crosschain/keeper/msg_server_vote_outbound_tx_test.go (3)

Line range hint 156-174:
Ensure comprehensive assertions in TestKeeper_VoteOutbound.

The test function should include more assertions to verify the state of the CrossChainTx object after the vote.

msg := types.MsgVoteOutbound{
	CctxHash:                          cctx.Index,
	OutboundTssNonce:                  cctx.GetCurrentOutboundParam().TssNonce,
	OutboundChain:                     cctx.GetCurrentOutboundParam().ReceiverChainId,
	Status:                            chains.ReceiveStatus_success,
	Creator:                           observer,
	ObservedOutboundHash:              sample.Hash().String(),
	ValueReceived:                     cctx.GetCurrentOutboundParam().Amount,
	ObservedOutboundBlockHeight:       10,
	ObservedOutboundEffectiveGasPrice: math.NewInt(21),
	ObservedOutboundGasUsed:           21,
	CoinType:                          cctx.InboundParams.CoinType,
}
_, err := msgServer.VoteOutbound(ctx, &msg)
require.NoError(t, err)
c, found := k.GetCrossChainTx(ctx, cctx.Index)
require.True(t, found)
require.Equal(t, types.CctxStatus_OutboundMined, c.CctxStatus.Status)
require.Equal(t, msg.Digest(), c.GetCurrentOutboundParam().BallotIndex)

// Additional assertions
require.NotNil(t, c.GetCurrentOutboundParam())
require.Equal(t, observer, c.GetCurrentOutboundParam().Creator)
require.Equal(t, 10, c.GetCurrentOutboundParam().ObservedOutboundBlockHeight)

Line range hint 214-235:
Ensure comprehensive assertions in TestKeeper_VoteOutbound for failed votes.

The test function should include more assertions to verify the state of the CrossChainTx object after the vote fails.

msg := types.MsgVoteOutbound{
	CctxHash:                          cctx.Index,
	OutboundTssNonce:                  cctx.GetCurrentOutboundParam().TssNonce,
	OutboundChain:                     cctx.GetCurrentOutboundParam().ReceiverChainId,
	Status:                            chains.ReceiveStatus_failed,
	Creator:                           observer,
	ObservedOutboundHash:              sample.Hash().String(),
	ValueReceived:                     cctx.GetCurrentOutboundParam().Amount,
	ObservedOutboundBlockHeight:       10,
	ObservedOutboundEffectiveGasPrice: math.NewInt(21),
	ObservedOutboundGasUsed:           21,
	CoinType:                          cctx.InboundParams.CoinType,
}
_, err := msgServer.VoteOutbound(ctx, &msg)
require.NoError(t, err)
c, found := k.GetCrossChainTx(ctx, cctx.Index)
require.True(t, found)
require.Equal(t, types.CctxStatus_PendingRevert, c.CctxStatus.Status)
require.Equal(t, oldParamsLen+1, len(c.OutboundParams))
require.Equal(t, types.TxFinalizationStatus_Executed, c.OutboundParams[oldParamsLen-1].TxFinalizationStatus)
require.Equal(t, types.TxFinalizationStatus_NotFinalized, cctx.GetCurrentOutboundParam().TxFinalizationStatus)

// Additional assertions
require.NotNil(t, c.GetCurrentOutboundParam())
require.Equal(t, observer, c.GetCurrentOutboundParam().Creator)
require.Equal(t, 10, c.GetCurrentOutboundParam().ObservedOutboundBlockHeight)

Line range hint 581-660:
Update function call to match the new signature for saving outbound.

The SaveOutbound function call should be updated to match the new simplified signature.

- k.SaveOutbound(ctx, cctx)
+ k.SaveOutbound(ctx, cctx)
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aed7caa and bd00a6f.

Files selected for processing (8)
  • changelog.md (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md (1 hunks)
  • x/crosschain/keeper/msg_server_vote_outbound_tx.go (4 hunks)
  • x/crosschain/keeper/msg_server_vote_outbound_tx_test.go (11 hunks)
  • x/crosschain/types/cctx.go (1 hunks)
  • x/crosschain/types/cctx_test.go (1 hunks)
  • x/observer/keeper/pending_nonces_test.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • changelog.md
  • docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md
Additional context used
Path-based instructions (6)
x/observer/keeper/pending_nonces_test.go (1)

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

x/crosschain/types/cctx.go (1)

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

x/crosschain/keeper/msg_server_vote_outbound_tx.go (1)

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

x/crosschain/types/cctx_test.go (1)

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

cmd/zetae2e/local/local.go (1)

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

x/crosschain/keeper/msg_server_vote_outbound_tx_test.go (1)

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

Additional comments not posted (9)
x/observer/keeper/pending_nonces_test.go (1)

141-189: LGTM!

The new test case test removal within range only using fixed value is well-structured and covers various edge cases for nonce removal. It ensures that the integrity of the NonceLow and NonceHigh values is maintained and that pending nonces for other chains are unaffected.

x/crosschain/types/cctx.go (1)

167-169: LGTM!

The new method SetOutboundBallotIndex is a valuable addition to the CrossChainTx struct. It enhances the control flow related to outbound parameters by providing a direct way to modify the ballot index.

x/crosschain/keeper/msg_server_vote_outbound_tx.go (4)

93-94: LGTM!

Setting the finalized ballot index in the cctx enhances the tracking of the current outbound parameters. This change ensures that the outbound parameters are accurately tracked and updated.


176-179: LGTM!

Removing the ballotIndex parameter from the SaveFailedOutbound function simplifies the method signature and streamlines the process of saving outbound transactions.


185-186: LGTM!

Removing the ballotIndex parameter from the SaveSuccessfulOutbound function simplifies the method signature and streamlines the process of saving outbound transactions.


200-206: LGTM!

Removing the ballotIndex parameter and processing all outbound parameters in a loop improves the robustness of the outbound transaction handling. This change ensures that all relevant outbound parameters are processed consistently.

cmd/zetae2e/local/local.go (1)

365-365: Ensure checkTrackers is called in the appropriate context.

The checkTrackers function should be called in a context where it makes sense to validate the absence of outbound trackers. Ensure this is the correct place.

x/crosschain/keeper/msg_server_vote_outbound_tx_test.go (2)

520-520: Update function call to match the new signature for successful outbound.

The SaveSuccessfulOutbound function call should be updated to match the new simplified signature.

- k.SaveSuccessfulOutbound(ctx, cctx)
+ k.SaveSuccessfulOutbound(ctx, cctx)

Likely invalid or redundant comment.


530-553: Update function call to match the new signature for multiple successful trackers.

The SaveSuccessfulOutbound function call should be updated to match the new simplified signature.

- k.SaveSuccessfulOutbound(ctx, cctx)
+ k.SaveSuccessfulOutbound(ctx, cctx)

Likely invalid or redundant comment.

x/crosschain/types/cctx_test.go Show resolved Hide resolved
cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.35%. Comparing base (d94047a) to head (10d601c).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2615      +/-   ##
===========================================
- Coverage    70.35%   70.35%   -0.01%     
===========================================
  Files          338      338              
  Lines        18594    18593       -1     
===========================================
- Hits         13082    13081       -1     
  Misses        4920     4920              
  Partials       592      592              
Files Coverage Δ
x/crosschain/keeper/msg_server_vote_outbound_tx.go 92.30% <100.00%> (-0.25%) ⬇️
x/crosschain/types/cctx.go 94.02% <100.00%> (+0.09%) ⬆️

cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
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.

Fixes setting the ballot index properly for cases when a revert is added . (previously the ballot index was getting set to the revert tx instead of the original outbound )

What is the change reflecting this?

cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
x/observer/keeper/pending_nonces_test.go Outdated Show resolved Hide resolved
x/observer/keeper/pending_nonces_test.go Outdated Show resolved Hide resolved
x/crosschain/types/cctx.go Show resolved Hide resolved
@kingpinXD
Copy link
Contributor Author

Fixes setting the ballot index properly for cases when a revert is added . (previously the ballot index was getting set to the revert tx instead of the original outbound )

What is the change reflecting this?

https://github.com/zeta-chain/zeta-node/blob/22f14acd3f5e32aeb370866cb6f3ab2576865fe5/x/crosschain/keeper/msg_server_vote_outbound_tx.go#L93-L94

Earlier this ballot was set in the SaveOutbound.
In case if a revert was added , the ballot index for outboundParam[0] was in fact added to outboundParam[1]

@lumtis lumtis changed the title refactor: tracker cleanup refactor: delete all trackers when finalizing CCTX Aug 5, 2024
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.

LGTM
@kingpinXD please use explicit PR title

@kingpinXD
Copy link
Contributor Author

LGTM @kingpinXD please use explicit PR title

@lumtis could you give me an example of what you mean, Imo the title reflects the change
Are you referring to the fact that pending nonces are also cleaned ? ( I did not add that in as the change keeps the same behaviour as before )

@lumtis
Copy link
Member

lumtis commented Aug 6, 2024

LGTM @kingpinXD please use explicit PR title

@lumtis could you give me an example of what you mean, Imo the title reflects the change Are you referring to the fact that pending nonces are also cleaned ? ( I did not add that in as the change keeps the same behaviour as before )

I changed the name from tracker cleanup to delete all trackers when finalizing CCTX before putting this comment.
tracker cleanup doesn't allow to understand the change by looking at PR title.

@kingpinXD
Copy link
Contributor Author

LGTM @kingpinXD please use explicit PR title

@lumtis could you give me an example of what you mean, Imo the title reflects the change Are you referring to the fact that pending nonces are also cleaned ? ( I did not add that in as the change keeps the same behaviour as before )

I changed the name from tracker cleanup to delete all trackers when finalizing CCTX before putting this comment. tracker cleanup doesn't allow to understand the change by looking at PR title.

okay that makes sense , thanks for the edit .
Got confused that you were requesting a further change

@kingpinXD kingpinXD added this pull request to the merge queue Aug 6, 2024
Merged via the queue into develop with commit e7fe02f Aug 6, 2024
28 checks passed
@kingpinXD kingpinXD deleted the outbound-tracker-cleanup branch August 6, 2024 20:34
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.

Remove all trackers for a cctx when finalizing
4 participants