|
26 | 26 | from chia.consensus.check_time_locks import check_time_locks |
27 | 27 | from chia.consensus.cost_calculator import NPCResult |
28 | 28 | from chia.full_node.bitcoin_fee_estimator import create_bitcoin_fee_estimator |
29 | | -from chia.full_node.eligible_coin_spends import EligibilityAndAdditions |
30 | 29 | from chia.full_node.fee_estimation import FeeBlockInfo, MempoolInfo, MempoolItemInfo |
31 | 30 | from chia.full_node.fee_estimator_interface import FeeEstimatorInterface |
32 | 31 | from chia.full_node.mempool import MEMPOOL_ITEM_FEE_LIMIT, Mempool, MempoolRemoveInfo, MempoolRemoveReason |
@@ -584,60 +583,51 @@ async def validate_spend_bundle( |
584 | 583 | removal_names: set[bytes32] = set() |
585 | 584 | additions_dict: dict[bytes32, Coin] = {} |
586 | 585 | addition_amount: int = 0 |
587 | | - # Map of coin ID to eligibility information |
588 | | - eligibility_and_additions: dict[bytes32, EligibilityAndAdditions] = {} |
589 | | - for spend in conds.spends: |
590 | | - coin_id = bytes32(spend.coin_id) |
591 | | - removal_names.add(coin_id) |
592 | | - spend_additions = [] |
593 | | - for puzzle_hash, amount, _ in spend.create_coin: |
594 | | - child_coin = Coin(coin_id, puzzle_hash, uint64(amount)) |
595 | | - spend_additions.append(child_coin) |
596 | | - additions_dict[child_coin.name()] = child_coin |
597 | | - addition_amount += child_coin.amount |
598 | | - is_eligible_for_dedup = bool(spend.flags & ELIGIBLE_FOR_DEDUP) |
599 | | - is_eligible_for_ff = bool(spend.flags & ELIGIBLE_FOR_FF) |
600 | | - eligibility_and_additions[coin_id] = EligibilityAndAdditions( |
601 | | - is_eligible_for_dedup=is_eligible_for_dedup, |
602 | | - spend_additions=spend_additions, |
603 | | - ff_puzzle_hash=bytes32(spend.puzzle_hash) if is_eligible_for_ff else None, |
604 | | - ) |
605 | | - removal_names_from_coin_spends: set[bytes32] = set() |
| 586 | + |
| 587 | + # Map of coin ID to SpendConditions |
| 588 | + spend_conditions = {bytes32(spend.coin_id): spend for spend in conds.spends} |
| 589 | + |
| 590 | + # if this happens, the SpendBundle doesn't match the |
| 591 | + # SpendBundleConditions. |
| 592 | + assert len(new_spend.coin_spends) == len(spend_conditions) |
| 593 | + |
606 | 594 | bundle_coin_spends: dict[bytes32, BundleCoinSpend] = {} |
607 | 595 | for coin_spend in new_spend.coin_spends: |
608 | 596 | coin_id = coin_spend.coin.name() |
609 | | - removal_names_from_coin_spends.add(coin_id) |
610 | | - eligibility_info = eligibility_and_additions.get( |
611 | | - coin_id, |
612 | | - EligibilityAndAdditions(is_eligible_for_dedup=False, spend_additions=[], ff_puzzle_hash=None), |
613 | | - ) |
| 597 | + removal_names.add(coin_id) |
| 598 | + |
| 599 | + # if this coin_id isn't found, the SpendBundle doesn't match the |
| 600 | + # SpendBundleConditions. |
| 601 | + spend_conds = spend_conditions.pop(coin_id) |
614 | 602 |
|
615 | | - supports_dedup = eligibility_info.is_eligible_for_dedup |
616 | | - if supports_dedup and not is_clvm_canonical(bytes(coin_spend.solution)): |
| 603 | + if bool(spend_conds.flags & ELIGIBLE_FOR_DEDUP) and not is_clvm_canonical(bytes(coin_spend.solution)): |
617 | 604 | return Err.INVALID_COIN_SOLUTION, None, [] |
618 | 605 |
|
619 | | - mark_as_fast_forward = eligibility_info.ff_puzzle_hash is not None and supports_fast_forward(coin_spend) |
620 | 606 | lineage_info = None |
621 | | - if mark_as_fast_forward: |
| 607 | + eligible_for_ff = bool(spend_conds.flags & ELIGIBLE_FOR_FF) and supports_fast_forward(coin_spend) |
| 608 | + if eligible_for_ff: |
622 | 609 | # Make sure the fast forward spend still has a version that is |
623 | 610 | # still unspent, because if the singleton has been melted, the |
624 | 611 | # fast forward spend will never become valid. |
625 | | - assert eligibility_info.ff_puzzle_hash is not None |
626 | | - lineage_info = await get_unspent_lineage_info_for_puzzle_hash(eligibility_info.ff_puzzle_hash) |
| 612 | + lineage_info = await get_unspent_lineage_info_for_puzzle_hash(bytes32(spend_conds.puzzle_hash)) |
627 | 613 | if lineage_info is None: |
628 | 614 | return Err.DOUBLE_SPEND, None, [] |
| 615 | + |
| 616 | + spend_additions = [] |
| 617 | + for puzzle_hash, amount, _ in spend_conds.create_coin: |
| 618 | + child_coin = Coin(coin_id, puzzle_hash, uint64(amount)) |
| 619 | + spend_additions.append(child_coin) |
| 620 | + additions_dict[child_coin.name()] = child_coin |
| 621 | + addition_amount += amount |
| 622 | + |
629 | 623 | bundle_coin_spends[coin_id] = BundleCoinSpend( |
630 | 624 | coin_spend=coin_spend, |
631 | | - eligible_for_dedup=supports_dedup, |
632 | | - eligible_for_fast_forward=mark_as_fast_forward, |
633 | | - additions=eligibility_info.spend_additions, |
| 625 | + eligible_for_dedup=bool(spend_conds.flags & ELIGIBLE_FOR_DEDUP), |
| 626 | + eligible_for_fast_forward=eligible_for_ff, |
| 627 | + additions=spend_additions, |
634 | 628 | latest_singleton_lineage=lineage_info, |
635 | 629 | ) |
636 | 630 |
|
637 | | - if removal_names != removal_names_from_coin_spends: |
638 | | - # If you reach here it's probably because your program reveal doesn't match the coin's puzzle hash |
639 | | - return Err.INVALID_SPEND_BUNDLE, None, [] |
640 | | - |
641 | 631 | # fast forward spends are only allowed when bundled with other, non-FF, spends |
642 | 632 | # in order to evict an FF spend, it must be associated with a normal |
643 | 633 | # spend that can be included in a block or invalidated some other way |
|
0 commit comments