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(crosschain): store priorityFee (GasTipCap) for EVM chains #2483

Merged
merged 23 commits into from
Jul 24, 2024

Conversation

swift1337
Copy link
Contributor

@swift1337 swift1337 commented Jul 15, 2024

Description

This PR adds priorityFee from EIP-1559 to ZetaChain state. Updates:

  • Added uint64 priorityFee to MsgVoteGasPrice so observers can propose priority fees from rpc.SuggestGasTipCap()
  • Added []uint64 priority_fee to crosschain.types.GasPrice{}. The logic is the same: we pick median price
  • Added string cctx.outbound_params.gas_priority_fee (same as string cctx.outbound_params.gas_priority_fee)
  • Minor refactoring in x/crosschain

Note that this PR unblocks #2387 which actually signs and broadcasts transactions with priority fees

Part of #1952

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

    • Introduced priorityFee for EIP-1559 transactions to enhance gas fee handling.
  • Enhancements

    • Updated various CLI commands and message structs to replace the supply parameter with priorityFee.
    • Improved error handling and message formatting in several functions.
  • Bug Fixes

    • Fixed field assignments and updated test cases for gas price management.
  • Documentation

    • Updated documentation to reflect changes related to priorityFee and gas price.
  • Refactor

    • Refactored multiple functions to include and handle priorityFee for gas calculations and transactions.

# Conflicts:
#	x/crosschain/keeper/msg_server_vote_gas_price.go
#	zetaclient/chains/bitcoin/observer/observer.go
#	zetaclient/chains/evm/observer/observer.go
#	zetaclient/chains/interfaces/interfaces.go
#	zetaclient/testutils/mocks/zetacore_client.go
#	zetaclient/zetacore/tx.go
#	zetaclient/zetacore/tx_test.go
@swift1337 swift1337 self-assigned this Jul 15, 2024
Copy link
Contributor

coderabbitai bot commented Jul 15, 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 primarily introduce the concept of priorityFee for gas calculations across various components of the system. This involves replacing the supply parameter with priorityFee in several places, updating message structures, protobuf definitions, and adjusting related functions and tests to accommodate this new approach. The update enhances the handling of EIP-1559 gas fees, improving the system's efficiency and accuracy in gas fee calculations.

Changes

File Path / Group Change Summary
changelog.md Added details about the introduction of priorityFee (gasTipCap) gas to the state.
docs/... Updated documentation to reflect the renaming of supply to priorityFee and additional fields for EIP-1559 priority fees.
proto/... Modified protobuf definitions to include priority_fee and related fields, removing supply.
testutil/network/genesis_state.go Included PriorityFees field in the GasPrice struct and reordered existing fields.
typescript/... Updated TypeScript definitions to add properties related to priorityFee and reflect the new gas fee structure.
x/crosschain/client/cli/... Changed CLI command to accept priorityFee instead of supply, with enhanced error handling.
x/crosschain/keeper/... Refactored multiple functions to handle priorityFee, updated error handling, and added new logic for gas fee calculations.
x/crosschain/types/... Added GasPriorityFee field in CrossChainTx struct creation and updated related message functions.
zetaclient/chains/... Updated observer methods to retrieve priorityFee and replaced supply with priorityFee in gas price voting calls.
zetaclient/testutils/mocks/... Modified mock client function signatures to accept priorityFee instead of supply.
zetaclient/zetacore/... Updated function logic to use priorityFee for constructing gas price vote messages.

Poem

🐇 In the land of code, where bytes take flight,
Priority fees now guide the light.
From fields of gas, old `supply` does fade,
A streamlined path, for fees well-paid.
EIP-1559, the beacon bright,
With changes swift, we reach new height.
Hopping through code, with joy we see,
A world improved by `priorityFee`.

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.

Copy link

!!!WARNING!!!
nosec detected in the following files: x/crosschain/keeper/msg_server_vote_gas_price.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
@swift1337
Copy link
Contributor Author

zetacored q crosschain show-gas-price 1337 -o json | jq
{
  "GasPrice": {
    "creator": "zeta1uk8yhdcenf60xwd5s429774mgmy2vu3qva2kt3",
    "index": "1337",
    "chain_id": "1337",
    "signers": [
      "zeta1uk8yhdcenf60xwd5s429774mgmy2vu3qva2kt3",
      "zeta16dwp2r6eccp2xw2mnyp3gmuwdlgxmvmtr8562a"
    ],
    "block_nums": [
      "707",
      "706"
    ],
    "prices": [
      "9",
      "9"
    ],
    "median_index": "1",
    "priority_fees": [
      "1",
      "1"
    ]
  }
}

