Esempio n. 1
0
 def setUp(self):
     self.blockchain_network = helpers.blockchain_network(
         protocol="Bitcoin",
         network_name="Mainnet",
         network_num=1,
         block_interval=600,
         final_tx_confirmations_count=6)
     opts = {
         "log_path":
         "",
         "to_stdout":
         True,
         "external_port":
         0,
         "node_id":
         "Test-Node-1",
         "blockchain_network":
         self.blockchain_network.network,
         "network_num":
         self.blockchain_network.network_num,
         "blockchain_protocol":
         self.blockchain_network.protocol,
         "blockchain_networks": [self.blockchain_network],
         "log_level":
         LogLevel.INFO,
         "log_format":
         LogFormat.PLAIN,
         "log_flush_immediately":
         True,
         "use_extensions":
         True,
         "thread_pool_parallelism_degree":
         config.get_thread_pool_parallelism_degree(
             str(constants.DEFAULT_THREAD_POOL_PARALLELISM_DEGREE), ),
         "log_level_overrides": {}
     }
     self.opts = Namespace()
     self.opts.__dict__ = opts
     log_config.create_logger(None, LogLevel.WARNING)
     self.event_loop_mock = EventLoopMock()
Esempio n. 2
0
def get_gateway_opts(port,
                     node_id=None,
                     external_ip=constants.LOCALHOST,
                     blockchain_address=None,
                     test_mode=None,
                     peer_gateways=None,
                     peer_relays=None,
                     peer_transaction_relays=None,
                     split_relays=False,
                     protocol_version=1,
                     sid_expire_time=30,
                     bloxroute_version="bloxroute 1.5",
                     include_default_btc_args=False,
                     include_default_eth_args=False,
                     blockchain_network_num=constants.DEFAULT_NETWORK_NUM,
                     min_peer_gateways=0,
                     remote_blockchain_ip=None,
                     remote_blockchain_port=None,
                     connect_to_remote_blockchain=False,
                     is_internal_gateway=False,
                     is_gateway_miner=False,
                     enable_buffered_send=False,
                     encrypt_blocks=True,
                     parallelism_degree=1,
                     cookie_file_path=COOKIE_FILE_PATH,
                     blockchain_block_hold_timeout_s=30,
                     blockchain_block_recovery_timeout_s=30,
                     stay_alive_duration=30 * 60,
                     source_version="v1.1.1.1",
                     initial_liveliness_check=30,
                     block_interval=600,
                     **kwargs) -> Namespace:
    if node_id is None:
        node_id = "Gateway at {0}".format(port)
    if peer_gateways is None:
        peer_gateways = []
    if peer_relays is None:
        peer_relays = []
    if peer_transaction_relays is None:
        peer_transaction_relays = []
    if blockchain_address is None:
        blockchain_address = ("127.0.0.1", 7000
                              )  # not real, just a placeholder
    if test_mode is None:
        test_mode = []
    if remote_blockchain_ip is not None and remote_blockchain_port is not None:
        remote_blockchain_peer = (remote_blockchain_ip, remote_blockchain_port)
    else:
        remote_blockchain_peer = None

    partial_apply_args = locals().copy()
    for kwarg, arg in partial_apply_args["kwargs"].items():
        partial_apply_args[kwarg] = arg

    partial_apply_args["outbound_peers"] = peer_gateways + peer_relays

    opts = get_common_opts(**partial_apply_args)

    opts.__dict__.update({
        "node_type":
        NodeType.GATEWAY,
        "bloxroute_version":
        bloxroute_version,
        "blockchain_ip":
        blockchain_address[0],
        "blockchain_port":
        blockchain_address[1],
        "blockchain_protocol":
        "Bitcoin",
        "blockchain_network":
        "Mainnet",
        "test_mode":
        test_mode,
        "peer_gateways":
        peer_gateways,
        "peer_relays":
        peer_relays,
        "peer_transaction_relays":
        peer_transaction_relays,
        "split_relays":
        split_relays,
        "protocol_version":
        protocol_version,
        "blockchain_block_interval":
        block_interval,
        "blockchain_ignore_block_interval_count":
        3,
        "blockchain_block_recovery_timeout_s":
        blockchain_block_recovery_timeout_s,
        "blockchain_block_hold_timeout_s":
        blockchain_block_hold_timeout_s,
        "min_peer_gateways":
        min_peer_gateways,
        "remote_blockchain_ip":
        remote_blockchain_ip,
        "remote_blockchain_port":
        remote_blockchain_port,
        "remote_blockchain_peer":
        remote_blockchain_peer,
        "connect_to_remote_blockchain":
        connect_to_remote_blockchain,
        "is_internal_gateway":
        is_internal_gateway,
        "is_gateway_miner":
        is_gateway_miner,
        "encrypt_blocks":
        encrypt_blocks,
        "enable_buffered_send":
        enable_buffered_send,
        "compact_block":
        True,
        "compact_block_min_tx_count":
        BTC_COMPACT_BLOCK_DECOMPRESS_MIN_TX_COUNT,
        "tune_send_buffer_size":
        False,
        "dump_short_id_mapping_compression":
        False,
        "thread_pool_parallelism_degree":
        config.get_thread_pool_parallelism_degree(str(parallelism_degree)),
        "max_block_interval":
        10,
        "cookie_file_path":
        cookie_file_path,
        "config_update_interval":
        60,
        "blockchain_message_ttl":
        10,
        "remote_blockchain_message_ttl":
        10,
        "stay_alive_duration":
        stay_alive_duration,
        "initial_liveliness_check":
        initial_liveliness_check,
        "has_fully_updated_tx_service":
        False,
        "source_version":
        source_version,
        "require_blockchain_connection":
        True
    })

    if include_default_btc_args:
        opts.__dict__.update({
            "blockchain_net_magic": 12345,
            "blockchain_version": 23456,
            "blockchain_nonce": 0,
            "blockchain_services": 1,
        })
    if include_default_eth_args:
        opts.__dict__.update({
            "private_key":
            "294549f8629f0eeb2b8e01aca491f701f5386a9662403b485c4efe7d447dfba3",
            "node_public_key": None,
            "remote_public_key": None,
            "network_id": 1,
            "chain_difficulty": 4194304,
            "genesis_hash":
            "1e8ff5fd9d06ab673db775cf5c72a6b2d63171cd26fe1e6a8b9d2d696049c781",
            "no_discovery": True,
        })
    for key, val in kwargs.items():
        opts.__dict__[key] = val
    return opts
