-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mining] Use -miningaddress for in-wallet mining. #923
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK bcdd0f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hell of a time downloading a binary to test this, so I'll just ask a few questions:
- If you specify
-miningaddress
with no value, it will just use a generic one and not give you an error? - If the destination is invalid, same thing?
- When do you see these errors?
I think I might rather see the validity tests for -miningaddress in veild.cpp and qt/veil.cpp, so that they get feedback when they try to start the daemon or qt; and have it not continue if they don't have a valid basecoin address that is theirs. Having the differentiation between basecoin and stealth is good, so we have a hook when we do allow stealth; but if it doesn't fail on startup until they correct their use of -miningaddress, it should.
If I can get the thing to download, I'll get some of my own answers to the above questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See changes needed.
src/wallet/wallet.cpp
Outdated
// Disallow Stealth Addresses for now | ||
CBitcoinAddress address(sAddress); | ||
if (address.IsValidStealthAddress()) { | ||
WalletLogPrintf("-miningaddress must be a basecoin address"); | ||
return GetScriptForMiningReserveKey(script); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary since this check is being done in veild.cpp and qt/veil.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also being done in rpc/mining.cpp--I presume as a backstop in case the arg was changed between startup and the rpc to start mining. If it's changed, and manages to get by here, the script will be empty, and I think that will make it fail when it tries to commit a block (I tried mining to stealth on testnet at some point and iirc that's what happened). Perhaps that is user error, since we should not be mutating miningaddress in-process? The difference is that we can't return an RPC error here, and I felt it was better to fall back to existing behavior (mining to an unexpected address) rather than surprising behavior (mining fails at the last possible moment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleared these checks out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking back on the original addition of the stealth check, I see I did add it to the rpc area too. But that was before I moved it to init. Looks like the checks in RPC can also be removed since there isn't any way to change the address after you start the wallet up. Not sure it needs to be removed right away (it's extra code on startup that I concern myself with, vs. extra code on an rpc call)
src/wallet/wallet.cpp
Outdated
if (IsValidDestination(dest)) { | ||
if (IsMine(dest) != ISMINE_SPENDABLE) { | ||
WalletLogPrintf("-miningaddress %s not under my control, falling back to random address", sAddress); | ||
return GetScriptForMiningReserveKey(script); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are good checks, but they should be done where miningaddress is being checked on startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move it to init.cpp so I could be sure the wallet was loaded, but it works for both veild and veil-qt (with a delay to load the wallet, of course). Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes, because of the IsMine(). Let me think about this a little bit more. I put in a good address that I didn't own, and I didn't see an error anywhere. I'm building this PR so I can do some extra debugging later.
Replaces the hook to get a mining address from the wallet with a retrieval of the address set as `-miningaddress`. Performs an additional safety check at startup that the wallet actually owns the given address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Supplying an empty miningaddress is the same as providing none, since the
getArg
lookups provide a default of""
. - As you found, yeah, the errors are on startup. See my comments below..
src/wallet/wallet.cpp
Outdated
if (IsValidDestination(dest)) { | ||
if (IsMine(dest) != ISMINE_SPENDABLE) { | ||
WalletLogPrintf("-miningaddress %s not under my control, falling back to random address", sAddress); | ||
return GetScriptForMiningReserveKey(script); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move it to init.cpp so I could be sure the wallet was loaded, but it works for both veild and veil-qt (with a delay to load the wallet, of course). Done.
src/wallet/wallet.cpp
Outdated
// Disallow Stealth Addresses for now | ||
CBitcoinAddress address(sAddress); | ||
if (address.IsValidStealthAddress()) { | ||
WalletLogPrintf("-miningaddress must be a basecoin address"); | ||
return GetScriptForMiningReserveKey(script); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleared these checks out.
|
||
auto pt = GetMainWallet(); | ||
if (pt && pt->IsMine(dest) != ISMINE_SPENDABLE) { | ||
return InitError(strprintf(_("Invalid -miningaddress: '%s' not owned by wallet"), sAddress)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has an issue; as it hangs up the wallet and doesn't exit:
2021-04-20T23:24:24Z ThreadStakeMiner: starting
2021-04-20T23:24:24Z Veil Miner started
2021-04-20T23:24:24Z Error: Invalid -miningaddress: 'bv1q7cmcjcazyxger9y9llnqpuhj33pmrn9hl0ny24' not owned by wallet
2021-04-20T23:24:24Z tor: Thread interrupt
2021-04-20T23:24:24Z torcontrol thread exit
2021-04-20T23:24:24Z opencon thread exit
2021-04-20T23:24:24Z dnsseed thread exit
2021-04-20T23:24:24Z Shutdown: In progress...
2021-04-20T23:24:24Z addcon thread exit
2021-04-20T23:24:24Z msghand thread exit
2021-04-20T23:24:24Z net thread exit
2021-04-20T23:24:24Z Imported mempool transactions from disk: 3 succeeded, 0 failed, 0 expired, 0 already there
2021-04-20T23:24:37Z ThreadStakeMiner: interrupted
2021-04-20T23:24:37Z Veil Miner started
./veil-cli stop
error: Could not connect to the server 127.0.0.1:58812
Make sure the veild server is running and that you are connecting to the correct RPC port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be an existing issue. I can reproduce it here:
Lines 1972 to 1974 in 02cc068
if (!addr.IsValidStealthAddress()) { | |
return InitError(strprintf(_("Invalid stealth address with -autospendaddress: '%s'"), strAutoSpendAddress)); | |
} |
Let me file a separate issue...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed PR #935 with a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK b2eb977
Tested on Win 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem
-miningaddress
is used for rpc progpow gpu mining, but ignored for in-wallet mining such as for RandomX and SHA256D.Root Cause
It's just not looking at the config value when it sets up the block script.
Solution
When the wallet attempts to retrieve a mining address, prefer the configured value for
-miningaddress
, falling back to the previous address generation from the wallet keys.Disallows stealth addresses as per current behavior validating
-miningaddress
at startup and in rpc mining.Performs an additional safety check that the wallet actually owns the given address, falling back to a random wallet address otherwise (preserving current behavior).
Bounty PR
#867
Bounty Payment Address
sv1qqpswvjy7s9yrpcmrt3fu0kd8rutrdlq675ntyjxjzn09f965z9dutqpqgg85esvg8mhmyka5kq5vae0qnuw4428vs9d2gu4nz643jv5a72wkqqq73mnxr
Testing Results
Tested on win10 x64 mining RandomX on testnet: both with basecoin and "mining" addresses.
Tested on win10 veild, veil-qt: Using a testnet basecoin address that was not mine. Successfully produced an error and exited.