Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bitcoin.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
server=1
rpcuser=username
rpcpassword=password
testnet4=1
regtest=1

[testnet4]
[regtest]
sv2=1
sv2port=8442
debug=sv2
3 changes: 2 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ in {
redis = {exec = withLogging "mkdir -p ${config.devenv.root}/.devenv/state/redis && redis-server --dir ${config.devenv.root}/.devenv/state/redis --port ${toString poolConfig.redis.port}" "redis.log";};
pool = {
exec = withLogging ''
DEVENV_ROOT=${config.devenv.root} BITCOIND_DATADIR=${bitcoindDataDir} ${config.devenv.root}/scripts/bitcoind-setup.sh
echo "Waiting for Mint..."
while ! nc -z localhost ${toString poolConfig.mint.port}; do
sleep 1
Expand Down Expand Up @@ -95,7 +96,7 @@ in {
exec = withLogging ''
mkdir -p ${bitcoindDataDir}
bitcoind -datadir=${bitcoindDataDir} -conf=${config.devenv.root}/bitcoin.conf
'' "bitcoind-testnet.log";
'' "bitcoind-regtest.log";
};
miner = {
exec = withLogging ''
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ update-bitcoind:
sed -i "s|rev = \".*\";|rev = \"$LATEST_COMMIT\";|" bitcoind.nix && \
sed -i "s|hash = \".*\";|hash = \"$HASH\";|" bitcoind.nix && \
echo "Done! bitcoind updated to commit $LATEST_COMMIT\nYou are now ready to test and commit"

# generate blocks in regtest
generate-blocks COUNT="1":
@echo "Generating {{COUNT}} blocks in regtest..."
@bitcoin-cli -datadir=.devenv/state/bitcoind -conf=$(pwd)/bitcoin.conf -rpcuser=username -rpcpassword=password -regtest -rpcwallet=regtest -generate {{COUNT}}
2 changes: 1 addition & 1 deletion protocols/v2/roles-logic-sv2/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub mod tests {
}

const PRIVATE_KEY_BTC: [u8; 32] = [34; 32];
const NETWORK: Network = Network::Testnet;
const NETWORK: Network = Network::Regtest;

#[cfg(feature = "prop_test")]
const BLOCK_REWARD: u64 = 625_000_000_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ coinbase_outputs = [
listen_jd_address = "127.0.0.1:34264"
# RPC config for mempool (it can be also the same TP if correctly configured)
core_rpc_url = "http://127.0.0.1"
core_rpc_port = 48332
core_rpc_port = 18443
core_rpc_user = "username"
core_rpc_pass = "password"
# Time interval used for JDS mempool update
Expand Down
64 changes: 64 additions & 0 deletions scripts/bitcoind-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

# bitcoind-setup.sh - Initialize regtest environment
# This script waits for bitcoind to be ready, then checks if we need to initialize
# the regtest environment with a wallet and some initial blocks. This should only
# need to be run once per dev environment setup or if you've reset your state. It's
# idempotent, so you can safely run it multiple times.

set -e

BITCOIN_CONF="${DEVENV_ROOT:-$(pwd)}/bitcoin.conf"
DATADIR="${BITCOIND_DATADIR:-$(pwd)/.devenv/state/bitcoind}"
RPC_ARGS="-datadir=${DATADIR} -conf=${BITCOIN_CONF} -rpcuser=username -rpcpassword=password -regtest"

create_and_load_wallet() {
echo "Creating/loading regtest wallet..."
if ! bitcoin-cli $RPC_ARGS createwallet "regtest" 2>/dev/null; then
echo "Wallet exists, attempting to load..."
bitcoin-cli $RPC_ARGS loadwallet "regtest" 2>/dev/null || echo "Wallet already loaded"
fi
}

echo "Waiting for bitcoind to be ready..."

# Wait for bitcoind RPC to be available
max_attempts=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
if bitcoin-cli $RPC_ARGS getblockchaininfo >/dev/null 2>&1; then
echo "bitcoind is ready!"
break
fi
attempt=$((attempt + 1))
echo "Attempt $attempt/$max_attempts: bitcoind not ready yet, waiting..."
sleep 2
done

if [ $attempt -eq $max_attempts ]; then
echo "ERROR: bitcoind failed to become ready after $max_attempts attempts"
exit 1
fi

BLOCK_HEIGHT=$(bitcoin-cli $RPC_ARGS getblockcount 2>/dev/null || echo "0")
echo "Current block height: $BLOCK_HEIGHT"

# Ensure we have at least 16 blocks and a wallet
if [ "$BLOCK_HEIGHT" -lt "16" ]; then
BLOCKS_NEEDED=$((16 - BLOCK_HEIGHT))
echo "Block height is $BLOCK_HEIGHT, need to generate $BLOCKS_NEEDED more blocks..."

create_and_load_wallet

echo "Generating $BLOCKS_NEEDED blocks to reach height 16..."
bitcoin-cli $RPC_ARGS -rpcwallet=regtest -generate $BLOCKS_NEEDED

NEW_HEIGHT=$(bitcoin-cli $RPC_ARGS getblockcount)
echo "✅ Regtest environment initialized! New block height: $NEW_HEIGHT"
else
echo "✅ Regtest environment already has sufficient blocks (height: $BLOCK_HEIGHT)"

create_and_load_wallet
fi

echo "bitcoind setup complete!"
Loading