Esempio n. 3
0
def set_extensions_parallelism(
        degree: int = constants.DEFAULT_THREAD_POOL_PARALLELISM_DEGREE
) -> None:
    task_pool_proxy.init(config.get_thread_pool_parallelism_degree(
        str(degree)))
Esempio n. 4
0
def get_common_opts(
    port: int,
    external_ip: str = constants.LOCALHOST,
    node_id: Optional[str] = None,
    outbound_peers: Optional[List[OutboundPeerModel]] = None,
    blockchain_network_num: int = constants.ALL_NETWORK_NUM,
    block_confirmations_count: int = 2,
    final_tx_confirmations_count: int = 4,
    rpc_port: int = 28332,
    continent: str = "NA",
    country: str = "United States",
    region: str = "us-east-1",
    parallelism_degree: int = 1,
    split_relays: bool = False,
    sid_expire_time: int = 30,
    rpc: bool = False,
    transaction_validation: bool = True,
    rpc_use_ssl: bool = False,
    **kwargs,
) -> CommonOpts:
    if node_id is None:
        node_id = f"Node at {port}"
    if outbound_peers is None:
        outbound_peers = []

    arg_parser = argparse.ArgumentParser(add_help=False)
    cli.add_argument_parser_logging(arg_parser, default_log_level=LogLevel.DEBUG)
    opts = arg_parser.parse_args([])
    # opts = Namespace()
    opts.__dict__.update(
        {
            "external_ip": external_ip,
            "external_port": port,
            "node_id": node_id,
            "memory_stats_interval": 3600,
            "dump_detailed_report_at_memory_usage": 100,
            "dump_removed_short_ids": False,
            "dump_removed_short_ids_path": "",
            "transaction_pool_memory_limit": 200000000,
            "use_extensions": constants.USE_EXTENSION_MODULES,
            "import_extensions": constants.USE_EXTENSION_MODULES,
            "tx_mem_pool_bucket_size": constants.DEFAULT_TX_MEM_POOL_BUCKET_SIZE,
            "throughput_stats_interval": constants.THROUGHPUT_STATS_INTERVAL_S,
            "info_stats_interval": constants.INFO_STATS_INTERVAL_S,
            "sync_tx_service": True,
            "source_version": "v1.0.0",
            "non_ssl_port": 3000,
            "enable_node_cache": True,
            "rpc_port": rpc_port,
            "rpc_host": constants.LOCALHOST,
            "rpc_user": "",
            "rpc_password": "",
            "rpc_use_ssl": rpc_use_ssl,
            "rpc_ssl_base_url": "",
            "continent": continent,
            "country": country,
            "region": region,
            "hostname": "bxlocal",
            "sdn_url": f"{constants.LOCALHOST}:8080",
            "enable_buffered_send": False,
            "block_compression_debug": False,
            "enable_tcp_quickack": True,
            "thread_pool_parallelism_degree": config.get_thread_pool_parallelism_degree(
                str(parallelism_degree)
            ),
            "data_dir": config.get_default_data_path(),
            "ca_cert_url": "https://certificates.blxrbdn.com/ca",
            "private_ssl_base_url": "https://certificates.blxrbdn.com",
            "rpc": rpc,
            "transaction_validation": transaction_validation,
            "using_private_ip_connection": False,
        }
    )

    for key, val in kwargs.items():
        opts.__dict__[key] = val
    common_opts = CommonOpts.from_opts(opts)

    # some attributes are usually set by the node runner
    common_opts.__dict__.update({
        "node_type": AbstractNode.NODE_TYPE,
        "outbound_peers": outbound_peers,
        "sid_expire_time": sid_expire_time,
        "split_relays": split_relays,
        "blockchain_networks": {
            0: blockchain_network(
                "Bitcoin",
                "Mainnet",
                0,
                15,
                15,
                final_tx_confirmations_count,
                block_confirmations_count,
                ),
            1: blockchain_network(
                "Bitcoin",
                "Testnet",
                1,
                15,
                15,
                final_tx_confirmations_count,
                block_confirmations_count,
                ),
            4: blockchain_network(
                "BitcoinCash",
                "Testnet",
                4,
                15,
                15,
                24,
                block_confirmations_count,
            ),
            5: blockchain_network(
                "Ethereum",
                "Mainnet",
                5,
                5,
                5,
                24,
                block_confirmations_count,
            ),
            3: blockchain_network(
                "Ethereum",
                "Testnet",
                3,
                5,
                5,
                final_tx_confirmations_count,
                block_confirmations_count,
            ),
            33: blockchain_network(
                "Ontology",
                "Mainnet",
                33,
                5,
                5,
                final_tx_confirmations_count,
                block_confirmations_count,
            ),
            10: blockchain_network(
                "Ethereum",
                "BSC-Mainnet",
                10,
                5,
                5,
                24,
                block_confirmations_count,
            ),
        },
        "blockchain_network_num": blockchain_network_num,
    })
    return common_opts
