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: special handle Bitcoin Testnet gas price estimator #2452

Merged
merged 4 commits into from
Jul 11, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jul 8, 2024

Description

Closes: 2386

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

    • Enhanced gas price posting for Bitcoin networks, including testnet and privnet.
    • Added logic to handle fee rates for different Bitcoin network types.
  • Bug Fixes

    • Improved fee rate retrieval and error handling in Bitcoin RPC.
  • Tests

    • Updated live tests to use specific chain IDs for Bitcoin networks.
    • Added a new test function for recent fee rate retrieval.
  • Documentation

    • Updated changelog to reflect new handling for Bitcoin testnet gas price estimator.

@ws4charlie ws4charlie marked this pull request as ready for review July 8, 2024 18:58
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

The recent changes introduced new functionality to handle Bitcoin gas price estimation for different network types, specifically privnet and testnet. This involved refactoring the PostGasPrice function and adding new constants and a function to calculate recent fee rates. Additionally, test functions were updated to use specific chain IDs, and a new test was added for recent fee rate retrieval. The changelog acknowledges a new feature addressing the Bitcoin testnet gas price estimator.

Changes

File Path Change Summary
zetaclient/chains/bitcoin/observer/observer.go Added import for rpc, refactored PostGasPrice to handle network types via specialHandleFeeRate function.
zetaclient/chains/bitcoin/rpc/rpc.go Introduced constants for fee rate calculation and added GetRecentFeeRate function.
zetaclient/chains/bitcoin/rpc/rpc_live_test.go Renamed getRPCClient to createRPCClient, updated test functions to use chain IDs, and added a new test for fee rate.
changelog.md Added a note on the new feature for the Bitcoin testnet gas price estimator.

Poem

In the world of code, where Bitcoin thrives,
Refactored gas prices now arrive.
For testnets and privnets, with care,
Fee rates calculated, changes to share.
Rabbits dance in glee, as functions align,
Code flows smoother, oh what a sign!


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

github-actions bot commented Jul 8, 2024

!!!WARNING!!!
nosec detected in the following files: zetaclient/chains/bitcoin/rpc/rpc.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 8, 2024
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 46 lines in your changes missing coverage. Please review.

Project coverage is 68.94%. Comparing base (9a527f9) to head (d092698).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2452      +/-   ##
===========================================
- Coverage    69.05%   68.94%   -0.12%     
===========================================
  Files          308      308              
  Lines        19192    19223      +31     
===========================================
  Hits         13253    13253              
- Misses        5264     5295      +31     
  Partials       675      675              
Files Coverage Δ
zetaclient/chains/bitcoin/rpc/rpc.go 0.00% <0.00%> (ø)
zetaclient/chains/bitcoin/observer/observer.go 33.92% <0.00%> (-1.14%) ⬇️

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: 3

Outside diff range and nitpick comments (1)
changelog.md (1)

92-92: Fix typographical issue: Add hyphen in "cherry-picked".

The term "cherry picked" should be hyphenated as "cherry-picked".

