diff options
| author | Bitflash <btf01@proton.me> | 2026-08-01 12:44:04 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-01 12:44:04 -0300 |
| commit | b426948b966405b65f3ea6c1994164b462980694 (patch) | |
| tree | f16357fe57bac2b6a6a8b61f1473e2861203cef1 /src | |
| parent | 24ed292f0524f1bc77c317b60d7ecf265596b3dd (diff) | |
mine: remember whether this node was mining, with the command line winning (#84)
Diffstat (limited to 'src')
| -rw-r--r-- | src/db.cpp | 39 | ||||
| -rw-r--r-- | src/gui.cpp | 7 | ||||
| -rw-r--r-- | src/main.cpp | 1 | ||||
| -rw-r--r-- | src/main.h | 9 | ||||
| -rw-r--r-- | src/main_gui.cpp | 5 |
5 files changed, 46 insertions, 15 deletions
| @@ -642,16 +642,29 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet) | |||
| 642 | ssKey >> strKey; | 642 | ssKey >> strKey; |
| 643 | if (strKey == "nTransactionFee") ssValue >> nTransactionFee; | 643 | if (strKey == "nTransactionFee") ssValue >> nTransactionFee; |
| 644 | if (strKey == "addrIncoming") ssValue >> addrIncoming; | 644 | if (strKey == "addrIncoming") ssValue >> addrIncoming; |
| 645 | // Mining-mode/pool settings (nMineMode, strParticipantPool, strPoolName, | 645 | |
| 646 | // strPoolDashboardUrl, dPoolFeePercent, fGenerateBitcoins) are intentionally | 646 | // Mining mode is restored, but only when no flag chose one. |
| 647 | // NOT restored here. They used to be, and LoadWallet() runs after CLI flags | 647 | // |
| 648 | // are parsed in main_gui.cpp, so a saved value would silently overwrite | 648 | // These settings used to be restored unconditionally. LoadWallet() |
| 649 | // whatever was just requested on the command line or in a previous Options | 649 | // runs after main_gui.cpp has parsed the command line, so a stored |
| 650 | // session -- no error, no log line. That's what caused pool name/address to | 650 | // value silently overwrote what had just been asked for -- no error, |
| 651 | // show correctly in the UI but stay stale in the logs, and mode to change | 651 | // no log line -- and the fix at the time was to stop restoring them |
| 652 | // behavior across restarts. Mode/pool config is decided fresh every launch | 652 | // at all. That traded a silent override for a different silent |
| 653 | // instead: CLI flags if given, otherwise the compiled-in default. Nothing to | 653 | // failure: a machine set to mine came back from every restart as a |
| 654 | // go stale, nothing to fight over load order. | 654 | // plain relay, looking exactly like one that had been asked to |
| 655 | // relay. A 32-core miner sat idle for hours that way, and the only | ||
| 656 | // evidence was memory usage that never climbed. | ||
| 657 | // | ||
| 658 | // Precedence is now explicit rather than accidental: a flag wins, | ||
| 659 | // and it says so in the log below. Only the two fields that decide | ||
| 660 | // whether this node mines are restored, plus the pool address a | ||
| 661 | // participant cannot work without. | ||
| 662 | if (!fMineModeFromCommandLine) | ||
| 663 | { | ||
| 664 | if (strKey == "nMineMode") ssValue >> nMineMode; | ||
| 665 | if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins; | ||
| 666 | if (strKey == "strParticipantPool") ssValue >> strParticipantPool; | ||
| 667 | } | ||
| 655 | } | 668 | } |
| 656 | } | 669 | } |
| 657 | } | 670 | } |
| @@ -673,8 +686,10 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet) | |||
| 673 | 686 | ||
| 674 | printf("nTransactionFee = %lld\n", nTransactionFee); | 687 | printf("nTransactionFee = %lld\n", nTransactionFee); |
| 675 | printf("addrIncoming = %s\n", addrIncoming.ToString().c_str()); | 688 | printf("addrIncoming = %s\n", addrIncoming.ToString().c_str()); |
| 676 | printf("nMineMode = %d, strParticipantPool = %s, fGenerateBitcoins = %d (from CLI/default, not wallet.dat)\n", | 689 | printf("nMineMode = %d, strParticipantPool = %s, fGenerateBitcoins = %d (%s)\n", |
| 677 | nMineMode, strParticipantPool.c_str(), fGenerateBitcoins); | 690 | nMineMode, strParticipantPool.c_str(), fGenerateBitcoins, |
| 691 | fMineModeFromCommandLine ? "from the command line, wallet.dat ignored" | ||
| 692 | : "remembered from wallet.dat, or the default"); | ||
| 678 | printf("strPoolName = %s, dPoolFeePercent = %.2f, strPoolDashboardUrl = %s (from CLI/default, not wallet.dat)\n", | 693 | printf("strPoolName = %s, dPoolFeePercent = %.2f, strPoolDashboardUrl = %s (from CLI/default, not wallet.dat)\n", |
| 679 | strPoolName.c_str(), dPoolFeePercent, strPoolDashboardUrl.c_str()); | 694 | strPoolName.c_str(), dPoolFeePercent, strPoolDashboardUrl.c_str()); |
| 680 | 695 | ||
diff --git a/src/gui.cpp b/src/gui.cpp index db6b69e..e2bb5cf 100644 --- a/src/gui.cpp +++ b/src/gui.cpp | |||
| @@ -795,6 +795,13 @@ static void DrawOptionsDialog() | |||
| 795 | if (!vfThreadRunning[3]) StartMinerThreads(); | 795 | if (!vfThreadRunning[3]) StartMinerThreads(); |
| 796 | } | 796 | } |
| 797 | 797 | ||
| 798 | // Remember the choice. Without this the node came back from every | ||
| 799 | // restart as a plain relay, and a machine that had been mining for | ||
| 800 | // days looked identical to one that had never been asked to. | ||
| 801 | CWalletDB().WriteSetting("nMineMode", nMineMode); | ||
| 802 | CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins); | ||
| 803 | CWalletDB().WriteSetting("strParticipantPool", strParticipantPool); | ||
| 804 | |||
| 798 | if (nMineMode == MINE_OPERATOR) { | 805 | if (nMineMode == MINE_OPERATOR) { |
| 799 | if (!gPoolServerRunning) { | 806 | if (!gPoolServerRunning) { |
| 800 | gPoolServerRunning = true; | 807 | gPoolServerRunning = true; |
diff --git a/src/main.cpp b/src/main.cpp index 1a4c9ea..f63f575 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -91,6 +91,7 @@ int nMinerThreads = 0; | |||
| 91 | int64 nTransactionFee = 0; | 91 | int64 nTransactionFee = 0; |
| 92 | CAddress addrIncoming; | 92 | CAddress addrIncoming; |
| 93 | int nMineMode = MINE_RELAY; | 93 | int nMineMode = MINE_RELAY; |
| 94 | bool fMineModeFromCommandLine = false; | ||
| 94 | string strParticipantPool; // participant mode: pool .btf address | 95 | string strParticipantPool; // participant mode: pool .btf address |
| 95 | string strPoolName = "Bitflash Pool"; | 96 | string strPoolName = "Bitflash Pool"; |
| 96 | string strPoolDashboardUrl; | 97 | string strPoolDashboardUrl; |
| @@ -64,9 +64,8 @@ extern CBlockIndex* pindexBest; | |||
| 64 | extern unsigned int nTransactionsUpdated; | 64 | extern unsigned int nTransactionsUpdated; |
| 65 | extern string strSetDataDir; | 65 | extern string strSetDataDir; |
| 66 | extern int nDropMessagesTest; | 66 | extern int nDropMessagesTest; |
| 67 | // Mining mode -- persisted in wallet.dat | 67 | // Mining mode -- remembered in wallet.dat, but the command line always wins. |
| 68 | // Mining mode -- decided fresh every launch (CLI flags, else default). Never | 68 | // See LoadWallet() in db.cpp for why the precedence has to be explicit. |
| 69 | // restored from wallet.dat; see LoadWallet() in db.cpp. | ||
| 70 | // MINE_RELAY (0): default. Node runs/syncs, never mines, no pool server. | 69 | // MINE_RELAY (0): default. Node runs/syncs, never mines, no pool server. |
| 71 | // MINE_SOLO (1): mine to own wallet, no pool server | 70 | // MINE_SOLO (1): mine to own wallet, no pool server |
| 72 | // MINE_OPERATOR (2): run pool server, mine to own wallet, distribute to miners | 71 | // MINE_OPERATOR (2): run pool server, mine to own wallet, distribute to miners |
| @@ -76,6 +75,10 @@ extern int nDropMessagesTest; | |||
| 76 | #define MINE_OPERATOR 2 | 75 | #define MINE_OPERATOR 2 |
| 77 | #define MINE_PARTICIPANT 3 | 76 | #define MINE_PARTICIPANT 3 |
| 78 | extern int nMineMode; | 77 | extern int nMineMode; |
| 78 | // Set by the startup parser when a flag chose the mode. LoadWallet leaves the | ||
| 79 | // stored mode alone when this is true, so a flag is never silently overruled by | ||
| 80 | // something a previous session wrote. | ||
| 81 | extern bool fMineModeFromCommandLine; | ||
| 79 | extern string strParticipantPool; // participant: pool .btf address | 82 | extern string strParticipantPool; // participant: pool .btf address |
| 80 | extern string strPoolName; // operator: announced pool name | 83 | extern string strPoolName; // operator: announced pool name |
| 81 | extern string strPoolDashboardUrl; // operator: optional dashboard URL | 84 | extern string strPoolDashboardUrl; // operator: optional dashboard URL |
diff --git a/src/main_gui.cpp b/src/main_gui.cpp index c593162..5c87fe0 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp | |||
| @@ -97,6 +97,7 @@ static void ParseStartupArguments(int argc, char* argv[]) | |||
| 97 | // their own mode below, so only the unqualified case is affected. | 97 | // their own mode below, so only the unqualified case is affected. |
| 98 | if (nMineMode == MINE_RELAY) | 98 | if (nMineMode == MINE_RELAY) |
| 99 | nMineMode = MINE_SOLO; | 99 | nMineMode = MINE_SOLO; |
| 100 | fMineModeFromCommandLine = true; | ||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | if (arg(argc,argv,"/solomine") || arg(argc,argv,"-solomine")) | 103 | if (arg(argc,argv,"/solomine") || arg(argc,argv,"-solomine")) |
| @@ -127,12 +128,16 @@ static void ParseStartupArguments(int argc, char* argv[]) | |||
| 127 | } | 128 | } |
| 128 | 129 | ||
| 129 | if (arg(argc,argv,"/operator") || arg(argc,argv,"-operator")) | 130 | if (arg(argc,argv,"/operator") || arg(argc,argv,"-operator")) |
| 131 | { | ||
| 130 | nMineMode = MINE_OPERATOR; | 132 | nMineMode = MINE_OPERATOR; |
| 133 | fMineModeFromCommandLine = true; | ||
| 134 | } | ||
| 131 | 135 | ||
| 132 | if (arg(argc,argv,"/participant") || arg(argc,argv,"-participant")) | 136 | if (arg(argc,argv,"/participant") || arg(argc,argv,"-participant")) |
| 133 | { | 137 | { |
| 134 | nMineMode = MINE_PARTICIPANT; | 138 | nMineMode = MINE_PARTICIPANT; |
| 135 | strParticipantPool = argval2(argc, argv, "/participant", "-participant"); | 139 | strParticipantPool = argval2(argc, argv, "/participant", "-participant"); |
| 140 | fMineModeFromCommandLine = true; | ||
| 136 | } | 141 | } |
| 137 | 142 | ||
| 138 | string poolName = argval2(argc, argv, "/poolname", "-poolname"); | 143 | string poolName = argval2(argc, argv, "/poolname", "-poolname"); |