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: fast inbound confirmation for EVM and Bitcoin chain #3551

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

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Feb 19, 2025

Description

This PR is still in the progress.

  • Use GetScanRangeInboundSafe and GetScanRangeInboundFast split blocks into SAFE range and FAST range and scan them separately.
  • Define static multipliers for ZRC20 liquidity cap on a per-chain basis.
  • Expose RPC ForeignCoinsFromAsset to fetch liquidity pool cap for given chain id and asset.
  • Create a method IsInboundEligibleForFastConfirmation to determine if an inbound can be fast confirmed.
  • Add proper confirmation mode FAST | SAFE to message MsgVoteInbound.
  • Replace tendermint with CometBFT in the zetaclient code.
  • E2E tests for both Eth deposit and BTC deposit.

Closes: #3458
Closes: #3459

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

    • Enabled faster inbound transaction confirmations for both EVM and Bitcoin chains.
    • Introduced a new API endpoint for querying foreign coins by chain ID and asset.
  • Refactor

    • Improved dynamic determination of transaction confirmation modes.
    • Streamlined liquidity cap management for enhanced protocol efficiency.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

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

This update implements inbound fast confirmation support for both EVM and Bitcoin chains. It adds new changelog entries, test cases, and methods to dynamically determine confirmation modes based on block numbers. Several tests have been revised to remove local block mining steps, and new functionalities were introduced in modules handling coins, liquidity cap calculations, and foreign coin queries. Additionally, the client configuration has been restructured to use CometBFT terminology instead of Tendermint, and logging is enhanced with additional context.

Changes

File(s) Change Summary
changelog.md Added new feature entry for inbound fast confirmation support for EVM and Bitcoin chains (PR 3551).
cmd/zetae2e/local/bitcoin.go, cmd/zetae2e/local/evm.go Introduced new fast confirmation deposit test cases; updated Bitcoin runner initialization to include a ZetaTxServer option.
e2e/e2etests/e2etests.go, e2e/e2etests/test_bitcoin_deposit_fast_confirmation.go, e2e/e2etests/test_eth_deposit_fast_confirmation.go Added new test constants and test functions for fast confirmation deposits for Bitcoin and ETH.
e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go, e2e/e2etests/test_bitcoin_deposit_call.go, e2e/e2etests/test_bitcoin_donation.go, e2e/e2etests/test_bitcoin_std_deposit.go, e2e/e2etests/test_bitcoin_std_deposit_and_call.go, e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go, e2e/e2etests/test_crosschain_swap.go Removed local Bitcoin network setup and block mining steps from multiple tests.
docs/openapi/openapi.swagger.yaml, proto/zetachain/zetacore/fungible/query.proto Added new endpoint and message definitions to query foreign coins by chain_id and asset.
x/crosschain/types/message_vote_inbound.go, x/crosschain/types/message_vote_inbound_test.go Added EligibleForFastConfirmation method and corresponding tests to determine fast confirmation eligibility.
x/fungible/keeper/foreign_coins_test.go, x/fungible/keeper/grpc_query_foreign_coins.go, x/fungible/keeper/grpc_query_foreign_coins_test.go Updated foreign coins query functionality and helper methods; added tests for ForeignCoinsFromAsset.
zetaclient/chains/base/confirmation.go, zetaclient/chains/base/confirmation_test.go, zetaclient/chains/base/observer.go, zetaclient/chains/bitcoin/observer/event.go, zetaclient/chains/bitcoin/observer/event_test.go, zetaclient/chains/bitcoin/observer/inbound.go, zetaclient/chains/evm/observer/inbound.go, zetaclient/chains/evm/observer/v2_inbound.go Enhanced inbound observation and confirmation handling by separating SAFE and FAST block ranges, dynamically determining confirmation mode, and adding fast confirmation eligibility checks.
zetaclient/chains/interfaces/interfaces.go Added GetForeignCoinsFromAsset method to the ZetacoreClient interface.
zetaclient/logs/fields.go Introduced new log field constant FieldConfirmationMode.
zetaclient/testutils/mocks/zetacore_client.go Added new method GetForeignCoinsFromAsset to the mock client.
zetaclient/zetacore/broadcast_test.go, zetaclient/zetacore/client.go, zetaclient/zetacore/client_fungible.go, zetaclient/zetacore/client_fungible_test.go, zetaclient/zetacore/client_test.go, zetaclient/zetacore/tx_test.go Renamed Tendermint references to CometBFT; updated client configuration and tests accordingly; added foreign coins retrieval in client.
go.mod Added new dependency: github.com/test-go/testify v1.1.4.
pkg/coin/coin.go, pkg/coin/coin_test.go Introduced a new method IsFungible on CoinType and corresponding tests.
pkg/constant/fast_confirmation_multiplier.go, pkg/constant/fast_confirmation_multiplier_test.go Added liquidity cap multiplier constants and functions for fast confirmation along with unit tests.

Sequence Diagram(s)

sequenceDiagram
    participant Observer
    participant BlockScanner
    participant TxServer
    participant Ledger

    Observer->>BlockScanner: Request SAFE block range
    BlockScanner-->>Observer: Return SAFE range (startSafe, endSafe)
    Observer->>BlockScanner: Request FAST block range
    BlockScanner-->>Observer: Return FAST range (startFast, endFast)
    Observer->>TxServer: Determine confirmation mode using block number
    TxServer-->>Observer: Return confirmation mode (FAST or SAFE)
    Observer->>Ledger: Post inbound vote with determined mode
    Ledger-->>Observer: Acknowledge vote
