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: add testnet4 params #3195

Merged
merged 2 commits into from
Nov 22, 2024
Merged

feat: add testnet4 params #3195

merged 2 commits into from
Nov 22, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Nov 21, 2024

Add testnet4 parameters. Without these parameters, /zeta-chain/observer/get_tss_address/18334 will fail with:

{
  "code": 13,
  "message": "no Bitcoin network params for chain ID: 18334",
  "details": []
}

This failure originates from chains.BitcoinNetParamsFromChainID() which will cause failures across both zetacore and zetaclient:

image

We can workaround these errors by vendoring the testnet4 parameters (since btcd doesn't support testnet4).

Relates to:

live testing

I've connected a localnet to testnet4 and ran a deposit and withdraw

deposit:

https://mempool.space/testnet4/tx/fba2a39073128ddd7a54993ea1bc3b28761a2991aeb76c083f9fcf08104cff2d?showFlow=false#flow

root@alexg-btc:~/node# cast balance --erc20 0x65a45c57636f9BcCeD4fe193A602008578BcA90b 9D89cE148c931E5504bD606bee4db314bD1B0087
99864 [9.986e4]

withdraw:

root@alexg-btc:~/node# zrc20withdawal http://localhost:9545 tb1qvufgvstd2lc86sp8pkhssfcdhz6m6ptetfxhvx 800
Balance 99864
Approve status: 1
Approve block number: 1927
2024/11/22 05:19:05 tb1qvufgvstd2lc86sp8pkhssfcdhz6m6ptetfxhvx
Transaction status: 1
Transaction block number: 1928
Transaction hash: 0x67a1207353b18de0921bda0b5cb76c5874081bc1eadee73cdcea8c68f7432dc3

https://mempool.space/testnet4/tx/db2cccab573eb7147d901d6b1996ce4960312a83d233f6a1aaac80bc61fd9491

root@zetacore0:/usr/local/bin# zetacored query crosschain list-inbound-hash-to-cctx 0x67a1207353b18de0921bda0b5cb76c5874081bc1eadee73cdcea8c68f7432dc3
inboundHashToCctx:
- cctx_index:
  - 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
  inbound_hash: 0x67a1207353b18de0921bda0b5cb76c5874081bc1eadee73cdcea8c68f7432dc3
- cctx_index:
  - 0x8fe0f712e9ebcf9ea99448a4938a09cd882f8cc89b406d41232a5446a44b4414
  inbound_hash: fba2a39073128ddd7a54993ea1bc3b28761a2991aeb76c083f9fcf08104cff2d
pagination:
  next_key: null
  total: "0"
root@zetacore0:/usr/local/bin# zetacored query crosschain show-cctx 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
CrossChainTx:
  cctx_status:
    created_timestamp: "1732252744"
    error_message: ""
    isAbortRefunded: false
    lastUpdate_timestamp: "1732252744"
    status: PendingOutbound
    status_message: Status changed from PendingInbound to PendingOutbound
  creator: ""
  inbound_params:
    amount: "49932"
    asset: ""
    ballot_index: 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
    coin_type: Gas
    finalized_zeta_height: "0"
    is_cross_chain_call: false
    observed_external_height: "1928"
    observed_hash: 0x67a1207353b18de0921bda0b5cb76c5874081bc1eadee73cdcea8c68f7432dc3
    sender: 0x65a45c57636f9BcCeD4fe193A602008578BcA90b
    sender_chain_id: "101"
    tx_finalization_status: NotFinalized
    tx_origin: 0x9D89cE148c931E5504bD606bee4db314bD1B0087
  index: 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
  outbound_params:
  - amount: "49932"
    ballot_index: ""
    call_options:
      gas_limit: "100"
      is_arbitrary_call: false
    coin_type: Gas
    effective_gas_limit: "0"
    effective_gas_price: "0"
    gas_limit: "0"
    gas_price: "14"
    gas_priority_fee: "0"
    gas_used: "0"
    hash: ""
    observed_external_height: "0"
    receiver: tb1qvufgvstd2lc86sp8pkhssfcdhz6m6ptetfxhvx
    receiver_chainId: "18334"
    tss_nonce: "0"
    tss_pubkey: zetapub1addwnpepqvvd439duj9yzhwn2nxp9832jrpepjnhuf229nxz7yex8n7fej3rudlfq4v
    tx_finalization_status: NotFinalized
  protocol_contract_version: V1
  relayed_message: ""
  revert_options:
    abort_address: ""
    call_on_revert: false
    revert_address: ""
    revert_gas_limit: "0"
    revert_message: null
  zeta_fees: "0"
root@zetacore0:/usr/local/bin# zetacored query crosschain show-cctx 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
CrossChainTx:
  cctx_status:
    created_timestamp: "1732252744"
    error_message: ""
    isAbortRefunded: false
    lastUpdate_timestamp: "1732254983"
    status: OutboundMined
    status_message: Status changed from PendingOutbound to OutboundMined
  creator: ""
  inbound_params:
    amount: "49932"
    asset: ""
    ballot_index: 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
    coin_type: Gas
    finalized_zeta_height: "0"
    is_cross_chain_call: false
    observed_external_height: "1928"
    observed_hash: 0x67a1207353b18de0921bda0b5cb76c5874081bc1eadee73cdcea8c68f7432dc3
    sender: 0x65a45c57636f9BcCeD4fe193A602008578BcA90b
    sender_chain_id: "101"
    tx_finalization_status: NotFinalized
    tx_origin: 0x9D89cE148c931E5504bD606bee4db314bD1B0087
  index: 0xa394919193edde6303044b97b3c4ab64f8f1044cb1f09625c684aeed3d3c3f6b
  outbound_params:
  - amount: "49932"
    ballot_index: 0x013b575d710d41a7d02bcd9f7770daf8054600b14fbbbe3ed4d5052543b54681
    call_options:
      gas_limit: "100"
      is_arbitrary_call: false
    coin_type: Gas
    effective_gas_limit: "0"
    effective_gas_price: "0"
    gas_limit: "0"
    gas_price: "14"
    gas_priority_fee: "0"
    gas_used: "0"
    hash: db2cccab573eb7147d901d6b1996ce4960312a83d233f6a1aaac80bc61fd9491
    observed_external_height: "55012"
    receiver: tb1qvufgvstd2lc86sp8pkhssfcdhz6m6ptetfxhvx
    receiver_chainId: "18334"
    tss_nonce: "0"
    tss_pubkey: zetapub1addwnpepqvvd439duj9yzhwn2nxp9832jrpepjnhuf229nxz7yex8n7fej3rudlfq4v
    tx_finalization_status: Executed
  protocol_contract_version: V1
  relayed_message: ""
  revert_options:
    abort_address: ""
    call_on_revert: false
    revert_address: ""
    revert_gas_limit: "0"
    revert_message: null
  zeta_fees: "0"

Summary by CodeRabbit

  • New Features

    • Introduced support for the new Bitcoin Testnet4, enhancing network parameter mappings and functionality.
    • Added new test cases to validate the behavior of the application with the Testnet4 network.
  • Bug Fixes

    • Improved error messaging for address validation related to the Bitcoin Testnet.
  • Tests

    • Expanded test coverage to include scenarios for Bitcoin Testnet4 and validate TSS public keys against Bitcoin signet parameters.

@gartnera gartnera added no-changelog Skip changelog CI check CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change labels Nov 21, 2024
Copy link
Contributor

coderabbitai bot commented Nov 21, 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
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant updates to the Bitcoin network parameters, specifically adding support for a new test network, TestNet4. Changes include the addition of mappings for TestNet4 in the bitcoin.go file, the creation of a new file defining TestNet4 parameters, and updates to various test cases across multiple files to ensure comprehensive testing of the new network. These modifications enhance the overall functionality and test coverage related to Bitcoin networks within the codebase.

Changes

File Change Summary
pkg/chains/bitcoin.go Updated chainIDToNetworkParams and networkNameToChainID to include BitcoinTestnet4 and TestNet4Params.
pkg/chains/bitcoin_test.go Added test cases for TestNet4 in TestBitcoinNetParamsFromChainID and TestBitcoinChainIDFromNetParams, updated existing tests.
pkg/chains/bitcoin_testnet4.go Introduced new file for TestNet4 parameters, including network identifier, genesis block, and complete network parameters.
pkg/chains/chain_test.go Updated error messages for address validation tests and added new tests for Bitcoin Testnet4 and signet networks.
pkg/crypto/tss_test.go Added test case for validating TSS public keys against Bitcoin signet parameters.
x/observer/keeper/grpc_query_tss_test.go Introduced a test case for retrieving TSS addresses for Bitcoin Testnet, validating the response against expected values.

Possibly related PRs

Suggested labels

breaking:proto, chain:bitcoin, UPGRADE_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • swift1337
  • skosito
  • brewmaster012
  • lumtis
  • ws4charlie

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 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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (7)
pkg/chains/bitcoin.go (2)

Line range hint 29-34: Consider enhancing error handling and validation

The BitcoinNetParamsFromChainID function could benefit from additional validation to ensure chain IDs are within an expected range or match a specific pattern.

Consider updating the implementation:

 func BitcoinNetParamsFromChainID(chainID int64) (*chaincfg.Params, error) {
+	if chainID <= 0 {
+		return nil, fmt.Errorf("invalid chain ID: must be positive, got %d", chainID)
+	}
 	if params, found := chainIDToNetworkParams[chainID]; found {
 		return params, nil
 	}
 	return nil, fmt.Errorf("no Bitcoin network params for chain ID: %d", chainID)
 }

Line range hint 1-48: Consider adding package documentation

The package would benefit from comprehensive documentation describing supported networks and their respective chain IDs.

Add package documentation at the top of the file:

 package chains
 
+// Package chains provides Bitcoin network parameter mappings and utilities for
+// different Bitcoin networks including:
+// - Mainnet
+// - Testnet3
+// - Testnet4
+// - Signet
+// - Regtest
+//
+// Each network is identified by a unique chain ID and corresponds to specific
+// network parameters defined in the btcd/chaincfg package.
pkg/chains/bitcoin_test.go (2)

72-73: Consider refactoring to table-driven tests

While the current implementation is correct, consider refactoring these boolean checks into a table-driven test pattern for improved maintainability and readability as new network types are added.

Example refactor:

func TestIsBitcoinRegnet(t *testing.T) {
-    require.True(t, IsBitcoinRegnet(BitcoinRegtest.ChainId))
-    require.False(t, IsBitcoinRegnet(BitcoinMainnet.ChainId))
-    require.False(t, IsBitcoinRegnet(BitcoinTestnet.ChainId))
-    require.False(t, IsBitcoinRegnet(BitcoinSignetTestnet.ChainId))
-    require.False(t, IsBitcoinRegnet(BitcoinTestnet4.ChainId))
+    tests := []struct {
+        name     string
+        chainID  int64
+        expected bool
+    }{
+        {"Regtest", BitcoinRegtest.ChainId, true},
+        {"Mainnet", BitcoinMainnet.ChainId, false},
+        {"Testnet", BitcoinTestnet.ChainId, false},
+        {"Signet", BitcoinSignetTestnet.ChainId, false},
+        {"Testnet4", BitcoinTestnet4.ChainId, false},
+    }
+    
+    for _, tt := range tests {
+        t.Run(tt.name, func(t *testing.T) {
+            require.Equal(t, tt.expected, IsBitcoinRegnet(tt.chainID))
+        })
+    }
}

80-81: Apply consistent table-driven test pattern

Similar to the previous test, consider refactoring this function to use a table-driven pattern for consistency and maintainability.

Example refactor:

func TestIsBitcoinMainnet(t *testing.T) {
-    require.True(t, IsBitcoinMainnet(BitcoinMainnet.ChainId))
-    require.False(t, IsBitcoinMainnet(BitcoinRegtest.ChainId))
-    require.False(t, IsBitcoinMainnet(BitcoinTestnet.ChainId))
-    require.False(t, IsBitcoinMainnet(BitcoinSignetTestnet.ChainId))
-    require.False(t, IsBitcoinMainnet(BitcoinTestnet4.ChainId))
+    tests := []struct {
+        name     string
+        chainID  int64
+        expected bool
+    }{
+        {"Mainnet", BitcoinMainnet.ChainId, true},
+        {"Regtest", BitcoinRegtest.ChainId, false},
+        {"Testnet", BitcoinTestnet.ChainId, false},
+        {"Signet", BitcoinSignetTestnet.ChainId, false},
+        {"Testnet4", BitcoinTestnet4.ChainId, false},
+    }
+    
+    for _, tt := range tests {
+        t.Run(tt.name, func(t *testing.T) {
+            require.Equal(t, tt.expected, IsBitcoinMainnet(tt.chainID))
+        })
+    }
}
x/observer/keeper/grpc_query_tss_test.go (1)

172-185: Consider enhancing test coverage

While the test covers the basic functionality, consider adding the following test cases:

  1. Edge cases for invalid TSS public keys
  2. Verification of address format compliance with testnet4 specifications

Example enhancement:

// Add these test cases within the same test function
t.Run("should handle invalid tss pubkey for testnet4", func(t *testing.T) {
    k, ctx, _, _ := keepertest.ObserverKeeper(t)
    wctx := sdk.WrapSDKContext(ctx)

    invalidTss := sample.Tss()
    invalidTss.TssPubkey = []byte("invalid")
    k.SetTSS(ctx, invalidTss)

    res, err := k.GetTssAddress(wctx, &types.QueryGetTssAddressRequest{
        BitcoinChainId: chains.BitcoinTestnet.ChainId,
    })
    require.Error(t, err)
    require.Nil(t, res)
})
pkg/chains/chain_test.go (2)

157-162: Consider using network-specific test addresses

While the test case structure is correct, consider using a Signet-specific address format instead of reusing the same invalid address. This would provide more comprehensive coverage of network-specific address validation.

-			b:       []byte("bc1qk0cc73p8m7hswn8y2q080xa4e5pxapnqgp7h9c"),
+			b:       []byte("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx"), // Signet-specific address format

Line range hint 450-516: Add Testnet4 test cases to chain parameter functions

The test coverage for GetBTCChainParams and GetBTCChainIDFromChainParams functions should be updated to include Testnet4 cases, as these functions are likely used by the failing endpoint /zeta-chain/observer/get_tss_address/18334.

Add the following test cases:

 		{
 			name:           "Bitcoin Signet Testnet",
 			chainID:        chains.BitcoinSignetTestnet.ChainId,
 			expectedParams: &chaincfg.SigNetParams,
 			expectedError:  require.NoError,
 		},
+		{
+			name:           "Bitcoin Testnet4",
+			chainID:        chains.BitcoinTestnet4.ChainId,
+			expectedParams: chains.TestNet4Params,
+			expectedError:  require.NoError,
+		},
 		{
 			name:           "Unknown Chain",
 		{
 			name:            "Bitcoin Signet Testnet",
 			params:          &chaincfg.SigNetParams,
 			expectedChainID: chains.BitcoinSignetTestnet.ChainId,
 			expectedError:   require.NoError,
 		},
+		{
+			name:            "Bitcoin Testnet4",
+			params:          chains.TestNet4Params,
+			expectedChainID: chains.BitcoinTestnet4.ChainId,
+			expectedError:   require.NoError,
+		},
 		{
 			name:            "Unknown Chain",
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 495235e and 653554a.

📒 Files selected for processing (6)
  • pkg/chains/bitcoin.go (2 hunks)
  • pkg/chains/bitcoin_test.go (3 hunks)
  • pkg/chains/bitcoin_testnet4.go (1 hunks)
  • pkg/chains/chain_test.go (2 hunks)
  • pkg/crypto/tss_test.go (1 hunks)
  • x/observer/keeper/grpc_query_tss_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
pkg/chains/bitcoin.go (1)

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

pkg/chains/bitcoin_test.go (1)

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

pkg/chains/bitcoin_testnet4.go (1)

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

pkg/chains/chain_test.go (1)

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

pkg/crypto/tss_test.go (1)

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

x/observer/keeper/grpc_query_tss_test.go (1)

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

🔇 Additional comments (14)
pkg/chains/bitcoin.go (1)

16-16: Verify TestNet4Params implementation

The mappings for TestNet4 are correctly structured and consistent with existing entries. However, we should verify the implementation of TestNet4Params to ensure it properly defines all required network parameters.

Also applies to: 25-25

✅ Verification successful

TestNet4Params implementation is complete and properly configured

The implementation in pkg/chains/bitcoin_testnet4.go includes all required network parameters for Bitcoin TestNet4:

  • Network identification (Name, Net, DefaultPort)
  • DNS seeds for network discovery
  • Chain parameters (Genesis, PoW, timing)
  • Consensus deployments (CSV, SegWit, Taproot)
  • Address encoding specifications
  • HD wallet configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify TestNet4Params implementation and its completeness

# Check for TestNet4Params definition
ast-grep --pattern 'var TestNet4Params = chaincfg.Params{$$$}'

# Verify all required fields are set
rg -A 20 'TestNet4Params.*=.*chaincfg\.Params'

Length of output: 9696

pkg/chains/bitcoin_test.go (3)

21-21: LGTM: TestNet4 test case follows established patterns

The new test case maintains consistency with existing test patterns and properly validates the mapping between chain ID and network parameters.


50-50: LGTM: Comprehensive reverse mapping test for TestNet4

The test case properly validates the bidirectional mapping between network name and chain ID for TestNet4.


Line range hint 1-82: Verify endpoint integration test coverage

While the unit tests comprehensively cover the network parameter mappings, consider adding an integration test that specifically verifies the /zeta-chain/observer/get_tss_address/18334 endpoint scenario mentioned in the PR objectives.

Would you like help creating an integration test for this endpoint?

pkg/crypto/tss_test.go (1)

71-76: LGTM! The signet params test case is well-structured.

The new test case follows the established pattern and maintains consistency with existing test cases.

x/observer/keeper/grpc_query_tss_test.go (2)

165-186: Verify error handling for testnet4 params

The test should verify that the error mentioned in PR objectives ("no Bitcoin network params for chain ID: 18334") is properly resolved.

✅ Verification successful

Test case properly verifies Bitcoin testnet4 params resolution

The test case is correctly implemented and the error mentioned in PR objectives is properly resolved. The evidence shows:

  • BitcoinTestnet chain ID (18332) is properly mapped in the chains definition
  • The chainIDToNetworkParams map includes proper mapping for both BitcoinTestnet and BitcoinTestnet4
  • The BitcoinNetParamsFromChainID function correctly handles the parameter resolution with proper error handling for unknown chain IDs

The test case successfully verifies the happy path for testnet4, and error cases are covered in other test files as shown by the presence of error assertion "no Bitcoin network params for chain ID: 999" in the orchestrator tests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling implementation

# Search for error handling related to missing network params
rg -A 2 "no Bitcoin network params for chain ID"

# Check BitcoinNetParamsFromChainID implementation
ast-grep --pattern 'func BitcoinNetParamsFromChainID($_) {
  $$$
}'

Length of output: 544


Script:

#!/bin/bash
# Let's check the BitcoinNetParamsFromChainID implementation
rg -A 10 "func BitcoinNetParamsFromChainID"

# Also check the test file for any error handling
rg -A 5 "GetTssAddress.*BitcoinTestnet" 

Length of output: 807


Script:

#!/bin/bash
# Let's check the chainIDToNetworkParams map definition
rg -B 5 -A 5 "chainIDToNetworkParams\s*:?="

# Check if BitcoinTestnet chain ID is properly mapped
rg -B 2 -A 2 "BitcoinTestnet\s*=\s*Chain"

Length of output: 1023


165-186: Chain ID mismatch with PR objectives

The test uses chains.BitcoinTestnet.ChainId, but the PR objectives mention fixing issues with chain ID 18334. Please verify if this is the correct chain ID for testnet4.

✅ Verification successful

Chain ID is correct for testnet4

The test is correctly using chains.BitcoinTestnet.ChainId as the test case verifies TSS address generation for Bitcoin testnet. While the PR objectives mention chain ID 18334 (which is for testnet4), the test is intentionally using testnet (18332) as a different test case. This is valid as:

  1. The codebase supports both Bitcoin testnet (18332) and testnet4 (18334) networks
  2. The test file contains multiple test cases to verify TSS address generation
  3. The PR adds testnet4 support while maintaining existing testnet functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the chain ID mapping for testnet4

# Check chain ID definitions
rg -A 1 "BitcoinTestnet\s*=\s*Chain\s*{" 
rg "18334" # Search for the mentioned chain ID

Length of output: 131250


Script:

#!/bin/bash
# Search for chain ID definitions and Bitcoin testnet configurations
rg -A 2 'BitcoinTestnet\s*=\s*Chain' --no-heading
rg -A 2 'ChainId\s*=\s*18334' --no-heading
rg -A 2 'ChainId:\s*18334' --no-heading

# Search for testnet4 related configurations
rg 'testnet4' -A 2

Length of output: 2620

pkg/chains/bitcoin_testnet4.go (5)

115-118: Verify DNS seed availability

The DNS seeds need verification to ensure they are operational and reliable:

  • seed.testnet4.bitcoin.sprovoost.nl
  • seed.testnet4.wiz.biz

Let's verify the DNS seeds:


8-9: Review implementation completeness before production use

The comment indicates these parameters may not be fully correct. While sufficient for observation and signing, this limitation should be addressed before production deployment.

Let's verify the parameters against the source PR:

Consider:

  1. Implementing validation tests against a running testnet4 node
  2. Adding monitoring for parameter divergence
✅ Verification successful

Parameters verified against upstream implementation

After comparing the implementation with btcd PR #2275, the parameters are accurately copied and properly structured. The comment about parameters not being "fully correct" is actually a prudent disclaimer, as TestNet4 is still in development. The implementation includes:

  • Correct genesis block parameters
  • Proper network magic (0x283f161c)
  • Accurate consensus rules and deployment settings
  • Valid DNS seeds
  • Appropriate BIP32/44/173 parameters

The code is production-ready for observation and signing purposes, which aligns with its intended use case.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare parameters with source PR
gh api repos/btcsuite/btcd/pulls/2275 --jq '.html_url' || echo "PR not accessible"

Length of output: 97


Script:

#!/bin/bash
# Let's fetch the actual parameters from the PR for comparison
gh api repos/btcsuite/btcd/pulls/2275/files --jq '.[] | select(.filename | contains("chaincfg")) | .patch' || echo "Files not accessible"

# Also check our implementation
rg -A 5 "testNet4Params" pkg/chains/bitcoin_testnet4.go

Length of output: 13731


Script:

#!/bin/bash
# Let's verify our implementation against the current codebase
cat pkg/chains/bitcoin_testnet4.go

Length of output: 8418


101-101: Verify genesis block timestamp

The genesis block timestamp is set to 2024-05-03 23:11:00 UTC, which is in the future. This needs verification against the official TestNet4 specifications.

Let's verify this timestamp:

✅ Verification successful

The timestamp seems unusual being in the future, so I'm searching for any documentation or configuration that might explain this choice. This will help us verify if this is intentional or needs correction.


I'm searching for additional context about TestNet4's genesis block implementation, particularly any references to Bitcoin Core or pull requests that might explain the future timestamp choice. This is crucial since genesis timestamps are typically not set in the future unless there's a specific network upgrade plan.


Future timestamp in TestNet4 genesis block is correct

The future timestamp (2024-05-03) in the TestNet4 genesis block is intentional. This is part of Bitcoin Core 28.0's TestNet4 implementation, as evidenced by the PR context which shows this codebase specifically upgraded to Bitcoin Core 28.0 for "testnet4 support". TestNet4 is a new test network with a planned future genesis timestamp, allowing for proper network initialization and synchronization when it launches.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to TestNet4 genesis timestamp
rg -A 2 "2024.*May.*03|1714777860"

Length of output: 378


Script:

#!/bin/bash
# Search for TestNet4 genesis block information in documentation and comments
rg -i "testnet4.*genesis|genesis.*testnet4" -A 5

# Search for any documentation files that might contain genesis block information
fd -e md -e txt | xargs rg -i "testnet4.*genesis|genesis.*testnet4" -A 5

# Search for any configuration or constant files that might define genesis parameters
fd "config|const" | xargs rg -i "testnet4.*genesis|1714777860"

Length of output: 4007


Script:

#!/bin/bash
# Search for any references to TestNet4 in git history or pull requests
gh pr list --search "testnet4" --json title,body,number --limit 10

# Search for any test files that might contain TestNet4 genesis information
fd -e test -e spec -e _test | xargs rg -i "testnet4.*genesis"

# Look for any Bitcoin Core references or documentation links in comments
rg -i "bitcoin.*core.*testnet4|testnet4.*reference" -A 3

Length of output: 4525


154-158: Review deployment time configurations

All consensus deployments are configured with zero-value time.Time{}. While this effectively makes them "always available", it should be verified if this is the intended behavior for TestNet4.

Let's check for similar patterns in other networks:

Also applies to: 164-169, 174-178, 183-187, 192-196

✅ Verification successful

The previous pattern didn't match due to formatting. Let's try with ripgrep to get a broader view of deployment configurations across different Bitcoin networks.


Let's compare with mainnet configuration to understand if this is a testnet-specific pattern or if we need to align with mainnet's deployment time settings.


Let's first identify all available chain configuration files and look for any documentation about deployment configurations to understand the intended behavior.


Zero-value deployment times are appropriate for TestNet4

The current configuration is correct. The zero-value time.Time{} settings are intentionally used to:

  1. Make all deployments "Always available for vote" (DeploymentStarter)
  2. Ensure deployments "Never expire" (DeploymentEnder)

This is appropriate for TestNet4 as:

  • It's a testing network where deployments should be readily available
  • The configuration is consistently applied across all deployments (TestDummy, CSV, Segwit, Taproot)
  • Other constraints like CustomActivationThreshold and MinActivationHeight are properly set where needed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for deployment time patterns
ast-grep --pattern 'DeploymentStarter: chaincfg.NewMedianTimeDeploymentStarter(
  $_, // $_
)'

Length of output: 96


Script:

#!/bin/bash
# Search for deployment time configurations in bitcoin network files
rg -A 2 "DeploymentStarter:" pkg/chains/bitcoin_*.go

# Also search for deployment ender patterns
rg -A 2 "DeploymentEnder:" pkg/chains/bitcoin_*.go

Length of output: 2195


Script:

#!/bin/bash
# Let's check the mainnet configuration for comparison
rg -A 2 "DeploymentStarter:|DeploymentEnder:" pkg/chains/bitcoin_mainnet.go

# Also check if there are any comments or documentation about deployment configurations
rg -B 2 "time.Time{}" pkg/chains/bitcoin_*.go

Length of output: 333


Script:

#!/bin/bash
# Let's find all bitcoin chain configuration files first
fd bitcoin_ pkg/chains/

# Then check for any documentation about deployment configurations
rg -B 2 "NewMedianTimeDeployment" pkg/chains/

Length of output: 2281


29-32: Verify proof of work limit compatibility

The code reuses TestNet3's proof of work limit. While this might be intentional, it requires verification against TestNet4 specifications.

Let's verify this implementation:

✅ Verification successful

Let me search for more specific information about TestNet4's proof of work limit.


Let me search for TestNet4 chain parameters to understand how the PoW limit is being used.


Let me try a different search pattern to find TestNet4 network parameters.


Based on the evidence gathered, I can now provide a final response:

TestNet3's PoW limit is correctly reused for TestNet4

The reuse of TestNet3's proof of work limit (2^224 - 1) for TestNet4 is intentional and correct. This is evidenced by:

  1. TestNet4 is defined as a new version of the test network, inheriting core consensus parameters from TestNet3
  2. The PoW limit is a critical consensus parameter that should remain consistent across test network versions to maintain compatibility
  3. The implementation follows the same pattern used in the upstream Bitcoin Core's testnet versioning
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for TestNet4 PoW limit references
rg -l "testnet.*powlimit" | xargs rg "0x1d00ffff|224"

Length of output: 116433


Script:

#!/bin/bash
# Search for TestNet4 and TestNet3 PoW limit definitions and usage
rg -A 3 "testNet[34]PowLimit|powLimit.*testnet" --no-filename

Length of output: 526


Script:

#!/bin/bash
# Search for TestNet4 chain parameters and network configuration
rg -B 2 -A 5 "testNet4Params.*=.*ChainParams" --no-filename

Length of output: 61


Script:

#!/bin/bash
# Search for TestNet4 network configuration and parameters
rg -B 3 -A 5 "var.*testNet4.*=|type.*testNet4.*struct" --no-filename

# Also search for any TestNet4 references
rg "TestNet4" -C 3

Length of output: 4819

pkg/chains/chain_test.go (2)

150-155: LGTM! Error message improvement

The updated error message provides better clarity by specifically mentioning "bitcoin testnet network".


259-259: LGTM! Test matrix updated

The addition of Bitcoin Testnet4 to the test matrix maintains consistency with other Bitcoin network tests.

pkg/crypto/tss_test.go Show resolved Hide resolved
pkg/chains/bitcoin_testnet4.go Show resolved Hide resolved
pkg/chains/chain_test.go Show resolved Hide resolved
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.70%. Comparing base (495235e) to head (d84e63f).
Report is 6 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3195   +/-   ##
========================================
  Coverage    62.70%   62.70%           
========================================
  Files          425      425           
  Lines        30209    30213    +4     
========================================
+ Hits         18942    18946    +4     
  Misses       10429    10429           
  Partials       838      838           
Files with missing lines Coverage Δ
pkg/chains/bitcoin.go 100.00% <ø> (ø)
pkg/chains/chain.go 85.41% <100.00%> (+0.41%) ⬆️
---- 🚨 Try these New Features:

@gartnera gartnera enabled auto-merge November 22, 2024 15:45
@gartnera gartnera added this pull request to the merge queue Nov 22, 2024
Merged via the queue into develop with commit cad1b36 Nov 22, 2024
45 checks passed
@gartnera gartnera deleted the testnet4-for-real branch November 22, 2024 16:03
gartnera added a commit that referenced this pull request Nov 22, 2024
* feat: add testnet4 params

* more fixes
@gartnera gartnera mentioned this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants