Skip to content

Commit

Permalink
make include_spends() take SpendBundleConditions, rather than NPCResult
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Sep 23, 2024
1 parent 24357a2 commit 63489b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions chia/consensus/block_body_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass, field
from typing import Awaitable, Callable, Collection, Dict, List, Optional, Set, Tuple, Union

from chia_rs import AugSchemeMPL, BLSCache, G1Element
from chia_rs import AugSchemeMPL, BLSCache, G1Element, SpendBundleConditions
from chiabip158 import PyBIP158

from chia.consensus.block_record import BlockRecord
Expand Down Expand Up @@ -85,7 +85,7 @@ def reset(self, fork_height: int, header_hash: bytes32) -> None:
self.removals_since_fork = {}
self.block_hashes = []

def include_spends(self, npc_result: Optional[NPCResult], block: FullBlock, header_hash: bytes32) -> None:
def include_spends(self, conds: Optional[SpendBundleConditions], block: FullBlock, header_hash: bytes32) -> None:
height = block.height

assert self.peak_height == height - 1
Expand All @@ -97,11 +97,10 @@ def include_spends(self, npc_result: Optional[NPCResult], block: FullBlock, head
self.peak_height = int(block.height)
self.peak_hash = header_hash

if npc_result is not None:
assert npc_result.conds is not None
if conds is not None:
assert block.foliage_transaction_block is not None
timestamp = block.foliage_transaction_block.timestamp
for spend in npc_result.conds.spends:
for spend in conds.spends:
self.removals_since_fork[bytes32(spend.coin_id)] = ForkRem(bytes32(spend.puzzle_hash), height)
for puzzle_hash, amount, hint in spend.create_coin:
coin = Coin(bytes32(spend.coin_id), bytes32(puzzle_hash), uint64(amount))
Expand Down
6 changes: 3 additions & 3 deletions chia/consensus/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ async def run_single_block(self, block: FullBlock, fork_info: ForkInfo) -> None:
)
assert npc.error is None

fork_info.include_spends(npc, block, block.header_hash)
fork_info.include_spends(None if npc is None else npc.conds, block, block.header_hash)

async def add_block(
self,
Expand Down Expand Up @@ -412,7 +412,7 @@ async def add_block(
# main chain, we still need to re-run it to update the additions and
# removals in fork_info.
await self.advance_fork_info(block, fork_info)
fork_info.include_spends(npc_result, block, header_hash)
fork_info.include_spends(None if npc_result is None else npc_result.conds, block, header_hash)
self.add_block_record(block_rec)
return AddBlockResult.ALREADY_HAVE_BLOCK, None, None

Expand Down Expand Up @@ -444,7 +444,7 @@ async def add_block(
# case we're validating blocks on a fork, the next block validation will
# need to know of these additions and removals. Also, _reconsider_peak()
# will need these results
fork_info.include_spends(npc_result, block, header_hash)
fork_info.include_spends(None if npc_result is None else npc_result.conds, block, header_hash)

# block_to_block_record() require the previous block in the cache
if not genesis and prev_block is not None:
Expand Down

0 comments on commit 63489b6

Please sign in to comment.