@swift1337 swift1337 marked this pull request as ready for review July 15, 2024 16:21
Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 65.33865% with 87 lines in your changes missing coverage. Please review.

Project coverage is 46.68%. Comparing base (960da02) to head (b6305d4).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2483      +/-   ##
===========================================
+ Coverage    46.58%   46.68%   +0.09%     
===========================================
  Files          461      464       +3     
  Lines        30666    30781     +115     
===========================================
+ Hits         14286    14369      +83     
- Misses       15533    15557      +24     
- Partials       847      855       +8     
Files Coverage Δ
pkg/math/cosmos_uint.go 100.00% <100.00%> (ø)
pkg/math/slice.go 100.00% <100.00%> (ø)
x/crosschain/keeper/cctx_gateway_observers.go 100.00% <100.00%> (ø)
x/crosschain/keeper/gas_price.go 100.00% <100.00%> (ø)
...osschain/keeper/grpc_query_zeta_conversion_rate.go 100.00% <100.00%> (ø)
.../crosschain/keeper/msg_server_migrate_tss_funds.go 83.66% <100.00%> (+0.10%) ⬆️
x/crosschain/types/cctx.go 93.93% <100.00%> (+0.04%) ⬆️
x/crosschain/types/message_vote_gas_price.go 100.00% <100.00%> (ø)
zetaclient/chains/evm/observer/observer.go 50.95% <100.00%> (+8.72%) ⬆️
zetaclient/zetacore/client_vote.go 56.48% <100.00%> (ø)
... and 8 more

@swift1337
Copy link
Contributor Author

@lumtis @ws4charlie In some cases in x/crosschain, we alter cctx.outbound_params and bump gasPrice by either some percent or by a factor of x2. I kept priorityFee the same without changes. Should I apply those factors to priorityFee as well?

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

Outside diff range, codebase verification and nitpick comments (8)
x/crosschain/types/message_vote_gas_price.go (1)

13-17: Add documentation for the new priorityFee parameter.

The priorityFee parameter should be documented to explain its purpose and usage.

+ //   - PriorityFee: The priority fee for EVM chains supporting EIP-1559.
typescript/zetachain/zetacore/crosschain/gas_price_pb.d.ts (1)

44-45: Add documentation for the new priorityFees field.

The priorityFees field is missing documentation. Adding a brief comment will improve code readability and maintainability.

/**
 * priority fees for EIP-1559
 *
 * @generated from field: repeated uint64 priority_fees = 8;
 */
priorityFees: bigint[];

Also applies to: 50-56

x/crosschain/client/cli/cli_gas_price.go (1)

81-81: Update the command usage description to include priorityFee.

The usage description should be updated to reflect the new priorityFee parameter.

Use:   "vote-gas-price [chain] [price] [priorityFee] [blockNumber]",
x/crosschain/keeper/gas_price.go (1)

39-51: Ensure complete test coverage for GetMedianGasPriceInUint function.

The function GetMedianGasPriceInUint is tested in two files:

  • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go: This file includes tests that handle the additional return value priorityFee.
  • x/crosschain/keeper/abci_test.go: This file does not include tests for the priorityFee return value.

Please add test cases in x/crosschain/keeper/abci_test.go to cover the priorityFee return value.

Analysis chain

Ensure test coverage for GetMedianGasPriceInUint function.

The GetMedianGasPriceInUint function now returns an additional parameter. Ensure that the test cases cover this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test coverage for the `GetMedianGasPriceInUint` function.

# Test: Search for the function usage in test files. Expect: Test cases should handle the additional return value.
rg --type go -A 5 $'GetMedianGasPriceInUint' --glob '*_test.go'

Length of output: 1561

docs/spec/crosschain/messages.md (1)

64-64: Avoid using hard tabs in markdown files.

Replace hard tabs with spaces for better readability and consistency.

-	uint64 priority_fee = 6;
+    uint64 priority_fee = 6;
Tools
Markdownlint

64-64: Column: 1
Hard tabs

(MD010, no-hard-tabs)

zetaclient/chains/evm/observer/observer.go (3)

349-351: Ensure test coverage for PostVoteGasPrice with priorityFee.

The current test cases do not cover the PostVoteGasPrice function with a non-zero priorityFee. Please add test cases that include calls to PostVoteGasPrice with a non-zero priorityFee to ensure proper test coverage.

  • zetaclient/zetacore/tx_test.go
Analysis chain

Ensure test coverage for PostVoteGasPrice with priorityFee.

The lines where PostVoteGasPrice is called with priorityFee should be covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for `PostVoteGasPrice` with `priorityFee`.

