Author

Topic: When bitcoind starts up, In where and which function difficulty is calculated? (Read 352 times)

jr. member
Activity: 48
Merit: 17
Quote
That error is completely unrelated to the difficulty. The getblocktemplate RPC will refuse to return a valid block template if it thinks it is not fully synced. That will happen if the timestamp of the most recent block is not within two hours of the computer's time.

Thank you so much for the reply. I'm a bit confused a little bit here. The most recent block is my genesis block. If I create a new genesis block and do the compiling and starting up process, same thing will happen. That's why I speculated about difficulty.You say there is no problem with the network and I can create transactions properly?
There are other conditions that can trigger this error, it is not just the timestamp. It may be possible that the fact that there is only the genesis block is what is causing the problem. I think it could be that just having the genesis block even if it is up to date will still cause the node to think it is still in InitialBlockDownload. You can just make the error go away by commenting out or removing these 2 lines in src/rpc/mining.cpp.

Thank you so so much for taking time and finding the solution. I truly appreciate it. I went and saw IsInitialBlockDownload function and read it carefully. The reason is very ambiguous to me.
staff
Activity: 3458
Merit: 6793
Just writing some code
Quote
That error is completely unrelated to the difficulty. The getblocktemplate RPC will refuse to return a valid block template if it thinks it is not fully synced. That will happen if the timestamp of the most recent block is not within two hours of the computer's time.

Thank you so much for the reply. I'm a bit confused a little bit here. The most recent block is my genesis block. If I create a new genesis block and do the compiling and starting up process, same thing will happen. That's why I speculated about difficulty.You say there is no problem with the network and I can create transactions properly?
There are other conditions that can trigger this error, it is not just the timestamp. It may be possible that the fact that there is only the genesis block is what is causing the problem. I think it could be that just having the genesis block even if it is up to date will still cause the node to think it is still in InitialBlockDownload. You can just make the error go away by commenting out or removing these 2 lines in src/rpc/mining.cpp.
jr. member
Activity: 48
Merit: 17
Quote
That error is completely unrelated to the difficulty. The getblocktemplate RPC will refuse to return a valid block template if it thinks it is not fully synced. That will happen if the timestamp of the most recent block is not within two hours of the computer's time.

Thank you so much for the reply. I'm a bit confused a little bit here. The most recent block is my genesis block. If I create a new genesis block and do the compiling and starting up process, same thing will happen. That's why I speculated about difficulty.You say there is no problem with the network and I can create transactions properly?
staff
Activity: 3458
Merit: 6793
Just writing some code
So you mean that if I change nBits and consensus.powLimit parameters in chainparams.cpp the whole network should work fine ? but I face a problem when I run two bitcoindd :
Yes.

The two servers start up properly but when i type the command "bicoin-cli getblocktemplate" I get

Code:
error code: -10
error message:
Bitcoin is downloading blocks...
That error is completely unrelated to the difficulty. The getblocktemplate RPC will refuse to return a valid block template if it thinks it is not fully synced. That will happen if the timestamp of the most recent block is not within two hours of the computer's time.
jr. member
Activity: 48
Merit: 17
The difficulty is merely a user facing thing. In reality, it does not calculate the difficulty at all and the difficulty itself is never used anywhere.

The only thing that matters when it comes to the proof of work is that the block hash, when interpreted as a 256 bit little endian integer, is less than or equal to the target value.

So you mean that if I change nBits and consensus.powLimit parameters in chainparams.cpp the whole network should work fine ? but I face a problem when I run two bitcoindd :

Code:
bitcoind -dns=0 -dnsseed=0 -port=15333 -rpcport=15332 -datadir=/home/.../.bitcoin2
and
Code:
bitcoind -dns=0 -dnsseed=0 -port=6333 -rpcport=6332 -addnode=127.0.0.1:15332 -debug=rpc

The two servers start up properly but when i type the command "bicoin-cli getblocktemplate" I get

Code:
error code: -10
error message:
Bitcoin is downloading blocks...

The problem is insanely strange to me since when I set those two parameters back to what they have been, The whole thing works fine. Here's my code http:// [url]https://github.com/chameleon1239/bitcoin.git . Would be really thankful if you take a look at it.

staff
Activity: 3458
Merit: 6793
Just writing some code
The difficulty is merely a user facing thing. In reality, it does not calculate the difficulty at all and the difficulty itself is never used anywhere.

The only thing that matters when it comes to the proof of work is that the block hash, when interpreted as a 256 bit little endian integer, is less than or equal to the target value.
jr. member
Activity: 48
Merit: 17
I am trying to understand bitcoin core deeply though debugging it is really a challenge for me because I'm newbie with gdb and not good with reading memory addresses and machine codes and getting variable values from there.

I wonder when starting up bitcoind where difficulty is calculated and how. I read the formula is pdiff/bdiff (current_difficulty). I f changed bdiff where pdiff is calculated?

There is a function in /src/rpc/blockchain.cpp named GetDifficulty but I think it is only used when rpc callings such as "bitcoin-cli getdifficulty" and "bitcoin-cli getblockheader   ". So what happens in the code if bitcoind is typed? Where will it be calculated?

Here is my own private version of bitcoin https://github.com/chameleon1239/bitcoin. I changed some parameters in chainparams.cpp and GetDifficulty function in  blockchain.cpp. but the whole code is untouched.

The problem I have with my code is -addnode command doesn't work properly.

Guys , the deadline is very close so any suggestions will be appreciated.
Jump to: