Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Decouple version numbers from run-bitcoind.sh to improve maintainability #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GideonBature
Copy link
Contributor

@GideonBature GideonBature commented Mar 31, 2025

Problem:

The script previously hardcoded version numbers and assumed specific directory structures in /opt/, making updates difficult and breaking user environments when new versions were introduced. Developers had to modify the script manually whenever a new version was released or when bitcoind was installed in a different location.

Solution:

This PR removes the hardcoded version numbers and introduces a configuration-based approach. The script now loads version numbers and bitcoind paths from either:

  1. A custom environment variable (BITCOIND_VERSIONS_CONFIG), allowing users to specify their own config file location.
  2. A configuration file (bitcoind_versions.conf), which developers can set up based on their local environment.

If no custom environment variable is provided (BITCOIND_VERSIONS_CONFIG), the script falls back to a default config file in the home directory (~/.bitcoind_versions.conf) or the script directory (./bitcoind_versions.conf).

Closes #28

@AdamuAbba
Copy link

Hey @GideonBature, I’d like to test this locally. Could you please guide me on how to do that? Thanks!

@GideonBature
Copy link
Contributor Author

Oh! So here is a guide on how to test it:

  1. Go to the corepc/contrib directory and create a file named bitcoind_versions.conf.
  2. Make sure you have bitcoind installed, use the command: where bitcoind to locate the path where your bitcoind was installed (that is if you are using a standard installed version). You can also make use of paths to other bitcoind custom installations you did.
  3. Next, use the command: bitcoind --version to check for the version of the bitcoind you want to make use. You can also use the exact version of any other bitcoind you installed apart from the standard installed one.
  4. In the file you created in (1), add the following to the file:
v28 28.1.0 281 /opt/bin/bitcoind

Used v28 to indicate the main version, 28.1.0 which is the exact version gotten from running the command: bitcoind --version, 281 is the first three digits of the version number without a dot(.). And lastly /opt/bin/bitcoind is the path to the bitcoind executable.

Note: Make sure you put the exact version of the bitcoind you are using because the script is going to check what you put in the config file against the version of the bitcoind whose path you included in the configuration file.

With this you should be able to test the script file. Thank you @AdamuAbba.

@tcharding
Copy link
Member

Thanks for the PR, I'll get to reviewing soon as I can.

Copy link

@AdamuAbba AdamuAbba left a comment

Choose a reason for hiding this comment

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

ACK #7fb7b7d; successfully ran a local test.

@tcharding
Copy link
Member

Thanks for your work! I'll come back to review this.

@nervana21
Copy link
Contributor

nervana21 commented Apr 5, 2025

tACK 7fb7b7d

Thanks @GideonBature!

This PR was tested and reviewed by checking out main at commit (870efdf), then applying the net diff from all four commits in this PR as a single patch.

corepc/contrib/run-bitcoind.patch


Reproduction process (macOS, bitcoind built from source):

# 1) Clone the repo and switch to main/master
git clone https://github.com/rust-bitcoin/corepc.git
cd corepc
git checkout main #or master

# 2) Add a config for the local bitcoind build
cat <<EOF > contrib/bitcoind_versions.conf
v28 28.99.0 289 /path/to/your/bitcoind
EOF

# 3) Attempt to run without the patch
cd contrib
./run-bitcoind.sh start v28

Pre-patch output:

./run-bitcoind.sh: line 168: /opt/bitcoin-28.0/bin/bitcoind: No such file or directory
Wrong bitcoind version, expected 28.0
./run-bitcoind.sh: line 172: /opt/bitcoin-28.0/bin/bitcoind: No such file or directory
# 4) Apply the patch and try again
git apply run-bitcoind.patch
./run-bitcoind.sh start v28

Post-patch output:

Starting bitcoind v28.99.0 (alias: v28)...
Bitcoin Core 28.99.0 nodes running (RPC port: 28949)

Suggest squashing commits for a cleaner history. Happy to provide the patch in other formats if that would be useful.

@GideonBature
Copy link
Contributor Author

tACK 7fb7b7d

Thanks @GideonBature!

This PR was tested and reviewed by checking out main at commit (870efdf), then applying the net diff from all four commits in this PR as a single patch.

corepc/contrib/run-bitcoind.patch

Reproduction process (macOS, bitcoind built from source):

# 1) Clone the repo and switch to main/master
git clone https://github.com/rust-bitcoin/corepc.git
cd corepc
git checkout main #or master

# 2) Add a config for the local bitcoind build
cat <<EOF > contrib/bitcoind_versions.conf
v28 28.99.0 289 /path/to/your/bitcoind
EOF

# 3) Attempt to run without the patch
cd contrib
./run-bitcoind.sh start v28

Pre-patch output:

