Skip to content

Commit

Permalink
simplify pre_validate_blocks_multiprocessing() by making it pre-valid…
Browse files Browse the repository at this point in the history
…ated one block at a time. That's how we use it in production code anyway
  • Loading branch information
arvidn committed Nov 7, 2024
1 parent 3d5752e commit a7c9bd9
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 283 deletions.
13 changes: 5 additions & 8 deletions chia/_tests/blockchain/blockchain_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations

import asyncio
from typing import Optional

from chia_rs import SpendBundleConditions

from chia.consensus.block_body_validation import ForkInfo
from chia.consensus.blockchain import AddBlockResult, Blockchain
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_blocks_multiprocessing
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block
from chia.types.full_block import FullBlock
from chia.types.validation_state import ValidationState
from chia.util.augmented_chain import AugmentedBlockchain
Expand Down Expand Up @@ -81,17 +80,15 @@ async def _validate_and_add_block(
conds = SpendBundleConditions([], 0, 0, 0, None, None, [], 0, 0, 0, True)
results = PreValidationResult(None, uint64(1), conds, uint32(0))
else:
futures = await pre_validate_blocks_multiprocessing(
future = await pre_validate_block(
blockchain.constants,
AugmentedBlockchain(blockchain),
[block],
block,
blockchain.pool,
{},
None,
ValidationState(ssi, diff, prev_ses_block),
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert pre_validation_results is not None
results = pre_validation_results[0]
results = await future
if results.error is not None:
if expected_result == AddBlockResult.INVALID_BLOCK and expected_error is None:
# We expected an error but didn't specify which one
Expand Down
Loading

0 comments on commit a7c9bd9

Please sign in to comment.