Skip to content

Validate chain/network parameter consistency to detect unsupported chains#2537

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/add-testnet4-support
Draft

Validate chain/network parameter consistency to detect unsupported chains#2537
Copilot wants to merge 5 commits intomasterfrom
copilot/add-testnet4-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 5, 2026

Bitcoin Core 28.0+ returns "chain": "testnet4" for testnet4 networks. embit 0.6.1 doesn't recognize this chain and defaults to elementsregtest with bech32 prefix ert, causing wallets to generate Liquid addresses that Bitcoin Core rejects.

Changes

  • Added validate_network_for_chain() in helpers.py: Maps chains to expected bech32 prefixes, detects mismatches when embit returns wrong network parameters (e.g., ert prefix for testnet4 chain)

  • Applied validation in Wallet.network property: Raises SpecterError with actionable message when chain/network mismatch detected, prevents address generation with wrong prefix

  • Applied validation in Node.network_parameters: Logs warning and falls back to mainnet parameters for node display (wallet operations still fail with clear error)

  • Added tests: Validates correct behavior for supported chains (main, test, regtest, signet, liquid chains) and proper error detection for unsupported chains

Example

Before:

# testnet4 → embit returns elementsregtest → generates ert1... addresses
wallet.network  # Returns network with bech32='ert' 
wallet.get_address(0)  # Generates ert1q7eppj...
# Bitcoin Core: "Invalid Bitcoin address"

After:

wallet.network  # Raises SpecterError
# "Chain 'testnet4' is not recognized. Recognized chains: main, test, regtest, signet, liquidv1, liquidtestnet, elementsregtest, elreg. Note: testnet4 support requires updating the embit library."
Original prompt

This section details on the original issue you should resolve

<issue_title>testnet4 support</issue_title>
<issue_description>does specter desktop support testnet4 ?

I get in this case addresses with prefix ert1 which bitcoin core cannot deal with:

Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]: [2026-01-03 22:05:45,816] ERROR in specter_error: Request error for method getreceivedbyaddress('ert1q7eppjgvgfupx5vhycatpglrh709cgkn6p3y3uq', 0): Invalid Bitcoin address
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]: Traceback (most recent call last):
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]:   File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/wallet/wallet.py", line 764, in getdata
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]:     value_on_address = self.rpc.getreceivedbyaddress(self.change_address, 0)
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]:                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]:   File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/rpc.py", line 509, in fn
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]:     raise RpcError(
Jan 03 22:05:45 raspberrypi5-c8-bf-64 specter[601]: cryptoadvance.specter.rpc.RpcError: Request error for method getreceivedbyaddress('ert1q7eppjgvgfupx5vhycatpglrh709cgkn6p3y3uq', 0): Invalid Bitcoin address

```</issue_description>

<agent_instructions>Please focus on the last comment only:

at least the chain should be detected correctly and and error message for example "not supported" displayed instead of generating wrong addresses</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@k9ert</author><body>
I'm not sure whether it's worth supporting testnet4 before we have reasonable support for signet.</body></comment_new>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 5, 2026

Deploy Preview for specter-desktop-docs canceled.

Name Link
🔨 Latest commit 5b7e10c
🔍 Latest deploy log https://app.netlify.com/projects/specter-desktop-docs/deploys/6984fed2f42fcf0008514903

Copilot AI and others added 4 commits February 5, 2026 20:26
Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
Co-authored-by: k9ert <117085+k9ert@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for testnet4 in Specter Desktop Validate chain/network parameter consistency to detect unsupported chains Feb 5, 2026
Copilot AI requested a review from k9ert February 5, 2026 20:37
Copy link
Copy Markdown
Contributor

@al-munazzim al-munazzim left a comment

Choose a reason for hiding this comment

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

Good workaround for the embit limitation. A few observations:

  1. Root cause filed upstream: Created embit#108 - once embit adds testnet4 support, this validation becomes simpler.

  2. Fallback to 'main' in node.py could confuse users: If someone connects to a testnet4 node, the node info display will show mainnet parameters while wallet operations fail. Consider: could we show 'unknown/unsupported' in the UI instead of mainnet values?

  3. Minor: The function-attribute caching pattern (validate_network_for_chain._known_chains_text) is unusual. A module-level constant would be more Pythonic:

_KNOWN_CHAINS = frozenset(['main', 'test', 'regtest', ...])
_KNOWN_CHAINS_TEXT = ', '.join(sorted(_KNOWN_CHAINS))
  1. Test coverage is good - covers valid chains and the testnet4 edge case.

Overall: ✅ Approve with minor suggestions. The approach is sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testnet4 support

3 participants