2
2
3
3
import asyncio
4
4
import time
5
+ from concurrent .futures import ThreadPoolExecutor
5
6
from datetime import datetime , timezone
6
7
from typing import TYPE_CHECKING , Any , ClassVar , Optional , cast
7
8
@@ -89,6 +90,8 @@ async def get_average_block_time(
89
90
90
91
91
92
class FullNodeRpcApi :
93
+ executor : ThreadPoolExecutor
94
+
92
95
if TYPE_CHECKING :
93
96
from chia .rpc .rpc_server import RpcApiProtocol
94
97
@@ -98,6 +101,7 @@ def __init__(self, service: FullNode) -> None:
98
101
self .service = service
99
102
self .service_name = "chia_full_node"
100
103
self .cached_blockchain_state : Optional [dict [str , Any ]] = None
104
+ self .executor = ThreadPoolExecutor (max_workers = 2 , thread_name_prefix = "node-rpc-" )
101
105
102
106
def get_routes (self ) -> dict [str , Endpoint ]:
103
107
return {
@@ -485,11 +489,14 @@ async def get_block_spends(self, request: dict[str, Any]) -> EndpointResult:
485
489
if block_generator is None : # if block is not a transaction block.
486
490
return {"block_spends" : []}
487
491
488
- spends = get_spends_for_trusted_block (
492
+ flags = get_flags_for_height_and_constants (full_block .height , self .service .constants )
493
+ spends = await asyncio .get_running_loop ().run_in_executor (
494
+ self .executor ,
495
+ get_spends_for_trusted_block ,
489
496
self .service .constants ,
490
497
block_generator .program ,
491
498
block_generator .generator_refs ,
492
- get_flags_for_height_and_constants ( full_block . height , self . service . constants ) ,
499
+ flags ,
493
500
)
494
501
495
502
return spends
@@ -506,11 +513,14 @@ async def get_block_spends_with_conditions(self, request: dict[str, Any]) -> End
506
513
if block_generator is None : # if block is not a transaction block.
507
514
return {"block_spends_with_conditions" : []}
508
515
509
- spends_with_conditions = get_spends_for_trusted_block_with_conditions (
516
+ flags = get_flags_for_height_and_constants (full_block .height , self .service .constants )
517
+ spends_with_conditions = await asyncio .get_running_loop ().run_in_executor (
518
+ self .executor ,
519
+ get_spends_for_trusted_block_with_conditions ,
510
520
self .service .constants ,
511
521
block_generator .program ,
512
522
block_generator .generator_refs ,
513
- get_flags_for_height_and_constants ( full_block . height , self . service . constants ) ,
523
+ flags ,
514
524
)
515
525
return {"block_spends_with_conditions" : spends_with_conditions }
516
526
@@ -885,7 +895,7 @@ async def create_block_generator(self, _: dict[str, Any]) -> EndpointResult:
885
895
if maybe_gen is not None :
886
896
# this also validates the signature
887
897
err , conds = await asyncio .get_running_loop ().run_in_executor (
888
- self .service . blockchain . pool ,
898
+ self .executor ,
889
899
run_block_generator2 ,
890
900
bytes (gen .program ),
891
901
gen .generator_refs ,
0 commit comments