# Buggy code
def __init__(
    self,
    rpc_client: JSONRPCClient,
    proxy_manager: ProxyManager,
    query_start_block: BlockNumber,
    default_registry: TokenNetworkRegistry,
    default_secret_registry: SecretRegistry,
    default_service_registry: Optional[ServiceRegistry],
    default_one_to_n_address: Optional[OneToNAddress],
    default_msc_address: Optional[MonitoringServiceAddress],
    transport: MatrixTransport,
    raiden_event_handler: EventHandler,
    message_handler: MessageHandler,
    routing_mode: RoutingMode,
    config: RaidenConfig,
    user_deposit: UserDeposit = None,
    api_server: Optional[APIServer] = None,
) -> None:
    super().__init__()
    self.tokennetworkaddrs_to_connectionmanagers: ConnectionManagerDict = dict()
    self.targets_to_identifiers_to_statuses: StatusesDict = defaultdict(dict)

    self.rpc_client = rpc_client
    self.proxy_manager = proxy_manager
    self.default_registry = default_registry
    self.query_start_block = query_start_block
    self.default_one_to_n_address = default_one_to_n_address
    self.default_secret_registry = default_secret_registry
    self.default_service_registry = default_service_registry
    self.default_msc_address = default_msc_address
    self.routing_mode = routing_mode
    self.config = config

    self.signer: Signer = LocalSigner(self.rpc_client.privkey)
    self.address = self.signer.address
    self.transport = transport

    self.user_deposit = user_deposit

    self.alarm = AlarmTask(
        proxy_manager=proxy_manager, sleep_time=self.config.blockchain.query_interval
    )
    self.raiden_event_handler = raiden_event_handler
    self.message_handler = message_handler
    self.blockchain_events: Optional[BlockchainEvents] = None

    self.api_server: Optional[APIServer] = api_server
    self.raiden_api: Optional[RaidenAPI] = None
    self.rest_api: Optional[RestAPI] = None
    if api_server is not None:
        self.raiden_api = RaidenAPI(self)
        self.rest_api = api_server.rest_api

    self.stop_event = Event()
    self.stop_event.set()  # inits as stopped
    self.greenlets: List[Greenlet] = list()

    self.last_log_time = datetime.now()
    self.last_log_block = BlockNumber(0)

    self.contract_manager = ContractManager(config.contracts_path)
    self.wal: Optional[WriteAheadLog] = None

    if self.config.database_path != ":memory:":
        database_dir = os.path.dirname(config.database_path)
        os.makedirs(database_dir, exist_ok=True)

        self.database_dir: Optional[str] = database_dir

        # Two raiden processes must not write to the same database. Even
        # though it's possible the database itself would not be corrupt,
        # the node's state could. If a database was shared among multiple
        # nodes, the database WAL would be the union of multiple node's
        # WAL. During a restart a single node can't distinguish its state
        # changes from the others, and it would apply it all, meaning that
        # a node would execute the actions of itself and the others.
        #
        # Additionally the database snapshots would be corrupt, because it
        # would not represent the effects of applying all the state changes
        # in order.
        lock_file = os.path.join(self.database_dir, ".lock")
        self.db_lock = filelock.FileLock(lock_file)
    else:
        self.database_dir = None
        self.serialization_file = None
        self.db_lock = None

    self.payment_identifier_lock = gevent.lock.Semaphore()

    # A list is not hashable, so use tuple as key here
    self.route_to_feedback_token: Dict[Tuple[Address, ...], UUID] = dict()

    # Flag used to skip the processing of all Raiden events during the
    # startup.
    #
    # Rationale: At the startup, the latest snapshot is restored and all
    # state changes which are not 'part' of it are applied. The criteria to
    # re-apply the state changes is their 'absence' in the snapshot, /not/
    # their completeness. Because these state changes are re-executed
    # in-order and some of their side-effects will already have been
    # completed, the events should be delayed until the state is
    # synchronized (e.g. an open channel state change, which has already
    # been mined).
    #
    # Incomplete events, i.e. the ones which don't have their side-effects
    # applied, will be executed once the blockchain state is synchronized
    # because of the node's queues.
    self.ready_to_process_events = False