Loading
sequenceDiagram
    participant TestRunner
    participant ChainParams
    participant DepositProcessor
    participant TxServer

    TestRunner->>ChainParams: Update chain parameters for fast confirmation
    ChainParams-->>TestRunner: Confirm parameters updated
    TestRunner->>DepositProcessor: Trigger fast confirmation deposit test
    DepositProcessor->>TxServer: Process deposit within fast cap
    TxServer-->>DepositProcessor: Return fast confirmation result
    DepositProcessor->>TestRunner: Assert deposit confirmed (FAST or SAFE)
Loading

Possibly related PRs

Suggested labels

SOLANA_TESTS, V2_TESTS, UPGRADE_LIGHT_TESTS

Suggested reviewers

  • lumtis
  • gartnera
  • kingpinXD
  • skosito

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.
  • @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.

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 52.68817% with 88 lines in your changes missing coverage. Please review.

Project coverage is 64.67%. Comparing base (4e5c732) to head (54d0dd2).

Files with missing lines Patch % Lines
zetaclient/chains/bitcoin/observer/inbound.go 0.00% 40 Missing ⚠️
zetaclient/chains/evm/observer/inbound.go 0.00% 17 Missing ⚠️
zetaclient/chains/evm/observer/v2_inbound.go 0.00% 17 Missing ⚠️
zetaclient/zetacore/client_fungible.go 61.90% 7 Missing and 1 partial ⚠️
pkg/chains/fast_confirmation.go 66.66% 2 Missing and 1 partial ⚠️
zetaclient/zetacore/client.go 70.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3551      +/-   ##
===========================================
- Coverage    64.69%   64.67%   -0.02%     
===========================================
  Files          466      468       +2     
  Lines        32477    32608     +131     
===========================================
+ Hits         21010    21090      +80     
- Misses       10512    10561      +49     
- Partials       955      957       +2     
Files with missing lines Coverage Δ
pkg/coin/coin.go 100.00% <100.00%> (ø)
x/crosschain/types/message_vote_inbound.go 100.00% <100.00%> (ø)
x/fungible/keeper/grpc_query_foreign_coins.go 86.95% <100.00%> (+4.09%) ⬆️
x/observer/types/chain_params.go 94.91% <100.00%> (+0.03%) ⬆️
zetaclient/chains/base/confirmation.go 100.00% <100.00%> (ø)
zetaclient/chains/base/observer.go 79.03% <100.00%> (+0.08%) ⬆️
zetaclient/chains/bitcoin/observer/event.go 96.12% <100.00%> (+0.26%) ⬆️
pkg/chains/fast_confirmation.go 66.66% <66.66%> (ø)
zetaclient/zetacore/client.go 58.57% <70.00%> (ø)
zetaclient/zetacore/client_fungible.go 61.90% <61.90%> (ø)
... and 3 more

@ws4charlie ws4charlie added zetaclient Issues related to ZetaClient zetacore Issues related to ZetaCore chain:bitcoin Bitcoin chain related chain:evm labels Feb 22, 2025
@ws4charlie ws4charlie marked this pull request as ready for review February 22, 2025 06:28
@ws4charlie ws4charlie requested a review from a team as a code owner February 22, 2025 06:28
@ws4charlie ws4charlie changed the title feat: WIP, fast inbound confirmation feat: fast inbound confirmation for EVM and Bitcoin chain Feb 22, 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: 7

🧹 Nitpick comments (22)
x/crosschain/types/message_vote_inbound.go (1)

159-180: LGTM! Well-structured implementation with clear logic.

The function effectively determines fast confirmation eligibility with proper handling of different protocol versions and clear documentation of the reasoning.

Consider defining protocol version constants and standardizing comment format:

+// Protocol version constants
+const (
+    ProtocolV1 = ProtocolContractVersion_V1
+    ProtocolV2 = ProtocolContractVersion_V2
+)

 func (msg *MsgVoteInbound) EligibleForFastConfirmation() bool {
-    // only fungible coins are eligible for fast confirmation
+    // Only fungible coins are eligible for fast confirmation
     if !msg.CoinType.IsFungible() {
         return false
     }

     switch msg.ProtocolContractVersion {
-    case ProtocolContractVersion_V1:
+    case ProtocolV1:
         // msg using protocol contract version V1 is not eligible for fast confirmation because:
         // 1. whether the receiver address is a contract or not is unknown
         // 2. it can be a depositAndCall (Gas or ZRC20) with empty payload
         // 3. it can be a message passing (CoinType_Zeta) calls 'onReceive'
         return false
-    case ProtocolContractVersion_V2:
+    case ProtocolV2:
         // in protocol contract version V2, simple deposit is distinguished from depositAndCall/NoAssetCall
         return !msg.IsCrossChainCall
     default:
         return false
     }
 }
x/crosschain/types/message_vote_inbound_test.go (1)

625-671: LGTM! Comprehensive test coverage with clear test cases.

The test suite effectively covers the main scenarios for fast confirmation eligibility.

