There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
def validate_chain(self):
for i in range(1, len(self.chain)):
current = self.chain[i]
previous = self.chain[i-1]
if current.hash != current.generate_hash():
return False
if previous.hash != previous.generate_hash():
return False
return True
According to instruction the function of validate_chain() method is:
In order to validate the entire blockchain, we must loop through each of the blocks stored inside the blockchain itself. Then, we will check through each of the blocks to ensure that the previous hash value matches with the hash value inside our previous block.
My question is:
What is the difference between using .hash and .generate_hash() ?
I believe hash is an instance variable that is created at when the block is instantiated. The method “generate_hash” is called during the comparison and we would expect that these two would not be equivalent, as for one thing the timestamp would be different.
Why are we not validating the previous block’s hash with the current block’s hash, and instead verifying it with what is being generated right now? I seem to be missing something here…