Skip to content

Commit

Permalink
avoid calling header_hash repeatedly in weight_proof (Chia-Network#4060)
Browse files Browse the repository at this point in the history
header_hash is a property that serializes and hash the foliage block, this is somewhat expensive, especially the serialization
  • Loading branch information
arvidn authored May 12, 2021
1 parent 25f4b6c commit 58a0eb5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chia/full_node/weight_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ async def __first_sub_slot_vdfs(
curr = header_blocks[curr_sub_rec.header_hash]
sub_slots_data: List[SubSlotData] = []
tmp_sub_slots_data: List[SubSlotData] = []
curr = header_blocks[curr.header_hash]
while curr.height < header_block.height:
if curr is None:
log.error("failed fetching block")
Expand Down Expand Up @@ -457,14 +456,17 @@ async def __slot_end_vdf(
# gets all vdfs first sub slot after challenge block to last sub slot
log.debug(f"slot end vdf start height {start_height}")
curr = header_blocks[self.blockchain.height_to_hash(start_height)]
curr_header_hash = curr.header_hash
sub_slots_data: List[SubSlotData] = []
tmp_sub_slots_data: List[SubSlotData] = []
while not blocks[curr.header_hash].is_challenge_block(self.constants):
while not blocks[curr_header_hash].is_challenge_block(self.constants):
if curr.first_in_sub_slot:
sub_slots_data.extend(tmp_sub_slots_data)

curr_prev_header_hash = curr.prev_header_hash
# add collected vdfs
for idx, sub_slot in enumerate(curr.finished_sub_slots):
prev_rec = blocks[curr.prev_header_hash]
prev_rec = blocks[curr_prev_header_hash]
eos_vdf_iters = prev_rec.sub_slot_iters
if idx == 0:
eos_vdf_iters = uint64(prev_rec.sub_slot_iters - prev_rec.ip_iters(self.constants))
Expand All @@ -473,6 +475,8 @@ async def __slot_end_vdf(
tmp_sub_slots_data.append(self.handle_block_vdfs(curr, blocks))

curr = header_blocks[self.blockchain.height_to_hash(uint32(curr.height + 1))]
curr_header_hash = curr.header_hash

if len(tmp_sub_slots_data) > 0:
sub_slots_data.extend(tmp_sub_slots_data)
log.debug(f"slot end vdf end height {curr.height} slots {len(sub_slots_data)} ")
Expand Down

0 comments on commit 58a0eb5

Please sign in to comment.