|
31 | 31 | #include <impl/btc/coin/transaction.hpp> |
32 | 32 | #include <impl/btc/config.hpp> |
33 | 33 | #include <impl/btc/config_pool.hpp> |
| 34 | +#include <impl/btc/coin/rpc_conf.hpp> // bitcoin.conf creds for the submitblock RPC backup (ARM B, #82/#744) |
34 | 35 | #include <impl/btc/node.hpp> |
35 | 36 | #include <impl/btc/auto_ratchet.hpp> // AutoRatchet V35->V36 forward-version-voting |
36 | 37 | #include <impl/btc/share_check.hpp> // RefHashParams + compute_ref_hash_for_work |
@@ -102,7 +103,13 @@ static void print_usage() |
102 | 103 | " --prefix HEX c2pool sharechain PREFIX (hex, <=8 bytes), an\n" |
103 | 104 | " INDEPENDENT per-network constant (no algebraic tie to\n" |
104 | 105 | " IDENTIFIER). Supply with --network-id to join a custom\n" |
105 | | - " p2pool chain; omit to use the compiled default prefix.\n"; |
| 106 | + " p2pool chain; omit to use the compiled default prefix.\n" |
| 107 | + " --coin-rpc H:P submitblock RPC backup (ARM B) endpoint override.\n" |
| 108 | + " Endpoint only (no secret); creds come from bitcoin.conf.\n" |
| 109 | + " --coin-rpc-auth PATH bitcoin.conf-style file with rpcuser/rpcpassword\n" |
| 110 | + " for the submitblock backup (default ~/.bitcoin/\n" |
| 111 | + " bitcoin.conf; keeps rpcpassword off the process table).\n" |
| 112 | + " Omit both to run daemonless (embedded P2P relay only).\n"; |
106 | 113 | } |
107 | 114 |
|
108 | 115 | /// BTC wire-protocol magic bytes per network (pchMessageStart). |
@@ -133,6 +140,8 @@ int main(int argc, char* argv[]) |
133 | 140 | uint16_t sharechain_port = 0; // 0 = default P2P_PORT (9333); --sharechain-port overrides (opt-in isolation) |
134 | 141 | std::string network_id_hex; // --network-id: c2pool IDENTIFIER override (empty = public net) |
135 | 142 | std::string prefix_hex; // --prefix: c2pool PREFIX override (empty = compiled default) |
| 143 | + std::string rpc_endpoint; // --coin-rpc HOST:PORT: submitblock backup endpoint override (no secret) |
| 144 | + std::string rpc_conf_path; // --coin-rpc-auth PATH: bitcoin.conf creds (default ~/.bitcoin/bitcoin.conf) |
136 | 145 |
|
137 | 146 | for (int i = 1; i < argc; ++i) |
138 | 147 | { |
@@ -221,6 +230,20 @@ int main(int argc, char* argv[]) |
221 | 230 | { |
222 | 231 | prefix_hex = argv[++i]; |
223 | 232 | } |
| 233 | + else if (arg == "--coin-rpc" && i + 1 < argc) |
| 234 | + { |
| 235 | + // --coin-rpc HOST:PORT — endpoint override for the submitblock RPC |
| 236 | + // backup (ARM B). Endpoint ONLY (no secret) so it is safe on argv; |
| 237 | + // rpcuser/rpcpassword come from bitcoin.conf (--coin-rpc-auth). |
| 238 | + rpc_endpoint = argv[++i]; |
| 239 | + } |
| 240 | + else if (arg == "--coin-rpc-auth" && i + 1 < argc) |
| 241 | + { |
| 242 | + // --coin-rpc-auth PATH — bitcoin.conf-style file carrying |
| 243 | + // rpcuser/rpcpassword for the submitblock RPC backup. Keeps the |
| 244 | + // rpcpassword OFF the process table (default ~/.bitcoin/bitcoin.conf). |
| 245 | + rpc_conf_path = argv[++i]; |
| 246 | + } |
224 | 247 | else |
225 | 248 | { |
226 | 249 | std::cerr << "unknown arg: " << arg << "\n"; |
@@ -379,6 +402,47 @@ int main(int argc, char* argv[]) |
379 | 402 |
|
380 | 403 | btc::coin::Node<btc::Config> coin_node(&ioc, &config); |
381 | 404 |
|
| 405 | + // ── #82/#744 submitblock RPC BACKUP arm (ARM B of the dual-path |
| 406 | + // broadcaster) ── The embedded coin-net P2P relay (submit_block_for_connect |
| 407 | + // -> submit_block_p2p_raw) is the always-primary daemonless path; this arms |
| 408 | + // the OPT-IN submitblock backup so a won block ALSO reaches a locally-run |
| 409 | + // bitcoind if the operator provisions one. Creds come from bitcoin.conf |
| 410 | + // (default ~/.bitcoin/bitcoin.conf, overridable with --coin-rpc-auth PATH) |
| 411 | + // so the rpcpassword NEVER touches argv; --coin-rpc HOST:PORT overrides only |
| 412 | + // the endpoint. No creds => arm stays UNARMED (has_rpc()==false) and |
| 413 | + // submit_block_hex returns false LOUDLY -- byte-identical to the daemonless |
| 414 | + // default. Mirrors main_dgb's NodeRPC arming (the #82 reference). |
| 415 | + { |
| 416 | + btc::coin::RpcConf rpc_conf; |
| 417 | + std::string conf_path = rpc_conf_path; |
| 418 | + if (conf_path.empty()) { |
| 419 | + const char* home = std::getenv("HOME"); |
| 420 | + conf_path = std::string(home ? home : ".") + "/.bitcoin/bitcoin.conf"; |
| 421 | + } |
| 422 | + if (btc::coin::load_rpc_conf(conf_path, rpc_conf)) { |
| 423 | + if (rpc_conf.port == 0) { |
| 424 | + // Bitcoin Core RPC defaults: mainnet 8332, testnet3 18332, |
| 425 | + // testnet4 48332, regtest 18443. |
| 426 | + rpc_conf.port = regtest ? 18443 |
| 427 | + : (testnet4 ? 48332 |
| 428 | + : (testnet ? 18332 : 8332)); |
| 429 | + } |
| 430 | + btc::coin::apply_endpoint_override(rpc_endpoint, rpc_conf); |
| 431 | + } else { |
| 432 | + // No conf creds; --coin-rpc alone still lets an operator point the |
| 433 | + // endpoint, but without user/pass the arm cannot fire. |
| 434 | + btc::coin::apply_endpoint_override(rpc_endpoint, rpc_conf); |
| 435 | + } |
| 436 | + if (rpc_conf.armed()) { |
| 437 | + coin_node.arm_submit_rpc(NetService(rpc_conf.host, rpc_conf.port), |
| 438 | + rpc_conf.userpass()); |
| 439 | + } else { |
| 440 | + LOG_INFO << "[BTC] submitblock RPC backup UNARMED " |
| 441 | + "(no bitcoin.conf creds; embedded P2P relay is the only " |
| 442 | + "broadcast arm)"; |
| 443 | + } |
| 444 | + } |
| 445 | + |
382 | 446 | // Constants for getheaders driver: protocol version sent in the message |
383 | 447 | // (matches what we advertised in version handshake — see B1 coin/p2p_node.hpp). |
384 | 448 | constexpr uint32_t BTC_PROTOCOL_VERSION = 70016; |
|
0 commit comments