# Test: Search for test cases where `PostVoteGasPrice` is called with `priorityFee`. Expect: At least one test case calling `PostVoteGasPrice` with `priorityFee`.
rg --type go 'PostVoteGasPrice.*priorityFee'

Length of output: 532


Script:

#!/bin/bash
# Description: Verify test coverage for `PostVoteGasPrice` with `priorityFee`.

# Search for test files that call the `PostVoteGasPrice` function.
rg --type go 'PostVoteGasPrice' -g '*_test.go' -A 3

Length of output: 323

Tools
GitHub Check: codecov/patch

[warning] 349-351: zetaclient/chains/evm/observer/observer.go#L349-L351
Added lines #L349 - L351 were not covered by tests


336-338: Ensure test coverage for SuggestGasTipCap failure scenario.

The failure scenario for SuggestGasTipCap is not explicitly tested in the codebase. Please add test cases to cover this scenario.

  • File: zetaclient/chains/evm/observer/observer.go
  • Lines: 336-338
Analysis chain

Ensure test coverage for SuggestGasTipCap failure scenario.

The lines where SuggestGasTipCap is called and its failure is handled should be covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for `SuggestGasTipCap` failure scenario.

# Test: Search for test cases where `SuggestGasTipCap` failure is simulated. Expect: At least one test case simulating the failure.
rg --type go 'SuggestGasTipCap.*return.*error'

Length of output: 48


Script:

#!/bin/bash
# Description: Verify test coverage for `SuggestGasTipCap` failure scenario.

# Test: Search for test cases where `SuggestGasTipCap` failure is simulated or handled.
# This includes looking for any error handling related to `SuggestGasTipCap`.

# Search for any usage of `SuggestGasTipCap` in test files.
rg --type go 'SuggestGasTipCap' -A 5

Length of output: 4007


Script:

#!/bin/bash
# Description: Verify test coverage for `SuggestGasTipCap` failure scenario.

# Test: Search for test cases in `rpc/backend/chain_info_test.go` that handle errors from `SuggestGasTipCap`.

# Search for error handling in `rpc/backend/chain_info_test.go`.
rg 'SuggestGasTipCap.*err' rpc/backend/chain_info_test.go -A 5

Length of output: 64


Script:

#!/bin/bash
# Description: Verify test coverage for `SuggestGasTipCap` failure scenario.

# Test: Search for any test files that handle errors from `SuggestGasTipCap` across the entire codebase.

# Search for error handling related to `SuggestGasTipCap` in test files.
rg 'SuggestGasTipCap.*err' -t go -g '*_test.go' -A 5

Length of output: 54

Tools
GitHub Check: codecov/patch

[warning] 336-338: zetaclient/chains/evm/observer/observer.go#L336-L338
Added lines #L336 - L338 were not covered by tests


340-340: Ensure test coverage for priorityFee fallback to zero.

The line where priorityFee falls back to zero should be covered by tests. Currently, there are no tests explicitly covering this scenario.

  • Add a test case in zetaclient/chains/evm/observer/observer_test.go to ensure priorityFee correctly falls back to zero when expected.
Analysis chain

Ensure test coverage for priorityFee fallback to zero.

The line where priorityFee falls back to zero should be covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for `priorityFee` fallback to zero.

# Test: Search for test cases where `priorityFee` is set to zero. Expect: At least one test case setting `priorityFee` to zero.
rg --type go 'priorityFee = big.NewInt\(0\)'

Length of output: 119


Script:

#!/bin/bash
# Description: Verify test coverage for `priorityFee` fallback to zero.

# Find all test files that might be related to observer.go
test_files=$(fd -e go -p 'observer_test.go')

# Search for test functions in the identified test files
for file in $test_files; do
  echo "Searching in $file"
  rg 'func Test' $file -A 5
done

Length of output: 9750


Script:

#!/bin/bash
# Description: Verify test coverage for `priorityFee` fallback to zero by searching for mentions of `priorityFee` in the relevant test file.

# Search for mentions of `priorityFee` in the observer_test.go file
rg 'priorityFee' zetaclient/chains/evm/observer/observer_test.go -A 5

Length of output: 69

Tools
GitHub Check: codecov/patch

[warning] 340-340: zetaclient/chains/evm/observer/observer.go#L340
Added line #L340 was not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0d79cfb and 975408f.

