From cdbf1fc5d6c32ee6e776624ec1ac1624674f5777 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 27 Aug 2021 11:36:44 -0400 Subject: [PATCH] Add -stratumaddress and better stratum error logging --- src/init.cpp | 4 +++- src/stratum.cpp | 32 ++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index c5f7b7bb2..2aaa490a0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -589,10 +589,12 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageGroup(_("Stratum server options:")); strUsage += HelpMessageOpt("-stratum", _("Enable stratum server (default: off)")); - strUsage += HelpMessageOpt("-stratumbind=", _("Bind to given address to listen for Stratum work requests. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)")); + strUsage += HelpMessageOpt("-stratumaddress=
", _("Mining address to use when special address of 'x' is sent by miner (default: none)")); + strUsage += HelpMessageOpt("-stratumbind=", _("Bind to given address to listen for Stratum work requests. Use [host]:port notation for IPv6. This option can be specified multiple times (default: bind to all interfaces)")); strUsage += HelpMessageOpt("-stratumport=", strprintf(_("Listen for Stratum work requests on (default: %u or testnet: %u)"), BaseParams().StratumPort(), BaseParams().StratumPort())); strUsage += HelpMessageOpt("-stratumallowip=", _("Allow Stratum work requests from specified source. Valid for are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times")); + // "ac" stands for "affects consensus" strUsage += HelpMessageGroup(_("Hush Smart Chain options:")); strUsage += HelpMessageOpt("-ac_algo", _("Choose PoW mining algorithm, default is Equihash (200,9)")); strUsage += HelpMessageOpt("-ac_blocktime", _("Block time in seconds, default is 60")); diff --git a/src/stratum.cpp b/src/stratum.cpp index 233277520..4dd30f524 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -681,15 +681,21 @@ std::string GetWorkUnit(StratumClient& client) if (Params().MiningRequiresPeers() && fvNodesEmpty) { + const std::string msg = strprintf("%s: Unable to get work unit, Hush is not connected!", __func__); + LogPrint("stratum", "%s\n", msg); throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Hush is not connected!"); } if (IsInitialBlockDownload()) { + const std::string msg = strprintf("%s: Unable to get work unit, Hush is still downloading blocks!", __func__); + LogPrint("stratum", "%s\n", msg); throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Hush is downloading blocks..."); } if (!client.m_authorized && client.m_aux_addr.empty()) { - throw JSONRPCError(RPC_INVALID_REQUEST, "Stratum client not authorized. Use mining.authorize first, with a Hush R.. address as the username."); + const std::string msg = strprintf("%s: Unable to get work unit, client not authorized! Use address 'x' to mine to the default address", __func__); + LogPrint("stratum", "%s\n", msg); + throw JSONRPCError(RPC_INVALID_REQUEST, "Stratum client not authorized. Use mining.authorize first, with a Hush R.. address as the username or 'x' to mine to the default address."); } static CBlockIndex* tip = NULL; // pindexPrev @@ -706,7 +712,7 @@ std::string GetWorkUnit(StratumClient& client) /** * We will check script later inside CustomizeWork, if it will be == CScript() << OP_FALSE it will mean - * that work need to be customized, and in that case cb.vout[0],scriptPubKey will be set to GetScriptForDestination(addr.Get()) . + * that work need to be customized, and in that case cb.vout[0].scriptPubKey will be set to GetScriptForDestination(addr.Get()) . * In other words to the address with which stratum client is authorized. */ const CScript scriptDummy = CScript() << OP_FALSE; @@ -721,6 +727,8 @@ std::string GetWorkUnit(StratumClient& client) // DecodeHexTx(new_work->block.vtx[0], "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff01aa2ce73b0000000023210325b4ca6736f90679f712be1454c5302050aae6edb51b0d2a051156bc868fec16ac4aabc560"); if (!new_work) { + const std::string msg = strprintf("%s: Out of memory!", __func__); + LogPrint("stratum", "%s\n", msg); throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); } @@ -1244,15 +1252,27 @@ UniValue stratum_mining_authorize(StratumClient& client, const UniValue& params) CBitcoinAddress addr(get_stripped_username(username)); + // If given the special address "x", mine to the default address given by -stratumaddress + // This means a miner can run a private pool without TLS and not + // worry about MITM attacks that change addresses, and leaks less metadata. + // It also means many miners can be used and updating their mining address does not + // require any changes on each miner, just restart hushd with a new -stratumaddress + if(addr.ToString() == "x") { + addr = CBitcoinAddress(GetArg("-stratumaddress", "")); + const std::string msg = strprintf("%s: Authorized client with default stratum address=%s", __func__, addr.ToString()); + LogPrint("stratum", "%s\n", msg); + } + if (!addr.IsValid()) { + const std::string msg = strprintf("%s: Invalid Hush address=%s", __func__, addr.ToString()); + LogPrint("stratum", "%s\n", msg); throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid Hush address: %s", username)); } - client.m_addr = addr; - client.m_mindiff = mindiff; + client.m_addr = addr; + client.m_mindiff = mindiff; client.m_authorized = true; - - client.m_send_work = true; + client.m_send_work = true; LogPrintf("Authorized stratum miner %s from %s, mindiff=%f\n", addr.ToString(), client.GetPeer().ToString(), mindiff);