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

feat: (BitcoinRBF-Step1) zetacore feeds latest gas price to pending Bitcoin CCTXs #3377

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jan 17, 2025

Description

The problem:

If a tx gets broadcasted to Bitcoin network using latest fee rate, it is less likely to get stuck. In most cases, an outbound tx got stuck when zetaclient had used an outdated lower fee rate in CCTX to send it out to Bitcoin network.

Bitcoin block time is 10 mins and much longer than other chains. When a Bitcoin tx gets stuck, it can sit in the mempool for hours or days depending on traffic. Reducing the chance of having txs stuck in mempool will address the problem at its root cause. RBF will come as the last remedy.

One of the long-term directions that guide us would be lowering the cross-chain gas fee. The gas price in the CCTX indicates how much gas was paid initially on the withdrawal. An outdated gas price should not guild TSS signers to file an outbound tx which will lead to either an overpaid or long pending outbound tx.

We already had the BTCOutboundGasPriceMultiplier = 2.0 to try avoid stuck outbound in mempool but we still have stuck txs since mainnet launch. This also explains why an outdated gas price misleads TSS signers. This multiplier needs to reduce to some level, like 1.2 to balance the quick finality and unnecessary high withdrawal fees.

The thoughts:

  • Have zetacore feed latest fee rate (every 10 mins) to pending Bitcoin CCTXs in the method CheckAndUpdateCCTXGasPriceBTC.
  • Say we have 10 pending cctxs CCTX1, CCTX2, CCTX3, CCTX4,... CCTX10 in zetacore, and zetaclient have broadcasted 4 outbounds [TX1, TX2, TX3, TX4] and they all get stuck in mempool, so keysign stopped already.
  • zetacore has no idea of what had happened for these 10 pending CCTXs. Maybe outbound is pending in mempool (it is just a guess), Maybe TSS signers are not working smoothly, or maybe the RPC is down, nobody knows.
  • In order to clear these 4 txs in mempool, only TX4 needs to be bumped, so that the average fee rate of the 4 txs will increase, making them a marketable package for miners.
  • In order to perform fee bumping on Tx4, zetaclient needs to know the latest fee rate, so it can bump the gas fee that accurately aligns with market.

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

Release Notes

  • New Features

    • Enhanced gas price management for cross-chain transactions, allowing Zetacore to feed the latest gas prices to pending Bitcoin cross-chain transactions
    • Improved support for gas price updates across different blockchain networks
  • Improvements

    • Refined gas price update mechanisms for EVM and Bitcoin chains
    • Updated naming conventions for cross-chain transaction gas price functions
    • Added more robust error handling for gas price updates
  • Technical Updates

    • Modified Bitcoin address handling in test utilities
    • Introduced new methods for chain-specific gas price calculations

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Caution

Review failed

The head commit changed during the review from ef21aa2 to 0275db0.


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>, please review it.
    • 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 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@ws4charlie ws4charlie changed the title feat(Bitcoin-RBF-Step-1):zetacore feeds latest gas price to pending Bitcoin CCTXs feat(BitcoinRBFStep1):zetacore feeds latest gas price to pending Bitcoin CCTXs Jan 17, 2025
@ws4charlie ws4charlie changed the title feat(BitcoinRBFStep1):zetacore feeds latest gas price to pending Bitcoin CCTXs feat: (BitcoinRBF-Step1) zetacore feeds latest gas price to pending Bitcoin CCTXs Jan 17, 2025
@ws4charlie ws4charlie marked this pull request as ready for review January 17, 2025 22:17
@ws4charlie ws4charlie requested a review from a team as a code owner January 17, 2025 22:17
@ws4charlie ws4charlie added zetacore Issues related to ZetaCore chain:bitcoin Bitcoin chain related labels Jan 17, 2025
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

🧹 Nitpick comments (5)
x/observer/types/crosschain_flags.go (1)

8-10: LGTM! Consider adding documentation about the rationale.

The switch from block-based to time-based intervals is well-aligned with Bitcoin's characteristics. The 10-minute retry interval matches Bitcoin's average block time.

Consider adding a comment explaining why 10 minutes was chosen as the retry interval, relating it to Bitcoin's average block time.

testutil/sample/crypto.go (1)

106-111: LGTM! Well-structured script generation function.

The new function properly generates P2WPKH scripts with appropriate error handling.

Consider adding a comment explaining that this is specifically for testing purposes and shouldn't be used in production code.

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

204-217: Add documentation for Bitcoin fee rate implementation.

