Skip to content
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

Fix crash when mining with empty keypool. #6567

Merged
merged 1 commit into from Aug 19, 2015
Merged

Conversation

@domob1812
Copy link
Contributor

domob1812 commented Aug 18, 2015

Since the introduction of the ScriptForMining callback, the mining functions (setgenerate and generate) crash with an assertion failure (due to a NULL pointer script returned) if the keypool is empty. Fix this by giving a proper error.

Since the introduction of the ScriptForMining callback, the mining
functions (setgenerate and generate) crash with an assertion failure
(due to a NULL pointer script returned) if the keypool is empty.  Fix
this by giving a proper error.
@@ -138,8 +138,12 @@ UniValue generate(const UniValue& params, bool fHelp)
boost::shared_ptr<CReserveScript> coinbaseScript;
GetMainSignals().ScriptForMining(coinbaseScript);

// If the keypool is exhausted, no script is returned at all. Catch this.
if (!coinbaseScript)
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");

This comment has been minimized.

Copy link
@jonasschnelli

jonasschnelli Aug 18, 2015

Member

This could also be triggered if the connected signal listener does not provide a script for other reasons than a non-filled keypool. But yes, right now only a empty keypool would emit this exception.

@jonasschnelli
Copy link
Member

jonasschnelli commented Aug 18, 2015

utACK.
In terms of modularity, the miner should not know the concept of "keypools" and therefore throw an generic exception with a possible error string passed over from the signal listener to the signal emitting part.

@domob1812
Copy link
Contributor Author

domob1812 commented Aug 18, 2015

I agree in principle (that's why the message/error is keypool specific only in the RPC code and not miner.cpp). However, the keypool is explicitly a "concept" part of the RPC interface (with the specific error code), thus I think it should be handled there.

Of course, if in the future more conditions can cause a missing script to be returned, one also needs to add a method to signal the error to the caller with more details.

@laanwj
Copy link
Member

laanwj commented Aug 19, 2015

This has been broken and fixed multiple times. Thanks a lot for adding a test.
ACK

@laanwj laanwj merged commit 2016576 into bitcoin:master Aug 19, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Aug 19, 2015
2016576 Fix crash when mining with empty keypool. (Daniel Kraft)
@domob1812 domob1812 deleted the domob1812:keypool-crash branch Aug 19, 2015
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Aug 20, 2015
Fix namecoin#25.  This implements the
upstream fix done in Bitcoin's bitcoin/bitcoin#6567
also for getauxblock.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.