-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathc2pool_refactored.cpp
More file actions
7233 lines (6629 loc) · 409 KB
/
Copy pathc2pool_refactored.cpp
File metadata and controls
7233 lines (6629 loc) · 409 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <set>
#include <thread>
#include <chrono>
#include <csignal>
#include <ctime>
#include <memory>
#include <vector>
#ifndef _WIN32
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <iomanip>
#include <sstream>
// Core includes
#include <core/settings.hpp>
#include <core/fileconfig.hpp>
#include <core/coinbase_builder.hpp>
#include <c2pool/storage/the_checkpoint.hpp>
#include <core/pack.hpp>
#include <core/filesystem.hpp>
#include <core/log.hpp>
#include <core/uint256.hpp>
#include <core/web_server.hpp>
#include <core/hash.hpp>
#include <core/address_utils.hpp>
#include <core/config.hpp>
// Pool infrastructure
#include <pool/node.hpp>
#include <pool/protocol.hpp>
#include <sharechain/sharechain.hpp>
#include <sharechain/stats_skiplist.hpp>
// LTC implementation
#include <impl/ltc/share.hpp>
#include <impl/ltc/share_check.hpp>
#include <impl/ltc/auto_ratchet.hpp>
#include <impl/ltc/share_messages.hpp>
#include <impl/ltc/coin/block.hpp>
#include <impl/ltc/node.hpp>
#include <impl/ltc/messages.hpp>
// NOTE: must follow node.hpp/messages.hpp. coin_node.hpp pulls in
// btclibs/serialize.h, which #undefs READWRITE and redefines it to the
// (s, ser_action, ...) form. Included earlier, the MESSAGE_FIELDS macros in
// messages.hpp expand against that wrong READWRITE and fail to compile under
// AppleClang/arm64 ("use of undeclared identifier s / ser_action").
#include <impl/ltc/coin/coin_node.hpp>
#include <impl/ltc/config.hpp>
// Chain seed discovery
#include <impl/ltc/coin/chain_seeds.hpp>
#include <impl/doge/coin/chain_seeds.hpp>
// Block explorer JSON serializer
#include <impl/ltc/coin/block_json.hpp>
// UTXO bootstrap pipeline (ordered block download for cold-start sync)
#include <core/coin/block_bootstrapper.hpp>
// Enhanced C2Pool components
#include <c2pool/node/enhanced_node.hpp>
#include <c2pool/hashrate/tracker.hpp>
#include <c2pool/difficulty/adjustment_engine.hpp>
#include <c2pool/storage/sharechain_storage.hpp>
#include <c2pool/storage/found_block_store.hpp>
#include <c2pool/payout/payout_manager.hpp>
// --- Platform-specific crash handler ---
#ifdef _WIN32
#include <windows.h>
#include <dbghelp.h>
#include <io.h>
static void write_crash_log(const char* reason) {
auto crash_path = core::filesystem::config_path() / "crash.log";
FILE* f = fopen(crash_path.string().c_str(), "a");
if (!f) return;
time_t now = time(nullptr);
struct tm tm_buf;
localtime_s(&tm_buf, &now);
char time_str[64];
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", &tm_buf);
fprintf(f, "\n=== CRASH: %s at %s\n", reason, time_str);
fprintf(f, "=== END CRASH ===\n");
fclose(f);
}
// Write a minidump (.dmp) that can be analyzed in WinDbg or Visual Studio.
// The dump includes full memory (data segments) so we can inspect stack,
// heap objects, and the faulting instruction context.
static void write_minidump(EXCEPTION_POINTERS* ep) {
auto dmp_path = core::filesystem::config_path() / "crash.dmp";
HANDLE hFile = CreateFileA(dmp_path.string().c_str(), GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return;
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ExceptionPointers = ep;
mei.ClientPointers = FALSE;
// MiniDumpWithDataSegs captures global/static data; MiniDumpWithThreadInfo
// captures thread times and start addresses for all threads.
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
static_cast<MINIDUMP_TYPE>(MiniDumpWithDataSegs |
MiniDumpWithThreadInfo |
MiniDumpWithHandleData),
ep ? &mei : NULL, NULL, NULL);
CloseHandle(hFile);
fprintf(stderr, "Minidump written to: %s\n", dmp_path.string().c_str());
}
// SEH (Structured Exception Handler) — catches access violations, stack
// overflows, illegal instructions, etc. at the OS level. Unlike C signal
// handlers, SEH provides the full EXCEPTION_POINTERS (instruction pointer,
// registers, exception code) which MiniDumpWriteDump needs.
static LONG WINAPI seh_exception_handler(EXCEPTION_POINTERS* ep) {
const char* desc = "unknown";
DWORD code = ep->ExceptionRecord->ExceptionCode;
switch (code) {
case EXCEPTION_ACCESS_VIOLATION: desc = "ACCESS_VIOLATION"; break;
case EXCEPTION_STACK_OVERFLOW: desc = "STACK_OVERFLOW"; break;
case EXCEPTION_ILLEGAL_INSTRUCTION: desc = "ILLEGAL_INSTRUCTION"; break;
case EXCEPTION_INT_DIVIDE_BY_ZERO: desc = "INT_DIVIDE_BY_ZERO"; break;
case EXCEPTION_FLT_DIVIDE_BY_ZERO: desc = "FLT_DIVIDE_BY_ZERO"; break;
case EXCEPTION_DATATYPE_MISALIGNMENT: desc = "DATATYPE_MISALIGNMENT"; break;
}
fprintf(stderr, "\n=== CRASH: SEH exception 0x%08lX (%s) at 0x%p ===\n",
code, desc, ep->ExceptionRecord->ExceptionAddress);
char msg[256];
snprintf(msg, sizeof(msg), "SEH 0x%08lX (%s) at 0x%p",
code, desc, ep->ExceptionRecord->ExceptionAddress);
write_crash_log(msg);
write_minidump(ep);
return EXCEPTION_EXECUTE_HANDLER; // terminate after handler
}
static void c2pool_terminate_handler() {
fprintf(stderr, "\n=== std::terminate() called ===\n");
auto eptr = std::current_exception();
if (eptr) {
try { std::rethrow_exception(eptr); }
catch (const std::exception& e) {
fprintf(stderr, "Unhandled exception: %s\n", e.what());
char msg[512];
snprintf(msg, sizeof(msg), "std::terminate — %s", e.what());
write_crash_log(msg);
}
catch (...) {
fprintf(stderr, "Unhandled non-std exception\n");
write_crash_log("std::terminate — unknown exception");
}
} else {
fprintf(stderr, "No active exception\n");
write_crash_log("std::terminate — no exception");
}
// Write a minidump even for std::terminate (no exception pointers available)
write_minidump(nullptr);
fprintf(stderr, "=== END ===\n");
_exit(134);
}
static void segfault_handler(int sig) {
fprintf(stderr, "\n=== CRASH (signal %d) ===\n", sig);
char msg[64];
snprintf(msg, sizeof(msg), "signal %d", sig);
write_crash_log(msg);
// No EXCEPTION_POINTERS from signal context, but the minidump still
// captures thread stacks and data segments for post-mortem analysis.
write_minidump(nullptr);
_exit(128 + sig);
}
#else // POSIX
#include <execinfo.h>
#include <cxxabi.h>
static void write_crash_log(const char* reason) {
int fd = open("/tmp/c2pool_crash.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
if (fd < 0) return;
FILE* f = fdopen(fd, "a");
if (!f) { close(fd); return; }
{
time_t now = time(nullptr);
struct tm tm_buf;
localtime_r(&now, &tm_buf);
char time_str[64];
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S %Z", &tm_buf);
fprintf(f, "\n=== CRASH: %s at %s\n", reason, time_str);
void* frames[64];
int n = backtrace(frames, 64);
char** syms = backtrace_symbols(frames, n);
if (syms) {
for (int i = 0; i < n; ++i)
fprintf(f, " %s\n", syms[i]);
free(syms);
}
fprintf(f, "=== END CRASH ===\n");
fclose(f);
}
}
static void c2pool_terminate_handler() {
fprintf(stderr, "\n=== std::terminate() called ===\n");
auto eptr = std::current_exception();
if (eptr) {
try { std::rethrow_exception(eptr); }
catch (const std::exception& e) {
fprintf(stderr, "Unhandled exception: %s\n", e.what());
char msg[512];
snprintf(msg, sizeof(msg), "std::terminate — %s", e.what());
write_crash_log(msg);
}
catch (...) {
fprintf(stderr, "Unhandled non-std exception\n");
write_crash_log("std::terminate — unknown exception");
}
} else {
fprintf(stderr, "No active exception\n");
write_crash_log("std::terminate — no exception");
}
void* frames[64];
int n = backtrace(frames, 64);
backtrace_symbols_fd(frames, n, STDERR_FILENO);
fprintf(stderr, "=== END ===\n");
_exit(134);
}
static void segfault_handler(int sig) {
void* frames[64];
int n = backtrace(frames, 64);
fprintf(stderr, "\n=== CRASH (signal %d) ===\n", sig);
backtrace_symbols_fd(frames, n, STDERR_FILENO);
fprintf(stderr, "=== END CRASH ===\n");
char msg[64];
snprintf(msg, sizeof(msg), "signal %d", sig);
write_crash_log(msg);
_exit(128 + sig);
}
#endif // _WIN32
// Integrated merged mining
#include <c2pool/merged/merged_mining.hpp>
#include <c2pool/merged/coin_broadcaster.hpp>
// Phase 5: Embedded DOGE node for daemonless merged mining
#include <impl/doge/coin/chain_params.hpp>
#include <impl/doge/coin/header_chain.hpp>
#include <impl/doge/coin/template_builder.hpp>
#include <impl/doge/coin/aux_chain_embedded.hpp>
#include <impl/doge/coin/auxpow_header.hpp>
// V36-compatible operational features
#include <impl/ltc/pool_monitor.hpp>
#include <impl/ltc/whale_departure.hpp>
#include <impl/ltc/redistribute.hpp>
// Coin daemon RPC
#include <impl/ltc/coin/rpc.hpp>
#include <impl/ltc/coin/node_interface.hpp>
#include <impl/ltc/coin/header_chain.hpp>
#include <impl/ltc/coin/mempool.hpp>
#include <impl/ltc/coin/mweb_builder.hpp>
#include <impl/ltc/coin/template_builder.hpp>
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <nlohmann/json.hpp>
#include <yaml-cpp/yaml.h>
#include <btclibs/util/strencodings.h>
// Bring the address validation types into scope
using Blockchain = c2pool::address::Blockchain;
using Network = c2pool::address::Network;
using NodeOwnerAddressSource = c2pool::payout::NodeOwnerPayoutConfig::AddressSource;
// Global signal handling
static bool g_shutdown_requested = false;
void signal_handler(int signal) {
LOG_INFO << "Received signal " << signal << ", initiating shutdown...";
g_shutdown_requested = true;
}
// C2Pool configuration
struct C2PoolConfig {
std::string m_name = "c2pool_sharechain";
bool m_testnet = false;
struct PoolConfig {
std::vector<std::byte> m_prefix = {std::byte{0xfc}, std::byte{0xc1}, std::byte{0xb7}, std::byte{0xdc}}; // mainnet
std::vector<std::byte> m_prefix_testnet = {std::byte{0xfc}, std::byte{0xc1}, std::byte{0xb7}, std::byte{0xdd}}; // testnet
} m_pool_config;
PoolConfig* pool() { return &m_pool_config; }
void set_testnet(bool testnet) {
m_testnet = testnet;
if (testnet) {
m_pool_config.m_prefix = m_pool_config.m_prefix_testnet;
m_name = "c2pool_sharechain_testnet";
}
}
};
void print_help() {
std::cout << "╔══════════════════════════════════════════════════════════════════════════════╗\n";
std::cout << "║ C2Pool - P2Pool Rebirth in C++ ║\n";
std::cout << "║ A modern, high-performance decentralized mining pool ║\n";
std::cout << "╚══════════════════════════════════════════════════════════════════════════════╝\n\n";
std::cout << "USAGE:\n";
std::cout << " c2pool [MODE] [OPTIONS]\n\n";
std::cout << "OPERATION MODES:\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << "🏊 INTEGRATED MODE (--integrated) - RECOMMENDED FOR POOL OPERATORS\n";
std::cout << " Complete mining pool solution with all features enabled:\n";
std::cout << " ✅ HTTP/JSON-RPC API Server (monitoring & stats)\n";
std::cout << " ✅ Stratum Mining Server (miner connections)\n";
std::cout << " ✅ Enhanced Sharechain Processing (persistent storage)\n";
std::cout << " ✅ Real-time Payout Tracking & Management\n";
std::cout << " ✅ Variable Difficulty (VARDIFF) Adjustment\n";
std::cout << " ✅ Multi-blockchain Support (LTC, BTC, ETH, XMR, ZEC, DOGE)\n";
std::cout << " ✅ Web Interface for Pool Monitoring\n";
std::cout << " ✅ Per-miner Statistics & Contribution Tracking\n";
std::cout << " ✅ Address Validation for All Blockchain Types\n\n";
std::cout << "🔗 SHARECHAIN MODE (--sharechain) - P2POOL NETWORK PARTICIPANT\n";
std::cout << " Dedicated P2P sharechain node for network participation:\n";
std::cout << " ✅ Enhanced Sharechain Processing\n";
std::cout << " ✅ LevelDB Persistent Storage\n";
std::cout << " ✅ P2P Network Communication\n";
std::cout << " ✅ Real-time Difficulty Tracking\n";
std::cout << " ✅ Protocol Compatibility (LTC-based)\n";
std::cout << " ✅ Share Validation & Network Consensus\n\n";
std::cout << "⚡ SOLO MODE (default) - INDEPENDENT SOLO MINING\n";
std::cout << " Standalone mining node without P2P sharechain:\n";
std::cout << " ✅ Direct Blockchain Connection\n";
std::cout << " ✅ Solo Mining (100% block rewards)\n";
std::cout << " ✅ Stratum Mining Server\n";
std::cout << " ✅ Local Difficulty Management\n";
std::cout << " ✅ Block Template Generation\n";
std::cout << " ✅ No P2P Dependencies\n";
std::cout << " ✅ Lightweight Operation\n\n";
std::cout << "COMMAND LINE OPTIONS:\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << " --help, -h Show this help message and exit\n";
std::cout << " --testnet Use testnet instead of mainnet\n";
std::cout << " --integrated Full P2P pool with sharechain (DEFAULT)\n";
std::cout << " --solo Solo pool mode (no P2P sharechain, local payouts)\n";
std::cout << " --custodial Custodial pool (coinbase to --address, stratum for accounting)\n";
std::cout << " --sharechain Sharechain-only mode (P2P node, no mining)\n";
std::cout << " --standalone Legacy solo: minimal stratum + RPC daemon, no embedded SPV\n";
std::cout << " --net CHAIN Blockchain: litecoin, digibyte, bitcoin, dogecoin\n";
std::cout << " (alias: --blockchain; default: litecoin)\n";
std::cout << " --config FILE Load configuration from YAML file\n";
std::cout << " --address ADDRESS Node operator payout address (optional; miners use stratum username)\n";
std::cout << " --no-embedded-ltc Disable embedded LTC SPV (use RPC daemon instead)\n";
std::cout << " --no-embedded-doge Disable embedded DOGE SPV\n";
std::cout << " --genesis Create genesis share if chain is empty (don't wait for peers)\n";
std::cout << " --wait-for-peers Wait for peers to download sharechain (DEFAULT)\n\n";
std::cout << "PAYOUT & FEE CONFIGURATION:\n";
std::cout << " --give-author PERCENT Developer donation (alias: --dev-donation; default: 0.1%)\n";
std::cout << " -f / --fee PERCENT Node owner fee (alias: --node-owner-fee; default: 0%)\n";
std::cout << " --node-owner-address ADDR Node owner payout address\n";
std::cout << " --redistribute MODE Redistribution mode: pplns, fee, boost, donate\n\n";
std::cout << "PORT CONFIGURATION:\n";
std::cout << " --p2pool-port PORT P2P sharechain port (alias: --p2p-port; default: 9326)\n";
std::cout << " -w / --worker-port PORT Stratum/worker port (alias: --stratum-port; default: 9327)\n";
std::cout << " --web-port PORT Web dashboard / JSON-RPC API port (alias: --http-port; default: 8080)\n";
std::cout << " --http-host HOST HTTP server bind address (default: 0.0.0.0)\n";
std::cout << " --external-ip ADDR Public IP or domain for stratum URL display (default: auto-detect)\n\n";
std::cout << "PARENT COIN DAEMON:\n";
std::cout << " --coind-address HOST RPC host (alias: --rpchost; default: 127.0.0.1)\n";
std::cout << " --coind-rpc-port PORT RPC port (alias: --rpcport; auto-detected from chain)\n";
std::cout << " --coind-p2p-port PORT P2P port (auto-detected; set 0 to disable)\n";
std::cout << " --coind-p2p-address HOST P2P address (default: same as --coind-address)\n";
std::cout << " USER PASS RPC credentials as positional args (or use flags below)\n";
std::cout << " --rpcuser USER RPC username\n";
std::cout << " --rpcpassword PASS RPC password\n\n";
std::cout << "MERGED MINING (p2pool-style individual flags):\n";
std::cout << " --merged-coind-address HOST Merged coin RPC host\n";
std::cout << " --merged-coind-rpc-port PORT Merged coin RPC port\n";
std::cout << " --merged-coind-rpc-user USER Merged coin RPC username\n";
std::cout << " --merged-coind-rpc-password PASS Merged coin RPC password\n";
std::cout << " --merged-coind-p2p-port PORT Merged coin P2P port\n";
std::cout << " --merged-coind-p2p-address HOST Merged coin P2P address\n\n";
std::cout << "MERGED MINING (c2pool spec format — alternative):\n";
std::cout << " --merged SPEC SYMBOL:CHAIN_ID:HOST:PORT:USER:PASS[:P2P_PORT]\n";
std::cout << " Example: DOGE:98:192.168.86.29:22555:user:pass\n";
std::cout << " Can be specified multiple times\n\n";
std::cout << "NETWORK TUNING (accepted for p2pool compatibility):\n";
std::cout << " --max-conns N Max outgoing P2P connections\n";
std::cout << " --outgoing-conns N Alias for --max-conns\n";
std::cout << " --disable-upnp Disable UPnP port forwarding\n\n";
std::cout << "STRATUM TUNING:\n";
std::cout << " --stratum-min-diff N Minimum per-connection difficulty (default: 0.001)\n";
std::cout << " --stratum-max-diff N Maximum per-connection difficulty (default: 65536)\n";
std::cout << " --stratum-target-time N Target seconds per pseudoshare (default: 3)\n";
std::cout << " --no-vardiff Disable automatic difficulty adjustment\n";
std::cout << " --max-coinbase-outputs N Max coinbase outputs per block (default: 4000, matches p2pool)\n\n";
std::cout << "EMBEDDED NODE OPTIONS:\n";
std::cout << " --embedded-ltc Use embedded LTC SPV node (no daemon needed)\n";
std::cout << " --embedded-doge Use embedded DOGE SPV node for merged mining\n";
std::cout << " --doge-testnet4alpha Use DOGE testnet4alpha (default: testnet3)\n";
std::cout << " --doge-p2p-address HOST Direct DOGE P2P peer address (e.g. your dogecoind)\n";
std::cout << " --doge-p2p-port PORT Direct DOGE P2P peer port (overrides auto-detect)\n";
std::cout << " --header-checkpoint H:HASH LTC header chain starting point\n";
std::cout << " --doge-header-checkpoint H:HASH DOGE header chain starting point\n\n";
std::cout << "COINBASE CUSTOMIZATION:\n";
std::cout << " --coinbase-text TEXT Custom text in coinbase scriptSig (replaces /c2pool/ tag)\n";
std::cout << " Max 20 chars with merged mining, 64 without\n";
std::cout << " Default: /c2pool/ (c2pool always identified by donation address)\n\n";
std::cout << "PRIVATE SHARECHAIN:\n";
std::cout << " --network-id ID Private network identifier (hex, e.g. DEADBEEF)\n";
std::cout << " Default: 0 (public p2pool network)\n";
std::cout << " Nonzero: creates a private sharechain. P2P prefix\n";
std::cout << " and THE metadata will carry this ID on the blockchain.\n";
std::cout << " Genesis shares are created automatically when chain is empty.\n";
std::cout << " --startup-mode MODE Sharechain startup behavior:\n";
std::cout << " auto — wait for peers (60s), then genesis if none (default)\n";
std::cout << " genesis — create new chain immediately, don't wait for peers\n";
std::cout << " wait — never create genesis, wait indefinitely for peers\n";
std::cout << " --startup-timeout N Seconds to wait for peers in auto mode (default: 60)\n\n";
std::cout << "V36 SHARE MESSAGE BLOB (CLI operator control):\n";
std::cout << " --message-blob-hex HEX Encrypted authority-signed message_data blob\n";
std::cout << " to embed in locally created V36 shares\n\n";
std::cout << "OPERATIONAL TUNING:\n";
std::cout << " --log-file FILE Log filename (default: debug.log in data dir)\n";
std::cout << " --log-rotation-mb N Rotate log file at N MB (default: 10)\n";
std::cout << " --log-max-mb N Max total rotated log space in MB (default: 50)\n";
std::cout << " --log-level LEVEL Log level: trace, debug, info, warning, error (default: trace)\n";
std::cout << " --p2p-max-peers N Max total P2P peers (default: 30)\n";
std::cout << " --ban-duration N P2P ban duration in seconds (default: 300)\n";
std::cout << " --rss-limit-mb N Abort if RSS exceeds N MB (default: 4000)\n";
std::cout << " --cors-origin ORIGIN CORS Access-Control-Allow-Origin (default: disabled)\n";
std::cout << " --payout-window N PPLNS payout window in seconds (default: 86400)\n";
std::cout << " --storage-save-interval N Periodic sharechain save interval in seconds (default: 300)\n";
std::cout << " --dashboard-dir PATH Dashboard static files directory (default: web-static)\n\n";
std::cout << "BLOCKCHAIN SUPPORT:\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << " Litecoin (LTC) Parent chain with embedded SPV\n";
std::cout << " DigiByte (DGB) Parent chain (Scrypt algo, --net digibyte)\n";
std::cout << " Dogecoin (DOGE) Merged mining aux chain (embedded SPV)\n";
std::cout << " PEP/BELLS/LKY/JKC/SHIC Merged mining aux chains (external daemons)\n";
std::cout << " Bitcoin (BTC) Protocol compatibility (future)\n\n";
std::cout << "DEFAULT NETWORK PORTS:\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << " P2P Sharechain: 9326 (for P2Pool network communication)\n";
std::cout << " Stratum / HTTP API: 9327 (for miners and monitoring)\n\n";
std::cout << "USAGE EXAMPLES:\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << " p2pool-compatible (LTC+DOGE merged mining):\n";
std::cout << " c2pool --integrated --net litecoin \\\n";
std::cout << " --coind-address 192.168.86.29 --coind-rpc-port 9332 \\\n";
std::cout << " --coind-p2p-port 9333 \\\n";
std::cout << " --merged-coind-address 192.168.86.29 \\\n";
std::cout << " --merged-coind-rpc-port 44556 --merged-coind-p2p-port 22556 \\\n";
std::cout << " --merged-coind-rpc-user dogerpc --merged-coind-rpc-password pass \\\n";
std::cout << " --address YOUR_LTC_ADDRESS --give-author 2 -f 0 \\\n";
std::cout << " litecoinrpc PASSWORD\n\n";
std::cout << " c2pool-style (spec format):\n";
std::cout << " c2pool --integrated --net litecoin \\\n";
std::cout << " --rpchost 192.168.86.29 --rpcport 9332 \\\n";
std::cout << " --rpcuser litecoinrpc --rpcpassword pass \\\n";
std::cout << " --merged DOGE:98:192.168.86.29:44556:dogerpc:pass\n\n";
std::cout << "API ENDPOINTS (Integrated Mode):\n";
std::cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
std::cout << " GET /api/stats Pool statistics and hashrate\n";
std::cout << " POST /api/getinfo Pool information and status\n";
std::cout << " POST /api/getminerstats Per-miner statistics\n";
std::cout << " POST /api/getpayoutinfo Payout information and balances\n";
std::cout << " Stratum: stratum+tcp://HOST:PORT (for miners)\n\n";
std::cout << "For detailed documentation, visit: https://github.com/frstrtr/c2pool\n";
std::cout << "Report issues at: https://github.com/frstrtr/c2pool/issues\n";
}
int main(int argc, char* argv[]) {
// Install crash handlers
std::set_terminate(c2pool_terminate_handler);
std::signal(SIGINT, signal_handler);
#ifdef _WIN32
// SEH handler catches access violations, stack overflows, etc. at OS level
// and writes a minidump (.dmp) for WinDbg/VS analysis.
SetUnhandledExceptionFilter(seh_exception_handler);
#else
std::signal(SIGTERM, signal_handler); // SIGTERM not reliably delivered on Windows
#endif
std::signal(SIGSEGV, segfault_handler);
std::signal(SIGABRT, segfault_handler);
// Initialize logging
core::log::Logger::init();
// Banner intentionally deferred — only the bordered log-file banner is
// emitted (see post-parse section below). Printing an unbordered copy
// here too cluttered journalctl output with duplicate headers.
// Default settings
auto settings = std::make_unique<core::Settings>();
settings->m_testnet = false;
// Port configuration with p2pool-compatible defaults
int p2p_port = 9326; // P2Pool P2P sharechain port (p2pool LTC mainnet default)
int stratum_port = 9327; // Stratum mining port (p2pool: -w / --worker-port)
int http_port = 8080; // Web dashboard / JSON-RPC API port
std::string http_host = "0.0.0.0"; // HTTP server host
std::string external_ip; // Public IP/domain for stratum URL (empty = auto-detect)
// Coin daemon RPC connection (used by integrated/solo modes for live block templates)
std::string rpc_host = "127.0.0.1";
int rpc_port = 0; // 0 = auto-detect from chain+testnet
std::string rpc_user;
std::string rpc_pass;
// Payout address (p2pool: --address)
std::string payout_address;
std::string config_file;
std::string solo_address;
std::string node_owner_address;
std::string node_owner_merged_address; // Explicit merged chain (DOGE) address for node fee
std::string node_owner_script; // Node owner script hex
double dev_donation = 0.1; // Developer donation percentage (default 0.1%)
double node_owner_fee = 0.0; // Node owner fee percentage
bool auto_detect_wallet = true; // Auto-detect wallet address
bool integrated_mode = true; // Default: full integrated pool (p2pool persist=true)
bool sharechain_mode = false;
bool solo_mode = false; // --solo: integrated pool without P2P sharechain
bool custodial_mode = false; // --custodial: all coinbase to --address, stratum for accounting
bool embedded_ltc = true; // Default: embedded LTC SPV (no daemon needed)
bool embedded_doge = true; // Default: embedded DOGE SPV for merged mining
bool doge_testnet4alpha = false; // Use DOGE testnet4alpha instead of standard testnet3
// Embedded SPV bootstrap checkpoints (mainnet defaults, skip millions of old headers)
// Override with --header-checkpoint / --doge-header-checkpoint or config YAML.
// Testnet: set via CLI or config (no hardcoded default).
std::string header_checkpoint_str = "3088000:4a7fc8d4668c69db4f40fcdeb99ad3dbd85545b742b48e1529ebbec641e547d1";
std::string doge_header_checkpoint_str = "6160000:51efd04daebddba43ae403662098524d99abf3edad3bddc3ea7b2938c6799939";
std::string doge_p2p_address; // --doge-p2p-address HOST
int doge_p2p_port = 0; // --doge-p2p-port PORT
Blockchain blockchain = Blockchain::LITECOIN; // Default to Litecoin
// Coin daemon P2P connection (for fast block relay alongside RPC)
std::string coind_p2p_address; // defaults to rpc_host (same machine as RPC)
int coind_p2p_port = -1; // -1 = auto-detect from chain; 0 = disabled
// Merged mining (auxiliary chain) configuration
// p2pool-style: --merged-coind-address, --merged-coind-rpc-port, etc.
// c2pool-style: --merged SYMBOL:CHAIN_ID:HOST:PORT:USER:PASS[:P2P_PORT]
std::vector<std::string> merged_chain_specs;
// p2pool-style merged chain flags (assembled into spec at the end)
std::string merged_coind_address;
int merged_coind_rpc_port = 0;
std::string merged_coind_rpc_user;
std::string merged_coind_rpc_pass;
int merged_coind_p2p_port = 0;
std::string merged_coind_p2p_address;
// Log level from CLI (overrides YAML)
std::string cli_log_level;
// Seed nodes from -n flag (p2pool compat)
std::vector<std::string> seed_nodes;
int max_outgoing_conns = 0;
bool max_outgoing_conns_set = false;
// Redistribute mode for shares from unnamed/broken miners
std::string redistribute_mode_str = "pplns";
// Stratum tuning (configurable via CLI or YAML)
core::StratumConfig stratum_config; // defaults: min=0.001, max=65536, target=10s, vardiff=true
// Operational tuning (configurable via CLI or YAML)
std::string log_file; // empty = default "debug.log"
int log_rotation_size_mb = 100; // rotate log at N MB
int log_max_total_mb = 1000; // keep ≤N MB of rotated logs (~10 backups)
std::string log_level_str; // empty = default (trace)
int p2p_max_peers = 30; // max total P2P peers
int p2p_ban_duration = 300; // ban duration in seconds
long rss_limit_mb = 4000; // abort if RSS exceeds N MB
std::string http_cors_origin = ""; // Access-Control-Allow-Origin (empty = disabled)
int payout_window_seconds = 86400; // PPLNS payout window (24h)
int cache_max_shared_hashes = 50000; // de-dup set cap
int cache_max_known_txs = 10000; // known TX cache cap
int cache_max_raw_shares = 50000; // raw share cache cap
int storage_save_interval = 300; // periodic save interval (seconds)
// Dashboard directory (web-static/ by default, relative to CWD)
std::string dashboard_dir = "web-static";
// Google Analytics measurement ID (e.g. G-XXXXXXXXXX)
std::string analytics_id;
// Lite block explorer
bool explorer_enabled = false;
std::string explorer_url;
uint32_t explorer_depth_ltc = 288;
uint32_t explorer_depth_doge = 1440;
// Custom explorer link prefixes (override Blockchair defaults)
std::string address_explorer_prefix;
std::string block_explorer_prefix;
std::string tx_explorer_prefix;
// Optional encrypted authority message_data blob for local V36 shares.
std::string operator_message_blob_hex;
// Coinbase scriptSig customization
std::string coinbase_text; // --coinbase-text (replaces /c2pool/ tag)
// Private sharechain
uint32_t network_id = 0; // 0 = public p2pool network, nonzero = private
// Startup mode: wait (default, p2pool persist=true), genesis, auto
enum class StartupMode { AUTO, GENESIS, WAIT };
StartupMode startup_mode = StartupMode::WAIT; // Default: wait for peers (persist=true)
int startup_timeout = 60; // seconds to wait for peers in auto mode
// Track which options were explicitly set via CLI so that --config file
// values only fill in gaps (CLI always wins).
std::set<std::string> cli_explicit;
// Helper function to parse blockchain string
auto parse_blockchain = [](const std::string& blockchain_str) -> Blockchain {
if (blockchain_str == "ltc" || blockchain_str == "litecoin") return Blockchain::LITECOIN;
if (blockchain_str == "dgb" || blockchain_str == "digibyte") return Blockchain::DIGIBYTE;
if (blockchain_str == "btc" || blockchain_str == "bitcoin") return Blockchain::BITCOIN;
if (blockchain_str == "eth" || blockchain_str == "ethereum") return Blockchain::ETHEREUM;
if (blockchain_str == "xmr" || blockchain_str == "monero") return Blockchain::MONERO;
if (blockchain_str == "zec" || blockchain_str == "zcash") return Blockchain::ZCASH;
if (blockchain_str == "doge" || blockchain_str == "dogecoin") return Blockchain::DOGECOIN;
LOG_ERROR << "Unknown blockchain: " << blockchain_str;
LOG_INFO << "Supported blockchains: ltc, dgb, btc, doge";
throw std::invalid_argument("Unknown blockchain type");
};
// Well-known P2P ports for coin daemons (same machine as RPC by default)
auto get_coin_p2p_port = [](const std::string& symbol, bool testnet) -> int {
if (symbol == "LTC" || symbol == "ltc") return testnet ? 19335 : 9333;
if (symbol == "DOGE" || symbol == "doge") return testnet ? 44556 : 22556;
if (symbol == "BTC" || symbol == "btc") return testnet ? 18333 : 8333;
if (symbol == "DGB" || symbol == "dgb") return testnet ? 12026 : 12024;
if (symbol == "PEP" || symbol == "pep") return testnet ? 44874 : 33874;
if (symbol == "BELLS" || symbol == "bells") return testnet ? 29919 : 19919;
if (symbol == "LKY" || symbol == "lky") return testnet ? 19917 : 9917;
if (symbol == "JKC" || symbol == "jkc") return testnet ? 19771 : 9771;
if (symbol == "SHIC" || symbol == "shic") return testnet ? 44864 : 33864;
if (symbol == "DINGO" || symbol == "dingo") return testnet ? 44117 : 33117;
return 0; // unknown chain — caller must specify explicitly
};
auto blockchain_to_symbol = [](Blockchain b) -> std::string {
switch (b) {
case Blockchain::LITECOIN: return "LTC";
case Blockchain::DIGIBYTE: return "DGB";
case Blockchain::BITCOIN: return "BTC";
case Blockchain::DOGECOIN: return "DOGE";
default: return "";
}
};
// Known P2P magic prefixes for common chains
auto get_chain_p2p_prefix = [&doge_testnet4alpha](const std::string& symbol, bool testnet) -> std::vector<std::byte> {
if (symbol == "DOGE" || symbol == "doge") {
if (!testnet) return ParseHexBytes("c0c0c0c0");
// --testnet = testnet3 (fcc1b7dc), --doge-testnet4alpha = testnet4alpha (d4a1f4a1)
return doge_testnet4alpha ? ParseHexBytes("d4a1f4a1") : ParseHexBytes("fcc1b7dc");
}
if (symbol == "LTC" || symbol == "ltc") {
return testnet ? ParseHexBytes("fdd2c8f1") : ParseHexBytes("fbc0b6db");
}
if (symbol == "BTC" || symbol == "btc") {
return testnet ? ParseHexBytes("0b110907") : ParseHexBytes("f9beb4d9");
}
if (symbol == "DGB" || symbol == "dgb") {
return testnet ? ParseHexBytes("fdc8bddd") : ParseHexBytes("fac3b6da");
}
if (symbol == "PEP" || symbol == "pep") {
return testnet ? ParseHexBytes("fec1dbcc") : ParseHexBytes("c0a0f0e0");
}
if (symbol == "BELLS" || symbol == "bells") {
return testnet ? ParseHexBytes("c3c3c3c3") : ParseHexBytes("c0c0c0c0");
}
if (symbol == "LKY" || symbol == "lky") {
return testnet ? ParseHexBytes("fcc1b7dc") : ParseHexBytes("fbc0b6db");
}
if (symbol == "JKC" || symbol == "jkc") {
return testnet ? ParseHexBytes("fcc1b7dc") : ParseHexBytes("fbc0b6db");
}
if (symbol == "SHIC" || symbol == "shic") {
return testnet ? ParseHexBytes("b1c1e1f1") : ParseHexBytes("b0c0e0f0");
}
if (symbol == "DINGO" || symbol == "dingo") {
return testnet ? ParseHexBytes("c2c2c2c2") : ParseHexBytes("c1c1c1c1");
}
return {}; // unknown chain — P2P broadcast disabled
};
// Parse command line arguments
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help" || arg == "-h") {
print_help();
return 0;
}
else if (arg == "--testnet") {
settings->m_testnet = true;
cli_explicit.insert("testnet");
}
// Log level (p2pool: --debug; c2pool extends with standard levels)
else if (arg == "--loglevel-trace") { cli_log_level = "trace"; cli_explicit.insert("log_level"); }
else if (arg == "--loglevel-debug" || arg == "--debug")
{ cli_log_level = "debug"; cli_explicit.insert("log_level"); }
else if (arg == "--loglevel-info") { cli_log_level = "info"; cli_explicit.insert("log_level"); }
else if (arg == "--loglevel-warning") { cli_log_level = "warning"; cli_explicit.insert("log_level"); }
else if (arg == "--loglevel-error") { cli_log_level = "error"; cli_explicit.insert("log_level"); }
else if (arg == "--loglevel-critical") { cli_log_level = "fatal"; cli_explicit.insert("log_level"); }
// Network / blockchain selection (p2pool: --net)
else if ((arg == "--net" || arg == "--blockchain") && i + 1 < argc) {
blockchain = parse_blockchain(argv[++i]);
cli_explicit.insert("blockchain");
}
// P2Pool P2P sharechain port (p2pool: --p2pool-port)
else if ((arg == "--p2pool-port" || arg == "--p2p-port") && i + 1 < argc) {
p2p_port = std::stoi(argv[++i]);
cli_explicit.insert("p2p_port");
}
// Worker/Stratum port (p2pool: -w / --worker-port)
else if ((arg == "--worker-port" || arg == "-w" || arg == "--stratum-port") && i + 1 < argc) {
stratum_port = std::stoi(argv[++i]);
cli_explicit.insert("stratum_port");
}
// Web dashboard / JSON-RPC API port
else if ((arg == "--http-port" || arg == "--web-port") && i + 1 < argc) {
http_port = std::stoi(argv[++i]);
cli_explicit.insert("http_port");
}
else if (arg == "--http-host" && i + 1 < argc) {
http_host = argv[++i];
cli_explicit.insert("http_host");
}
else if (arg == "--external-ip" && i + 1 < argc) {
external_ip = argv[++i];
cli_explicit.insert("external_ip");
}
else if (arg == "--integrated") {
integrated_mode = true;
cli_explicit.insert("integrated");
}
else if (arg == "--solo") {
solo_mode = true;
integrated_mode = true; // solo is a variant of integrated
cli_explicit.insert("solo");
cli_explicit.insert("integrated");
}
else if (arg == "--custodial") {
custodial_mode = true;
integrated_mode = true; // custodial is a variant of integrated
cli_explicit.insert("custodial");
cli_explicit.insert("integrated");
}
else if (arg == "--sharechain") {
sharechain_mode = true;
integrated_mode = false;
cli_explicit.insert("sharechain");
cli_explicit.insert("integrated");
}
else if (arg == "--standalone") {
// Legacy solo mode: minimal stratum + RPC daemon, no embedded SPV
integrated_mode = false;
embedded_ltc = false;
embedded_doge = false;
cli_explicit.insert("integrated");
cli_explicit.insert("embedded_ltc");
cli_explicit.insert("embedded_doge");
}
else if (arg == "--embedded-ltc") {
embedded_ltc = true;
cli_explicit.insert("embedded_ltc");
}
else if (arg == "--no-embedded-ltc") {
embedded_ltc = false;
cli_explicit.insert("embedded_ltc");
}
else if (arg == "--embedded-doge") {
embedded_doge = true;
cli_explicit.insert("embedded_doge");
}
else if (arg == "--no-embedded-doge") {
embedded_doge = false;
cli_explicit.insert("embedded_doge");
}
else if (arg == "--doge-testnet4alpha") {
doge_testnet4alpha = true;
cli_explicit.insert("doge_testnet4alpha");
}
else if (arg == "--header-checkpoint" && i + 1 < argc) {
header_checkpoint_str = argv[++i];
cli_explicit.insert("header_checkpoint");
}
else if (arg == "--doge-header-checkpoint" && i + 1 < argc) {
doge_header_checkpoint_str = argv[++i];
cli_explicit.insert("doge_header_checkpoint");
}
else if (arg == "--doge-p2p-address" && i + 1 < argc) {
doge_p2p_address = argv[++i];
cli_explicit.insert("doge_p2p_address");
}
else if (arg == "--doge-p2p-port" && i + 1 < argc) {
doge_p2p_port = std::stoi(argv[++i]);
cli_explicit.insert("doge_p2p_port");
}
else if (arg == "--config" && i + 1 < argc) {
config_file = argv[++i];
}
// Payout address (p2pool: --address)
else if ((arg == "--address" || arg == "--solo-address") && i + 1 < argc) {
payout_address = argv[++i];
solo_address = payout_address; // legacy compat
cli_explicit.insert("solo_address");
cli_explicit.insert("address");
}
// Donation (p2pool: --give-author)
else if ((arg == "--give-author" || arg == "--dev-donation") && i + 1 < argc) {
dev_donation = std::stod(argv[++i]);
cli_explicit.insert("dev_donation");
}
// Node owner fee (p2pool: -f / --fee)
else if ((arg == "-f" || arg == "--fee" || arg == "--node-owner-fee") && i + 1 < argc) {
node_owner_fee = std::stod(argv[++i]);
cli_explicit.insert("node_owner_fee");
}
else if (arg == "--node-owner-address" && i + 1 < argc) {
node_owner_address = argv[++i];
cli_explicit.insert("node_owner_address");
}
else if ((arg == "--node-owner-merged-address" || arg == "--merged-operator-address") && i + 1 < argc) {
node_owner_merged_address = argv[++i];
cli_explicit.insert("node_owner_merged_address");
}
else if (arg == "--node-owner-script" && i + 1 < argc) {
node_owner_script = argv[++i];
cli_explicit.insert("node_owner_script");
}
else if (arg == "--auto-detect-wallet") {
auto_detect_wallet = true;
cli_explicit.insert("auto_detect_wallet");
}
else if (arg == "--no-auto-detect-wallet") {
auto_detect_wallet = false;
cli_explicit.insert("auto_detect_wallet");
}
// Parent coin daemon RPC (p2pool: --coind-address, --coind-rpc-port)
else if ((arg == "--coind-address" || arg == "--rpchost" || arg == "--bitcoind-address") && i + 1 < argc) {
rpc_host = argv[++i];
cli_explicit.insert("rpc_host");
}
else if ((arg == "--coind-rpc-port" || arg == "--rpcport" || arg == "--bitcoind-rpc-port") && i + 1 < argc) {
rpc_port = std::stoi(argv[++i]);
cli_explicit.insert("rpc_port");
}
else if ((arg == "--rpcuser") && i + 1 < argc) {
rpc_user = argv[++i];
cli_explicit.insert("rpc_user");
}
else if ((arg == "--rpcpassword") && i + 1 < argc) {
rpc_pass = argv[++i];
cli_explicit.insert("rpc_pass");
}
// c2pool-style merged (colon-separated spec)
else if (arg == "--merged" && i + 1 < argc) {
merged_chain_specs.push_back(argv[++i]);
cli_explicit.insert("merged");
}
// p2pool-style merged chain flags
else if (arg == "--merged-coind-address" && i + 1 < argc) {
merged_coind_address = argv[++i];
cli_explicit.insert("merged_coind_address");
}
else if (arg == "--merged-coind-rpc-port" && i + 1 < argc) {
merged_coind_rpc_port = std::stoi(argv[++i]);
cli_explicit.insert("merged_coind_rpc_port");
}
else if (arg == "--merged-coind-rpc-user" && i + 1 < argc) {
merged_coind_rpc_user = argv[++i];
cli_explicit.insert("merged_coind_rpc_user");
}
else if (arg == "--merged-coind-rpc-password" && i + 1 < argc) {
merged_coind_rpc_pass = argv[++i];
cli_explicit.insert("merged_coind_rpc_pass");
}
else if (arg == "--merged-coind-p2p-port" && i + 1 < argc) {
merged_coind_p2p_port = std::stoi(argv[++i]);
cli_explicit.insert("merged_coind_p2p_port");
}
else if (arg == "--merged-coind-p2p-address" && i + 1 < argc) {
merged_coind_p2p_address = argv[++i];
cli_explicit.insert("merged_coind_p2p_address");
}
// Parent coin daemon P2P (p2pool: --coind-p2p-port / --bitcoind-p2p-port)
else if ((arg == "--coind-p2p-port" || arg == "--bitcoind-p2p-port") && i + 1 < argc) {
coind_p2p_port = std::stoi(argv[++i]);
cli_explicit.insert("coind_p2p_port");
}
else if (arg == "--coind-p2p-address" && i + 1 < argc) {
coind_p2p_address = argv[++i];
cli_explicit.insert("coind_p2p_address");
}
// Connection limits (p2pool: --max-conns, --outgoing-conns, --disable-upnp)
else if (arg == "--max-conns" && i + 1 < argc) {
max_outgoing_conns = std::stoi(argv[++i]);
max_outgoing_conns_set = true;
}
else if (arg == "--outgoing-conns" && i + 1 < argc) {
max_outgoing_conns = std::stoi(argv[++i]);
max_outgoing_conns_set = true;
}
else if (arg == "--disable-upnp") {
/* no-op, c2pool doesn't use UPnP */
}
else if (arg == "--message-blob-hex" && i + 1 < argc) {
operator_message_blob_hex = argv[++i];
cli_explicit.insert("message_blob_hex");
}
else if (arg == "--coinbase-text" && i + 1 < argc) {
coinbase_text = argv[++i];
cli_explicit.insert("coinbase_text");
}
else if ((arg == "--network-id" || arg == "--chain-id") && i + 1 < argc) {
network_id = static_cast<uint32_t>(std::stoul(argv[++i], nullptr, 16));
cli_explicit.insert("network_id");
}
else if (arg == "--startup-mode" && i + 1 < argc) {
std::string mode = argv[++i];
if (mode == "genesis") startup_mode = StartupMode::GENESIS;
else if (mode == "wait") startup_mode = StartupMode::WAIT;
else startup_mode = StartupMode::AUTO;
cli_explicit.insert("startup_mode");
}
else if (arg == "--genesis") {
startup_mode = StartupMode::GENESIS;
cli_explicit.insert("startup_mode");
}
else if (arg == "--wait-for-peers") {
startup_mode = StartupMode::WAIT;
cli_explicit.insert("startup_mode");
}
else if (arg == "--startup-timeout" && i + 1 < argc) {
startup_timeout = std::stoi(argv[++i]);
cli_explicit.insert("startup_timeout");
}
// Legacy support for old --port option
else if (arg == "--port" && i + 1 < argc) {
p2p_port = std::stoi(argv[++i]);
cli_explicit.insert("p2p_port");
LOG_WARNING << "--port is deprecated, use --p2pool-port instead";
}
// Redistribute mode for empty/broken miner addresses
else if (arg == "--redistribute" && i + 1 < argc) {
redistribute_mode_str = argv[++i];
cli_explicit.insert("redistribute");
}
// Stratum tuning
else if (arg == "--stratum-min-diff" && i + 1 < argc) {
stratum_config.min_difficulty = std::stod(argv[++i]);
cli_explicit.insert("stratum_min_diff");
}