Skip to content

Conversation

fdefelici
Copy link
Contributor

@fdefelici fdefelici commented Jul 24, 2025

Description

This PR is the first step in refactoring the BitcoinRegtestController to enhance logic correctness, reduce code duplication, increase test coverage. and improve documentation.

It primarily introduces a port of the BitcoinRPCRequest implementation, with the following key changes:

  • Introduces a RpcTransport layer using the reqwest crate (as used in StacksClient from the stacks-signer package).
  • Adds a BitcoinRpcClient layer that exposes the relevant RPC APIs.
  • Aligns the reqwest version used across stacks-node and stacks-signer with the version already resolved in Cargo.lock
  • Includes a small enhancement to BitcoinCoreController to make it suitable for the new tests added in this PR.

To simplify review, the code introduced here is not yet integrated with the rest of the codebase. Follow-up PRs will handle that integration:

  • A PR to apply the BitcoinCoreController improvements (currently marked with TODOs).
  • One PR (or more if get to big) replacing the existing BitcoinRPCRequest with the new BitcoinRpcClient in BitcoinRegtestController.

Applicable issues

Additional info (benefits, drawbacks, caveats)

A few design decisions were made with the goal of preserving the current usage of the Bitcoin RPC API. Feedback on the following points would be appreciated:

  • Limited Rpc API Scope: This implementation includes only the subset of the Bitcoin RPC API currently used in the codebase, both in terms of available methods and supported input/output parameters. The idea is to keep the implementation minimal for now, with the flexibility to expand it as needed in the future.

  • Nonce Handling in RpcTransport: The original BitcoinRegtestController code uses a fixed nonce value ("stacks") as the id parameter in RPC requests (see code example below). To stay consistent, this PR allows customizable nonces in RpcTransport. However, if this behavior is not strictly required, we could simplify the implementation by generating nonces automatically and internally, avoiding the need to expose this as a configurable option. Would removing nonce configurability be acceptable, or is there a use case for keeping it?

pub fn get_raw_transaction(config: &Config, txid: &Txid) -> RPCResult<String> {
debug!("Get raw transaction {txid}");
let payload = BitcoinRPCRequest {
method: "getrawtransaction".to_string(),
params: vec![format!("{txid}").into()],
id: "stacks".to_string(),
jsonrpc: "2.0".to_string(),
};

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

fdefelici added 27 commits July 8, 2025 10:01
@fdefelici fdefelici self-assigned this Jul 24, 2025
@fdefelici fdefelici marked this pull request as ready for review July 24, 2025 14:28
@fdefelici fdefelici dismissed stale reviews from jcnelson and obycode via ec2db90 August 14, 2025 10:21
@fdefelici
Copy link
Contributor Author

PR updated with the merge of #6366 (related to BitcoinAddress regtest HRP management).

Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

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

LGTM!

@fdefelici fdefelici enabled auto-merge August 14, 2025 15:42
@fdefelici fdefelici added this pull request to the merge queue Aug 14, 2025
Merged via the queue into stacks-network:develop with commit 8715d36 Aug 14, 2025
3 of 4 checks passed
@fdefelici fdefelici deleted the refactor/bitcoin-rpc branch August 14, 2025 16:10
@github-project-automation github-project-automation bot moved this from Status: In Review to Status: ✅ Done in Stacks Core Eng Aug 14, 2025
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 57.92929% with 833 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.23%. Comparing base (495fe91) to head (cff3c9b).
⚠️ Report is 70 commits behind head on develop.

Files with missing lines Patch % Lines
...ode/src/burnchains/rpc/bitcoin_rpc_client/tests.rs 50.76% 352 Missing ⚠️
stacks-node/src/tests/bitcoin_rpc_integrations.rs 38.17% 332 Missing ⚠️
...cks-node/src/burnchains/rpc/rpc_transport/tests.rs 64.10% 70 Missing ⚠️
...-node/src/burnchains/rpc/bitcoin_rpc_client/mod.rs 89.20% 27 Missing ⚠️
stackslib/src/chainstate/stacks/mod.rs 43.24% 21 Missing ⚠️
...rc/burnchains/rpc/bitcoin_rpc_client/test_utils.rs 87.50% 13 Missing ⚠️
stacks-node/src/tests/bitcoin_regtest.rs 88.70% 7 Missing ⚠️
...tacks-node/src/burnchains/rpc/rpc_transport/mod.rs 91.30% 6 Missing ⚠️
...ommon/src/deps_common/bitcoin/network/serialize.rs 54.54% 5 Missing ⚠️

❌ Your project status has failed because the head coverage (58.23%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6329      +/-   ##
===========================================
+ Coverage    49.06%   58.23%   +9.17%     
===========================================
  Files          552      558       +6     
  Lines       352098   354077    +1979     
===========================================
+ Hits        172759   206199   +33440     
+ Misses      179339   147878   -31461     
Files with missing lines Coverage Δ
stacks-node/src/burnchains/mod.rs 62.50% <ø> (ø)
stacks-node/src/tests/mod.rs 45.17% <ø> (ø)
stackslib/src/burnchains/bitcoin/address.rs 54.02% <ø> (+5.36%) ⬆️
...ommon/src/deps_common/bitcoin/network/serialize.rs 50.96% <54.54%> (+3.08%) ⬆️
...tacks-node/src/burnchains/rpc/rpc_transport/mod.rs 91.30% <91.30%> (ø)
stacks-node/src/tests/bitcoin_regtest.rs 89.09% <88.70%> (+69.09%) ⬆️
...rc/burnchains/rpc/bitcoin_rpc_client/test_utils.rs 87.50% <87.50%> (ø)
stackslib/src/chainstate/stacks/mod.rs 73.51% <43.24%> (+9.81%) ⬆️
...-node/src/burnchains/rpc/bitcoin_rpc_client/mod.rs 89.20% <89.20%> (ø)
...cks-node/src/burnchains/rpc/rpc_transport/tests.rs 64.10% <64.10%> (ø)
... and 2 more

... and 400 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 495fe91...cff3c9b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Refactor: BitcoinRPCRequest Porting
4 participants