Files ignored due to path filters (3)
  • x/crosschain/types/cross_chain_tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/crosschain/types/gas_price.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/crosschain/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (33)
  • changelog.md (1 hunks)
  • docs/cli/zetacored/zetacored_tx_crosschain_vote-gas-price.md (1 hunks)
  • docs/openapi/openapi.swagger.yaml (2 hunks)
  • docs/spec/crosschain/messages.md (1 hunks)
  • proto/zetachain/zetacore/crosschain/cross_chain_tx.proto (1 hunks)
  • proto/zetachain/zetacore/crosschain/gas_price.proto (1 hunks)
  • proto/zetachain/zetacore/crosschain/tx.proto (1 hunks)
  • testutil/network/genesis_state.go (1 hunks)
  • typescript/zetachain/zetacore/crosschain/cross_chain_tx_pb.d.ts (1 hunks)
  • typescript/zetachain/zetacore/crosschain/gas_price_pb.d.ts (1 hunks)
  • typescript/zetachain/zetacore/crosschain/tx_pb.d.ts (1 hunks)
  • x/crosschain/client/cli/cli_gas_price.go (2 hunks)
  • x/crosschain/keeper/abci.go (2 hunks)
  • x/crosschain/keeper/abci_test.go (1 hunks)
  • x/crosschain/keeper/cctx_gateway_observers.go (1 hunks)
  • x/crosschain/keeper/gas_payment.go (11 hunks)
  • x/crosschain/keeper/gas_price.go (1 hunks)
  • x/crosschain/keeper/grpc_query_zeta_conversion_rate.go (1 hunks)
  • x/crosschain/keeper/initiate_outbound.go (2 hunks)
  • x/crosschain/keeper/msg_server_migrate_tss_funds.go (4 hunks)
  • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go (5 hunks)
  • x/crosschain/keeper/msg_server_vote_gas_price.go (2 hunks)
  • x/crosschain/keeper/msg_server_vote_gas_price_test.go (6 hunks)
  • x/crosschain/keeper/msg_server_whitelist_erc20.go (2 hunks)
  • x/crosschain/types/cctx.go (1 hunks)
  • x/crosschain/types/message_vote_gas_price.go (1 hunks)
  • x/crosschain/types/message_vote_gas_price_test.go (3 hunks)
  • zetaclient/chains/bitcoin/observer/observer.go (1 hunks)
  • zetaclient/chains/evm/observer/observer.go (1 hunks)
  • zetaclient/chains/interfaces/interfaces.go (1 hunks)
  • zetaclient/testutils/mocks/zetacore_client.go (1 hunks)
  • zetaclient/zetacore/client_vote.go (2 hunks)
  • zetaclient/zetacore/tx_test.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • docs/cli/zetacored/zetacored_tx_crosschain_vote-gas-price.md
  • proto/zetachain/zetacore/crosschain/cross_chain_tx.proto
  • x/crosschain/types/message_vote_gas_price_test.go
Additional context used
Path-based instructions (24)
proto/zetachain/zetacore/crosschain/gas_price.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

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

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

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

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

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

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

x/crosschain/client/cli/cli_gas_price.go (1)

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

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

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

x/crosschain/keeper/cctx_gateway_observers.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_gas_price.go (1)

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

proto/zetachain/zetacore/crosschain/tx.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/crosschain/keeper/abci.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_whitelist_erc20.go (1)

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

zetaclient/zetacore/client_vote.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.

zetaclient/chains/interfaces/interfaces.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_migrate_tss_funds.go (1)

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

testutil/network/genesis_state.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_gas_price_test.go (1)

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

x/crosschain/keeper/gas_payment.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.

zetaclient/zetacore/tx_test.go (1)

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

zetaclient/chains/evm/observer/observer.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_migrate_tss_funds_test.go (1)

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

zetaclient/testutils/mocks/zetacore_client.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
x/crosschain/keeper/initiate_outbound.go

[warning] 35-35: x/crosschain/keeper/initiate_outbound.go#L35
Added line #L35 was not covered by tests


[warning] 37-37: x/crosschain/keeper/initiate_outbound.go#L37
Added line #L37 was not covered by tests

x/crosschain/keeper/gas_price.go

[warning] 59-60: x/crosschain/keeper/gas_price.go#L59-L60
Added lines #L59 - L60 were not covered by tests

x/crosschain/keeper/msg_server_vote_gas_price.go

[warning] 54-54: x/crosschain/keeper/msg_server_vote_gas_price.go#L54
Added line #L54 was not covered by tests

x/crosschain/keeper/gas_payment.go

[warning] 62-62: x/crosschain/keeper/gas_payment.go#L62
Added line #L62 was not covered by tests


[warning] 68-71: x/crosschain/keeper/gas_payment.go#L68-L71
Added lines #L68 - L71 were not covered by tests


