Adding extension for primitive types required and exported from rust-… by Sansh2356 · Pull Request #398 · braidpool/braidpool · GitHub
Skip to content

Adding extension for primitive types required and exported from rust-…#398

Open
Sansh2356 wants to merge 14 commits into
devfrom
replace-fork-rust-bitcoin
Open

Adding extension for primitive types required and exported from rust-…#398
Sansh2356 wants to merge 14 commits into
devfrom
replace-fork-rust-bitcoin

Conversation

@Sansh2356

Copy link
Copy Markdown
Contributor
  • Adding extensions for Network, Hrp and Params to reduce the issue of maintaining both the bech32 and rust-bitcoin fork as per our deps that will also hamper the SV2 integration due to mixed version of same deps and also will include the extensions required to support cpunet.
  • There were other inclusion to these in our forked repository to accommodate the full inclusion of cpunet such as genesis block hash and Magic which is required for establishing the p2p message communication but were not in use or would not be used at least in the near changes so have not included those.
  • Addressing Removing customized rust-bitcoin dependency #396 .

Copilot AI review requested due to automatic review settings March 1, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a rust_btc_wrapper module intended to carve out a small set of Bitcoin-network primitives (Network/HRP/Params/Address parsing) needed for CPUNet support, reducing reliance on maintaining a full custom rust-bitcoin fork, and updates coinbase address error plumbing accordingly (Issue #396).

Changes:

  • Added rust_btc_wrapper modules for NetworkExtension, chain Params, HRP constants, and a custom Address parser scaffold.
  • Updated CoinbaseError::AddressError to wrap a new crate-level ParseError and adjusted coinbase template address parsing error mapping.
  • Added bitcoin-internals dependency and exported the new wrapper module from node.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
node/src/template_creator.rs Adjusts address parse error mapping to new CoinbaseError::AddressError(ParseError) shape.
node/src/error.rs Introduces custom parsing error types (Base58/Bech32/ParseError) and updates CoinbaseError.
node/src/rust_btc_wrapper/mod.rs New module root exporting the wrapper extensions.
node/src/rust_btc_wrapper/network_ext.rs Adds NetworkExtension with serde, parsing, and Core-arg helpers (+ tests).
node/src/rust_btc_wrapper/params_ext.rs Adds chain parameter sets keyed by NetworkExtension (+ tests).
node/src/rust_btc_wrapper/hrp_ext.rs Adds HRP type/constants including CPUNet HRP (tc).
node/src/rust_btc_wrapper/address_ext.rs Adds custom address parsing/scipt_pubkey generation (currently with unsafe unwrap/expect paths).
node/src/lib.rs Exposes rust_btc_wrapper module.
node/Cargo.toml Adds bitcoin-internals dependency.
Cargo.lock Locks bitcoin-internals addition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/network_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/error.rs Outdated
Comment thread node/src/rust_btc_wrapper/network_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
Comment thread node/src/rust_btc_wrapper/address_ext.rs Outdated
@Sansh2356

Sansh2356 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

Updating this PR instead of closing with newer adaptation of implementing the Cpunet struct itself for handling all the functionalities related to Hrp,Params and parsing etc .

@zaidmstrr zaidmstrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approach ACK dc1fd3e

Thanks for taking this up. The approach used here is exactly what I thought initially about creating a separate utility file which serves the purpose of custom cpunet. This PR does the exact same. I haven't reviewed the code yet.

@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from dc1fd3e to bc19ce9 Compare April 11, 2026 10:11
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch 2 times, most recently from 9c1d2c6 to 60eeb25 Compare May 2, 2026 15:19

@zaidmstrr zaidmstrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As the goal of this PR is to remove the cpunet dependency from the custom rust-bitcoin. But I still see the dependency of custom rust-bitcoin in Cargo.toml. I think it would be good if you replaced that with the non custom version of it.

@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from a02cb3d to 62b2c97 Compare May 5, 2026 14:54

@zaidmstrr zaidmstrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have some suggestions described below. You can look at them.

Comment thread node/src/cpunet.rs Outdated
Comment thread node/src/cpunet.rs Outdated
Comment thread node/src/cpunet.rs Outdated
Comment thread node/src/cpunet.rs Outdated
Comment thread node/src/cpunet.rs Outdated
@Sansh2356

Copy link
Copy Markdown
Contributor Author

@zaidmstrr applied the suggestions .

@mcelrath

mcelrath commented May 8, 2026

Copy link
Copy Markdown
Collaborator

● PR #398 status: NEEDS‑WORK. Multiple reviewers agree the cpunet hash migration isn’t fully wired through, and there
are correctness blockers.

High‑priority blockers

  1. RPC bead IDs are wrong on cpunet. Several endpoints still use block_header.block_hash() instead of the new cpunet
    hash, which breaks lookups (notably get_genesis, get_parents, get_children, get_node_info). File:
    node/src/rpc_server.rs (e.g., around lines 386, 611, 660, 870).
  2. DB migration required. Existing cpunet rows hashed with the old algorithm won’t match new lookups; parent
    reconstruction can fail without a migration/rebuild of stored Bead.hash (db layer / handlers).
  3. Panic paths introduced. consensus_decode uses unwrap() in node/src/uncommitted_metadata/mod.rs:52, and expect()
    exists in braidpool-common/src/cpunet.rs:36. These can panic on malformed input.

Medium / notes

  • compute_block_hash checks "cpunet" case‑sensitively, risking silent fallback and hash/PoW divergence
    (node/src/utils/mod.rs).
  • FinalTemplate::block_hash still uses standard SHA256d; for cpunet this can diverge from the new hash if surfaced
    externally.
  • Minor perf note: avoid double hashing in stratum.rs (compute once and reuse).

@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from 7213fa9 to 84cc859 Compare May 8, 2026 21:58
@Sansh2356

Sansh2356 commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

● PR #398 status: NEEDS‑WORK. Multiple reviewers agree the cpunet hash migration isn’t fully wired through, and there are correctness blockers.

High‑priority blockers

1. RPC bead IDs are wrong on cpunet. Several endpoints still use block_header.block_hash() instead of the new cpunet
   hash, which breaks lookups (notably get_genesis, get_parents, get_children, get_node_info). File:
   node/src/rpc_server.rs (e.g., around lines 386, 611, 660, 870).

2. DB migration required. Existing cpunet rows hashed with the old algorithm won’t match new lookups; parent
   reconstruction can fail without a migration/rebuild of stored Bead.hash (db layer / handlers).

3. Panic paths introduced. consensus_decode uses unwrap() in node/src/uncommitted_metadata/mod.rs:52, and expect()
   exists in braidpool-common/src/cpunet.rs:36. These can panic on malformed input.

Medium / notes

* compute_block_hash checks "cpunet" case‑sensitively, risking silent fallback and hash/PoW divergence
  (node/src/utils/mod.rs).

* FinalTemplate::block_hash still uses standard SHA256d; for cpunet this can diverge from the new hash if surfaced
  externally.

* Minor perf note: avoid double hashing in stratum.rs (compute once and reuse).

The issue number 2 have been identified earlier and require separation of DB structures according to the network kind being used, will be filing an issue with regards to this by tomorrow .

@Sansh2356 Sansh2356 mentioned this pull request May 12, 2026
37 tasks
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from 84cc859 to 7dff966 Compare May 15, 2026 16:41
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from 7dff966 to 12b3ea4 Compare May 27, 2026 16:24
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch 2 times, most recently from ce722ed to 6c79f41 Compare June 4, 2026 04:51
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from 6c79f41 to b00ddda Compare June 11, 2026 12:47
@mcelrath

Copy link
Copy Markdown
Collaborator

Sansh2356 added 12 commits June 23, 2026 12:24
Removing inline wrappers in cpunet module and changing like name() etc.
…common

Moving the cpunet module into separate crate and updating the workspace,
updating the import paths and Cargo.toml accordingly.

This is aimed at using the common utils to be exported from the commons
crate across all the sub-crates present which will help in maintaining
structure and less coupling required due to separate imports .
chore: updating tests with network as function param
@Sansh2356 Sansh2356 force-pushed the replace-fork-rust-bitcoin branch from b00ddda to 17d423f Compare June 25, 2026 11:42
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.

4 participants