# Traceback (urllib3.exceptions.ReadTimeoutError)
Traceback (most recent call last):
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1344, in getresponse
response.begin()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/gevent/_socket3.py", line 496, in recv_into
self._wait(self._read_event)
File "src/gevent/_hub_primitives.py", line 290, in gevent.__hub_primitives.wait_on_socket
File "src/gevent/_hub_primitives.py", line 295, in gevent.__hub_primitives.wait_on_socket
File "src/gevent/_hub_primitives.py", line 286, in gevent.__hub_primitives._primitive_wait
File "src/gevent/_hub_primitives.py", line 287, in gevent.__hub_primitives._primitive_wait
File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_hub_primitives.py", line 55, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_waiter.py", line 151, in gevent.__waiter.Waiter.get
File "src/gevent/_greenlet_primitives.py", line 61, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_greenlet_primitives.py", line 61, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_greenlet_primitives.py", line 65, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/util/retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/packages/six.py", line 686, in reraise
raise value
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 389, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 307, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='geth.mainnet.ethnodes.brainbot.com', port=8545): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/cli.py", line 610, in run
run_services(kwargs)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/runners.py", line 21, in run_services
app = run_app(**options)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/app.py", line 438, in run_app
raiden_app.start()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/app.py", line 91, in start
self.raiden.start()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 364, in start
self._synchronize_with_blockchain()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 670, in _synchronize_with_blockchain
self._poll_until_target(latest_confirmed_block_number)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 993, in _poll_until_target
poll_result = self.blockchain_events.fetch_logs_in_batch(target_block_number)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/blockchain/events.py", line 488, in fetch_logs_in_batch
decoded_result = self._query_and_track(from_block, to_block)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/blockchain/events.py", line 556, in _query_and_track
RPCEndpoint("eth_getLogs"), [filter_params]
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/manager.py", line 149, in request_blocking
response = self._make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/manager.py", line 128, in _make_request
return request_func(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/cache.py", line 134, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/gas_price_strategy.py", line 34, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/attrdict.py", line 33, in middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/normalize_errors.py", line 25, in middleware
result = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 75, in apply_formatters
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 75, in apply_formatters
response = make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/exception_retry_request.py", line 104, in middleware
return make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/providers/rpc.py", line 83, in make_request
**self.get_request_kwargs()
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/_utils/request.py", line 34, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs)  # type: ignore
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='geth.mainnet.ethnodes.brainbot.com', port=8545): Read timed out. (read timeout=10)

# Fixed code
def __init__(
    self,
    rpc_client: JSONRPCClient,
    proxy_manager: ProxyManager,
    query_start_block: BlockNumber,
    default_registry: TokenNetworkRegistry,
    default_secret_registry: SecretRegistry,
    default_service_registry: Optional[ServiceRegistry],
    default_one_to_n_address: Optional[OneToNAddress],
    default_msc_address: Optional[MonitoringServiceAddress],
    transport: MatrixTransport,
    raiden_event_handler: EventHandler,
    message_handler: MessageHandler,
    routing_mode: RoutingMode,
    config: RaidenConfig,
    user_deposit: UserDeposit = None,
    api_server: Optional[APIServer] = None,
) -> None:
    super().__init__()
    self.tokennetworkaddrs_to_connectionmanagers: ConnectionManagerDict = dict()
    self.targets_to_identifiers_to_statuses: StatusesDict = defaultdict(dict)

    self.rpc_client = rpc_client
    self.proxy_manager = proxy_manager
    self.default_registry = default_registry
    self.query_start_block = query_start_block
    self.default_one_to_n_address = default_one_to_n_address
    self.default_secret_registry = default_secret_registry
    self.default_service_registry = default_service_registry
    self.default_msc_address = default_msc_address
    self.routing_mode = routing_mode
    self.config = config

    self.signer: Signer = LocalSigner(self.rpc_client.privkey)
    self.address = self.signer.address
    self.transport = transport

    self.user_deposit = user_deposit

    self.alarm = AlarmTask(
        proxy_manager=proxy_manager, sleep_time=self.config.blockchain.query_interval
    )
    self.raiden_event_handler = raiden_event_handler
    self.message_handler = message_handler
    self.blockchain_events: Optional[BlockchainEvents] = None

    self.api_server: Optional[APIServer] = api_server
    self.raiden_api: Optional[RaidenAPI] = None
    self.rest_api: Optional[RestAPI] = None
    if api_server is not None:
        self.raiden_api = RaidenAPI(self)
        self.rest_api = api_server.rest_api

    self.stop_event = Event()
    self.stop_event.set()  # inits as stopped
    self.greenlets: List[Greenlet] = list()

    self.last_log_time = time.monotonic()
    self.last_log_block = BlockNumber(0)

    self.contract_manager = ContractManager(config.contracts_path)
    self.wal: Optional[WriteAheadLog] = None

    if self.config.database_path != ":memory:":
        database_dir = os.path.dirname(config.database_path)
        os.makedirs(database_dir, exist_ok=True)

        self.database_dir: Optional[str] = database_dir

        # Two raiden processes must not write to the same database. Even
        # though it's possible the database itself would not be corrupt,
        # the node's state could. If a database was shared among multiple
        # nodes, the database WAL would be the union of multiple node's
        # WAL. During a restart a single node can't distinguish its state
        # changes from the others, and it would apply it all, meaning that
        # a node would execute the actions of itself and the others.
        #
        # Additionally the database snapshots would be corrupt, because it
        # would not represent the effects of applying all the state changes
        # in order.
        lock_file = os.path.join(self.database_dir, ".lock")
        self.db_lock = filelock.FileLock(lock_file)
    else:
        self.database_dir = None
        self.serialization_file = None
        self.db_lock = None

    self.payment_identifier_lock = gevent.lock.Semaphore()

    # A list is not hashable, so use tuple as key here
    self.route_to_feedback_token: Dict[Tuple[Address, ...], UUID] = dict()

    # Flag used to skip the processing of all Raiden events during the
    # startup.
    #
    # Rationale: At the startup, the latest snapshot is restored and all
    # state changes which are not 'part' of it are applied. The criteria to
    # re-apply the state changes is their 'absence' in the snapshot, /not/
    # their completeness. Because these state changes are re-executed
    # in-order and some of their side-effects will already have been
    # completed, the events should be delayed until the state is
    # synchronized (e.g. an open channel state change, which has already
    # been mined).
    #
    # Incomplete events, i.e. the ones which don't have their side-effects
    # applied, will be executed once the blockchain state is synchronized
    # because of the node's queues.
    self.ready_to_process_events = False