[warning] 77-80: x/crosschain/keeper/gas_payment.go#L77-L80
Added lines #L77 - L80 were not covered by tests

zetaclient/chains/evm/observer/observer.go

[warning] 336-338: zetaclient/chains/evm/observer/observer.go#L336-L338
Added lines #L336 - L338 were not covered by tests


[warning] 340-340: zetaclient/chains/evm/observer/observer.go#L340
Added line #L340 was not covered by tests


[warning] 349-351: zetaclient/chains/evm/observer/observer.go#L349-L351
Added lines #L349 - L351 were not covered by tests

zetaclient/chains/bitcoin/observer/observer.go

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

Markdownlint
docs/spec/crosschain/messages.md

64-64: Column: 1
Hard tabs

(MD010, no-hard-tabs)

Additional comments not posted (48)
proto/zetachain/zetacore/crosschain/gas_price.proto (2)

19-19: Note: Consider calculating median_index_priority_fees on demand.

It might be more efficient to calculate the median_index_priority_fees on demand rather than storing it, as noted by swift1337.


19-19: Ensure compatibility with existing systems.

Adding the priority_fees field is a significant change. Ensure that all systems interacting with this message are updated to handle the new field.

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

17-23: LGTM! Ensure the new parameter is handled correctly.

The addition of the priorityFee parameter looks good. Ensure that all parts of the system handle this new parameter correctly.

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

27-29: Add test coverage for the new error handling logic.

The new error handling logic for missing chain info should be covered by tests to ensure its correctness.


35-37: Add test coverage for the new error handling logic.

The new error handling logic for missing CCTXGateway should be covered by tests to ensure its correctness.

Tools
GitHub Check: codecov/patch

[warning] 35-35: x/crosschain/keeper/initiate_outbound.go#L35
Added line #L35 was not covered by tests


[warning] 37-37: x/crosschain/keeper/initiate_outbound.go#L37
Added line #L37 was not covered by tests

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

28-28: Verify the usage of the new parameter in GetMedianGasPriceInUint.

The GetMedianGasPriceInUint function now returns an additional parameter. Ensure that this change is consistent with the function's definition and usage throughout the codebase.

Verification successful

Verify the usage of the new parameter in GetMedianGasPriceInUint.

The GetMedianGasPriceInUint function now returns an additional parameter. Based on the search results, all instances of this function handle the new return value correctly. The function's usage is consistent with its definition throughout the codebase.

  • Files and lines where the function is used:
    • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go
    • x/crosschain/keeper/cctx_gateway_observers.go
    • x/crosschain/keeper/abci_test.go
    • x/crosschain/keeper/grpc_query_zeta_conversion_rate.go
    • x/crosschain/keeper/msg_server_migrate_tss_funds.go
    • x/crosschain/keeper/gas_payment.go
    • x/crosschain/keeper/gas_price.go
    • x/crosschain/keeper/abci.go
    • x/crosschain/keeper/msg_server_whitelist_erc20.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `GetMedianGasPriceInUint` function to ensure consistency with the new parameter.

# Test: Search for the function usage. Expect: All usages should handle the additional return value.
rg --type go -A 5 $'GetMedianGasPriceInUint'

Length of output: 5719

x/crosschain/client/cli/cli_gas_price.go (1)

95-97: Ensure proper error handling for priorityFee parsing.

The error handling for priorityFee parsing is consistent with other parameters.

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

53-74: Ensure test coverage for medianValue function.

The medianValue function is crucial for calculating the median of the priority fees. Ensure that the test cases cover this function.

Verification successful

Test coverage for medianValue function is confirmed.

The medianValue function is indirectly tested through the GetMedianGasPriceInUint function, which is covered by tests in x/crosschain/keeper/msg_server_migrate_tss_funds_test.go.

  • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test coverage for the `medianValue` function.

# Test: Search for the function usage in test files. Expect: Test cases should cover various scenarios for median calculation.
rg --type go -A 5 $'medianValue' --glob '*_test.go'

Length of output: 50


Script:

#!/bin/bash
# Description: Verify the test coverage for the `medianValue` function.

# Test: Search for test functions that might indirectly test the medianValue function.
rg --type go -A 10 'func Test' --glob '*_test.go' | grep -i 'median\|priority\|fee\|gas'

Length of output: 63987


Script:

#!/bin/bash
# Description: Search for all occurrences of the `medianValue` function within the codebase to identify where it is invoked.

# Search for the `medianValue` function definition and its invocations.
rg --type go 'medianValue'

Length of output: 281


Script:

