Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Apr 1, 2015

  • Get rid of the optimized hashing code (which wasn't even been used for regtest, which is the only thing for which it matters...).
  • Introduce a separate 'generate' RPC call for the regtest-specific 'setgenerate' behaviour.
  • Make regtest mining faster by using the mining loops from miner.cpp.
  • Avoid the 1000s of errors when mining long regtest chains.
  • Abstract out some of the mining code.
  • Fix a bug where chainActive.Tip() was accessed outside of cs_main.

@jgarzik
Copy link
Contributor

jgarzik commented Apr 1, 2015

Nice.. I've wanted something like 'generate' Passes quick-glance review. Will test.

@fanquake
Copy link
Member

fanquake commented Apr 1, 2015

Travis failure

Running testscript wallet.py...
Initializing test directory /tmp/testFqH6I5
Mining blocks...
JSONRPC error: value is type 
  File "/home/travis/build/bitcoin/bitcoin/bitcoin-i686-pc-linux-gnu/qa/rpc-tests/test_framework.py", line 117, in main
    self.run_test()
  File "/home/travis/build/bitcoin/bitcoin/bitcoin-i686-pc-linux-gnu/qa/rpc-tests/wallet.py", line 43, in run_test
    self.nodes[0].generate(1)
  File "/home/travis/build/bitcoin/bitcoin/bitcoin-i686-pc-linux-gnu/qa/rpc-tests/python-bitcoinrpc/bitcoinrpc/authproxy.py", line 126, in __call__
    raise JSONRPCException(response['error'])
Cleaning up
Failed

@sipa sipa force-pushed the simplehash branch 2 times, most recently from 1f5872d to 6f25142 Compare April 1, 2015 18:09
@sipa
Copy link
Member Author

sipa commented Apr 1, 2015

@fanquake Fixed.

mapArgs ["-genproclimit"] = itostr(nGenProcLimit);
GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit);
}
mapArgs["-gen"] = (fGenerate ? "1" : "0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably change this at some point too to not update the mapArgs. Throughout the program we assume that mapArgs is read-only after initialization. This kind of r/w access would need proper locking around everything. No change needed for this pull but I'm just reminded of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

@laanwj
Copy link
Member

laanwj commented Apr 8, 2015

This is obviously the right way to go, utACK

Edit: tested ACK

// the double-SHA256 state, and compute the result.
CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash);
pblock->nNonce++;
*phash = pblock->GetHash();

// Return the nonce if the hash has at least some zero bits,
// caller will check if it has enough to reach the target
if (((uint16_t*)phash)[15] == 0)
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we directly return CheckProofOfWork() here instead of true and remove the later UintToArith256(hash) <= hashTarget check in ScanLoop() [which means you can also remove the uint256 *phash param in ScanHash()] ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even without CheckProofOfWork, that check belongs inside ScanHash so you can save the hash parameter and the hash parameter and you can reuse the arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); instead of repeating the conversion every time ((uint16_t*)phash)[15] == 0. At that point, I'm not sure it's worth it to remove the optimization but I'm still not opposed to removing it.
And of course it can be && in the condition rather than returning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just CheckProofOfWork would be fine, if we removed its error reporting (which imho we should in any case...), as now regtest mining beyond the first 2016 blocks prints 1000s of error messages to the log for each miner block as a result.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you at least move the check in ScanLoop inside ScanHash for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not doing that as long as it produces this much debug output - that makes it effectively unusable for mining a >2016 long block chain. That error output should probably be discussed elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I misunderstood. Yes, that seems fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as said in the other PR I plan to solve the warning problem soon as part of the consensus work for blockheader.
At that point that check can be directly replaced by CheckProofOfWork, I'm not proposing to do it now.

@laanwj laanwj merged commit e2edf95 into bitcoin:master Apr 9, 2015
laanwj added a commit that referenced this pull request Apr 9, 2015
e2edf95 Bugfix: make CreateNewBlock return pindexPrev (Pieter Wuille)
6b04508 Introduce separate 'generate' RPC call (Pieter Wuille)
0df67f1 Simplify hash loop code (Pieter Wuille)
@gavinandresen
Copy link
Contributor

