forked from re-vault/revault-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregtest_manager
executable file
·136 lines (121 loc) · 3.99 KB
/
regtest_manager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
if [ "$0" = "$BASH_SOURCE" ];then
echo "You should source this script to benefit of aliases and functions."
exit 0
fi
# Just spin up two nodes by default
n_nodes=2
# Generates blocks not too quickly and keep everyone in sync
generate_fake_load_regtest () {
while true;do
for n in $(seq 4);do
for i in $(seq $n_nodes);do
bcli="bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$((9000 + $i))"
for _ in $(seq 10);do
address="$bcli getnewaddress"
$bcli sendtoaddress $($bcli getnewaddress) 10 > /dev/null
done
$miner generatetoaddress 1 $($bcli getnewaddress) > /dev/null
sleep 0.001
done
done
sleep 20
done
}
start_regtest () {
# Use the global env bitcoind by default
if [ -z "$BITCOIND_PATH" ];then BITCOIND_PATH="/usr/local/bin/bitcoind";fi
BITCOIND="$BITCOIND_PATH -daemon -regtest -txindex -whitelist=\"127.0.0.1\" -rpcpassword=\"test\" -rpcuser=\"test\" -debug"
PREFIX_DIR="$PWD/regtest"
if [ "$#" == "1" ];then
n_nodes=$1
fi
for i in $(seq $n_nodes);do
bc_rpc=$((9000 + $i))
bc_port=$((10000 + $i))
bc_dir="$PREFIX_DIR/bcdir$i"
mkdir -p "$bc_dir"
conf_file="$bc_dir/bitcoin.conf"
cat <<EOF > "$conf_file"
[regtest]
connect=127.0.0.1:$(($bc_port - 1))
rpcuser=test
rpcpassword=test
rpcport=$bc_rpc
datadir=$bc_dir
bind=127.0.0.1:$bc_port
EOF
eval "$BITCOIND -datadir=$bc_dir" > /dev/null
alias "bdreg$i"="$BITCOIND -connect=127.0.0.1:$(($bc_port - 1)) -rpcport=$bc_rpc -datadir=$bc_dir -bind=127.0.0.1:$bc_port"
echo "Started bitcoind #$i with P2P port $bc_port, RPC port $bc_rpc and datadir $bc_dir"
alias "bcreg$i"="bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$bc_rpc"
echo "==> You can access the bitcoind startup command line with 'bdreg$i', and the bitcoin CLI with 'bcreg$i'."
echo ""
done
echo ""
echo "Started $n_nodes pairs of bitcoind and nodes with rpc user \"test\" and pass \"test\" (and poor alias names)."
sleep 0.4
echo "Now generating some coins.."
sleep 0.3
# Use the first node as the block generator
miner="bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=9001"
for n in $(seq 60);do
if [ "$n" = "1" ];then
while [ $($miner getblockchaininfo &> /dev/null; echo $?) -ne 0 ];do
echo "Waiting for bitcoind to warmup.."
sleep 1
done
fi
for i in $(seq $n_nodes);do
bcli="bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$((9000 + $i))"
$miner generatetoaddress 1 $($bcli getnewaddress) > /dev/null
sleep 0.001
done
echo -en "\r$n/60 blocks generated"
done
echo ""
echo "We generate a fake load of transaction to populate fee estimation buckets"
for n in $(seq 4);do
for i in $(seq $n_nodes);do
bcli="bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$((9000 + $i))"
for _ in $(seq 10);do
address="$bcli getnewaddress"
$bcli sendtoaddress $($bcli getnewaddress) 10 > /dev/null
done
$miner generatetoaddress 1 $($bcli getnewaddress) > /dev/null
sleep 0.001
done
echo -en "\r$n/4 rounds completed"
done
echo ""
echo "We continue fake load in the background."
generate_fake_load_regtest &
}
soft_stop_regtest () {
for i in $(seq $n_nodes);do
bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$((9000 + $i)) stop \
> /dev/null && echo "bitcoind #$i stopped"
done
}
# Stop the regression testing network and __deletes the data directories__
stop_regtest () {
PREFIX_DIR="$PWD/regtest"
if ! test -d "$PREFIX_DIR";then
echo "No regtest/ directory here..."
return
fi
for i in $(seq $n_nodes);do
bitcoin-cli -regtest -rpcpassword=test -rpcuser=test -rpcport=$((9000 + $i)) stop > /dev/null
rm -rf "$PREFIX_DIR/bcdir$i"
echo "bitcoind #$i stopped"
done
}
# Don't use if you're up-to-date
kill_regtest () {
echo "Getting bitcoin and lightning daemons PID with a hacky hack, and killing them :
prefer using 'stop_regtest' if you run lightningd > 0.7.2";
for i in $(ps -edf |grep -E 'bitcoind|lightningd' |grep regtest |cut -c 10-15);do
kill -9 $i
done
rm -rf $PWD/regtest
}