<blockquote>
  <p>What am I doing wrong?</p>
</blockquote>

<p>Not setting the difficulty high enough. A standard computer can do 1 MH/s SHA256d hashes, or about 2^20 hashes. That means in your scenario, solving a regtest block will take about 1 second. If you want it to take longer, increase the difficulty.</p>

<p>Also, note that if you're using an 0.9.* version of bitcoin, then setting the regtest difficulty to below <code>~uint256(0) &gt;&gt; 16</code> won't really do much, as the mining code won't even check a result that doesn't hash to below that difficulty.</p>

<p>If you're using the most recent code, though, then rather than adjusting the regtest parameters, you could also just add your own set of parameters.</p>

CC BY-SA 3.0
2015-05-27T16:04:44.983Z
_If you're using the most recent code, though, then rather than adjusting the regtest parameters, you could also just add your own set of parameters._  - if adding new own set of parameters, where am I going to call them? I mean, even a parameter, such as `nSubsidyHalvingInterval`, doesn't show up anywhere else (like in main.cpp) than in chainparams.cpp only!?
Aliakbar Ahmadi
CC BY-SA 3.0
2015-05-27T16:11:59.757Z
You would have to modify the startup process to recognize some new flag (like `-myparams`) and select the parameters based on that flag. Then all calls to `Params()` will return your params.
morsecoder
CC BY-SA 3.0
2015-05-27T16:51:03.993Z
Unfortunately I can't follow you with _modify the startup process_, do you mean a flag, like `-regtest` or `-testnet`?If so, I searched for them in src but only found out - to my perception - that out of `bitcoind.cpp` there isn't any call for parameters defined in `chainparams.cpp`..Could you please give me hints or give me concrete instructions on how to set new set of parameters?
Aliakbar Ahmadi
CC BY-SA 3.0
2015-05-27T15:57:52.627Z
2015-05-27T15:57:52.627Z
morsecoder
<p>I'm playing around with the code and tried to adjust difficulty by changing code from </p>

<blockquote>
  <p>bnProofOfWorkLimit = ~uint256(0) >> 1</p>
</blockquote>

<p>to </p>

<pre><code>bnProofOfWorkLimit = ~uint256(0) &gt;&gt; 20
</code></pre>

<p>inside code block for Regression Test in <a href="https://github.com/bitcoin/bitcoin/blob/0.10/src/chainparams.cpp#L262" rel="nofollow"><code>chainparams.cpp</code></a> (bitcoin-0.10.0).</p>

<p>I configured, did make, then make install with binaries in a custom directory (not default <code>/usr/local/bin/bitcoind</code> !), started bitcoind in regtest mode and generated some blocks. <br/>
Somehow it feels like it takes same amount of time for generating blocks as before modifying the code.</p>

<p>What am I doing wrong?</p>

<hr>

<p><strong>UPDATE:</strong></p>

<p>Changed difficulty in chainparams.cpp from</p>

<blockquote>
  <p>bnProofOfWorkLimit = ~uint256(0) >> 1</p>
</blockquote>

<p>to</p>

<pre><code>bnProofOfWorkLimit = ~uint256(0) &gt;&gt; 32
</code></pre>

<p>still getting this:</p>

<pre><code>Bitcoin version v0.10.0.0-g047a898 (Fri, 13 Feb 2015 09:55:11 +0100)
Using OpenSSL version OpenSSL 1.0.1f 6 Jan 2014
Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
Default data directory /home/aliakbar/.bitcoin
Using data directory /home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest
Using config file /home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/bitcoin.conf
Using at most 125 connections (1024 file descriptors available)
Using 4 threads for script verification
Binding RPC on address ::1 port 23333 (IPv4+IPv6 bind any: 0)
Binding RPC on address 127.0.0.1 port 23333 (IPv4+IPv6 bind any: 0)
Using wallet wallet.dat
init message: Verifying wallet...
CDBEnv::Open : LogDir=/home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/database ErrorFile=/home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/db.log
Bound to [::]:13333
Bound to 0.0.0.0:13333
init message: Loading block index...
Opening LevelDB in /home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/blocks/index
Opened LevelDB successfully
Opening LevelDB in /home/aliakbar/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/chainstate
Opened LevelDB successfully
LoadBlockIndexDB: last block file = 0
LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=0, size=0, heights=0...0, time=1970-01-01...1970-01-01)
Checking all blk files are present...
LoadBlockIndexDB(): transaction index disabled
Initializing databases...
Pre-allocating up to position 0x1000000 in blk00000.dat
ERROR: CheckProofOfWork() : nBits below minimum work
ERROR: CheckBlockHeader() : proof of work failed
InvalidChainFound: invalid block=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206  height=0  log2_work=1  date=2011-02-02 23:16:42
</code></pre>

