PR feedback from @mkalinin

This commit is contained in:
Hsiao-Wei Wang 2021-11-17 23:45:41 +08:00
parent e56bbb8c44
commit 28762096d3
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E

View File

@ -45,19 +45,15 @@ def get_pow_block_at_terminal_total_difficulty(pow_chain: Dict[Hash32, PowBlock]
# `pow_chain` abstractly represents all blocks in the PoW chain
for block in pow_chain.values():
block_reached_ttd = block.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY
# Genesis block
if block.parent_hash == Hash32():
# No parent exists, so reaching TTD alone qualifies as valid terminal block
if block_reached_ttd:
if block_reached_ttd:
# If genesis block, no parent exists so reaching TTD alone qualifies as valid terminal block
if block.parent_hash == Hash32():
return block
# Continue to iterate the next block
if block.parent_hash not in pow_chain:
continue
parent = pow_chain[block.parent_hash]
parent_reached_ttd = parent.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY
if block_reached_ttd and not parent_reached_ttd:
return block
else:
parent = pow_chain[block.parent_hash]
parent_reached_ttd = parent.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY
if not parent_reached_ttd:
return block
return None
```