|
| 1 | +# Create Pull Request for Issue #346 Fix |
| 2 | + |
| 3 | +## Quick Links |
| 4 | + |
| 5 | +**Create PR Now:** |
| 6 | +``` |
| 7 | +https://github.com/DigiByte-Core/digibyte/compare/develop...claude/investigate-digibyte-issue-018eRW2M8brZzweTZpj1e89B?expand=1 |
| 8 | +``` |
| 9 | + |
| 10 | +**Or use GitHub CLI:** |
| 11 | +```bash |
| 12 | +gh pr create --base develop --head claude/investigate-digibyte-issue-018eRW2M8brZzweTZpj1e89B --title "Fix: getmininginfo difficulty field always returns Groestl difficulty (Issue #346)" --body-file PR_DESCRIPTION.md |
| 13 | +``` |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## PR Details |
| 18 | + |
| 19 | +**Title:** |
| 20 | +``` |
| 21 | +Fix: getmininginfo difficulty field always returns Groestl difficulty (Issue #346) |
| 22 | +``` |
| 23 | + |
| 24 | +**Base Branch:** `develop` |
| 25 | +**Head Branch:** `claude/investigate-digibyte-issue-018eRW2M8brZzweTZpj1e89B` |
| 26 | + |
| 27 | +**Description:** (Copy from PR_DESCRIPTION.md or use below) |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +# Fix: getmininginfo difficulty field always returns Groestl difficulty (Issue #346) |
| 32 | + |
| 33 | +## Summary |
| 34 | +Fixes #346 - The `difficulty` field in `getmininginfo` RPC was returning a frozen/incorrect value because it was always querying Groestl's difficulty instead of the current mining algorithm's difficulty. |
| 35 | + |
| 36 | +## Problem Description |
| 37 | +In DigiByte v8.26.1, users reported that the `difficulty` field in the `getmininginfo` RPC method displays a frozen value that doesn't update correctly. The `difficulties` field (plural) works as expected, but the singular `difficulty` field was broken. |
| 38 | + |
| 39 | +## Root Cause |
| 40 | +During the Bitcoin Core v26.2 merge, the `GetDifficulty()` call in `getmininginfo` lost the algorithm parameter. |
| 41 | + |
| 42 | +**In v8.22.2 (working):** |
| 43 | +```cpp |
| 44 | +obj.pushKV("difficulty", (double)GetDifficulty(tip, NULL, miningAlgo)); |
| 45 | +``` |
| 46 | + |
| 47 | +**In v8.26.1 (broken):** |
| 48 | +```cpp |
| 49 | +obj.pushKV("difficulty", (double)GetDifficulty(tip)); |
| 50 | +``` |
| 51 | + |
| 52 | +Since DigiByte's `GetDifficulty()` function signature is: |
| 53 | +```cpp |
| 54 | +double GetDifficulty(const CBlockIndex* tip = NULL, const CBlockIndex* blockindex = nullptr, int algo = 2); |
| 55 | +``` |
| 56 | +
|
| 57 | +When called with only one parameter, `algo` defaults to `2` (ALGO_GROESTL), causing it to always return Groestl's difficulty regardless of the user's configured mining algorithm. |
| 58 | +
|
| 59 | +## Changes Made |
| 60 | +- **File:** `src/rpc/mining.cpp` |
| 61 | +- **Line 526:** Restored the `miningAlgo` parameter to the `GetDifficulty()` call |
| 62 | +- **Change:** `GetDifficulty(tip)` → `GetDifficulty(tip, nullptr, miningAlgo)` |
| 63 | +
|
| 64 | +## Testing |
| 65 | +This fix ensures that: |
| 66 | +1. The `difficulty` field returns the difficulty for the **current mining algorithm** (as set by `-miningalgo`) |
| 67 | +2. Behavior matches DigiByte v8.22.2 |
| 68 | +3. The field updates correctly as blocks arrive for different algorithms |
| 69 | +
|
| 70 | +**Test commands:** |
| 71 | +```bash |
| 72 | +# Test with different algorithms |
| 73 | +digibyted -miningalgo=sha256d |
| 74 | +digibyte-cli getmininginfo | jq '.difficulty' |
| 75 | +
|
| 76 | +digibyted -miningalgo=scrypt |
| 77 | +digibyte-cli getmininginfo | jq '.difficulty' |
| 78 | +
|
| 79 | +# Verify difficulty matches the corresponding value in difficulties object |
| 80 | +digibyte-cli getmininginfo | jq '{difficulty, difficulties}' |
| 81 | +``` |
| 82 | + |
| 83 | +## Impact |
| 84 | +- **Severity:** Medium - Affects mining operations and monitoring |
| 85 | +- **Affected versions:** DigiByte v8.26.0, v8.26.1 |
| 86 | +- **Scope:** Users running any algorithm other than Groestl see incorrect difficulty values |
| 87 | + |
| 88 | +## Additional Context |
| 89 | +This is a regression introduced during the Bitcoin Core v26.2 merge. It highlights the importance of preserving DigiByte-specific multi-algorithm functionality when integrating upstream Bitcoin changes. The `difficulties` field was unaffected because it explicitly iterates through all algorithms with the correct parameters. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +**Repository:** `DigiByte-Core/digibyte` |
| 94 | +**Branch:** `claude/investigate-digibyte-issue-018eRW2M8brZzweTZpj1e89B` |
| 95 | +**Target:** `develop` |
| 96 | +**Commits:** |
| 97 | +- c6f3663 - Fix: getmininginfo difficulty field returns frozen value for wrong algorithm |
| 98 | +- 0cda24a - docs: Add PR and GitHub issue response documentation for #346 |
| 99 | +- c70d433 - docs: Update PR and issue response with correct repository info |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Checklist |
| 104 | +- [x] Code fix applied (src/rpc/mining.cpp) |
| 105 | +- [x] Commit message follows conventional format |
| 106 | +- [x] Fix tested against v8.22.2 behavior |
| 107 | +- [x] Documentation provided |
| 108 | +- [x] Issue #346 referenced |
| 109 | +- [ ] PR created |
| 110 | +- [ ] GitHub issue #346 updated with response |
| 111 | + |
| 112 | +## Files Changed |
| 113 | +``` |
| 114 | +src/rpc/mining.cpp | 2 +- |
| 115 | +PR_DESCRIPTION.md | 71 +++++++++++++++++++++ |
| 116 | +GITHUB_ISSUE_RESPONSE.md | 99 +++++++++++++++++++++++++++++ |
| 117 | +3 files changed, 171 insertions(+), 1 deletion(-) |
| 118 | +``` |
0 commit comments