./run-bitcoind.sh: line 168: /opt/bitcoin-28.0/bin/bitcoind: No such file or directory
Wrong bitcoind version, expected 28.0
./run-bitcoind.sh: line 172: /opt/bitcoin-28.0/bin/bitcoind: No such file or directory
# 4) Apply the patch and try again
git apply run-bitcoind.patch
./run-bitcoind.sh start v28

Post-patch output:

Starting bitcoind v28.99.0 (alias: v28)...
Bitcoin Core 28.99.0 nodes running (RPC port: 28949)

Suggest squashing commits for a cleaner history. Happy to provide the patch in other formats if that would be useful.

This is awesome. Thank you! Will squash the commits.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Looking good, two change requests please.

@GideonBature GideonBature force-pushed the run-bitcoind_script branch 2 times, most recently from a3c2301 to bcb840e Compare April 10, 2025 15:41
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this. Still a few things to, bash is hard to get right.

@tcharding
Copy link
Member

tcharding commented Apr 10, 2025

You mentioned throwing an example config file in someplace. I rekon that is a good idea. This is the one I've been using to test thing

# run-bitcoind configuration
#
# This file configures the `run-bitcoind.sh` script found in the `corepc` repository.

v17 0.17.2 172 /opt/bitcoin-0.17.2/bin/bitcoind
v18 0.18.1 181 /opt/bitcoin-0.18.1/bin/bitcoind
v19 0.19.1 191 /opt/bitcoin-0.19.1/bin/bitcoind
v20 0.20.2 202 /opt/bitcoin-0.20.2/bin/bitcoind
v21 0.21.2 212 /opt/bitcoin-0.21.2/bin/bitcoind
v22 22.1 221 /opt/bitcoin-22.1/bin/bitcoind
v23 23.2 232 /opt/bitcoin-23.2/bin/bitcoind
v24 24.2 242 /opt/bitcoin-24.2/bin/bitcoind
v25 25.2 252 /opt/bitcoin-25.2/bin/bitcoind
v26 26.2 262 /opt/bitcoin-26.2/bin/bitcoind
v27 27.1 271 /opt/bitcoin-27.1/bin/bitcoind
v28 28.1 281 /opt/bitcoin-28.0/bin/bitcoind

@GideonBature
Copy link
Contributor Author

You mentioned throwing an example config file in someplace. I rekon that is a good idea. This is the one I've been using to test thing

# run-bitcoind configuration
#
# This file configures the `run-bitcoind.sh` script found in the `corepc` repository.

v17 0.17.2 172 /opt/bitcoin-0.17.2/bin/bitcoind
v18 0.18.1 181 /opt/bitcoin-0.18.1/bin/bitcoind
v19 0.19.1 191 /opt/bitcoin-0.19.1/bin/bitcoind
v20 0.20.2 202 /opt/bitcoin-0.20.2/bin/bitcoind
v21 0.21.2 212 /opt/bitcoin-0.21.2/bin/bitcoind
v22 22.1 221 /opt/bitcoin-22.1/bin/bitcoind
v23 23.2 232 /opt/bitcoin-23.2/bin/bitcoind
v24 24.2 242 /opt/bitcoin-24.2/bin/bitcoind
v25 25.2 252 /opt/bitcoin-25.2/bin/bitcoind
v26 26.2 262 /opt/bitcoin-26.2/bin/bitcoind
v27 27.1 271 /opt/bitcoin-27.1/bin/bitcoind
v28 28.1 281 /opt/bitcoin-28.0/bin/bitcoind

:) Thank you!

I have implemented the changes... Thank you so much for the reviews.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Almost there! Thanks for sticking with this.


- Examples

v28 28.1 280 /opt/bitcoin-28.0/bin/bitcoind
Copy link
Member

Choose a reason for hiding this comment

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

Woops I think this mistake was mine last review, should be 28.0


v28 28.1 280 /opt/bitcoin-28.0/bin/bitcoind
v24 24.2 242 /opt/bitcoin-24.2/bin/bitcoind
v21 0.21.2 212 /opt/bitcoin-0.21.2/bin/bitcoind
EOF
Copy link
Member

Choose a reason for hiding this comment

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

Since we have another iteration anyways, perhaps a new line before the EOF, makes the output slightly better when an incorrect command is given. Not really important though.


echo "Two connected bitcoind v${version_number} instances running, one node has JSON-RPC listening on port ${rpc_port}"
sleep 1 # Let nodes connect
echo "Two connected bitcoind v${version_number} instances running, one node has JSON-RPC listening on port ${rpc_port})"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
echo "Two connected bitcoind v${version_number} instances running, one node has JSON-RPC listening on port ${rpc_port})"
echo "Two connected bitcoind v${version_number} instances running, one node has JSON-RPC listening on port ${rpc_port}"

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.

run-bitcoind.sh implies things about the environment
4 participants