def service_kwargs_for_farmer( root_path: pathlib.Path, config: Dict, config_pool: Dict, keychain: Keychain, consensus_constants: ConsensusConstants, ) -> Dict: connect_peers = [] fnp = config.get("full_node_peer") if fnp is not None: connect_peers.append(PeerInfo(fnp["host"], fnp["port"])) # TOD: Remove once we have pool server api = Farmer(config, config_pool, keychain, consensus_constants) kwargs = dict( root_path=root_path, api=api, node_type=NodeType.FARMER, advertised_port=config["port"], service_name=SERVICE_NAME, server_listen_ports=[config["port"]], connect_peers=connect_peers, auth_connect_peers=False, on_connect_callback=api._on_connect, ) if config["start_rpc_server"]: kwargs["rpc_info"] = (FarmerRpcApi, config["rpc_port"]) return kwargs
def service_kwargs_for_farmer(root_path): service_name = "farmer" config = load_config_cli(root_path, "config.yaml", service_name) keychain = Keychain() connect_peers = [ PeerInfo(config["full_node_peer"]["host"], config["full_node_peer"]["port"]) ] # TOD: Remove once we have pool server config_pool = load_config_cli(root_path, "config.yaml", "pool") api = Farmer(config, config_pool, keychain) kwargs = dict( root_path=root_path, api=api, node_type=NodeType.FARMER, advertised_port=config["port"], service_name=service_name, server_listen_ports=[config["port"]], connect_peers=connect_peers, on_connect_callback=api._on_connect, rpc_start_callback_port=(start_farmer_rpc_server, config["rpc_port"]), ) return kwargs
async def main(): farmer = Farmer() harvester_peer = PeerInfo(farmer.config["harvester_peer"]["host"], farmer.config["harvester_peer"]["port"]) full_node_peer = PeerInfo(farmer.config["full_node_peer"]["host"], farmer.config["full_node_peer"]["port"]) host, port = parse_host_port(farmer) server = ChiaServer(port, farmer, NodeType.FARMER) asyncio.get_running_loop().add_signal_handler(signal.SIGINT, server.close_all) asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, server.close_all) async def on_connect(): # Sends a handshake to the harvester pool_sks: List[PrivateKey] = [ PrivateKey.from_bytes(bytes.fromhex(ce)) for ce in farmer.key_config["pool_sks"] ] msg = HarvesterHandshake([sk.get_public_key() for sk in pool_sks]) yield OutboundMessage(NodeType.HARVESTER, Message("harvester_handshake", msg), Delivery.BROADCAST) _ = await server.start_server(host, on_connect) await asyncio.sleep(1) # Prevents TCP simultaneous connect with harvester _ = await server.start_client(harvester_peer, None) _ = await server.start_client(full_node_peer, None) await server.await_closed()
async def setup_farmer(port, dic={}): config = load_config(root_path, "config.yaml", "farmer") pool_sk = bt.pool_sk pool_target = create_puzzlehash_for_pk( BLSPublicKey(bytes(pool_sk.get_public_key()))) wallet_sk = bt.wallet_sk wallet_target = create_puzzlehash_for_pk( BLSPublicKey(bytes(wallet_sk.get_public_key()))) key_config = { "wallet_sk": bytes(wallet_sk).hex(), "wallet_target": wallet_target.hex(), "pool_sks": [bytes(pool_sk).hex()], "pool_target": pool_target.hex(), } test_constants_copy = test_constants.copy() for k in dic.keys(): test_constants_copy[k] = dic[k] net_config = load_config(root_path, "config.yaml") ping_interval = net_config.get("ping_interval") network_id = net_config.get("network_id") farmer = Farmer(config, key_config, test_constants_copy) assert ping_interval is not None assert network_id is not None server = ChiaServer(port, farmer, NodeType.FARMER, ping_interval, network_id) _ = await server.start_server(farmer._on_connect) yield (farmer, server) server.close_all() await server.await_closed()
async def async_main(): root_path = DEFAULT_ROOT_PATH net_config = load_config(root_path, "config.yaml") config = load_config_cli(root_path, "config.yaml", "farmer") # TOD: Remove once we have pool server config_pool = load_config_cli(root_path, "config.yaml", "pool") initialize_logging("Farmer %(name)-25s", config["logging"], root_path) log = logging.getLogger(__name__) setproctitle("chia_farmer") keychain = Keychain() farmer = Farmer(config, config_pool, keychain) ping_interval = net_config.get("ping_interval") network_id = net_config.get("network_id") assert ping_interval is not None assert network_id is not None server = ChiaServer( config["port"], farmer, NodeType.FARMER, ping_interval, network_id, root_path, config, ) try: asyncio.get_running_loop().add_signal_handler(signal.SIGINT, server.close_all) asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, server.close_all) except NotImplementedError: log.info("signal handlers unsupported") _ = await server.start_server(farmer._on_connect) farmer.set_server(server) rpc_cleanup = None if config["start_rpc_server"]: # Starts the RPC server rpc_cleanup = await start_farmer_rpc_server(farmer, server.close_all, config["rpc_port"]) await asyncio.sleep(10) # Allows full node to startup farmer._start_bg_tasks() await server.await_closed() farmer._shut_down = True # Waits for the rpc server to close if rpc_cleanup is not None: await rpc_cleanup() log.info("Closed RPC server.") log.info("Farmer fully closed.")
async def setup_farmer(port, dic={}): print("root path", root_path) config = load_config(root_path, "config.yaml", "farmer") config_pool = load_config(root_path, "config.yaml", "pool") test_constants_copy = test_constants.copy() for k in dic.keys(): test_constants_copy[k] = dic[k] net_config = load_config(root_path, "config.yaml") ping_interval = net_config.get("ping_interval") network_id = net_config.get("network_id") config["xch_target_puzzle_hash"] = bt.fee_target.hex() config["pool_public_keys"] = [ bytes(epk.get_public_key()).hex() for epk in bt.keychain.get_all_public_keys() ] config_pool["xch_target_puzzle_hash"] = bt.fee_target.hex() farmer = Farmer(config, config_pool, bt.keychain, test_constants_copy) assert ping_interval is not None assert network_id is not None server = ChiaServer( port, farmer, NodeType.FARMER, ping_interval, network_id, root_path, config, f"farmer_server_{port}", ) farmer.set_server(server) _ = await start_server(server, farmer._on_connect) yield (farmer, server) _.close() server.close_all() await server.await_closed()
async def setup_farmer( port, consensus_constants: ConsensusConstants, full_node_port: Optional[uint16] = None, ): config = load_config(bt.root_path, "config.yaml", "farmer") config_pool = load_config(bt.root_path, "config.yaml", "pool") config["xch_target_puzzle_hash"] = bt.farmer_ph.hex() config["pool_public_keys"] = [bytes(pk).hex() for pk in bt.pool_pubkeys] config_pool["xch_target_puzzle_hash"] = bt.pool_ph.hex() if full_node_port: connect_peers = [PeerInfo(self_hostname, full_node_port)] else: connect_peers = [] api = Farmer(config, config_pool, bt.keychain, consensus_constants) started = asyncio.Event() async def start_callback(): nonlocal started started.set() service = Service( root_path=bt.root_path, api=api, node_type=NodeType.FARMER, advertised_port=port, service_name="farmer", server_listen_ports=[port], on_connect_callback=api._on_connect, connect_peers=connect_peers, auth_connect_peers=False, start_callback=start_callback, parse_cli_args=False, ) run_task = asyncio.create_task(service.run()) await started.wait() yield api, api.server service.stop() await run_task
async def async_main(): root_path = DEFAULT_ROOT_PATH net_config = load_config(root_path, "config.yaml") config = load_config_cli(root_path, "config.yaml", "farmer") try: check_keys(root_path) key_config = load_config(root_path, "keys.yaml") except FileNotFoundError: raise RuntimeError("Keys not generated. Run `chia generate keys`") initialize_logging("Farmer %(name)-25s", config["logging"], root_path) log = logging.getLogger(__name__) setproctitle("chia_farmer") farmer = Farmer(config, key_config) ping_interval = net_config.get("ping_interval") network_id = net_config.get("network_id") assert ping_interval is not None assert network_id is not None server = ChiaServer( config["port"], farmer, NodeType.FARMER, ping_interval, network_id, root_path, config, ) try: asyncio.get_running_loop().add_signal_handler(signal.SIGINT, server.close_all) asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, server.close_all) except NotImplementedError: log.info("signal handlers unsupported") _ = await server.start_server(farmer._on_connect) farmer.set_server(server) await asyncio.sleep(10) # Allows full node to startup farmer._start_bg_tasks() await server.await_closed() farmer._shut_down = True log.info("Farmer fully closed.")
async def main(): config = load_config_cli("config.yaml", "farmer") try: key_config = load_config("keys.yaml") except FileNotFoundError: raise RuntimeError( "Keys not generated. Run python3 ./scripts/regenerate_keys.py.") initialize_logging("Farmer %(name)-25s", config["logging"]) log = logging.getLogger(__name__) setproctitle("chia_farmer") farmer = Farmer(config, key_config) harvester_peer = PeerInfo(config["harvester_peer"]["host"], config["harvester_peer"]["port"]) full_node_peer = PeerInfo(config["full_node_peer"]["host"], config["full_node_peer"]["port"]) server = ChiaServer(config["port"], farmer, NodeType.FARMER) asyncio.get_running_loop().add_signal_handler(signal.SIGINT, server.close_all) asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, server.close_all) async def on_connect(): # Sends a handshake to the harvester pool_sks: List[PrivateKey] = [ PrivateKey.from_bytes(bytes.fromhex(ce)) for ce in key_config["pool_sks"] ] msg = HarvesterHandshake([sk.get_public_key() for sk in pool_sks]) yield OutboundMessage(NodeType.HARVESTER, Message("harvester_handshake", msg), Delivery.BROADCAST) _ = await server.start_server(config["host"], on_connect) await asyncio.sleep(1) # Prevents TCP simultaneous connect with harvester _ = await server.start_client(harvester_peer, None) _ = await server.start_client(full_node_peer, None) await server.await_closed() log.info("Farmer fully closed.")
async def main(): root_path = DEFAULT_ROOT_PATH net_config = load_config(root_path, "config.yaml") config = load_config_cli(root_path, "config.yaml", "farmer") try: key_config = load_config(root_path, "keys.yaml") except FileNotFoundError: raise RuntimeError("Keys not generated. Run chia-generate-keys") initialize_logging("Farmer %(name)-25s", config["logging"]) log = logging.getLogger(__name__) setproctitle("chia_farmer") farmer = Farmer(config, key_config) harvester_peer = PeerInfo(config["harvester_peer"]["host"], config["harvester_peer"]["port"]) full_node_peer = PeerInfo(config["full_node_peer"]["host"], config["full_node_peer"]["port"]) ping_interval = net_config.get("ping_interval") network_id = net_config.get("network_id") assert ping_interval is not None assert network_id is not None server = ChiaServer(config["port"], farmer, NodeType.FARMER, ping_interval, network_id) asyncio.get_running_loop().add_signal_handler(signal.SIGINT, server.close_all) asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, server.close_all) _ = await server.start_server(farmer._on_connect, config) await asyncio.sleep(2) # Prevents TCP simultaneous connect with harvester _ = await server.start_client(harvester_peer, None, config) _ = await server.start_client(full_node_peer, None, config) farmer.set_server(server) farmer._start_bg_tasks() await server.await_closed() farmer._shut_down = True log.info("Farmer fully closed.")