Esempio n. 5
0
 def setUp(self):
     self.blockchain_network = helpers.blockchain_network(
         protocol="Bitcoin",
         network_name="Mainnet",
         network_num=1,
         block_interval=600,
         final_tx_confirmations_count=6)
     self.set_ssl_folder()
     opts = {
         "log_path":
         "",
         "to_stdout":
         True,
         "external_port":
         0,
         "external_ip":
         "1.1.1.1",
         "node_id":
         None,
         "blockchain_network":
         self.blockchain_network.network,
         "network_num":
         self.blockchain_network.network_num,
         "blockchain_protocol":
         self.blockchain_network.protocol,
         "blockchain_networks": {
             self.blockchain_network.network_num: self.blockchain_network
         },
         "log_level":
         LogLevel.INFO,
         "log_format":
         LogFormat.PLAIN,
         "log_flush_immediately":
         True,
         "log_fluentd_enable":
         False,
         "log_fluentd_host":
         None,
         "use_extensions":
         True,
         "log_fluentd_queue_size":
         1000,
         "thread_pool_parallelism_degree":
         config.get_thread_pool_parallelism_degree(
             str(constants.DEFAULT_THREAD_POOL_PARALLELISM_DEGREE), ),
         "log_level_overrides": {},
         "source_version":
         "v1.0.0",
         "ca_cert_url":
         self.ssl_folder_url,
         "private_ssl_base_url":
         self.ssl_folder_url,
         "data_dir":
         config.get_default_data_path(),
         "log_level_fluentd":
         LogLevel.DEBUG,
         "log_level_stdout":
         LogLevel.TRACE,
         "sdn_url":
         "https://localhost:8080",
     }
     for item in CommonOpts.__dataclass_fields__:
         if item not in opts:
             opts[item] = None
     self.opts = CommonOpts.from_opts(Namespace(**opts))
     log_config.create_logger(None, LogLevel.WARNING)
     self.event_loop_mock = EventLoopMock()