mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-11-11 01:28:17 +03:00
correct end of sub epoch, bad vdfs
This commit is contained in:
parent
e990b8e264
commit
45942160e3
@ -122,12 +122,7 @@ class WeightProofFactory:
|
||||
self.constants.SUB_EPOCH_SUB_BLOCKS, prev_ses_hash, weight_proof.sub_epochs, fork_point_difficulty
|
||||
)
|
||||
last_ses = summaries[uint32(len(summaries) - 1)]
|
||||
self.log.info(f"last ses {last_ses}")
|
||||
block_idx = get_last_ses_block_idx(
|
||||
self.constants,
|
||||
weight_proof.recent_reward_chain,
|
||||
last_ses.num_sub_blocks_overflow,
|
||||
)
|
||||
block_idx = get_last_ses_block_idx(self.constants, weight_proof.recent_reward_chain)
|
||||
if block_idx is None:
|
||||
self.log.error(f"could not find first block after last sub epoch end")
|
||||
return False
|
||||
@ -143,7 +138,6 @@ class WeightProofFactory:
|
||||
challenge = ChallengeChainSubSlot(
|
||||
cc_vdf, icc_vdf, last_ses.get_hash(), last_ses.new_sub_slot_iters, last_ses.new_difficulty
|
||||
)
|
||||
self.log.info(f"last ses challenge slot {challenge}")
|
||||
expected_challenge = weight_proof.recent_reward_chain[block_idx].challenge_chain_sp_vdf.challenge
|
||||
if challenge.get_hash() != expected_challenge:
|
||||
self.log.error(
|
||||
@ -497,11 +491,18 @@ def map_summaries(
|
||||
|
||||
|
||||
def get_last_ses_block_idx(
|
||||
constants: ConsensusConstants, recent_reward_chain: List[RewardChainSubBlock], overflows: uint8
|
||||
constants: ConsensusConstants, recent_reward_chain: List[RewardChainSubBlock]
|
||||
) -> Optional[uint32]:
|
||||
print(f"get_last_ses_block_idx overflows {overflows}")
|
||||
for idx, block in enumerate(reversed(recent_reward_chain)):
|
||||
if uint8(block.sub_block_height % constants.SUB_EPOCH_SUB_BLOCKS) == overflows:
|
||||
return len(recent_reward_chain) - 1 - idx
|
||||
if uint8(block.sub_block_height % constants.SUB_EPOCH_SUB_BLOCKS) == 0:
|
||||
idx = len(recent_reward_chain) - 1 - idx # reverse
|
||||
# find next block with different challenge chain challenge
|
||||
curr = recent_reward_chain[idx]
|
||||
next = recent_reward_chain[idx + 1]
|
||||
while curr.challenge_chain_ip_vdf.challenge == next.challenge_chain_ip_vdf.challenge:
|
||||
idx += 1
|
||||
curr = recent_reward_chain[idx]
|
||||
next = recent_reward_chain[idx + 1]
|
||||
return idx + 1
|
||||
|
||||
return None
|
||||
|
@ -163,20 +163,15 @@ class TestWeightProof:
|
||||
assert sub_epoch_blocks_n == sub_epoch_end.height - prev_sub_epoch_end.height
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_last_ses_block_idx_(self, default_400_blocks):
|
||||
async def test_get_last_ses_block_idx(self, default_400_blocks):
|
||||
header_cache, height_to_hash, sub_blocks = load_blocks_dont_validate(default_400_blocks)
|
||||
sub_epoch_end, _ = get_prev_ses_block(sub_blocks, default_400_blocks[-1].prev_header_hash)
|
||||
print(f"sub_epoch_summary_included, height: {sub_epoch_end.height} {sub_epoch_end.sub_epoch_summary_included}")
|
||||
reward_blocks: List[RewardChainSubBlock] = []
|
||||
for block in header_cache.values():
|
||||
reward_blocks.append(block.reward_chain_sub_block)
|
||||
|
||||
first_after_se: SubBlockRecord = sub_blocks[height_to_hash[sub_epoch_end.height + 1]]
|
||||
print(f"before weight : {sub_epoch_end.weight}")
|
||||
# find last ses
|
||||
print(f"diff {first_after_se.weight - sub_epoch_end.weight}, weight {sub_epoch_end.weight}")
|
||||
idx = get_last_ses_block_idx(reward_blocks, first_after_se.weight - sub_epoch_end.weight, sub_epoch_end.weight)
|
||||
assert idx == first_after_se.height
|
||||
idx = get_last_ses_block_idx(test_constants, reward_blocks)
|
||||
assert idx is not None
|
||||
assert idx == sub_epoch_end.height
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_weight_proof_map_summaries_1(self, default_400_blocks):
|
||||
@ -226,8 +221,7 @@ class TestWeightProof:
|
||||
print(f"fork point is {curr.height} (not included)")
|
||||
print(f"num of blocks in proof: {num_of_blocks}")
|
||||
print(f"num of full sub epochs in proof: {sub_epochs}")
|
||||
print("last ses end of challenge slot")
|
||||
print(f"{header_cache[height_to_hash[9961]].finished_sub_slots[-1].challenge_chain}")
|
||||
print(f"\n_____________ {header_cache[height_to_hash[9961]].finished_sub_slots[-1].challenge_chain} __________")
|
||||
|
||||
wpf = WeightProofFactory(test_constants, sub_blocks, header_cache, height_to_hash)
|
||||
wpf.log.setLevel(logging.INFO)
|
||||
|
Loading…
Reference in New Issue
Block a user