Skip to content

feat: add multi-network support (testnet/signet/regtest)#14

Open
b-l-u-e wants to merge 7 commits into2140-dev:masterfrom
b-l-u-e:feat/multi-network-support
Open

feat: add multi-network support (testnet/signet/regtest)#14
b-l-u-e wants to merge 7 commits into2140-dev:masterfrom
b-l-u-e:feat/multi-network-support

Conversation

@b-l-u-e
Copy link
Copy Markdown
Collaborator

@b-l-u-e b-l-u-e commented Mar 7, 2026

This PR adds multi-network support: the app detects the connected chain via getblockchaininfo RPC and stores fee estimates per network so mainnet and testnet data are not mixed.

  • Detection: Backend calls getblockchaininfo on startup and when serving fee/blockcount; chain and chain_display are returned to the frontend.
  • Storage: fee_estimates table has a network column with a migration for existing DBs; collector and read paths filter by current network.
  • UI: Reusable NetworkBadge shows the detected network (MAINNET / TESTNET / SIGNET / REGTEST) on the dashboard, Stats, and Mempool pages.
  • Config/docs: rpc_config.ini.example documents port mapping; README updated with multi-network behaviour.

Dependency

i believe this branch depends on #13

Closes #7

@b-l-u-e b-l-u-e requested a review from ismaelsadeeq March 7, 2026 11:38
@ismaelsadeeq
Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Could you rebase this onto the latest master there have been some recent fixes that need to be incorporated.

Also, to make the review easier, it would be great if you could split this into atomic commits, with each commit relating to a single, isolated change

@b-l-u-e
Copy link
Copy Markdown
Collaborator Author

b-l-u-e commented Mar 10, 2026

Thanks for the PR!

Could you rebase this onto the latest master there have been some recent fixes that need to be incorporated.

Also, to make the review easier, it would be great if you could split this into atomic commits, with each commit relating to a single, isolated change

Thank you for the feedback I will adjust the changes

@b-l-u-e b-l-u-e force-pushed the feat/multi-network-support branch from ff94a34 to 25c0867 Compare March 10, 2026 19:07
Copy link
Copy Markdown
Collaborator

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

I did a first pass at this.

The organization of the commits seems somewhat arbitrary and does not flow.
You are testing something before it is introduced.

Did you test this locally? I have a branch already with some data, and running this branch seems to cause a recurrent crash in the backend process.

logs
objc[61969]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,161 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,161 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61970]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61970]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,216 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,216 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61971]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61971]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,265 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,265 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61972]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61972]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,353 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,353 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61973]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61973]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,433 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,433 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61974]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61974]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,456 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,457 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61975]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61975]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,521 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,521 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61976]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61976]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,585 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,586 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61977]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61977]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,599 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,599 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61978]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61978]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,655 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,656 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61979]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61979]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2026-03-12 14:24:40,726 - services.database_service - INFO - Database initialised at /Users/abubakarismail/Desktop/Work/bitcoin-dev/bitcoin-core-fees/backend/src/services/fee_analysis.db
2026-03-12 14:24:40,726 - collector - INFO - Starting high-resolution fee estimate collector (7s interval)...
objc[61980]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[61980]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

@b-l-u-e
Copy link
Copy Markdown
Collaborator Author

b-l-u-e commented Mar 13, 2026

Did you test this locally? I have a branch already with some data, and running this branch seems to cause a recurrent crash in the backend process.

yeah it was working on my end... i ran the command again to see if will face the same issue and still running

show logs

2026-03-13 09:44:54,655 - collector - INFO - [Collector] SAVED: target=7 height=295362 rate=1.00 sat/vB
2026-03-13 09:44:54,662 - urllib3.connectionpool - DEBUG - http://localhost:38332 "POST / HTTP/1.1" 200 155
2026-03-13 09:44:54,665 - urllib3.connectionpool - DEBUG - http://localhost:38332 "POST / HTTP/1.1" 200 795
2026-03-13 09:44:54,668 - urllib3.connectionpool - DEBUG - http://localhost:38332 "POST / HTTP/1.1" 200 39
2026-03-13 09:44:54,668 - rpc_service - DEBUG - Network detected: SIGNET (chain=signet)
2026-03-13 09:44:54,670 - urllib3.connectionpool - DEBUG - http://localhost:38332 "POST / HTTP/1.1" 200 39
2026-03-13 09:44:54,673 - urllib3.connectionpool - DEBUG - http://localhost:38332 "POST / HTTP/1.1" 200 519
2026-03-13 09:44:54,677 - services.database_service - DEBUG - Saved estimate: poll_height=295362, target=144, feerate=1.0010000000000001, network=signet
2026-03-13 09:44:54,677 - collector - INFO - [Collector] SAVED: target=144 height=295362 rate=1.00 sat/vB

Copy link
Copy Markdown
Collaborator

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

yeah it was working on my end... i ran the command again to see if will face the same issue and still running

I debugged this today, and it seems this is not an issue introduced in this PR.
The fork safety crash is a known macOS issue unrelated to these changes export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES suppresses it locally, and I can confirm the branch behaves as expected on my end.

I'd suggest one change in approach — rather than a single fee_analysis.db with a network column, separate the databases by directory to match Bitcoin Core's style data dir convention:

  fee_analysis.db              # mainnet — unchanged, no migration
  testnet3/fee_analysis.db
  signet/fee_analysis.db
  regtest/fee_analysis.db
  e.t.c
  • The current OR network IS NULL fallback in get_estimates_in_range is fragile and can be prone to bugs.
  • WHERE network = ? can be dropped from every DB call since isolation is handled at the file level and we just append the test directory, it is easy to reason about.
  • Existing mainnet data is untouched no migration needed, the root fee_analysis.db path stays the same
  • With this, it is easy to wipe a network rm -rf testnet3/ without touching another network data

@ismaelsadeeq
Copy link
Copy Markdown
Collaborator

ismaelsadeeq commented Mar 24, 2026

A nice extension to this would be to serve estimates for other networks as well, all from the same frontend u.i.

For example, the page could be reloaded to show available networks without needing to restart. The node’s configuration file (rpc_config.ini) could include an added option for the mainnet configuration, and all testnet configurations, excluding regtest.

Then, the UI could display the available networks. I think this aligns well with #14 (review)

Screenshot 2026-03-24 at 16 06 35

@b-l-u-e
Copy link
Copy Markdown
Collaborator Author

b-l-u-e commented Mar 24, 2026

the dropdown-style im wandering which option will be better a single active chain per process with one collector targeting the selected RPC or parallel RPC connections with collectors per configured chain with the UI only selecting which chain’s data to fetch.

@ismaelsadeeq
Copy link
Copy Markdown
Collaborator

Parallel RPC connections with collectors per configured chain with the UI only selecting which chain’s data to fetch.

This is more ideal

@b-l-u-e b-l-u-e force-pushed the feat/multi-network-support branch from 25c0867 to 2ee6eb2 Compare March 28, 2026 16:28
@b-l-u-e b-l-u-e marked this pull request as draft March 28, 2026 16:32
@b-l-u-e
Copy link
Copy Markdown
Collaborator Author

b-l-u-e commented Mar 28, 2026

i faced an issue with lint formatting

@b-l-u-e b-l-u-e marked this pull request as ready for review March 29, 2026 19:18
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.

Support multiple network not just mainnet

2 participants