Consider adding these additional test cases for better coverage:

 func TestMsgVoteInbound_EligibleForFastConfirmation(t *testing.T) {
     tests := []struct {
         name     string
         msg      types.MsgVoteInbound
         eligible bool
     }{
+        {
+            name: "not eligible when cross chain call is true",
+            msg: func() types.MsgVoteInbound {
+                msg := sample.InboundVote(coin.CoinType_Gas, 1, 7000)
+                msg.ProtocolContractVersion = types.ProtocolContractVersion_V2
+                msg.IsCrossChainCall = true
+                return msg
+            }(),
+            eligible: false,
+        },
+        {
+            name: "eligible for different fungible coin types",
+            msg: func() types.MsgVoteInbound {
+                msg := sample.InboundVote(coin.CoinType_ERC20, 1, 7000)
+                msg.ProtocolContractVersion = types.ProtocolContractVersion_V2
+                return msg
+            }(),
+            eligible: true,
+        },
         // existing test cases...
     }
zetaclient/chains/base/observer.go (1)

383-426: Consider enhancing error handling and metrics.

While the implementation is solid, consider these improvements:

  1. Add specific error types for different failure scenarios to aid in error tracking and resolution.
  2. Include metrics to track the distribution of FAST vs SAFE confirmation modes.

Example implementation:

 // PostVoteInbound posts a vote for the given vote message and returns the ballot.
 func (ob *Observer) PostVoteInbound(
 	ctx context.Context,
 	msg *crosschaintypes.MsgVoteInbound,
 	retryGasLimit uint64,
 ) (string, error) {
 	const gasLimit = zetacore.PostVoteInboundGasLimit
+
+	// Track confirmation mode distribution
+	metrics.InboundConfirmationModes.WithLabelValues(
+		ob.chain.Name,
+		msg.ConfirmationMode.String(),
+	).Inc()
+
 	var (
 		txHash   = msg.InboundHash
 		coinType = msg.CoinType
 	)
x/fungible/keeper/grpc_query_foreign_coins.go (1)

67-82: Enhance error handling and input validation.

The error messages could be more descriptive, and the method would benefit from input validation for the chain ID and asset format.

 func (k Keeper) ForeignCoinsFromAsset(
     c context.Context,
     req *types.QueryGetForeignCoinsFromAssetRequest,
 ) (*types.QueryGetForeignCoinsFromAssetResponse, error) {
     if req == nil {
         return nil, status.Error(codes.InvalidArgument, "invalid request")
     }
+    if req.ChainId <= 0 {
+        return nil, status.Error(codes.InvalidArgument, "chain ID must be positive")
+    }
+    if req.Asset == "" {
+        return nil, status.Error(codes.InvalidArgument, "asset address cannot be empty")
+    }
     ctx := sdk.UnwrapSDKContext(c)

     fCoin, found := k.GetForeignCoinFromAsset(ctx, req.Asset, req.ChainId)
     if !found {
-        return nil, status.Error(codes.NotFound, "not found")
+        return nil, status.Errorf(codes.NotFound, "foreign coin not found for asset %s on chain %d", req.Asset, req.ChainId)
     }

     return &types.QueryGetForeignCoinsFromAssetResponse{ForeignCoins: fCoin}, nil
 }
zetaclient/zetacore/client_fungible_test.go (2)

20-41: Add test cases for invalid chain IDs and malformed addresses.

The test suite would benefit from additional test cases to cover invalid inputs and error scenarios.

 tests := []struct {
     name    string
     chainID int64
     asset   string
     errMsg  string
 }{
     // existing test cases...
+    {
+        name:    "invalid chain ID",
+        chainID: -1,
+        asset:   erc20Asset,
+        errMsg:  "chain ID must be positive",
+    },
+    {
+        name:    "malformed asset address",
+        chainID: 1,
+        asset:   "0xinvalid",
+        errMsg:  "invalid asset address format",
+    },
 }

88-115: Improve test organization and naming.

This test case could be integrated into the table-driven test suite above with a more descriptive name.

Consider merging this test into the table-driven test suite in Test_GetForeignCoinsFromAsset with a descriptive name like "successful retrieval of ERC20 foreign coins".

pkg/constant/fast_confirmation_multiplier.go (2)

16-57: Consider a more maintainable approach for chain management.

The current implementation requires explicit addition of new chains to the map. This could lead to maintenance overhead and potential issues if a new chain is added without updating this map.

Consider implementing a more dynamic approach, such as:

  1. Using a configuration file that can be updated without code changes
  2. Implementing a default behavior for new chains
  3. Adding runtime configuration capabilities through admin APIs

68-72: Document truncation behavior in amount cap calculation.

The function truncates decimal places without rounding, which might lead to unexpected behavior for values close to the next integer.

Add a comment explaining the truncation behavior:

 // CalcInboundFastAmountCap calculates the amount cap for inbound fast confirmation.
+// Note: The result is truncated (not rounded) to the nearest integer towards zero.
 func CalcInboundFastAmountCap(liquidityCap sdkmath.Uint, multiplier sdkmath.LegacyDec) *big.Int {
pkg/constant/fast_confirmation_multiplier_test.go (2)

13-72: Enhance test coverage for edge cases.

Consider adding test cases for:

  1. Non-existent chain IDs to verify the behavior
  2. Chain IDs at the boundaries of int64

Add the following test cases:

 tests := []struct {
     name     string
     chainID  int64
     expected sdkmath.LegacyDec
 }{
+    // Edge cases
+    {name: "Non-existent chain", chainID: 999999, expected: sdkmath.LegacyDec{}},
+    {name: "Maximum chain ID", chainID: 9223372036854775807, expected: sdkmath.LegacyDec{}},
+    {name: "Minimum chain ID", chainID: -9223372036854775808, expected: sdkmath.LegacyDec{}},

74-113: Add descriptive comments for test cases.

The test cases would benefit from comments explaining the test scenarios and expected behaviors.

Add descriptive comments:

 tests := []struct {
     name         string
     liquidityCap sdkmath.Uint
     multiplier   sdkmath.LegacyDec
     expected     *big.Int
 }{
+    // Test standard percentage calculation
     {
         name:         "1% of 10000",
         liquidityCap: sdkmath.NewUintFromString("10000"),
         multiplier:   sdkmath.LegacyMustNewDecFromStr("0.01"),
         expected:     big.NewInt(100),
     },
+    // Test handling of small percentages
     {
         name:         "0.15% of 10000",
e2e/e2etests/test_eth_deposit_fast_confirmation.go (1)

54-56: Consider making the liquidity cap percentage configurable.

The hardcoded 50% increase for liquidity cap could be made configurable to allow for different test scenarios without code changes.

+const defaultLiquidityCapIncrease = 50
 // set ZRC20 liquidity cap to 150% of the current supply
 // note: the percentage should not be too small as it may block other tests
-liquidityCap, _ := mathpkg.IncreaseUintByPercent(supplyUint, 50)
+liquidityCap, _ := mathpkg.IncreaseUintByPercent(supplyUint, defaultLiquidityCapIncrease)
zetaclient/chains/base/confirmation.go (1)

72-103: Enhance error handling for better observability.

While the function logic is sound, consider improving error handling:

 func (ob *Observer) IsInboundEligibleForFastConfirmation(
     ctx context.Context,
     msg *crosschaintypes.MsgVoteInbound,
 ) (bool, error) {
     chainID := msg.SenderChainId
     multiplier, enabled := constant.GetInboundFastConfirmationLiquidityMultiplier(chainID)
     if !enabled {
-        return false, nil
+        return false, errors.Errorf("fast confirmation not enabled for chain %d", chainID)
     }

     if !msg.EligibleForFastConfirmation() {
-        return false, nil
+        return false, errors.New("message not eligible for fast confirmation")
     }

     fCoins, err := ob.zetacoreClient.GetForeignCoinsFromAsset(ctx, chainID, msg.Asset)
     if err != nil {
         return false, errors.Wrapf(err, "unable to get foreign coins for asset %s on chain %d", msg.Asset, chainID)
     }

     fastAmountCap := constant.CalcInboundFastAmountCap(fCoins.LiquidityCap, multiplier)
     if msg.Amount.BigInt().Cmp(fastAmountCap) > 0 {
-        return false, nil
+        return false, errors.Errorf("amount %s exceeds fast confirmation cap %s", msg.Amount, fastAmountCap)
     }

     return true, nil
 }
zetaclient/chains/bitcoin/observer/event.go (1)

186-188: Consider extracting confirmation mode determination to reduce duplication.

The confirmation mode determination logic is duplicated in both NewInboundVoteFromLegacyMemo and NewInboundVoteFromStdMemo. Consider extracting this into a helper method to improve maintainability.

+func (ob *Observer) getConfirmationModeForEvent(event *BTCInboundEvent) crosschaintypes.ConfirmationMode {
+    return ob.GetInboundConfirmationMode(event.BlockNumber)
+}

Then use it in both functions:

-confirmationMode := ob.GetInboundConfirmationMode(event.BlockNumber)
+confirmationMode := ob.getConfirmationModeForEvent(event)

Also applies to: 227-229

zetaclient/chains/base/confirmation_test.go (2)

226-265: Add test cases for edge cases in Test_GetInboundConfirmationMode.

The test cases only cover basic scenarios. Consider adding test cases for:

  • Block number at the boundary of SAFE/FAST confirmation
  • Zero block number
  • Maximum block number

351-442: Enhance test coverage for Test_IsInboundEligibleForFastConfirmation.

The test cases are well-structured but could be more comprehensive. Consider adding test cases for:

  • Different coin types
  • Edge cases for amount calculations
  • Different protocol contract versions

Additionally, consider extracting the test setup into a helper function to improve readability:

func setupTestInboundEligibility(t *testing.T, chain chains.Chain, liquidityCap sdkmath.Uint) *testSuite {
    ob := newTestSuite(t, chain)
    ob.zetacore.On("GetForeignCoinsFromAsset", mock.Anything, chain.ChainId, mock.Anything).
        Maybe().
        Return(fungibletypes.ForeignCoins{LiquidityCap: liquidityCap}, nil)
    return ob
}
e2e/runner/bitcoin.go (1)

284-285: Document the change in confirmation block count.

The reduction in confirmation blocks from 6 to 1 is a significant change that should be documented. Consider adding a comment explaining why this change was made and its implications for fast confirmation.

-// mine 1 block to confirm the transaction
+// mine 1 block to confirm the transaction
+// Note: Reduced from 6 blocks to 1 block to support fast confirmation feature
zetaclient/chains/bitcoin/observer/event_test.go (2)

370-372: Add test cases for different confirmation modes.

The test only mocks SAFE confirmation mode. Consider adding test cases for:

  • FAST confirmation mode
  • Edge cases between SAFE and FAST modes

428-430: Add test cases for different confirmation modes.

Similar to the previous test, this test only mocks SAFE confirmation mode. Consider adding test cases for:

  • FAST confirmation mode
  • Edge cases between SAFE and FAST modes
zetaclient/chains/evm/observer/inbound.go (1)

133-137: Consider adding error handling and logging for FAST block scanning.

The FAST block scanning implementation could benefit from similar error handling and logging as the SAFE block scanning section.

 // scan FAST confirmed blocks if available
 _, endBlockFast := ob.GetScanRangeInboundFast(config.MaxBlocksPerScan)
 if endBlockSafe < endBlockFast {
-    ob.observeInboundInBlockRange(ctx, endBlockSafe, endBlockFast-1)
+    lastScannedNew := ob.observeInboundInBlockRange(ctx, endBlockSafe, endBlockFast-1)
+    logger.Debug().
+        Uint64("from", endBlockSafe).
+        Uint64("to", lastScannedNew).
+        Msg("observed blocks for fast inbounds")
 }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 134-136: zetaclient/chains/evm/observer/inbound.go#L134-L136
Added lines #L134 - L136 were not covered by tests

docs/openapi/openapi.swagger.yaml (2)

29453-29478: Endpoint Definition and Parameter Validation

The new endpoint /zeta-chain/fungible/foreign_coins/{chain_id}/{asset} is defined clearly with an appropriate GET method, summary, operationId, responses, and path parameters. The inclusion of both required parameters (chain_id and asset) is correctly handled.

One optional suggestion: Consider reviewing the data type for chain_id. Although it is currently defined as a string with format: int64, many OpenAPI definitions prefer using an integer type for numeric IDs. If your backend expects a numeric value, you might update it as follows:

-          type: string
-          format: int64
+          type: integer
+          format: int64

If the chain identifier is indeed a string in your context, then the current configuration is acceptable.


59614-59624: Response Schema Implementation

The new schema fungibleQueryGetForeignCoinsFromAssetResponse has been added properly. Defining the response as an object with a property foreignCoins that references the fungibleForeignCoins definition is clear and maintains consistency with existing patterns.

For enhanced clarity to API consumers, consider adding a brief description for the foreignCoins property to summarize its contents. This additional documentation could improve usability of the API.

go.mod (1)

313-314: Confirm Dependency Duplication Intent
The new dependency "github.com/test-go/testify v1.1.4" appears to be added alongside an existing dependency "github.com/stretchr/testify v1.10.0". This could lead to potential conflicts or redundancy unless the new import is intentionally meant to serve a different purpose. Please verify if both dependencies are required or if this is an oversight. Consider aligning to a single version if possible.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca40945 and 8c1b25f.

⛔ Files ignored due to path filters (3)
  • typescript/zetachain/zetacore/fungible/query_pb.d.ts is excluded by !**/*_pb.d.ts
  • x/fungible/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/fungible/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
📒 Files selected for processing (46)
  • changelog.md (1 hunks)
  • cmd/zetae2e/local/bitcoin.go (2 hunks)
  • cmd/zetae2e/local/evm.go (1 hunks)
  • docs/openapi/openapi.swagger.yaml (2 hunks)
  • e2e/e2etests/e2etests.go (4 hunks)
  • e2e/e2etests/helpers.go (0 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go (0 hunks)
  • e2e/e2etests/test_bitcoin_deposit_call.go (0 hunks)
  • e2e/e2etests/test_bitcoin_deposit_fast_confirmation.go (1 hunks)
  • e2e/e2etests/test_bitcoin_donation.go (0 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit.go (0 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.go (0 hunks)
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go (0 hunks)
  • e2e/e2etests/test_crosschain_swap.go (0 hunks)
  • e2e/e2etests/test_eth_deposit_fast_confirmation.go (1 hunks)
  • e2e/e2etests/test_eth_deposit_liquidity_cap.go (2 hunks)
  • e2e/runner/bitcoin.go (1 hunks)
  • e2e/txserver/liquidity_cap.go (1 hunks)
  • go.mod (1 hunks)
  • pkg/coin/coin.go (1 hunks)
  • pkg/coin/coin_test.go (1 hunks)
  • pkg/constant/fast_confirmation_multiplier.go (1 hunks)
  • pkg/constant/fast_confirmation_multiplier_test.go (1 hunks)
  • proto/zetachain/zetacore/fungible/query.proto (2 hunks)
  • x/crosschain/types/message_vote_inbound.go (1 hunks)
  • x/crosschain/types/message_vote_inbound_test.go (1 hunks)
  • x/fungible/keeper/foreign_coins_test.go (1 hunks)
  • x/fungible/keeper/grpc_query_foreign_coins.go (1 hunks)
  • x/fungible/keeper/grpc_query_foreign_coins_test.go (7 hunks)
  • zetaclient/chains/base/confirmation.go (3 hunks)
  • zetaclient/chains/base/confirmation_test.go (5 hunks)
  • zetaclient/chains/base/observer.go (1 hunks)
  • zetaclient/chains/bitcoin/observer/event.go (4 hunks)
  • zetaclient/chains/bitcoin/observer/event_test.go (2 hunks)
  • zetaclient/chains/bitcoin/observer/inbound.go (2 hunks)
  • zetaclient/chains/evm/observer/inbound.go (1 hunks)
  • zetaclient/chains/evm/observer/v2_inbound.go (3 hunks)
  • zetaclient/chains/interfaces/interfaces.go (2 hunks)
  • zetaclient/logs/fields.go (1 hunks)
  • zetaclient/testutils/mocks/zetacore_client.go (2 hunks)
  • zetaclient/zetacore/broadcast_test.go (2 hunks)
  • zetaclient/zetacore/client.go (5 hunks)
  • zetaclient/zetacore/client_fungible.go (1 hunks)
  • zetaclient/zetacore/client_fungible_test.go (1 hunks)
  • zetaclient/zetacore/client_test.go (4 hunks)
  • zetaclient/zetacore/tx_test.go (8 hunks)
💤 Files with no reviewable changes (8)
  • e2e/e2etests/test_bitcoin_donation.go
  • e2e/e2etests/test_bitcoin_std_deposit.go
  • e2e/e2etests/helpers.go
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
  • e2e/e2etests/test_crosschain_swap.go
  • e2e/e2etests/test_bitcoin_deposit_call.go
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.go
✅ Files skipped from review due to trivial changes (2)
  • zetaclient/zetacore/client_test.go
  • changelog.md
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Go code, point out issues relative to ...

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

  • e2e/runner/bitcoin.go
  • cmd/zetae2e/local/evm.go
  • zetaclient/zetacore/tx_test.go
  • x/crosschain/types/message_vote_inbound.go
  • pkg/coin/coin.go
  • zetaclient/chains/bitcoin/observer/event_test.go
  • zetaclient/chains/base/observer.go
  • e2e/e2etests/test_eth_deposit_liquidity_cap.go
  • zetaclient/zetacore/client_fungible.go
  • zetaclient/chains/bitcoin/observer/event.go
  • cmd/zetae2e/local/bitcoin.go
  • e2e/e2etests/test_eth_deposit_fast_confirmation.go
  • zetaclient/chains/base/confirmation.go
  • zetaclient/chains/evm/observer/inbound.go
  • pkg/coin/coin_test.go
  • e2e/txserver/liquidity_cap.go
  • x/crosschain/types/message_vote_inbound_test.go
  • e2e/e2etests/test_bitcoin_deposit_fast_confirmation.go
  • x/fungible/keeper/grpc_query_foreign_coins.go
  • pkg/constant/fast_confirmation_multiplier_test.go
  • zetaclient/zetacore/broadcast_test.go
  • zetaclient/logs/fields.go
  • x/fungible/keeper/grpc_query_foreign_coins_test.go
  • zetaclient/chains/base/confirmation_test.go
  • zetaclient/chains/bitcoin/observer/inbound.go
  • zetaclient/chains/interfaces/interfaces.go
  • zetaclient/zetacore/client_fungible_test.go
  • zetaclient/zetacore/client.go
  • zetaclient/chains/evm/observer/v2_inbound.go
  • pkg/constant/fast_confirmation_multiplier.go
  • x/fungible/keeper/foreign_coins_test.go
  • zetaclient/testutils/mocks/zetacore_client.go
  • e2e/e2etests/e2etests.go
`**/*.proto`: Review the Protobuf definitions, point out iss...

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

  • proto/zetachain/zetacore/fungible/query.proto
🧠 Learnings (1)
zetaclient/chains/bitcoin/observer/inbound.go (1)
Learnt from: ws4charlie
PR: zeta-chain/node#2899
File: zetaclient/chains/bitcoin/observer/inbound.go:131-132
Timestamp: 2024-11-12T13:20:12.658Z
Learning: ObserveInbound coverage will be improved in future refactor.
🪛 GitHub Check: codecov/patch
zetaclient/zetacore/client_fungible.go

[warning] 33-39: zetaclient/zetacore/client_fungible.go#L33-L39
Added lines #L33 - L39 were not covered by tests

zetaclient/chains/evm/observer/inbound.go

[warning] 116-129: zetaclient/chains/evm/observer/inbound.go#L116-L129
Added lines #L116 - L129 were not covered by tests


[warning] 134-136: zetaclient/chains/evm/observer/inbound.go#L134-L136
Added lines #L134 - L136 were not covered by tests

zetaclient/chains/bitcoin/observer/inbound.go

[warning] 32-42: zetaclient/chains/bitcoin/observer/inbound.go#L32-L42
Added lines #L32 - L42 were not covered by tests


[warning] 45-52: zetaclient/chains/bitcoin/observer/inbound.go#L45-L52
Added lines #L45 - L52 were not covered by tests


[warning] 57-65: zetaclient/chains/bitcoin/observer/inbound.go#L57-L65
Added lines #L57 - L65 were not covered by tests


[warning] 110-121: zetaclient/chains/bitcoin/observer/inbound.go#L110-L121
Added lines #L110 - L121 were not covered by tests

zetaclient/zetacore/client.go

[warning] 137-137: zetaclient/zetacore/client.go#L137
Added line #L137 was not covered by tests

zetaclient/chains/evm/observer/v2_inbound.go

[warning] 109-120: zetaclient/chains/evm/observer/v2_inbound.go#L109-L120
Added lines #L109 - L120 were not covered by tests


[warning] 201-202: zetaclient/chains/evm/observer/v2_inbound.go#L201-L202
Added lines #L201 - L202 were not covered by tests


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

🔇 Additional comments (31)
zetaclient/chains/base/observer.go (2)

398-401: LGTM! Enhanced logging for confirmation modes.

The addition of logs.FieldConfirmationMode improves observability by explicitly logging the confirmation mode (FAST or SAFE) for inbound votes, which aligns well with the PR's objective of implementing fast inbound confirmation support.


383-426:

❓ Verification inconclusive

Verify confirmation mode propagation and logging consistency.

Please ensure:

  1. The confirmation mode is properly propagated through all relevant components.
  2. The logging fields for confirmation modes are consistently used across the codebase.

Run this script to check logging consistency:


🏁 Script executed:

#!/bin/bash
# Check for consistent use of confirmation mode logging across the codebase
rg -A 2 "FieldConfirmationMode" 

Length of output: 345


Verification of Confirmation Mode Propagation & Logging Consistency

The recent script execution confirms that the FieldConfirmationMode logging field is used consistently in the codebase (e.g., in zetaclient/chains/base/observer.go and zetaclient/logs/fields.go). However, please ensure that the confirmation mode itself is appropriately propagated throughout all relevant system components—as the logging check does not fully verify the underlying propagation logic.

  • Confirm that the value returned by msg.ConfirmationMode.String() is correctly handled in all downstream components.
  • Double-check that any other modules or services relying on confirmation mode have been updated accordingly.
zetaclient/chains/bitcoin/observer/inbound.go (4)

31-42: Consider improving test coverage for safe inbound scanning.
The logic for scanning SAFE confirmed blocks and handling errors is mostly sound, yet lines 32-42 remain uncovered by tests. It would be beneficial to add integration tests that verify the behavior when:

  1. startBlockSafe is >= endBlockSafe (no scanning).
  2. An error occurs within [startBlockSafe, endBlockSafe-1].
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 32-42: zetaclient/chains/bitcoin/observer/inbound.go#L32-L42
Added lines #L32 - L42 were not covered by tests


44-53: Persisting the last scanned block is sound, but ensure edge cases are tested.
Persisting the updated last scanned block only if it exceeds the current record is a good approach. However, these lines are also not covered by tests. Consider adding a test that verifies the block-saving logic when no inbound transactions are observed or when errors prevent scanning all blocks in the range.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 45-52: zetaclient/chains/bitcoin/observer/inbound.go#L45-L52
Added lines #L45 - L52 were not covered by tests


56-67: Add tests for FAST confirmation scanning.
The FAST confirmation logic at lines 56-67 is well-structured, but it appears untested. Consider adding unit or integration tests that simulate scenarios where endBlockFast is both just below and above endBlockSafe, ensuring correct behavior and error handling.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 57-65: zetaclient/chains/bitcoin/observer/inbound.go#L57-L65
Added lines #L57 - L65 were not covered by tests


110-123: Validate fast confirmation eligibility checks through dedicated test scenarios.
Skipping inbounds that are not eligible for fast confirmation is crucial logic. Currently, lines 110-121 lack coverage, making it difficult to ensure correctness in edge cases. Recommend adding tests that confirm inbound transactions are properly skipped or returned if IsInboundEligibleForFastConfirmation returns false or an error.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 110-121: zetaclient/chains/bitcoin/observer/inbound.go#L110-L121
Added lines #L110 - L121 were not covered by tests

zetaclient/logs/fields.go (1)

6-18: New field key aligns with enhanced confirmation logic.
The addition of FieldConfirmationMode is consistent with the broader fast confirmation enhancement. No issues detected.

zetaclient/zetacore/client_fungible.go (2)

19-24: Reasonable approach for handling gas assets.
Using an empty string when the asset address is a zero address effectively differentiates standard assets from gas assets. This design is clear and maintainable.


31-39: Test the error handling path to improve coverage.
If Fungible.ForeignCoinsFromAsset fails, lines 33-39 wrap and return the error. Consider adding a test case that triggers an error response from Fungible.ForeignCoinsFromAsset to ensure the wrapping and early return paths are exercised.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 33-39: zetaclient/zetacore/client_fungible.go#L33-L39
Added lines #L33 - L39 were not covered by tests

e2e/e2etests/test_eth_deposit_liquidity_cap.go (1)

26-26: LGTM! Improved code clarity and efficiency.

The changes simplify the liquidity cap management by replacing message-based transactions with direct method calls, reducing complexity and improving maintainability.

Also applies to: 65-65

pkg/constant/fast_confirmation_multiplier.go (1)

11-14: Verify the default multiplier value.

The default multiplier of 0.00025 (0.025%) seems quite small. This could significantly limit the fast confirmation capability for large transactions.

Please confirm if this restrictive multiplier aligns with the business requirements and performance expectations.

zetaclient/zetacore/broadcast_test.go (1)

83-83: LGTM! Consistent terminology update.

The changes correctly update the test setup to use CometBFT terminology instead of Tendermint, maintaining consistency across the codebase.

Also applies to: 97-99

e2e/e2etests/test_eth_deposit_fast_confirmation.go (2)

67-68: LGTM: Clear test case for fast confirmation.

The test case properly validates fast confirmation for deposits within the cap limit.


80-82: LGTM: Comprehensive test for safe confirmation.

The test case effectively validates that deposits exceeding the cap trigger safe confirmation mode.

e2e/e2etests/test_bitcoin_deposit_fast_confirmation.go (1)

83-85: LGTM: Proper cleanup of mining routine.

The test correctly uses defer to ensure the mining routine is stopped after the test.

pkg/coin/coin_test.go (1)

153-173: LGTM: Comprehensive test coverage for IsFungible method.

The test cases cover all coin types and edge cases, following consistent test patterns.

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

21-21: LGTM: Proper integration of fast confirmation test.

The test is correctly integrated into the ETH happy path test suite.

x/fungible/keeper/grpc_query_foreign_coins_test.go (3)

17-65: LGTM!

The test function is well-structured with comprehensive test cases covering successful queries, not found scenarios, and invalid requests.


67-116: LGTM!

The test function is well-implemented with comprehensive test cases that validate the ForeignCoinsFromAsset query functionality, including edge cases and error scenarios.


118-171: LGTM!

The test function thoroughly validates pagination functionality with comprehensive test cases for offset-based, key-based, and total count queries.

zetaclient/chains/base/confirmation.go (1)

47-55: LGTM!

The function provides a clean implementation for determining the confirmation mode based on block confirmation status.

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

27-40: LGTM!

The addition of the fast confirmation test case aligns with the PR objectives and maintains consistent test organization.

x/fungible/keeper/foreign_coins_test.go (1)

19-28: LGTM!

The refactoring improves test maintainability by utilizing the sample package for consistent test data generation.

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

67-67: LGTM! Well-designed interface method.

The new method GetForeignCoinsFromAsset follows Go interface design principles with clear parameter names and proper error handling.

zetaclient/zetacore/client.go (1)

61-62: LGTM! Consistent renaming from Tendermint to CometBFT.

The renaming from Tendermint to CometBFT is consistent throughout the file, improving code clarity and reflecting the current terminology.

Also applies to: 70-76, 302-304

zetaclient/zetacore/tx_test.go (1)

102-102: LGTM! Consistent test updates for CometBFT changes.

The test cases have been properly updated to use withCometBFT instead of withTendermint, maintaining consistency with the main code changes. The test coverage remains comprehensive, including both success and error scenarios.

Also applies to: 149-149, 176-176, 200-200, 237-237, 278-278, 315-315, 348-348

zetaclient/chains/evm/observer/inbound.go (1)

115-131:

❓ Verification inconclusive

LGTM! Clean implementation of SAFE block scanning.

The code effectively handles SAFE confirmed blocks with proper error handling and logging.

Please ensure test coverage is added for this critical section:


🏁 Script executed:

#!/bin/bash
# Check test coverage for the ObserveInbound function
go test -coverprofile=coverage.out ./zetaclient/chains/evm/observer/
go tool cover -func=coverage.out | grep ObserveInbound

Length of output: 17972


SAFE Block Scanning Implementation Verified – Further Test Coverage Verification Required

The implementation for scanning SAFE-confirmed blocks (lines 115–131) is clean, with proper error handling and logging in place. However, the automated test coverage command failed to produce any output due to build errors in other parts of the code (e.g., issues in go-ethereum and pkg/coin/pkg/chains), which prevents reliable verification of test coverage for the ObserveInbound function.

  • Action Required:
    • Manually verify and resolve the build errors reported by the test suite.
    • Ensure comprehensive test coverage is added for the ObserveInbound function, either by fixing the dependencies causing the build failures or by isolating and testing this code separately.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 116-129: zetaclient/chains/evm/observer/inbound.go#L116-L129
Added lines #L116 - L129 were not covered by tests

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

13-14: LGTM! Well-structured mock implementation.

The new mock method follows the established patterns and includes proper error handling.

Also applies to: 257-283

e2e/e2etests/e2etests.go (1)

16-16: LGTM! Well-organized test additions.

The new test entries for fast confirmation are properly structured and placed in their respective sections (ETH and Bitcoin).

Also applies to: 92-92, 240-245, 689-694

proto/zetachain/zetacore/fungible/query.proto (2)

28-34: Enhance RPC Addition Verification
The addition of the ForeignCoinsFromAsset RPC looks well-structured and adheres to RESTful design with a clear HTTP mapping (/zeta-chain/fungible/foreign_coins/{chain_id}/{asset}). Ensure that related server logic and client calls are updated accordingly to handle type validations and error conditions for the new parameters.


83-91: Validate New Message Definitions Consistency
The definitions for QueryGetForeignCoinsFromAssetRequest and QueryGetForeignCoinsFromAssetResponse are clear and consistent with existing patterns. Please double-check that downstream components (e.g., keeper implementations and test cases) correctly integrate these message types.

Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

Left some comments.

Q: let's say at T1 we have fast-observed pending cctx. At T2 we toggle the switch to disable fast observation for chainID. What would happen to this cctx?

}

// ensure the deposit amount does not exceed amount cap
fastAmountCap := constant.CalcInboundFastAmountCap(fCoins.LiquidityCap, multiplier)
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: does EACH pending cctx for chain_id+asset decrease the liquidity cap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, it is a static number which can only be manually updated with proposal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's consider a scenario where we have 100 ETH in a pool and allow fast cctx for deposits up to 0.05 ETH.

Now, imagine we have 1000 pending cctx, which would result in a deposit of 50 ETH (50% of the pool's value). Isn't it too risky to consider all of these cctx "fast"?

I believe each deposit should reduce the "fwindow" of pending cctx "fast" liquidity cap.

cc @lumtis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you probably mean some rate limit logic. There was a discussion under 3458 to protect against chain-level attack.

@ws4charlie
Copy link
Contributor Author

Left some comments.

Q: let's say at T1 we have fast-observed pending cctx. At T2 we toggle the switch to disable fast observation for chainID. What would happen to this cctx?

If fast observation is disabled halfway, the cctx will be eventually be created using SAFE mode. The pending ballot with minority votes will be pending for a while and cleaned up by zetacore eventually.

…ove divisor related file to chains pkg; renaming and comments
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.

The flow is unclear to me and might be simplified imo

vote creation -> you check the inbound is elligible for fast observation with the amount, if so, set ConfirmationMode_FAST

When ConfirmationMode_FAST is set then when you get the number of block confirmed with the fast value, the vote get sent

if lastBlock < lastScanned+confirmation {
return 0, 0
return nextBlock, nextBlock
Copy link
Member

Choose a reason for hiding this comment

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

Why this change here?

Copy link
Contributor Author

@ws4charlie ws4charlie Feb 26, 2025

Choose a reason for hiding this comment

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

The pair of (0, 0) gives no info about where we are now? Returning (nextBlock, nextBlock) tells the caller the next block to scan. The caller uses it to calculate FAST block range.

Comment on lines +94 to +95
if msg.ConfirmationMode == types.ConfirmationMode_FAST {
eligible, err := ob.IsInboundEligibleForFastConfirmation(ctx, &msg)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we check IsInboundEligibleForFastConfirmation when ConfirmationMode is true?

ConfirmationMode should be set at the inbound creation when IsInboundEligibleForFastConfirmation returns true

Copy link
Contributor Author

@ws4charlie ws4charlie Feb 26, 2025

Choose a reason for hiding this comment

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

The reason is that we need to skip posting vote if the msg carries FAST mode but not eligible for fast confirmation.

Comment on lines +189 to +192
confirmationMode := types.ConfirmationMode_FAST
if ob.IsBlockConfirmedForInboundSafe(event.Raw.BlockNumber) {
confirmationMode = types.ConfirmationMode_SAFE
}
Copy link
Member

Choose a reason for hiding this comment

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

This is when IsInboundEligibleForFastConfirmation should be used

It is unclear to me why we use IsBlockConfirmedForInboundSafe

Copy link
Contributor Author

@ws4charlie ws4charlie Feb 26, 2025

Choose a reason for hiding this comment

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

The same situation for caller. The caller (holding the vote message) needs to decide skip the vote or not. By default, the confirmation should be already FAST when logic arrives here. If the BlockNumber has safe confirmation count, then it's marked as SAFE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli breaking:proto chain:bitcoin Bitcoin chain related chain:evm zetaclient Issues related to ZetaClient zetacore Issues related to ZetaCore
Projects
None yet
4 participants