The repurposing of GasPriorityFee for Bitcoin fee rate should be documented more clearly. Consider adding a comment explaining that in Bitcoin's context, this field stores the fee rate in sat/vB.

 // CheckAndUpdateCCTXGasPriceBTC updates the fee rate for the given Bitcoin chain CCTX
+// Note: Bitcoin does not have a priority fee concept. The GasPriorityFee field is
+// repurposed to store the current fee rate in satoshis per virtual byte (sat/vB).
 func CheckAndUpdateCCTXGasPriceBTC(

219-231: Consider using constants for supported chains.

The chain support logic is clear, but consider defining constants for supported chain types to make maintenance easier and prevent magic numbers.

+// Supported chain types for gas price updates
+const (
+    ChainTypeEVM     = "evm"
+    ChainTypeBitcoin = "bitcoin"
+    ChainTypeZeta    = "zeta"
+)

 func IsCCTXGasPriceUpdateSupported(chainID int64, additionalChains []zetachains.Chain) bool {
     switch {
     case zetachains.IsZetaChain(chainID, additionalChains):
         return false
     case zetachains.IsEVMChain(chainID, additionalChains):
         return true
     case zetachains.IsBitcoinChain(chainID, additionalChains):
         return true
     default:
         return false
     }
 }
x/crosschain/keeper/abci_test.go (1)

609-672: Add edge cases to Bitcoin gas price tests.

While the basic functionality is well tested, consider adding edge cases such as:

  • Zero fee rate handling
  • Maximum fee rate handling
  • Invalid fee rate handling
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bdfc0b and ef21aa2.

📒 Files selected for processing (8)
  • changelog.md (1 hunks)
  • testutil/sample/crypto.go (2 hunks)
  • x/crosschain/keeper/abci.go (5 hunks)
  • x/crosschain/keeper/abci_test.go (11 hunks)
  • x/crosschain/module.go (1 hunks)
  • x/crosschain/types/cctx_test.go (1 hunks)
  • x/crosschain/types/revert_options_test.go (1 hunks)
  • x/observer/types/crosschain_flags.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
x/observer/types/crosschain_flags.go (1)

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

x/crosschain/module.go (1)

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

x/crosschain/types/revert_options_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_test.go (1)

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

testutil/sample/crypto.go (1)

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

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

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

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

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

🔇 Additional comments (8)
x/crosschain/types/revert_options_test.go (1)

52-52: LGTM! Clean adaptation to the new BtcAddressP2WPKH return type.

The test correctly handles the new return type by explicitly converting the address to string format.

x/crosschain/module.go (1)

175-175: LGTM! Consistent naming convention applied.

The method name change follows Go's convention of treating acronyms as single words in camelCase (CCTX → CCTx).

testutil/sample/crypto.go (1)

95-104: LGTM! Enhanced type safety with structured address type.

The return type change from string to *btcutil.AddressWitnessPubKeyHash improves type safety and provides direct access to address functionality.

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

22-24: LGTM! Function type renamed following Go conventions.

The renaming of CheckAndUpdateCctxGasPriceFunc to CheckAndUpdateCCTXGasPriceFunc follows Go's standard naming convention for acronyms.


Line range hint 30-102: LGTM! Robust implementation of gas price update logic.

The implementation correctly:

  • Fetches and validates gas price increase flags
  • Iterates through supported chains
  • Handles errors appropriately
  • Emits typed events for gas price increases
x/crosschain/types/cctx_test.go (1)

143-143: LGTM! Improved Bitcoin address handling in tests.

The change correctly uses the string representation of the Bitcoin address, ensuring proper address format handling in tests.

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

674-729: LGTM! Comprehensive chain support test coverage.

The test cases thoroughly cover all supported and unsupported chains, ensuring proper gas price update behavior.

changelog.md (1)

5-8: LGTM! Clear and concise feature documentation.

The changelog entry clearly describes the new Bitcoin gas price update feature.

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 81.66667% with 11 lines in your changes missing coverage. Please review.

Project coverage is 63.25%. Comparing base (4bdfc0b) to head (0275db0).

Files with missing lines Patch % Lines
x/crosschain/keeper/abci.go 81.66% 9 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3377      +/-   ##
===========================================
+ Coverage    63.22%   63.25%   +0.02%     
===========================================
  Files          436      436              
  Lines        30636    30664      +28     
===========================================
+ Hits         19369    19395      +26     
- Misses       10432    10434       +2     
  Partials       835      835              
Files with missing lines Coverage Δ
x/observer/types/crosschain_flags.go 100.00% <ø> (ø)
x/crosschain/keeper/abci.go 80.43% <81.66%> (+3.16%) ⬆️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chain:bitcoin Bitcoin chain related zetacore Issues related to ZetaCore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant