Returns a ValidatorConfig created by loading a TOML file from the
    filesystem.

def load_toml_validator_config(filename):
    """Returns a ValidatorConfig created by loading a TOML file from the
    filesystem.
    """
    if not os.path.exists(filename):
        LOGGER.info(
            "Skipping validator config loading from non-existent config file:"
            " %s", filename)
        return ValidatorConfig()

    LOGGER.info("Loading validator information from config: %s", filename)

    try:
        with open(filename) as fd:
            raw_config = fd.read()
    except IOError as e:
        raise LocalConfigurationError(
            "Unable to load validator configuration file: {}".format(str(e)))

    toml_config = toml.loads(raw_config)
    invalid_keys = set(toml_config.keys()).difference(
        ['bind', 'endpoint', 'peering', 'seeds', 'peers', 'network_public_key',
         'network_private_key', 'scheduler', 'permissions', 'roles',
         'opentsdb_url', 'opentsdb_db', 'opentsdb_username',
         'opentsdb_password', 'minimum_peer_connectivity',
         'maximum_peer_connectivity', 'state_pruning_block_depth',
         'fork_cache_keep_time',
         'component_thread_pool_workers', 'network_thread_pool_workers',
         'signature_thread_pool_workers'])
    if invalid_keys:
        raise LocalConfigurationError(
            "Invalid keys in validator config: "
            "{}".format(", ".join(sorted(list(invalid_keys)))))
    bind_network = None
    bind_component = None
    bind_consensus = None
    for bind in toml_config.get("bind", []):
        if "network" in bind:
            bind_network = bind[bind.find(":") + 1:]
        if "component" in bind:
            bind_component = bind[bind.find(":") + 1:]
        if "consensus" in bind:
            bind_consensus = bind[bind.find(":") + 1:]

    network_public_key = None
    network_private_key = None

    if toml_config.get("network_public_key") is not None:
        network_public_key = toml_config.get("network_public_key").encode()

    if toml_config.get("network_private_key") is not None:
        network_private_key = toml_config.get("network_private_key").encode()

    config = ValidatorConfig(
        bind_network=bind_network,
        bind_component=bind_component,
        bind_consensus=bind_consensus,
        endpoint=toml_config.get("endpoint", None),
        peering=toml_config.get("peering", None),
        seeds=toml_config.get("seeds", None),
        peers=toml_config.get("peers", None),
        network_public_key=network_public_key,
        network_private_key=network_private_key,
        scheduler=toml_config.get("scheduler", None),
        permissions=parse_permissions(toml_config.get("permissions", None)),
        roles=toml_config.get("roles", None),
        opentsdb_url=toml_config.get("opentsdb_url", None),
        opentsdb_db=toml_config.get("opentsdb_db", None),
        opentsdb_username=toml_config.get("opentsdb_username", None),
        opentsdb_password=toml_config.get("opentsdb_password", None),
        minimum_peer_connectivity=toml_config.get(
            "minimum_peer_connectivity", None),
        maximum_peer_connectivity=toml_config.get(
            "maximum_peer_connectivity", None),
        state_pruning_block_depth=toml_config.get(
            "state_pruning_block_depth", None),
        fork_cache_keep_time=toml_config.get(
            "fork_cache_keep_time", None),
        component_thread_pool_workers=toml_config.get(
            "component_thread_pool_workers", None),
        network_thread_pool_workers=toml_config.get(
            "network_thread_pool_workers", None),
        signature_thread_pool_workers=toml_config.get(
            "signature_thread_pool_workers", None)
    )

    return config