27
27
from chia .consensus .get_block_generator import get_block_generator
28
28
from chia .consensus .pos_quality import UI_ACTUAL_SPACE_CONSTANT_FACTOR
29
29
from chia .full_node .fee_estimator_interface import FeeEstimatorInterface
30
+ from chia .full_node .full_block_utils import GeneratorBlockInfo , get_height_and_tx_status_from_block
30
31
from chia .full_node .full_node import FullNode
31
32
from chia .protocols .outbound_message import NodeType
32
33
from chia .rpc .rpc_server import Endpoint , EndpointResult
@@ -481,15 +482,15 @@ async def get_block_spends(self, request: dict[str, Any]) -> EndpointResult:
481
482
if "header_hash" not in request :
482
483
raise ValueError ("No header_hash in request" )
483
484
header_hash = bytes32 .from_hexstr (request ["header_hash" ])
484
- full_block : Optional [FullBlock ] = await self .service .block_store .get_full_block (header_hash )
485
- if full_block is None :
485
+ block_info : Optional [GeneratorBlockInfo ] = await self .service .block_store .get_block_info (header_hash )
486
+ if block_info is None :
486
487
raise ValueError (f"Block { header_hash .hex ()} not found" )
487
488
488
- block_generator = await get_block_generator (self .service .blockchain .lookup_block_generators , full_block )
489
+ block_generator = await get_block_generator (self .service .blockchain .lookup_block_generators , block_info )
489
490
if block_generator is None : # if block is not a transaction block.
490
491
return {"block_spends" : []}
491
492
492
- flags = get_flags_for_height_and_constants (full_block .height , self .service .constants )
493
+ flags = get_flags_for_height_and_constants (block_info .height , self .service .constants )
493
494
spends = await asyncio .get_running_loop ().run_in_executor (
494
495
self .executor ,
495
496
get_spends_for_trusted_block ,
@@ -505,15 +506,15 @@ async def get_block_spends_with_conditions(self, request: dict[str, Any]) -> End
505
506
if "header_hash" not in request :
506
507
raise ValueError ("No header_hash in request" )
507
508
header_hash = bytes32 .from_hexstr (request ["header_hash" ])
508
- full_block : Optional [FullBlock ] = await self .service .block_store .get_full_block (header_hash )
509
- if full_block is None :
509
+ block_info : Optional [GeneratorBlockInfo ] = await self .service .block_store .get_block_info (header_hash )
510
+ if block_info is None :
510
511
raise ValueError (f"Block { header_hash .hex ()} not found" )
511
512
512
- block_generator = await get_block_generator (self .service .blockchain .lookup_block_generators , full_block )
513
+ block_generator = await get_block_generator (self .service .blockchain .lookup_block_generators , block_info )
513
514
if block_generator is None : # if block is not a transaction block.
514
515
return {"block_spends_with_conditions" : []}
515
516
516
- flags = get_flags_for_height_and_constants (full_block .height , self .service .constants )
517
+ flags = get_flags_for_height_and_constants (block_info .height , self .service .constants )
517
518
spends_with_conditions = await asyncio .get_running_loop ().run_in_executor (
518
519
self .executor ,
519
520
get_spends_for_trusted_block_with_conditions ,
@@ -792,7 +793,9 @@ async def get_puzzle_and_solution(self, request: dict[str, Any]) -> EndpointResu
792
793
assert block_generator is not None
793
794
794
795
try :
795
- puzzle , solution = get_puzzle_and_solution_for_coin (
796
+ puzzle , solution = await asyncio .get_running_loop ().run_in_executor (
797
+ self .executor ,
798
+ get_puzzle_and_solution_for_coin ,
796
799
block_generator .program ,
797
800
block_generator .generator_refs ,
798
801
self .service .constants .MAX_BLOCK_COST_CLVM ,
@@ -807,16 +810,18 @@ async def get_additions_and_removals(self, request: dict[str, Any]) -> EndpointR
807
810
if "header_hash" not in request :
808
811
raise ValueError ("No header_hash in request" )
809
812
header_hash = bytes32 .from_hexstr (request ["header_hash" ])
810
-
811
- block : Optional [FullBlock ] = await self .service .block_store .get_full_block (header_hash )
812
- if block is None :
813
+ block_bytes : Optional [bytes ] = await self .service .block_store .get_full_block_bytes (header_hash )
814
+ if block_bytes is None :
813
815
raise ValueError (f"Block { header_hash .hex ()} not found" )
814
816
817
+ block_view = memoryview (block_bytes )
818
+ height , _is_tx_block = get_height_and_tx_status_from_block (block_view )
819
+
815
820
async with self .service .blockchain .priority_mutex .acquire (priority = BlockchainMutexPriority .low ):
816
- if self .service .blockchain .height_to_hash (block . height ) != header_hash :
821
+ if self .service .blockchain .height_to_hash (height ) != header_hash :
817
822
raise ValueError (f"Block at { header_hash .hex ()} is no longer in the blockchain (it's in a fork)" )
818
- additions : list [CoinRecord ] = await self .service .coin_store .get_coins_added_at_height (block . height )
819
- removals : list [CoinRecord ] = await self .service .coin_store .get_coins_removed_at_height (block . height )
823
+ additions : list [CoinRecord ] = await self .service .coin_store .get_coins_added_at_height (height )
824
+ removals : list [CoinRecord ] = await self .service .coin_store .get_coins_removed_at_height (height )
820
825
821
826
return {
822
827
"additions" : [coin_record_dict_backwards_compat (cr .to_json_dict ()) for cr in additions ],
0 commit comments