Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions chia/_tests/timelord/test_new_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
)

Expand Down
3 changes: 3 additions & 0 deletions chia/timelord/timelord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading