forked from frstrtr/c2pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlitecoin_testnet.sh
More file actions
executable file
·350 lines (293 loc) · 7.78 KB
/
litecoin_testnet.sh
File metadata and controls
executable file
·350 lines (293 loc) · 7.78 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
# Litecoin Testnet Node Setup and Management Script
set -e
# Configuration
LITECOIN_DIR="$HOME/.litecoin"
TESTNET_DIR="$LITECOIN_DIR/testnet4"
CONF_FILE="$LITECOIN_DIR/litecoin.conf"
PID_FILE="$TESTNET_DIR/litecoind.pid"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log() {
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if litecoind is available
check_litecoin_binary() {
if ! command -v litecoind &> /dev/null; then
error "litecoind not found in PATH"
echo "Please install Litecoin Core from: https://litecoin.org/"
echo "Or on Ubuntu/Debian: sudo apt-get install litecoind"
exit 1
fi
if ! command -v litecoin-cli &> /dev/null; then
error "litecoin-cli not found in PATH"
exit 1
fi
log "Found Litecoin binaries: $(litecoind --version | head -1)"
}
# Create Litecoin configuration
setup_config() {
log "Setting up Litecoin testnet configuration..."
mkdir -p "$LITECOIN_DIR"
cat > "$CONF_FILE" << 'EOF'
# Litecoin Testnet Configuration for C2Pool Testing
# Network
testnet=1
listen=1
server=1
# RPC Configuration
rpcuser=ltctest
rpcpassword=ltctest123
rpcport=19332
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
# Connections
maxconnections=50
addnode=testnet-seed.ltc.xurious.com
addnode=seed-b.litecoin.loshan.co.uk
addnode=dnsseed-testnet.thrasher.io
# Mining (for testing)
gen=0
genproclimit=1
# Logging
debug=1
logips=1
logtimestamps=1
# Performance
dbcache=512
maxmempool=300
# Features needed for pool operation
txindex=1
addressindex=1
timestampindex=1
spentindex=1
# Block creation
blockmaxweight=4000000
blockmaxsize=4000000
EOF
success "Created Litecoin configuration at $CONF_FILE"
}
# Start Litecoin daemon
start_daemon() {
log "Starting Litecoin testnet daemon..."
if is_running; then
warn "Litecoin daemon is already running (PID: $(cat $PID_FILE))"
return 0
fi
# Start daemon
litecoind -daemon -testnet -datadir="$LITECOIN_DIR" -conf="$CONF_FILE"
# Wait for startup
log "Waiting for daemon to start..."
for i in {1..30}; do
if litecoin-cli -testnet getblockchaininfo &>/dev/null; then
success "Litecoin daemon started successfully"
return 0
fi
sleep 1
echo -n "."
done
error "Failed to start Litecoin daemon"
return 1
}
# Check if daemon is running
is_running() {
if [[ -f "$PID_FILE" ]]; then
local pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
return 0
else
rm -f "$PID_FILE"
fi
fi
return 1
}
# Stop daemon
stop_daemon() {
log "Stopping Litecoin daemon..."
if ! is_running; then
warn "Litecoin daemon is not running"
return 0
fi
litecoin-cli -testnet stop
# Wait for shutdown
for i in {1..30}; do
if ! is_running; then
success "Litecoin daemon stopped"
return 0
fi
sleep 1
echo -n "."
done
error "Failed to stop daemon gracefully"
return 1
}
# Get daemon status
status() {
if is_running; then
success "Litecoin daemon is running (PID: $(cat $PID_FILE))"
# Get blockchain info
echo ""
log "Blockchain Information:"
litecoin-cli -testnet getblockchaininfo | jq '{
chain: .chain,
blocks: .blocks,
headers: .headers,
verificationprogress: .verificationprogress,
size_on_disk: .size_on_disk,
pruned: .pruned
}'
echo ""
log "Network Information:"
litecoin-cli -testnet getnetworkinfo | jq '{
version: .version,
subversion: .subversion,
connections: .connections,
localaddresses: .localaddresses
}'
echo ""
log "Mining Information:"
litecoin-cli -testnet getmininginfo | jq '{
blocks: .blocks,
difficulty: .difficulty,
networkhashps: .networkhashps,
pooledtx: .pooledtx,
testnet: .testnet
}'
else
error "Litecoin daemon is not running"
return 1
fi
}
# Generate test blocks
generate_blocks() {
local count=${1:-10}
log "Generating $count test blocks..."
if ! is_running; then
error "Litecoin daemon is not running"
return 1
fi
# Get a test address
local address=$(litecoin-cli -testnet getnewaddress "mining_test")
log "Mining to address: $address"
# Generate blocks
local blocks=$(litecoin-cli -testnet generatetoaddress "$count" "$address")
success "Generated $count blocks"
echo "Block hashes:"
echo "$blocks" | jq -r '.[]'
# Show updated status
echo ""
log "Updated blockchain status:"
litecoin-cli -testnet getblockchaininfo | jq '{blocks: .blocks, difficulty: .difficulty}'
}
# Monitor daemon logs
logs() {
local lines=${1:-50}
local debug_log="$TESTNET_DIR/debug.log"
if [[ -f "$debug_log" ]]; then
log "Showing last $lines lines from debug.log:"
tail -n "$lines" "$debug_log"
else
error "Debug log not found at $debug_log"
fi
}
# Test RPC connection
test_rpc() {
log "Testing RPC connection..."
if ! is_running; then
error "Litecoin daemon is not running"
return 1
fi
echo "RPC Test Results:"
echo "=================="
echo -n "getblockchaininfo: "
if litecoin-cli -testnet getblockchaininfo &>/dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
return 1
fi
echo -n "getnetworkinfo: "
if litecoin-cli -testnet getnetworkinfo &>/dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
return 1
fi
echo -n "getmininginfo: "
if litecoin-cli -testnet getmininginfo &>/dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
return 1
fi
success "All RPC tests passed"
}
# Main command handling
case "${1:-}" in
start)
check_litecoin_binary
setup_config
start_daemon
;;
stop)
stop_daemon
;;
restart)
stop_daemon
sleep 2
start_daemon
;;
status)
status
;;
generate)
generate_blocks "${2:-10}"
;;
logs)
logs "${2:-50}"
;;
test)
test_rpc
;;
setup)
check_litecoin_binary
setup_config
success "Setup complete. Run '$0 start' to start the daemon."
;;
*)
echo "Litecoin Testnet Node Management"
echo "================================"
echo ""
echo "Usage: $0 {start|stop|restart|status|generate|logs|test|setup}"
echo ""
echo "Commands:"
echo " setup - Setup configuration (run this first)"
echo " start - Start Litecoin testnet daemon"
echo " stop - Stop Litecoin testnet daemon"
echo " restart - Restart daemon"
echo " status - Show daemon status and blockchain info"
echo " generate - Generate test blocks (default: 10)"
echo " logs - Show daemon logs (default: last 50 lines)"
echo " test - Test RPC connection"
echo ""
echo "Examples:"
echo " $0 setup"
echo " $0 start"
echo " $0 generate 50"
echo " $0 status"
exit 1
;;
esac