<p>What am I doing wrong? Do I have to adjust difficulty somewhere else than in chainparams.cpp?</p>

<bitcoind><difficulty><regtest>
Rise difficulty in code, still no changes after rebuild
Aliakbar Ahmadi
# Rise difficulty in code, still no changes after rebuild

(Asked by: username_0 on 2015-05-27)

I'm playing around with the code and tried to adjust difficulty by changing code from

> bnProofOfWorkLimit = ~uint256(0) >> 1

to

```
bnProofOfWorkLimit = ~uint256(0) >> 20

```

inside code block for Regression Test in [`chainparams.cpp`](https://github.com/bitcoin/bitcoin/blob/0.10/src/chainparams.cpp#L262) (bitcoin-0.10.0).

I configured, did make, then make install with binaries in a custom directory (not default `/usr/local/bin/bitcoind` !), started bitcoind in regtest mode and generated some blocks.   
Somehow it feels like it takes same amount of time for generating blocks as before modifying the code.

What am I doing wrong?

---

**UPDATE:**

Changed difficulty in chainparams.cpp from

> bnProofOfWorkLimit = ~uint256(0) >> 1

to

```
bnProofOfWorkLimit = ~uint256(0) >> 32

```

still getting this:

```
Bitcoin version v0.10.0.0-g047a898 (Fri, 13 Feb 2015 09:55:11 +0100)
Using OpenSSL version OpenSSL 1.0.1f 6 Jan 2014
Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
Default data directory /home/username_0/.bitcoin
Using data directory /home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest
Using config file /home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/bitcoin.conf
Using at most 125 connections (1024 file descriptors available)
Using 4 threads for script verification
Binding RPC on address ::1 port 23333 (IPv4+IPv6 bind any: 0)
Binding RPC on address 127.0.0.1 port 23333 (IPv4+IPv6 bind any: 0)
Using wallet wallet.dat
init message: Verifying wallet...
CDBEnv::Open : LogDir=/home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/database ErrorFile=/home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/db.log
Bound to [::]:13333
Bound to 0.0.0.0:13333
init message: Loading block index...
Opening LevelDB in /home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/blocks/index
Opened LevelDB successfully
Opening LevelDB in /home/username_0/Downloads/bitcoin-0.10.0_test1/build/bin/test1/regtest/chainstate
Opened LevelDB successfully
LoadBlockIndexDB: last block file = 0
LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=0, size=0, heights=0...0, time=1970-01-01...1970-01-01)
Checking all blk files are present...
LoadBlockIndexDB(): transaction index disabled
Initializing databases...
Pre-allocating up to position 0x1000000 in blk00000.dat
ERROR: CheckProofOfWork() : nBits below minimum work
ERROR: CheckBlockHeader() : proof of work failed
InvalidChainFound: invalid block=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206  height=0  log2_work=1  date=2011-02-02 23:16:42

```

What am I doing wrong? Do I have to adjust difficulty somewhere else than in chainparams.cpp?

**Tags:** bitcoind, difficulty, regtest


---

## 1 answers

### Answer by username_1 on 2015-05-27. Score: 1

> What am I doing wrong?

Not setting the difficulty high enough. A standard computer can do 1 MH/s SHA256d hashes, or about 2^20 hashes. That means in your scenario, solving a regtest block will take about 1 second. If you want it to take longer, increase the difficulty.

Also, note that if you're using an 0.9.\* version of bitcoin, then setting the regtest difficulty to below `~uint256(0) >> 16` won't really do much, as the mining code won't even check a result that doesn't hash to below that difficulty.

If you're using the most recent code, though, then rather than adjusting the regtest parameters, you could also just add your own set of parameters.

> **Comments:**
> **username_0**: _If you're using the most recent code, though, then rather than adjusting the regtest parameters, you could also just add your own set of parameters._  - if adding new own set of parameters, where am I going to call them? I mean, even a parameter, such as `nSubsidyHalvingInterval`, doesn't show up anywhere else (like in main.cpp) than in chainparams.cpp only!?  
> **username_1**: You would have to modify the startup process to recognize some new flag (like `-myparams`) and select the parameters based on that flag. Then all calls to `Params()` will return your params.  
> **username_0**: Unfortunately I can't follow you with _modify the startup process_, do you mean a flag, like `-regtest` or `-testnet`?If so, I searched for them in src but only found out - to my perception - that out of `bitcoind.cpp` there isn't any call for parameters defined in `chainparams.cpp`..Could you please give me hints or give me concrete instructions on how to set new set of parameters?  

---

