Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 31, 2025

This PR adds support for configuring the Bitcoin network via a NETWORK environment variable in the docker/knots/entrypoint.sh script, addressing the need for easy network switching between mainnet, testnet, and regtest environments.

Changes Made

  • Network Configuration: Added NETWORK environment variable support with three valid values:

    • mainnet (default) - no additional configuration needed
    • testnet - adds testnet=1 to bitcoin.conf
    • regtest - adds regtest=1 to bitcoin.conf
  • Configuration File Approach: Network settings are written directly to the bitcoin.conf file instead of using command line flags, following Bitcoin Core best practices and configuration management standards

  • Input Validation: Added early validation that exits with a descriptive error message if an invalid network value is provided

  • Documentation: Enhanced script comments to document the new network configuration feature and usage

Usage

Users can now configure the Bitcoin network in their docker-compose.yaml:

services:
  knots:
    environment:
      - RPC_USER=${RPC_USER}
      - RPC_PASSWORD=${RPC_PASSWORD}
      - NETWORK=testnet  # Add this line for testnet

Or via direct environment variable:

docker run -e NETWORK=regtest knots

Backward Compatibility

The changes are fully backward compatible:

  • If NETWORK is not set, defaults to mainnet (existing behavior)
  • All existing environment variables and configurations remain unchanged
  • Network configuration is properly integrated with the existing bitcoin.conf file structure

Implementation Details

The implementation writes network configuration directly to the bitcoin.conf file:

  • testnet=1 for testnet mode
  • regtest=1 for regtest mode
  • No additional config for mainnet (default behavior)

This approach is cleaner, more maintainable, and follows Bitcoin Core's standard configuration file approach rather than relying on command line flags. It ensures all configuration is centralized in the bitcoin.conf file for easier debugging and management.

This enables developers to easily switch between networks for testing and development without modifying configuration files or rebuilding containers.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@esomore esomore marked this pull request as ready for review July 31, 2025 18:41
…iable

Co-authored-by: esomore <7858567+esomore@users.noreply.github.com>
@esomore
Copy link
Contributor

esomore commented Jul 31, 2025

put the network in the conf file

Copilot AI changed the title [WIP] Add NETWORK environment variable support to configure mainnet/regtest/testnet for bitcoind Add Bitcoin network configuration support via NETWORK environment variable Jul 31, 2025
Copilot AI requested a review from esomore July 31, 2025 18:47
Co-authored-by: esomore <7858567+esomore@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

put the network in the conf file

Updated to put the network configuration in the bitcoin.conf file instead of using command line flags. Now testnet=1 and regtest=1 are written directly to the config file, which is cleaner and more consistent with Bitcoin Core configuration management. Commit: 65e0b4d

Copilot AI changed the title Add Bitcoin network configuration support via NETWORK environment variable Add Bitcoin network configuration support via NETWORK environment variable in bitcoin.conf Jul 31, 2025
Copilot AI requested a review from esomore July 31, 2025 18:55
@esomore esomore merged commit e3ac10b into main Jul 31, 2025
6 of 9 checks passed
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.

2 participants