programmingbitcoin
programmingbitcoin copied to clipboard
MAX_TARGET in Chapter 9 Exercise 13
The instructions for the exercise in chapter 9's helper.py says:
# if the new target is bigger than MAX_TARGET, set to MAX_TARGET
However, MAX_TARGET is not defined in helper.py, and the answer in answers.py makes no reference to MAX_TARGET.
I think MAX_TARGET must be 0xffff * 256**(0x1d-3), since Block.difficulty in block.py has these comments:
def difficulty(self):
'''Returns the block difficulty based on the bits'''
# note difficulty is (target of lowest difficulty) / (self's target)
# lowest difficulty has bits that equal 0xffff001d
target = self.target()
difficulty = 0xffff * 256**(0x1d-3) / target
return difficulty
Yes, I used that value in my code, and it seemed to be essential for verifying the difficulty adjustments for the initial blocks of the main chain, right after the genesis block, back when very few computers were contributing hash power. I was just surprised not to see the value in the actual sample code, only the comments, given that it seems to be important.
@Engelberg Yes, I agree! As far as resolving the issue with a PR goes, seems like:
- [ ]
helper.pyshould have the constantMAX_TARGET - [ ] answer should be updated to use
MAX_TARGET, - [ ] a sentence or two in the chapter text explaining this