Use `service_kwargs_for_full_node(_simulator)?`.
This commit is contained in:
parent
589d7a0621
commit
f333def7dd
|
@ -27,7 +27,6 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class Harvester:
|
||||
config: Dict
|
||||
provers: Dict[Path, PlotInfo]
|
||||
failed_to_open_filenames: Dict[Path, int]
|
||||
no_key_filenames: Set[Path]
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
from multiprocessing import freeze_support
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
from src.consensus.constants import ConsensusConstants
|
||||
from src.rpc.full_node_rpc_api import FullNodeRpcApi
|
||||
from src.server.outbound_message import NodeType
|
||||
from src.server.start_service import run_service
|
||||
from src.util.block_tools import BlockTools
|
||||
from src.util.config import load_config_cli
|
||||
from src.util.default_root import DEFAULT_ROOT_PATH
|
||||
from src.util.path import mkdir, path_from_root
|
||||
from src.simulator.full_node_simulator import FullNodeSimulator
|
||||
from src.simulator.simulator_constants import test_constants
|
||||
from src.util.block_tools import BlockTools
|
||||
|
||||
from .full_node_simulator import FullNodeSimulator
|
||||
from .simulator_constants import test_constants
|
||||
|
||||
|
||||
# See: https://bugs.python.org/issue29288
|
||||
u"".encode("idna")
|
||||
|
||||
SERVICE_NAME = "full_node"
|
||||
|
||||
def service_kwargs_for_full_node(root_path):
|
||||
service_name = "full_node"
|
||||
|
||||
config = load_config_cli(root_path, "config.yaml", "full_node")
|
||||
db_path = path_from_root(root_path, config["simulator_database_path"])
|
||||
mkdir(db_path.parent)
|
||||
|
||||
config["database_path"] = config["simulator_database_path"]
|
||||
def service_kwargs_for_full_node_simulator(
|
||||
root_path: Path,
|
||||
config: Dict,
|
||||
consensus_constants: ConsensusConstants,
|
||||
bt: BlockTools,
|
||||
) -> Dict:
|
||||
mkdir(path_from_root(root_path, config["database_path"]).parent)
|
||||
|
||||
api = FullNodeSimulator(
|
||||
config,
|
||||
root_path=root_path,
|
||||
consensus_constants=test_constants,
|
||||
name=service_name,
|
||||
bt=BlockTools(),
|
||||
consensus_constants=consensus_constants,
|
||||
name=SERVICE_NAME,
|
||||
bt=bt,
|
||||
)
|
||||
|
||||
async def start_callback():
|
||||
await api._start()
|
||||
|
||||
def stop_callback():
|
||||
api._close()
|
||||
|
||||
async def await_closed_callback():
|
||||
await api._await_closed()
|
||||
|
||||
kwargs = dict(
|
||||
root_path=root_path,
|
||||
api=api,
|
||||
node_type=NodeType.FULL_NODE,
|
||||
advertised_port=config["port"],
|
||||
service_name=service_name,
|
||||
service_name=SERVICE_NAME,
|
||||
server_listen_ports=[config["port"]],
|
||||
on_connect_callback=api._on_connect,
|
||||
start_callback=start_callback,
|
||||
stop_callback=stop_callback,
|
||||
await_closed_callback=await_closed_callback,
|
||||
rpc_info=(FullNodeRpcApi, config["rpc_port"]),
|
||||
)
|
||||
return kwargs
|
||||
|
||||
|
||||
def main():
|
||||
kwargs = service_kwargs_for_full_node(DEFAULT_ROOT_PATH)
|
||||
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
|
||||
config["database_path"] = config["simulator_database_path"]
|
||||
kwargs = service_kwargs_for_full_node_simulator(
|
||||
DEFAULT_ROOT_PATH,
|
||||
config,
|
||||
test_constants,
|
||||
BlockTools(),
|
||||
)
|
||||
return run_service(**kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -7,22 +7,23 @@ from src.consensus.constants import ConsensusConstants
|
|||
from src.full_node.full_node import FullNode
|
||||
from src.server.connection import NodeType
|
||||
from src.server.server import ChiaServer
|
||||
from src.simulator.full_node_simulator import FullNodeSimulator
|
||||
from src.timelord_launcher import spawn_process, kill_processes
|
||||
from src.util.keychain import Keychain, bytes_to_mnemonic
|
||||
from src.wallet.wallet_node import WalletNode
|
||||
from src.util.config import load_config
|
||||
from src.server.connection import PeerInfo
|
||||
from src.util.ints import uint16, uint32
|
||||
from src.simulator.start_simulator import service_kwargs_for_full_node_simulator
|
||||
from src.server.start_farmer import service_kwargs_for_farmer
|
||||
from src.server.start_full_node import service_kwargs_for_full_node
|
||||
from src.server.start_harvester import service_kwargs_for_harvester
|
||||
from src.server.start_introducer import service_kwargs_for_introducer
|
||||
from src.server.start_timelord import service_kwargs_for_timelord
|
||||
from src.server.start_service import Service
|
||||
from src.util.ints import uint16, uint32
|
||||
from src.util.make_test_constants import make_test_constants_with_genesis
|
||||
from tests.time_out_assert import time_out_assert
|
||||
from src.util.chech32 import encode_puzzle_hash
|
||||
|
||||
from tests.time_out_assert import time_out_assert
|
||||
|
||||
test_constants, bt = make_test_constants_with_genesis(
|
||||
{
|
||||
"DIFFICULTY_STARTING": 1,
|
||||
|
@ -40,8 +41,7 @@ test_constants, bt = make_test_constants_with_genesis(
|
|||
}
|
||||
)
|
||||
|
||||
global_config = load_config(bt.root_path, "config.yaml")
|
||||
self_hostname = global_config["self_hostname"]
|
||||
self_hostname = bt.config["self_hostname"]
|
||||
|
||||
|
||||
def constants_for_dic(dic):
|
||||
|
@ -69,42 +69,33 @@ async def setup_full_node(
|
|||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
config = load_config(bt.root_path, "config.yaml", "full_node")
|
||||
config = bt.config["full_node"]
|
||||
config["database_path"] = db_name
|
||||
config["send_uncompact_interval"] = send_uncompact_interval
|
||||
config["peer_connect_interval"] = 3
|
||||
config["introducer_peer"]["host"] = "::1"
|
||||
if introducer_port is not None:
|
||||
config["introducer_peer"]["port"] = introducer_port
|
||||
config["port"] = port
|
||||
config["rpc_port"] = port + 1000
|
||||
|
||||
if not simulator:
|
||||
api: FullNode = FullNode(
|
||||
config=config,
|
||||
root_path=bt.root_path,
|
||||
consensus_constants=consensus_constants,
|
||||
name=f"full_node_{port}",
|
||||
if simulator:
|
||||
kwargs = service_kwargs_for_full_node_simulator(
|
||||
bt.root_path, bt.config["full_node"], consensus_constants, bt
|
||||
)
|
||||
else:
|
||||
api = FullNodeSimulator(
|
||||
config=config,
|
||||
root_path=bt.root_path,
|
||||
consensus_constants=consensus_constants,
|
||||
name=f"full_node_sim_{port}",
|
||||
bt=bt,
|
||||
kwargs = service_kwargs_for_full_node(
|
||||
bt.root_path, bt.config["full_node"], consensus_constants
|
||||
)
|
||||
|
||||
service = Service(
|
||||
root_path=bt.root_path,
|
||||
api=api,
|
||||
node_type=NodeType.FULL_NODE,
|
||||
advertised_port=port,
|
||||
service_name="full_node",
|
||||
server_listen_ports=[port],
|
||||
auth_connect_peers=False,
|
||||
on_connect_callback=api._on_connect,
|
||||
parse_cli_args=False,
|
||||
kwargs.update(
|
||||
dict(
|
||||
parse_cli_args=False,
|
||||
)
|
||||
)
|
||||
|
||||
service = Service(**kwargs)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api, service._api.server
|
||||
|
@ -123,7 +114,7 @@ async def setup_wallet_node(
|
|||
key_seed=None,
|
||||
starting_height=None,
|
||||
):
|
||||
config = load_config(bt.root_path, "config.yaml", "wallet")
|
||||
config = bt.config["wallet"]
|
||||
if starting_height is not None:
|
||||
config["starting_height"] = starting_height
|
||||
config["initial_num_public_keys"] = 5
|
||||
|
|
Loading…
Reference in New Issue