From b668fbb2b905ea874686886b4d4e337f7f94e94f Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 18 Nov 2025 13:49:36 +0100 Subject: [PATCH 1/2] make timelord/test_new_peak.py a bit more robust --- chia/_tests/timelord/test_new_peak.py | 19 +++++++++++++------ chia/timelord/timelord.py | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/chia/_tests/timelord/test_new_peak.py b/chia/_tests/timelord/test_new_peak.py index 7fd284ccfa31..8d71cf152e4a 100644 --- a/chia/_tests/timelord/test_new_peak.py +++ b/chia/_tests/timelord/test_new_peak.py @@ -22,6 +22,13 @@ from chia.timelord.timelord_api import TimelordAPI +def last_unfinished(tl: TimelordAPI) -> timelord_protocol.NewUnfinishedBlockTimelord: + if len(tl.timelord.unfinished_blocks) > 0: + return tl.timelord.unfinished_blocks[-1] + else: + return tl.timelord.overflow_blocks[-1] + + class TestNewPeak: @pytest.mark.anyio async def test_timelord_new_peak_basic( @@ -127,7 +134,7 @@ async def test_timelord_new_peak_unfinished_not_orphaned( ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert timelord_api.timelord.unfinished_blocks[-1].get_hash() == timelord_unf_block.get_hash() + assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b1, block_2) assert timelord_unf_block.reward_chain_block.total_iters <= new_peak.reward_chain_block.total_iters await timelord_api.new_peak_timelord(new_peak) @@ -193,7 +200,7 @@ async def test_timelord_new_peak_unfinished_orphaned( await get_rc_prev(b1, block_1), ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert timelord_api.timelord.unfinished_blocks[-1].get_hash() == timelord_unf_block.get_hash() + assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b2, block_2) # timelord knows unfinished block_1 that has lower iterations, @@ -208,7 +215,7 @@ async def test_timelord_new_peak_unfinished_orphaned( == peak.reward_chain_block.get_hash() ) # check unfinished block_1 is still in cache - assert timelord_api.timelord.unfinished_blocks[-1].get_hash() == timelord_unf_block.get_hash() + assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() # full node gets block_1 unfinished block_1_unf = UnfinishedBlock( @@ -371,7 +378,7 @@ async def test_timelord_new_peak_unfinished_eos( # add unfinished and make sure we cache it await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert timelord_api.timelord.unfinished_blocks[-1].get_hash() == timelord_unf_block.get_hash() + assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b1, block_1) assert timelord_unf_block.reward_chain_block.total_iters >= new_peak.reward_chain_block.total_iters await timelord_api.new_peak_timelord(new_peak) @@ -531,9 +538,9 @@ async def test_timelord_new_peak_is_in_unfinished_cache( ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert timelord_api.timelord.unfinished_blocks[-1].get_hash() == timelord_unf_block.get_hash() + assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() assert ( - timelord_api.timelord.unfinished_blocks[-1].reward_chain_block.get_hash() + last_unfinished(timelord_api).reward_chain_block.get_hash() == timelord_unf_block.reward_chain_block.get_hash() ) diff --git a/chia/timelord/timelord.py b/chia/timelord/timelord.py index c1d9c0b45faa..1ad9115940ac 100644 --- a/chia/timelord/timelord.py +++ b/chia/timelord/timelord.py @@ -80,6 +80,9 @@ class Timelord: _protocol_check: ClassVar[RpcServiceProtocol] = cast("Timelord", None) + unfinished_blocks: list[timelord_protocol.NewUnfinishedBlockTimelord] + overflow_blocks: list[timelord_protocol.NewUnfinishedBlockTimelord] + @property def server(self) -> ChiaServer: # This is a stop gap until the class usage is refactored such the values of From 3e49161423e8b7894c8bb532b5d2a0ab588d8142 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 19 Nov 2025 19:51:55 +0100 Subject: [PATCH 2/2] review comments --- chia/_tests/timelord/test_new_peak.py | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/chia/_tests/timelord/test_new_peak.py b/chia/_tests/timelord/test_new_peak.py index 8d71cf152e4a..33b069ae5439 100644 --- a/chia/_tests/timelord/test_new_peak.py +++ b/chia/_tests/timelord/test_new_peak.py @@ -3,7 +3,7 @@ from typing import Optional import pytest -from chia_rs import BlockRecord, FullBlock, SubEpochSummary, UnfinishedBlock +from chia_rs import BlockRecord, FullBlock, SubEpochSummary, UnfinishedBlock, is_overflow_block from chia_rs.sized_bytes import bytes32 from chia_rs.sized_ints import uint64, uint128 @@ -22,11 +22,11 @@ from chia.timelord.timelord_api import TimelordAPI -def last_unfinished(tl: TimelordAPI) -> timelord_protocol.NewUnfinishedBlockTimelord: - if len(tl.timelord.unfinished_blocks) > 0: - return tl.timelord.unfinished_blocks[-1] - else: +def last_unfinished(tl: TimelordAPI, *, overflow: bool) -> timelord_protocol.NewUnfinishedBlockTimelord: + if overflow: return tl.timelord.overflow_blocks[-1] + else: + return tl.timelord.unfinished_blocks[-1] class TestNewPeak: @@ -134,7 +134,8 @@ async def test_timelord_new_peak_unfinished_not_orphaned( ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() + overflow = is_overflow_block(bt.constants, timelord_unf_block.reward_chain_block.signage_point_index) + assert last_unfinished(timelord_api, overflow=overflow).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b1, block_2) assert timelord_unf_block.reward_chain_block.total_iters <= new_peak.reward_chain_block.total_iters await timelord_api.new_peak_timelord(new_peak) @@ -200,7 +201,9 @@ async def test_timelord_new_peak_unfinished_orphaned( await get_rc_prev(b1, block_1), ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() + + overflow = is_overflow_block(bt.constants, timelord_unf_block.reward_chain_block.signage_point_index) + assert last_unfinished(timelord_api, overflow=overflow).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b2, block_2) # timelord knows unfinished block_1 that has lower iterations, @@ -215,7 +218,8 @@ async def test_timelord_new_peak_unfinished_orphaned( == peak.reward_chain_block.get_hash() ) # check unfinished block_1 is still in cache - assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() + overflow = is_overflow_block(bt.constants, timelord_unf_block.reward_chain_block.signage_point_index) + assert last_unfinished(timelord_api, overflow=overflow).get_hash() == timelord_unf_block.get_hash() # full node gets block_1 unfinished block_1_unf = UnfinishedBlock( @@ -378,7 +382,8 @@ async def test_timelord_new_peak_unfinished_eos( # add unfinished and make sure we cache it await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() + overflow = is_overflow_block(bt.constants, timelord_unf_block.reward_chain_block.signage_point_index) + assert last_unfinished(timelord_api, overflow=overflow).get_hash() == timelord_unf_block.get_hash() new_peak = timelord_peak_from_block(b1, block_1) assert timelord_unf_block.reward_chain_block.total_iters >= new_peak.reward_chain_block.total_iters await timelord_api.new_peak_timelord(new_peak) @@ -538,9 +543,10 @@ async def test_timelord_new_peak_is_in_unfinished_cache( ) await timelord_api.new_unfinished_block_timelord(timelord_unf_block) - assert last_unfinished(timelord_api).get_hash() == timelord_unf_block.get_hash() + overflow = is_overflow_block(bt.constants, timelord_unf_block.reward_chain_block.signage_point_index) + assert last_unfinished(timelord_api, overflow=overflow).get_hash() == timelord_unf_block.get_hash() assert ( - last_unfinished(timelord_api).reward_chain_block.get_hash() + last_unfinished(timelord_api, overflow=overflow).reward_chain_block.get_hash() == timelord_unf_block.reward_chain_block.get_hash() )