[RPC] Reworked getnetworkhashps with tweaks to -mine and getmininginfo#876
Merged
codeofalltrades merged 2 commits intoVeil-Project:masterfrom Dec 10, 2020
Merged
Conversation
Collaborator
codeofalltrades
left a comment
There was a problem hiding this comment.
0807f52
One question about logic.
Collaborator
|
ACK 0807f52 |
codeofalltrades
added a commit
that referenced
this pull request
Dec 10, 2020
…thms without restarting wallet 6ed4626 [RPC][Mining] Provide ability to change mining algorithm (Cave Spectre) Pull request description: ### Note This is built on top of #876 and also contains a couple corrections to get the `getnetworkhashps` help. ### Problem In order to switch mining algorithms, you must shut down the wallet and restart with a new `-mine=` flag. ### Root Cause Never implemented ### Solution Add `setminingalgo` cli command to allow you to switch between different algorithms. This RPC command requires you to turn off mining before issuing the command and will error if it does not work. ### Testing ``` $ veil-cli help setminingalgo setminingalgo algorithm Changes your mining algorithm to [algorithm]. Note that mining must be turned off when command is used. Arguments: 1. algorithm (string, required) Algorithm to mine [progpow, randomx, sha256d]. Result: { "success": true|false, (boolean) Status of the switch "message": "text", (text) Informational message about the switch } Examples: > veil-cli setminingalgo sha256d > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "setminingalgo", "params": [sha256d] }' -H 'content-type: text/plain;' http://127.0.0.1:58812/ ``` ``` $ veil-cli setminingalgo randomx { "success": true, "message": "Mining algorithm changed from sha256d to randomx" } veil-cli getmininginfo { [...] "algorithm": "randomx", "difficulty": 0.003707938785486674, "networkhashps": 22.73835278085342, [...] } ``` ``` $ veil-cli setminingalgo sha257d error code: -8 error message: sha257d is not a supported mining type $ veil-cli setminingalgo sha256d { "success": true, "message": "Mining algorithm changed from randomx to sha256d" } $ veil-cli getmininginfo { [...] "algorithm": "sha256d", "difficulty": 18.1774015474177, "networkhashps": 23.05669884097939, [...] } ``` ``` $ veil-cli generatecontinuous true 1 $ veil-cli setminingalgo progpow error code: -8 error message: mining must be stopped to change algorithm $ veil-cli generatecontinuous false $ veil-cli setminingalgo progpow { "success": true, "message": "Mining algorithm changed from sha256d to progpow" } $ veil-cli getmininginfo { [...] "algorithm": "progpow", "difficulty": 164.7481194885794, "networkhashps": 23.16038554216868, [...] } ``` Tree-SHA512: 89c8a5032856afcf48ba0ec6c0c9636d9f451e705efe1b9545c3b1719e7db7897d6721a5bf2663f4e3b0d05600c46acff5b6e9c4dd7d3ec3ab2fc47311a328d4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Problem]
#340 -
getnetworkhashpsseems to be unrelated to actual network hash#32 -
getmininginfohas vastly changing difficulties[Root Cause]
As greatly discussed in #340, the
getnetworkhashpsnever accurately reflected PoW vs. PoS; as if one of the blocks was a PoS block, and one was a PoW block, the average calculated would vary wildly. Likewise,getmininginfowould only report on the last block, which gets even crazier with 4 different block types.[Solution]
First was a need to get your current mining algorithm; this is a separate commit. The original code was getting the mining algorithm only when generation was started; so the startup flag sat unused until that time. This also had the side effect of not realizing you would be mining randomX, until you started mining, due to a typo in the
-mineflag [e.g. sha256 instead of sha256d. By changing the code to read the flag on startup, it opened the ability to sanity check it on startup; so users using an incorrect flag will now be told so. This also opens the ability to switch mining algorithms without stopping the daemon [although that's for a future PR, as care is needed to make sure you're told to stop mining before switching algorithms].With that out of the way,
getnetworkhashpswas expanded to still function as would be expected, but instead of just randomly using whatever blocks it found; it now focuses on only the blocks related to the currently set algorithm. e.g. if you want the average network hashes per second over the last 120 blocks [the default] it will be between the last 120 blocks of the specific algorithm you're configured for. An algorithm parameter was added so that you can specify a different algorithm if you chose, including the historical xr16t, or if you care about PoS. Note that this is actually calculating the change in difficulty over time, and not hashes. That research was also out of scope for this PR, and if the logic needs to change it will be a separate PR.The output to
getnetworkhashpsis also included ingetmininginfo, which in testing revealed thatgetmininginfodisplays the difficulty for the last block; and not the difficulty for the algorithm that you're actually mining. So that logic was changed to report the difficulty for whatever algorithm you're set to mine. An 'algorithm' field was also added to the output so it can be clear what algorithm the difficulty relates to:Given the availability of all the difficulties with the
getblockchaininfocommand, a parameter to get mining info for a different algorithm was not added.