#!/bin/bash
# Description: Verify if the functionality involving `priorityFee` or the function that uses `medianValue` is covered by tests.

# Search for test cases that involve `priorityFee` or the function that uses `medianValue` within the test files.
rg --type go -A 10 'priorityFee' --glob '*_test.go'

Length of output: 4121

Tools
GitHub Check: codecov/patch

[warning] 59-60: x/crosschain/keeper/gas_price.go#L59-L60
Added lines #L59 - L60 were not covered by tests

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

66-66: Ensure proper error handling for gas price retrieval.

The function retrieves the median gas price and priority fee. Ensure that the error handling logic is robust and covers all edge cases.


71-71: LGTM! Ensure proper usage of GasPriorityFee.

The code changes are approved. Verify that the GasPriorityFee is used correctly throughout the codebase.

x/crosschain/keeper/msg_server_vote_gas_price.go (5)

11-11: Import errors from the correct package.

Ensure that the errors package is imported correctly and used consistently.


40-47: LGTM! Ensure proper initialization of GasPrice struct.

The code changes are approved. Verify that the GasPrice struct is initialized correctly with the new PriorityFees field.


60-60: Ensure test coverage for updated logic.

The line updating PriorityFees is not covered by tests. Ensure that the test cases are updated to cover this logic.


69-69: LGTM! Ensure proper appending of PriorityFees.

The code changes are approved. Verify that the PriorityFees are appended correctly in all scenarios.


78-78: LGTM! Ensure proper voting logic.

The code changes are approved. Verify that the voting logic correctly handles the new PriorityFees field.

proto/zetachain/zetacore/crosschain/tx.proto (2)

107-107: LGTM! Ensure proper initialization of priority_fee.

The code changes are approved. Verify that the priority_fee field is initialized correctly in all relevant parts of the codebase.


111-111: LGTM! Ensure proper usage of priority_fee.

The code changes are approved. Verify that the priority_fee field is used correctly throughout the codebase.

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

123-123: Ensure proper error handling for gas price retrieval.

The function retrieves the median gas price and priority fee. Ensure that the error handling logic is robust and covers all edge cases.


161-161: LGTM! Ensure proper usage of GasPriorityFee.

The code changes are approved. Verify that the GasPriorityFee is used correctly throughout the codebase.

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

108-111: Ensure proper error handling for median gas price retrieval.

The function correctly retrieves the median gas price and priority fee. Ensure that this method handles all edge cases for gas price retrieval.


158-158: LGTM! Priority fee added to outbound parameters.

The priority fee is correctly added to the outbound parameters.

zetaclient/zetacore/client_vote.go (2)

49-49: LGTM! Priority fee parameter added to function signature.

The priority fee parameter is correctly added to the function signature and used in the message creation.


60-60: Ensure proper handling of priority fee in message creation.

The priority fee is correctly included in the MsgVoteGasPrice message. Ensure that the priority fee is correctly handled in all related methods and functions.

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

199-199: LGTM! Priority fee field added to outbound parameters.

The priority fee field is correctly added to the outbound parameters.

zetaclient/chains/interfaces/interfaces.go (1)

82-82: LGTM! Method signature updated correctly.

The priorityFee parameter has been correctly added to the PostVoteGasPrice method.

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

92-92: LGTM! Median gas price and priority fee retrieval integrated correctly.

The MigrateTSSFundsForChain function now retrieves the priorityFee alongside the median gas price.


139-139: LGTM! priorityFee parameter added to OutboundParams.

The priorityFee parameter has been correctly added to the OutboundParams in the MigrateTSSFundsForChain function.

testutil/network/genesis_state.go (2)

224-230: LGTM! PriorityFees field added to GasPrice struct.

The PriorityFees field has been correctly added to the GasPrice struct in the AddCrosschainData function.


224-230: LGTM! PriorityFees field added to GasPrice struct.

The PriorityFees field has been correctly added to the GasPrice struct in the SetupZetaGenesisState function.

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

211-263: LGTM! New test case for priorityFee parameter added.

The new test case works with a priority fee correctly tests the priorityFee parameter in the VoteGasPrice function.

typescript/zetachain/zetacore/crosschain/cross_chain_tx_pb.d.ts (1)

231-235: Addition of gasPriorityFee field looks good.

The new field gasPriorityFee has been correctly added to the OutboundParams class.

x/crosschain/keeper/gas_payment.go (6)

20-31: Addition of ChainGasParams struct looks good.

The new struct ChainGasParams is correctly defined and includes the necessary fields for calculating gas fees.


Line range hint 33-50: Updates to PayGasAndUpdateCctx function look good.

