# Buggy code
def __init__(self, config=None, autoload_discovery=True):
    """
    A Session object is created which is configured with the Tribler configuration object.

    Only a single session instance can exist at a time in a process.

    :param config: a TriblerConfig object or None, in which case we
    look for a saved session in the default location (state dir). If
    we can't find it, we create a new TriblerConfig() object to
    serve as startup config. Next, the config is saved in the directory
    indicated by its 'state_dir' attribute.
    :param autoload_discovery: only false in the Tunnel community tests
    """
    addObserver(self.unhandled_error_observer)

    patch_crypto_be_discovery()

    self._logger = logging.getLogger(self.__class__.__name__)

    self.session_lock = RLock()

    self.config = config or TriblerConfig()
    self._logger.info(
        "Session is using state directory: %s", self.config.get_state_dir()
    )

    self.get_ports_in_config()
    self.create_state_directory_structure()

    self.selected_ports = self.config.selected_ports

    self.init_keypair()

    self.lm = TriblerLaunchMany()
    self.notifier = Notifier()

    self.upgrader_enabled = True
    self.upgrader = None
    self.readable_status = ""  # Human-readable string to indicate the status during startup/shutdown of Tribler

    self.autoload_discovery = autoload_discovery


# Traceback (ValueError)
ERROR   1576450617.34                 community:695  (TriblerTunnelCommunity)  Exception occurred while handling packet!
Traceback (most recent call last):
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 692, in on_packet_from_circuit
self.decode_map_private[msg_id](source_address, data, circuit_id)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 76, in wrapper
return inner_wrapper(self, source_address, data)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/lazy_community.py", line 104, in wrapper
return func(self, source_address, *unpacked)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 74, in inner_wrapper
return func(inner_self, inner_source_address, *combo)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 774, in on_created
self._ours_on_created_extended(circuit, payload)
File "/home/tribler/tribler/Tribler/community/triblertunnel/community.py", line 447, in _ours_on_created_extended
super(TriblerTunnelCommunity, self)._ours_on_created_extended(circuit, payload)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 551, in _ours_on_created_extended
payload.auth, hop.public_key.key.pk)
File "/home/tribler/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/tunnelcrypto.py", line 51, in verify_and_generate_shared_secret
libnacl.crypto_auth_verify(auth, dh_received, shared_secret)
File "/home/tribler/.local/lib/python3.7/site-packages/libnacl/__init__.py", line 887, in crypto_auth_verify
raise ValueError('Invalid secret key')
ValueError: Invalid secret key

# Fixed code
def __init__(self, config=None, autoload_discovery=True):
    """
    A Session object is created which is configured with the Tribler configuration object.

    Only a single session instance can exist at a time in a process.

    :param config: a TriblerConfig object or None, in which case we
    look for a saved session in the default location (state dir). If
    we can't find it, we create a new TriblerConfig() object to
    serve as startup config. Next, the config is saved in the directory
    indicated by its 'state_dir' attribute.
    :param autoload_discovery: only false in the Tunnel community tests
    """
    addObserver(self.unhandled_error_observer)

    patch_crypto_be_discovery()

    self._logger = logging.getLogger(self.__class__.__name__)

    self.session_lock = RLock()

    self.config = config or TriblerConfig()
    self._logger.info(
        "Session is using state directory: %s", self.config.get_state_dir()
    )

    self.get_ports_in_config()
    self.create_state_directory_structure()

    self.selected_ports = self.config.selected_ports

    self.lm = TriblerLaunchMany()
    self.notifier = Notifier()

    self.upgrader_enabled = True
    self.upgrader = None
    self.readable_status = ""  # Human-readable string to indicate the status during startup/shutdown of Tribler

    self.autoload_discovery = autoload_discovery
    self.trustchain_keypair = None