Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better timestamps on simulated chains #16326

Merged
merged 6 commits into from
Sep 16, 2023
Merged
27 changes: 18 additions & 9 deletions chia/simulator/block_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,12 @@ def get_consecutive_blocks(
if not use_timestamp_residual:
self._block_time_residual = 0.0

full_block, block_record, self._block_time_residual = get_full_block_and_block_record(
(
full_block,
block_record,
self._block_time_residual,
new_timestamp,
) = get_full_block_and_block_record(
arvidn marked this conversation as resolved.
Show resolved Hide resolved
constants,
blocks,
sub_slot_start_total_iters,
Expand Down Expand Up @@ -793,10 +798,9 @@ def get_consecutive_blocks(
previous_generator = None
keep_going_until_tx_block = False
assert full_block.foliage_transaction_block is not None
last_timestamp = full_block.foliage_transaction_block.timestamp
else:
if guarantee_transaction_block:
continue
elif guarantee_transaction_block:
continue
last_timestamp = new_timestamp
block_list.append(full_block)
if full_block.transactions_generator is not None:
compressor_arg = detect_potential_template_generator(
Expand Down Expand Up @@ -1043,7 +1047,12 @@ def get_consecutive_blocks(
if not use_timestamp_residual:
self._block_time_residual = 0.0

full_block, block_record, self._block_time_residual = get_full_block_and_block_record(
(
full_block,
block_record,
self._block_time_residual,
new_timestamp,
) = get_full_block_and_block_record(
constants,
blocks,
sub_slot_start_total_iters,
Expand Down Expand Up @@ -1082,9 +1091,9 @@ def get_consecutive_blocks(
previous_generator = None
keep_going_until_tx_block = False
assert full_block.foliage_transaction_block is not None
last_timestamp = full_block.foliage_transaction_block.timestamp
elif guarantee_transaction_block:
continue
last_timestamp = new_timestamp

block_list.append(full_block)
if full_block.transactions_generator is not None:
Expand Down Expand Up @@ -1696,7 +1705,7 @@ def get_full_block_and_block_record(
normalized_to_identity_cc_ip: bool = False,
current_time: bool = False,
block_time_residual: float = 0.0,
) -> Tuple[FullBlock, BlockRecord, float]:
) -> Tuple[FullBlock, BlockRecord, float, uint64]:
time_delta, block_time_residual = round_timestamp(time_per_block, block_time_residual)
if current_time is True:
timestamp = uint64(max(int(time.time()), last_timestamp + time_delta))
Expand Down Expand Up @@ -1752,7 +1761,7 @@ def get_full_block_and_block_record(
normalized_to_identity_cc_ip,
)

return full_block, block_record, block_time_residual
return full_block, block_record, block_time_residual, timestamp


# these are the costs of unknown conditions, as defined chia_rs here:
Expand Down