- * [2396](https://github.com/zeta-chain/node/issues/2386) - special handle bitcoin testnet gas price estimator
+ * [2396](https://github.com/zeta-chain/node/issues/2386) - special handle bitcoin testnet gas price estimator
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f45a56b and f7656f5.

Files selected for processing (4)
  • changelog.md (1 hunks)
  • zetaclient/chains/bitcoin/observer/observer.go (3 hunks)
  • zetaclient/chains/bitcoin/rpc/rpc.go (2 hunks)
  • zetaclient/chains/bitcoin/rpc/rpc_live_test.go (9 hunks)
Additional context used
Path-based instructions (3)
zetaclient/chains/bitcoin/rpc/rpc.go (1)

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

zetaclient/chains/bitcoin/rpc/rpc_live_test.go (1)

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

zetaclient/chains/bitcoin/observer/observer.go (1)

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

GitHub Check: codecov/patch
zetaclient/chains/bitcoin/rpc/rpc.go

[warning] 122-125: zetaclient/chains/bitcoin/rpc/rpc.go#L122-L125
Added lines #L122 - L125 were not covered by tests


[warning] 129-130: zetaclient/chains/bitcoin/rpc/rpc.go#L129-L130
Added lines #L129 - L130 were not covered by tests


[warning] 132-134: zetaclient/chains/bitcoin/rpc/rpc.go#L132-L134
Added lines #L132 - L134 were not covered by tests


[warning] 136-138: zetaclient/chains/bitcoin/rpc/rpc.go#L136-L138
Added lines #L136 - L138 were not covered by tests


[warning] 142-144: zetaclient/chains/bitcoin/rpc/rpc.go#L142-L144
Added lines #L142 - L144 were not covered by tests


[warning] 146-147: zetaclient/chains/bitcoin/rpc/rpc.go#L146-L147
Added lines #L146 - L147 were not covered by tests


[warning] 152-153: zetaclient/chains/bitcoin/rpc/rpc.go#L152-L153
Added lines #L152 - L153 were not covered by tests


[warning] 157-157: zetaclient/chains/bitcoin/rpc/rpc.go#L157
Added line #L157 was not covered by tests

zetaclient/chains/bitcoin/observer/observer.go

[warning] 346-347: zetaclient/chains/bitcoin/observer/observer.go#L346-L347
Added lines #L346 - L347 were not covered by tests


[warning] 638-641: zetaclient/chains/bitcoin/observer/observer.go#L638-L641
Added lines #L638 - L641 were not covered by tests


[warning] 644-646: zetaclient/chains/bitcoin/observer/observer.go#L644-L646
Added lines #L644 - L646 were not covered by tests


[warning] 648-652: zetaclient/chains/bitcoin/observer/observer.go#L648-L652
Added lines #L648 - L652 were not covered by tests


[warning] 654-655: zetaclient/chains/bitcoin/observer/observer.go#L654-L655
Added lines #L654 - L655 were not covered by tests


[warning] 659-661: zetaclient/chains/bitcoin/observer/observer.go#L659-L661
Added lines #L659 - L661 were not covered by tests


[warning] 664-664: zetaclient/chains/bitcoin/observer/observer.go#L664
Added line #L664 was not covered by tests

LanguageTool
changelog.md

[misspelling] ~89-~89: This word is normally spelled with a hyphen.
Context: ...//pull/2327) - partially cherry picked the fix to Bitcoin outbound dust amount...

(EN_COMPOUNDS_CHERRY_PICKED)

Additional comments not posted (3)
zetaclient/chains/bitcoin/rpc/rpc.go (1)

18-22: Constants look good.

The constants feeRateCountBackBlocks and defaultTestnetFeeRate are clear and appropriate for their intended use.

zetaclient/chains/bitcoin/rpc/rpc_live_test.go (2)

Line range hint 94-112:
Function changes look good.

The createRPCClient function improvements enhance maintainability by using chain IDs from the chains package instead of hardcoding values.


420-430: Test function looks good.

The LiveTestGetRecentFeeRate function is straightforward and includes necessary assertions to validate the results.

zetaclient/chains/bitcoin/rpc/rpc.go Outdated Show resolved Hide resolved
zetaclient/chains/bitcoin/observer/observer.go Outdated Show resolved Hide resolved
zetaclient/chains/bitcoin/observer/observer.go Outdated Show resolved Hide resolved
@ronaldoguedess
Copy link

👏🏻👏🏻

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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f7656f5 and 3dc39b6.

Files selected for processing (2)
  • zetaclient/chains/bitcoin/observer/observer.go (3 hunks)
  • zetaclient/chains/bitcoin/rpc/rpc.go (2 hunks)
Additional context used
Path-based instructions (2)
zetaclient/chains/bitcoin/rpc/rpc.go (1)

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

zetaclient/chains/bitcoin/observer/observer.go (1)

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

GitHub Check: codecov/patch
zetaclient/chains/bitcoin/rpc/rpc.go

[warning] 123-126: zetaclient/chains/bitcoin/rpc/rpc.go#L123-L126
Added lines #L123 - L126 were not covered by tests


[warning] 130-131: zetaclient/chains/bitcoin/rpc/rpc.go#L130-L131
Added lines #L130 - L131 were not covered by tests


[warning] 133-135: zetaclient/chains/bitcoin/rpc/rpc.go#L133-L135
Added lines #L133 - L135 were not covered by tests


[warning] 137-139: zetaclient/chains/bitcoin/rpc/rpc.go#L137-L139
Added lines #L137 - L139 were not covered by tests


[warning] 143-145: zetaclient/chains/bitcoin/rpc/rpc.go#L143-L145
Added lines #L143 - L145 were not covered by tests


[warning] 147-148: zetaclient/chains/bitcoin/rpc/rpc.go#L147-L148
Added lines #L147 - L148 were not covered by tests


[warning] 153-154: zetaclient/chains/bitcoin/rpc/rpc.go#L153-L154
Added lines #L153 - L154 were not covered by tests


[warning] 158-158: zetaclient/chains/bitcoin/rpc/rpc.go#L158
Added line #L158 was not covered by tests

zetaclient/chains/bitcoin/observer/observer.go

[warning] 345-346: zetaclient/chains/bitcoin/observer/observer.go#L345-L346
Added lines #L345 - L346 were not covered by tests


[warning] 349-350: zetaclient/chains/bitcoin/observer/observer.go#L349-L350
Added lines #L349 - L350 were not covered by tests


[warning] 352-352: zetaclient/chains/bitcoin/observer/observer.go#L352
Added line #L352 was not covered by tests


[warning] 355-355: zetaclient/chains/bitcoin/observer/observer.go#L355
Added line #L355 was not covered by tests


[warning] 357-357: zetaclient/chains/bitcoin/observer/observer.go#L357
Added line #L357 was not covered by tests


[warning] 359-359: zetaclient/chains/bitcoin/observer/observer.go#L359
Added line #L359 was not covered by tests


[warning] 362-363: zetaclient/chains/bitcoin/observer/observer.go#L362-L363
Added lines #L362 - L363 were not covered by tests


[warning] 365-366: zetaclient/chains/bitcoin/observer/observer.go#L365-L366
Added lines #L365 - L366 were not covered by tests


[warning] 368-368: zetaclient/chains/bitcoin/observer/observer.go#L368
Added line #L368 was not covered by tests


[warning] 378-378: zetaclient/chains/bitcoin/observer/observer.go#L378
Added line #L378 was not covered by tests


[warning] 380-380: zetaclient/chains/bitcoin/observer/observer.go#L380
Added line #L380 was not covered by tests


[warning] 647-649: zetaclient/chains/bitcoin/observer/observer.go#L647-L649
Added lines #L647 - L649 were not covered by tests


[warning] 651-655: zetaclient/chains/bitcoin/observer/observer.go#L651-L655
Added lines #L651 - L655 were not covered by tests


[warning] 657-659: zetaclient/chains/bitcoin/observer/observer.go#L657-L659
Added lines #L657 - L659 were not covered by tests

Additional comments not posted (3)
zetaclient/chains/bitcoin/rpc/rpc.go (1)

123-159: Function implementation looks good.

The GetRecentFeeRate function is well-structured and includes necessary error handling.

Tools
GitHub Check: codecov/patch

[warning] 123-126: zetaclient/chains/bitcoin/rpc/rpc.go#L123-L126
Added lines #L123 - L126 were not covered by tests


[warning] 130-131: zetaclient/chains/bitcoin/rpc/rpc.go#L130-L131
Added lines #L130 - L131 were not covered by tests


[warning] 133-135: zetaclient/chains/bitcoin/rpc/rpc.go#L133-L135
Added lines #L133 - L135 were not covered by tests


[warning] 137-139: zetaclient/chains/bitcoin/rpc/rpc.go#L137-L139
Added lines #L137 - L139 were not covered by tests


[warning] 143-145: zetaclient/chains/bitcoin/rpc/rpc.go#L143-L145
Added lines #L143 - L145 were not covered by tests


[warning] 147-148: zetaclient/chains/bitcoin/rpc/rpc.go#L147-L148
Added lines #L147 - L148 were not covered by tests


[warning] 153-154: zetaclient/chains/bitcoin/rpc/rpc.go#L153-L154
Added lines #L153 - L154 were not covered by tests


[warning] 158-158: zetaclient/chains/bitcoin/rpc/rpc.go#L158
Added line #L158 was not covered by tests

zetaclient/chains/bitcoin/observer/observer.go (2)

345-380: Function changes look good.

The PostGasPrice function correctly delegates special handling to the new specialHandleFeeRate function for non-mainnet network types.

Tools
GitHub Check: codecov/patch

[warning] 345-346: zetaclient/chains/bitcoin/observer/observer.go#L345-L346
Added lines #L345 - L346 were not covered by tests


[warning] 349-350: zetaclient/chains/bitcoin/observer/observer.go#L349-L350
Added lines #L349 - L350 were not covered by tests


[warning] 352-352: zetaclient/chains/bitcoin/observer/observer.go#L352
Added line #L352 was not covered by tests


[warning] 355-355: zetaclient/chains/bitcoin/observer/observer.go#L355
Added line #L355 was not covered by tests


[warning] 357-357: zetaclient/chains/bitcoin/observer/observer.go#L357
Added line #L357 was not covered by tests


[warning] 359-359: zetaclient/chains/bitcoin/observer/observer.go#L359
Added line #L359 was not covered by tests


[warning] 362-363: zetaclient/chains/bitcoin/observer/observer.go#L362-L363
Added lines #L362 - L363 were not covered by tests


[warning] 365-366: zetaclient/chains/bitcoin/observer/observer.go#L365-L366
Added lines #L365 - L366 were not covered by tests


[warning] 368-368: zetaclient/chains/bitcoin/observer/observer.go#L368
Added line #L368 was not covered by tests


[warning] 378-378: zetaclient/chains/bitcoin/observer/observer.go#L378
Added line #L378 was not covered by tests


[warning] 380-380: zetaclient/chains/bitcoin/observer/observer.go#L380
Added line #L380 was not covered by tests


647-661: Function implementation looks good.

The specialHandleFeeRate function is well-structured and includes necessary error handling.

Tools
GitHub Check: codecov/patch

[warning] 647-649: zetaclient/chains/bitcoin/observer/observer.go#L647-L649
Added lines #L647 - L649 were not covered by tests


[warning] 651-655: zetaclient/chains/bitcoin/observer/observer.go#L651-L655
Added lines #L651 - L655 were not covered by tests


[warning] 657-659: zetaclient/chains/bitcoin/observer/observer.go#L657-L659
Added lines #L657 - L659 were not covered by tests

zetaclient/chains/bitcoin/rpc/rpc.go Show resolved Hide resolved
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 3dc39b6 and 570fe7e.

Files selected for processing (1)
  • zetaclient/chains/bitcoin/observer/observer.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • zetaclient/chains/bitcoin/observer/observer.go

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 570fe7e and d092698.

Files selected for processing (1)
  • changelog.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • changelog.md

@lumtis lumtis added this pull request to the merge queue Jul 11, 2024
Merged via the queue into develop with commit ce8afec Jul 11, 2024
28 of 30 checks passed
@lumtis lumtis deleted the fix-btc-testnet-gas-estimator branch July 11, 2024 14:50
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.

fix: lower Bitcoin testnet3 fee rate by modifying the gas estimator
4 participants