The function correctly handles the new ChainGasParams struct and performs the necessary operations.


59-95: Addition of ChainGasParams function looks good.

The function correctly retrieves the necessary parameters for calculating gas fees and handles errors appropriately.

Tools
GitHub Check: codecov/patch

[warning] 62-62: x/crosschain/keeper/gas_payment.go#L62
Added line #L62 was not covered by tests


[warning] 68-71: x/crosschain/keeper/gas_payment.go#L68-L71
Added lines #L68 - L71 were not covered by tests


[warning] 77-80: x/crosschain/keeper/gas_payment.go#L77-L80
Added lines #L77 - L80 were not covered by tests


Line range hint 119-144: Updates to PayGasNativeAndUpdateCctx function look good.

The function correctly handles the new PriorityFee field and performs the necessary operations.


Line range hint 173-293: Updates to PayGasInERC20AndUpdateCctx function look good.

The function correctly handles the new PriorityFee field and performs the necessary operations.


Line range hint 333-409: Updates to PayGasInZetaAndUpdateCctx function look good.

The function correctly handles the new PriorityFee field and performs the necessary operations.

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

363-363: Addition of test case for GetMedianGasPriceInUint looks good.

The test case correctly verifies the functionality and provides adequate test coverage.

zetaclient/zetacore/tx_test.go (1)

150-150: Updates to PostVoteGasPrice test case look good.

The test case correctly verifies the functionality and provides adequate test coverage.

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

104-104: Ensure correctness of priorityFee handling in test case.

The test case should correctly handle and verify the priorityFee parameter.

Verification successful

Ensure correctness of priorityFee handling in test case.

The test case correctly handles and verifies the priorityFee parameter with appropriate assertions.

  • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go: Assertions verifying priorityFee are present.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify correctness of `priorityFee` handling in test case.

# Test: Search for assertions on `priorityFee` in the test case. Expect: Assertions verifying `priorityFee`.
rg --type go 'require.Equal.*priorityFee'

Length of output: 333


138-138: Ensure correctness of priorityFee handling in test case for BTC chain.

The test case should correctly handle and verify the priorityFee parameter.

Verification successful

The test case correctly handles and verifies the priorityFee parameter.

The assertions on priorityFee in the test case confirm its correctness.

  • x/crosschain/keeper/msg_server_migrate_tss_funds_test.go: require.Equal(t, priorityFee.String(), cctx.GetCurrentOutboundParam().GasPriorityFee)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify correctness of `priorityFee` handling in test case for BTC chain.

# Test: Search for assertions on `priorityFee` in the test case. Expect: Assertions verifying `priorityFee`.
rg --type go 'require.Equal.*priorityFee'

Length of output: 333


122-122: Ensure correctness of priorityFee handling in test case.

The test case should correctly handle and verify the priorityFee parameter.

Verification successful

The handling of priorityFee in the test case is correct.

The priorityFee is properly initialized using k.GetMedianGasPriceInUint(ctx, chain.ChainId) and verified through assertions to ensure its correctness.

  • Initialization: gp, priorityFee, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId)
  • Verification: require.Equal(t, priorityFee.String(), cctx.GetCurrentOutboundParam().GasPriorityFee)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify correctness of `priorityFee` handling in test case.

# Test: Search for assertions on `priorityFee` in the test case. Expect: Assertions verifying `priorityFee`.
rg --type go 'require.Equal.*priorityFee'

Length of output: 333


Script:

#!/bin/bash
# Description: Verify initialization and handling of `priorityFee` in the test case.

# Search for initialization and manipulation of `priorityFee` in the test file.
rg --type go 'priorityFee' -A 5 x/crosschain/keeper/msg_server_migrate_tss_funds_test.go

Length of output: 965


155-155: Ensure correctness of priorityFee handling in test case for BTC chain.

The test case should correctly handle and verify the priorityFee parameter.

Verification successful

The assertions for priorityFee are present in the test case. To ensure correctness, we need to verify the setup and usage of priorityFee within the test case, including its initialization and any related logic.


The priorityFee is initialized by the GetMedianGasPriceInUint function and used in assertions. To ensure correctness, we need to verify that the GetMedianGasPriceInUint function correctly sets the priorityFee for the BTC chain.


The handling of priorityFee in the test case for the BTC chain is correct.

The priorityFee is properly initialized using the GetMedianGasPriceInUint function and verified through assertions in the test case.

  • The priorityFee is derived from the median value of entity.PriorityFees.
  • The test case correctly asserts that the priorityFee matches the expected value.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify correctness of `priorityFee` handling in test case for BTC chain.