This makes -regtest block generation MUCH slower.

Before:
cd qa/rpc-tests; rm -rf cache; time mempool_resurrect_test.py --> 26 seconds.

After: --> 2 minutes 10 seconds.

laanwj added a commit that referenced this pull request Apr 9, 2015
New wallet tests have been added in the meantime and need to be updated
to use `generate` instead of `setgenerate`.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Apr 10, 2015
This reverts commit e2edf95 6b04508 0df67f1,
except the changes to the RPC tests.

A `generate` RPC call is introduced based on the old code.
laanwj added a commit that referenced this pull request Apr 10, 2015
48265f3 Revert mining changes in #5957 (Wladimir J. van der Laan)
@laanwj
Copy link
Member

laanwj commented Apr 10, 2015

Apparently I merged this too soon, sorry.

@sdaftuar noticed that this was giving problems with travis due to the slowdown @gavinandresen remarks on. I've thus reverted the changes to the mining code for now (but not the generate RPC call) in 48265f3.

@jtimon
Copy link
Contributor

jtimon commented Apr 10, 2015

Reopened #4793, which also does some code simplifications in miner.cpp.
I haven't measured regtest performance but it shouldn't make it slower, in fact I expect to make it slightly faster apart from saving some logs produced by CheckProofOfWork (though not all of them yet).
@gavinandresen can you test it?

@dexX7
Copy link
Contributor

dexX7 commented Apr 11, 2015

While it's sort of easy to mitigate, changing the API of Bitcoin Core (setgenerate true n) introduces the risk of breaking system that currently use that API. Imho, similar to the depreciation of accounting system, it would be more gentle, to provide some backwards compability and clearly tag setgenerate (regtest) as depreciated, for one version.

@sipa
Copy link
Member Author

sipa commented Apr 11, 2015 via email

@dexX7
Copy link
Contributor

dexX7 commented Apr 11, 2015

I see your point, and I don't have specific use-cases, but there are a few references to setgenerate, e.g. in the Bitcoin developer guide, the Bitcoin wiki or BitcoinJ's "how to test applications", which may serve as indicator.

This change may be announced on the mailing list, to enquire additional feedback from actual users, which may, or may not be out there.

@sipa
Copy link
Member Author

sipa commented Apr 11, 2015 via email

@msgilligan
Copy link

Here's the line in BitcoinClient.java in the OmniJ / bitcoin-spock project and something we are planning on contributing to bitcoinj to allow people to easily test their apps in RegTest mode:

https://github.com/OmniLayer/OmniJ/blob/master/bitcoin-rpc/src/main/java/com/msgilligan/bitcoin/rpc/BitcoinClient.java#L195

If we are the only external use-case we can handle this change when it happens, but we may not be the only case.

laanwj added a commit to laanwj/bitcoin that referenced this pull request Apr 21, 2015
Ever since bitcoin#5957 there has been the problem that older RPC test cases
(as can be found plenty in open pulls) use setgenerate() on regtest,
assuming a different interpretation of the arguments. Directly
generating a number of blocks has been split off into a new method
`generate` - however using `setgenerate` with the previous arguments will
result in spawning an unreasonable number of threads, and well, simply
not work as expected without clear indication of the error.

Add an error to point the user at the right method.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Jun 10, 2015
Do not translate -help-debug options, Many technical terms, and
only a very small audience, so is unnecessary stress to translators.

Brings the code up to date with translation string policy in
`doc/translation_strings_policy.md`.

Also remove no-longer-relevant "In this mode -genproclimit controls how
many blocks are generated immediately." (as of bitcoin#5957) from regtest help.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Jul 3, 2015
No longer relevant after bitcoin#5957. This hack existed because of another
hack where the numthreads parameter, on regtest, doubled as how many
blocks to generate.
AllanDoensen referenced this pull request in AllanDoensen/BitcoinUnlimited Apr 23, 2017
No longer relevant after #5957. This hack existed because of another
hack where the numthreads parameter, on regtest, doubled as how many
blocks to generate.

Conflicts:
	src/miner.cpp
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants