1414from chia .consensus .blockchain_interface import BlockRecordsProtocol
1515from chia .consensus .coinbase import create_farmer_coin , create_pool_coin
1616from chia .consensus .constants import ConsensusConstants
17- from chia .consensus .cost_calculator import NPCResult
1817from chia .full_node .mempool_check_conditions import mempool_check_time_locks
1918from chia .types .blockchain_format .coin import Coin
2019from chia .types .blockchain_format .sized_bytes import bytes32
@@ -125,19 +124,22 @@ async def validate_block_body(
125124 get_coin_records : Callable [[Collection [bytes32 ]], Awaitable [List [CoinRecord ]]],
126125 block : Union [FullBlock , UnfinishedBlock ],
127126 height : uint32 ,
128- npc_result : Optional [NPCResult ],
127+ conds : Optional [SpendBundleConditions ],
129128 fork_info : ForkInfo ,
130129 bls_cache : Optional [BLSCache ],
131130 * ,
132131 validate_signature : bool = True ,
133- ) -> Tuple [Optional [Err ], Optional [NPCResult ]]:
132+ ) -> Tuple [Optional [Err ], Optional [SpendBundleConditions ]]:
134133 """
135134 This assumes the header block has been completely validated.
136- Validates the transactions and body of the block. Returns None for the first value if everything
137- validates correctly, or an Err if something does not validate. For the second value, returns a CostResult
138- only if validation succeeded, and there are transactions. In other cases it returns None. The NPC result is
139- the result of running the generator with the previous generators refs. It is only present for transaction
140- blocks which have spent coins.
135+ Validates the transactions and body of the block.
136+ Returns None for the first value if everything validates correctly, or an
137+ Err if something does not validate.
138+ For the second value, returns a SpendBundleConditions only if validation
139+ succeeded, and there are transactions. In other cases it returns None.
140+ conds is the result of running the generator with the previous generators
141+ refs. It must be set for transaction blocks and must be None for
142+ non-transaction blocks.
141143 fork_info specifies the fork context of this block. In case the block
142144 extends the main chain, it can be empty, but if the block extends a fork
143145 of the main chain, the fork info is mandatory in order to validate the block.
@@ -291,8 +293,7 @@ async def validate_block_body(
291293 if block .transactions_generator is not None :
292294 # Get List of names removed, puzzles hashes for removed coins and conditions created
293295
294- assert npc_result is not None
295- cost = uint64 (0 if npc_result .conds is None else npc_result .conds .cost )
296+ cost = uint64 (0 if conds is None else conds .cost )
296297
297298 # 7. Check that cost <= MAX_BLOCK_COST_CLVM
298299 log .debug (
@@ -303,19 +304,16 @@ async def validate_block_body(
303304 return Err .BLOCK_COST_EXCEEDS_MAX , None
304305
305306 # 8. The CLVM program must not return any errors
306- if npc_result .error is not None :
307- return Err (npc_result .error ), None
307+ assert conds is not None
308308
309- assert npc_result .conds is not None
310-
311- for spend in npc_result .conds .spends :
309+ for spend in conds .spends :
312310 removals .append (bytes32 (spend .coin_id ))
313311 removals_puzzle_dic [bytes32 (spend .coin_id )] = bytes32 (spend .puzzle_hash )
314312 for puzzle_hash , amount , _ in spend .create_coin :
315313 c = Coin (bytes32 (spend .coin_id ), bytes32 (puzzle_hash ), uint64 (amount ))
316314 additions .append ((c , c .name ()))
317315 else :
318- assert npc_result is None
316+ assert conds is None
319317
320318 # 9. Check that the correct cost is in the transactions info
321319 if block .transactions_info .cost != cost :
@@ -459,10 +457,7 @@ async def validate_block_body(
459457
460458 # reserve fee cannot be greater than UINT64_MAX per consensus rule.
461459 # run_generator() would fail
462- assert_fee_sum : uint64 = uint64 (0 )
463- if npc_result :
464- assert npc_result .conds is not None
465- assert_fee_sum = uint64 (npc_result .conds .reserve_fee )
460+ assert_fee_sum = uint64 (0 if conds is None else conds .reserve_fee )
466461
467462 # 17. Check that the assert fee sum <= fees, and that each reserved fee is non-negative
468463 if fees < assert_fee_sum :
@@ -483,24 +478,21 @@ async def validate_block_body(
483478
484479 # 21. Verify conditions
485480 # verify absolute/relative height/time conditions
486- if npc_result is not None :
487- assert npc_result .conds is not None
488-
481+ if conds is not None :
489482 error = mempool_check_time_locks (
490483 removal_coin_records ,
491- npc_result . conds ,
484+ conds ,
492485 prev_transaction_block_height ,
493486 prev_transaction_block_timestamp ,
494487 )
495- if error :
488+ if error is not None :
496489 return error , None
497490
498491 # create hash_key list for aggsig check
499492 pairs_pks : List [G1Element ] = []
500493 pairs_msgs : List [bytes ] = []
501- if npc_result :
502- assert npc_result .conds is not None
503- pairs_pks , pairs_msgs = pkm_pairs (npc_result .conds , constants .AGG_SIG_ME_ADDITIONAL_DATA )
494+ if conds is not None :
495+ pairs_pks , pairs_msgs = pkm_pairs (conds , constants .AGG_SIG_ME_ADDITIONAL_DATA )
504496
505497 # 22. Verify aggregated signature
506498 # TODO: move this to pre_validate_blocks_multiprocessing so we can sync faster
@@ -520,4 +512,4 @@ async def validate_block_body(
520512 if not bls_cache .aggregate_verify (pairs_pks , pairs_msgs , block .transactions_info .aggregated_signature ):
521513 return Err .BAD_AGGREGATE_SIGNATURE , None
522514
523- return None , npc_result
515+ return None , conds
0 commit comments