# Test: Search for assertions on `priorityFee` in the test case. Expect: Assertions verifying `priorityFee`.
rg --type go 'require.Equal.*priorityFee'

Length of output: 333


Script:

#!/bin/bash
# Description: Verify initialization and usage of `priorityFee` in the test case for BTC chain.

# Search for the initialization of `priorityFee` in the test file.
rg --type go 'priorityFee :=' x/crosschain/keeper/msg_server_migrate_tss_funds_test.go

# Search for other usages of `priorityFee` in the test file.
rg --type go 'priorityFee' x/crosschain/keeper/msg_server_migrate_tss_funds_test.go

Length of output: 496


Script:

#!/bin/bash
# Description: Verify the handling of `priorityFee` in the `GetMedianGasPriceInUint` function for BTC chain.

# Search for the definition of `GetMedianGasPriceInUint` function.
rg --type go 'func GetMedianGasPriceInUint' 

# Search for the usage of `priorityFee` within the `GetMedianGasPriceInUint` function.
rg --type go 'priorityFee' $(rg --files-with-matches 'func GetMedianGasPriceInUint')

Length of output: 4354

zetaclient/testutils/mocks/zetacore_client.go (1)

657-677: Ensure correctness of PostVoteGasPrice mock method.

The mock method should correctly simulate the behavior of the real method and adhere to best practices.

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

379-379: Verify the correctness of the added parameter.

The added parameter 0 for priorityFee in the PostVoteGasPrice function call seems correct. Ensure that this value is appropriate for all use cases.

Verification successful

Verify the correctness of the added parameter.

The added parameter 0 for priorityFee in the PostVoteGasPrice function call is correctly used across the codebase. Ensure that this value is appropriate for all use cases.

  • zetaclient/zetacore/client_vote.go
  • zetaclient/zetacore/tx_test.go
  • zetaclient/testutils/mocks/zetacore_client.go
  • zetaclient/chains/interfaces/interfaces.go
  • zetaclient/chains/bitcoin/observer/observer.go
  • zetaclient/chains/evm/observer/observer.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the PostVoteGasPrice function with the new priorityFee parameter.

# Test: Search for the function usage. Expect: Only occurances with the correct number of parameters.
rg --type go -A 5 $'PostVoteGasPrice'

Length of output: 3375

Tools
GitHub Check: codecov/patch

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

typescript/zetachain/zetacore/crosschain/tx_pb.d.ts (2)

423-425: Addition of priority_fee field is correct.

The new field priority_fee is correctly added to the MsgVoteGasPrice class.


428-430: Verify the impact of field reordering.

The block_number field is moved down. Ensure this reordering does not affect the functionality or serialization of the message.

changelog.md (1)

34-34: Entry for new feature looks good.

The entry for adding priorityFee (gasTipCap) gas to the state is clear and consistent with the rest of the changelog.

@lumtis
Copy link
Member

lumtis commented Jul 23, 2024

Missed this comment

Should I apply those factors to priorityFee as well?

Let's keep it without factor for now

@lumtis lumtis added the UPGRADE_TESTS Run make start-upgrade-tests label Jul 23, 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.

Looks good to me
Will approve once upgrade test passes

@ws4charlie
Copy link
Contributor

@lumtis @ws4charlie In some cases in x/crosschain, we alter cctx.outbound_params and bump gasPrice by either some percent or by a factor of x2. I kept priorityFee the same without changes. Should I apply those factors to priorityFee as well?

I think you're talking about gas stability pool updating the gas price. If it's stability pool, the answer would be Yes.
To unblock a EIP-1559 transaction stuck in mempool, we'll have to bump both gas price and gasTipCap. Otherwise, transaction replacement won't be accepted by Ethereum.

Here is the bump percentage in Ethereum source code: https://github.com/ethereum/go-ethereum/blob/87246f3cbaf10f83f56bc4d45f0f3e36e83e71e9/core/txpool/legacypool/legacypool.go#L146

Here is a doc from Alchemy: https://docs.alchemy.com/docs/retrying-an-eip-1559-transaction

The Github issue contains the details in section Pending Transaction replacement.

@swift1337
Copy link
Contributor Author

@ws4charlie priorityFee bump: f50abea

@swift1337 swift1337 enabled auto-merge July 24, 2024 17:35
@swift1337 swift1337 added this pull request to the merge queue Jul 24, 2024
Merged via the queue into develop with commit a27aa9a Jul 24, 2024
28 checks passed
@swift1337 swift1337 deleted the feat/vote-priority-fee branch July 24, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants