Author

Topic: "12. Check that nBits value matches the difficulty rules" (Read 1717 times)

newbie
Activity: 37
Merit: 0
Thanks genjix!  That was what I was looking for.  Much appreciated.   Grin
legendary
Activity: 1232
Merit: 1076
you go to the previous block and find what the next difficulty should be. the bits returned should be the same as the current block's bits.

the function is called GetNextWorkRequired and it takes the previous block to the current one as an argument
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
A block is not USING a difficulty, it's at SOME difficulty regardless if it wants to or not.
newbie
Activity: 37
Merit: 0
I have a beginner question on this rule:

"12. Check that nBits value matches the difficulty rules"
https://en.bitcoin.it/wiki/Protocol_rules#.22block.22_messages

I understand how to convert the nBits to a difficulty.  But what does "match the difficulty rules" means?

I'm assuming this means check if the difficulty the block is using seems reasonable.  But do we have to calculate what the difficulty should be for any given block, and if so how?  I was trying to find some sample code for this but came up empty handed.

Google turned up this but I'm afraid I'm not really understanding what it does:
https://github.com/bitcoin/bitcoin/blob/master/src/bitcoinrpc.cpp#L203

Many thanks for a point in the right direction!
Jump to: