def _initialize_whitelists(self, chain_state: ChainState): """ Whitelist neighbors and mediated transfer targets on transport """ for neighbour in views.all_neighbour_nodes(chain_state): if neighbour == ConnectionManager.BOOTSTRAP_ADDR: continue self.transport.whitelist(neighbour) events_queues = views.get_all_messagequeues(chain_state) for event_queue in events_queues.values(): for event in event_queue: if isinstance(event, SendLockedTransfer): transfer = event.transfer if transfer.initiator == self.address: self.transport.whitelist(address=transfer.target)
def _initialize_whitelists(self, chain_state: ChainState): """ Whitelist neighbors and mediated transfer targets on transport """ for neighbour in views.all_neighbour_nodes(chain_state): if neighbour == ConnectionManager.BOOTSTRAP_ADDR: continue self.transport.whitelist(neighbour) events_queues = views.get_all_messagequeues(chain_state) for event_queue in events_queues.values(): for event in event_queue: is_initiator = ( type(event) == SendLockedTransfer and event.transfer.initiator == self.address ) if is_initiator: self.transport.whitelist(address=event.transfer.target)
def _start_transport(self, chain_state: ChainState): """ Initialize the transport and related facilities. Note: The transport must not be started before the node has caught up with the blockchain through `AlarmTask.first_run()`. This synchronization includes the on-chain channel state and is necessary to reject new messages for closed channels. """ assert self.alarm.is_primed(), f"AlarmTask not primed. node:{self!r}" assert self.ready_to_process_events, f"Event procossing disable. node:{self!r}" self.transport.start( raiden_service=self, message_handler=self.message_handler, prev_auth_data=chain_state.last_transport_authdata, ) for neighbour in views.all_neighbour_nodes(chain_state): if neighbour != ConnectionManager.BOOTSTRAP_ADDR: self.start_health_check_for(neighbour)
def start_neighbours_healthcheck(self): for neighbour in views.all_neighbour_nodes( self.wal.state_manager.current_state): if neighbour != ConnectionManager.BOOTSTRAP_ADDR: self.start_health_check_for(neighbour)
def start_neighbours_healthcheck(self, chain_state: ChainState): for neighbour in views.all_neighbour_nodes(chain_state): if neighbour != ConnectionManager.BOOTSTRAP_ADDR: self.start_health_check_for(neighbour)
def get_best_routes( chain_state: ChainState, token_network_id: TokenNetworkID, one_to_n_address: Optional[Address], from_address: InitiatorAddress, to_address: TargetAddress, amount: PaymentAmount, previous_address: Optional[Address], config: Dict[str, Any], privkey: bytes, ) -> Tuple[List[RouteState], Optional[UUID]]: services_config = config.get("services", None) # the pfs should not be requested when the target is linked via a direct channel if to_address in views.all_neighbour_nodes(chain_state): neighbours = get_best_routes_internal( chain_state=chain_state, token_network_id=token_network_id, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, ) channel_state = views.get_channelstate_by_token_network_and_partner( chain_state=chain_state, token_network_id=token_network_id, partner_address=Address(to_address), ) for route_state in neighbours: if to_address == route_state.node_address and ( channel_state # other conditions about e.g. channel state are checked in best routes internal and channel.get_distributable( sender=channel_state.our_state, receiver=channel_state.partner_state) >= amount): return [route_state], None if (services_config and services_config["pathfinding_service_address"] is not None and one_to_n_address is not None): pfs_answer_ok, pfs_routes, pfs_feedback_token = get_best_routes_pfs( chain_state=chain_state, token_network_id=token_network_id, one_to_n_address=one_to_n_address, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, config=services_config, privkey=privkey, ) if pfs_answer_ok: log.info("Received route(s) from PFS", routes=pfs_routes, feedback_token=pfs_feedback_token) return pfs_routes, pfs_feedback_token else: log.warning("Request to Pathfinding Service was not successful, " "falling back to internal routing.") return ( get_best_routes_internal( chain_state=chain_state, token_network_id=token_network_id, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, ), None, )
def get_best_routes( chain_state: ChainState, token_network_address: TokenNetworkAddress, one_to_n_address: Optional[Address], from_address: InitiatorAddress, to_address: TargetAddress, amount: PaymentAmount, previous_address: Optional[Address], config: Dict[str, Any], privkey: bytes, ) -> Tuple[List[RouteState], Optional[UUID]]: pfs_config = config.get("pfs_config", None) is_direct_partner = to_address in views.all_neighbour_nodes(chain_state) can_use_pfs = pfs_config and one_to_n_address is not None log.debug( "Getting route for payment", source=to_checksum_address(from_address), target=to_checksum_address(to_address), amount=amount, target_is_direct_partner=is_direct_partner, can_use_pfs=can_use_pfs, ) # the pfs should not be requested when the target is linked via a direct channel if is_direct_partner: internal_routes = get_best_routes_internal( chain_state=chain_state, token_network_address=token_network_address, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, ) channel_state = views.get_channelstate_by_token_network_and_partner( chain_state=chain_state, token_network_address=token_network_address, partner_address=Address(to_address), ) for route_state in internal_routes: if to_address == route_state.next_hop_address and ( channel_state # other conditions about e.g. channel state are checked in best routes internal and channel.get_distributable( sender=channel_state.our_state, receiver=channel_state.partner_state) >= amount): return [route_state], None if can_use_pfs: assert one_to_n_address # mypy doesn't realize this has been checked above pfs_answer_ok, pfs_routes, pfs_feedback_token = get_best_routes_pfs( chain_state=chain_state, token_network_address=token_network_address, one_to_n_address=one_to_n_address, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, pfs_config=pfs_config, privkey=privkey, ) if pfs_answer_ok: log.info("Received route(s) from PFS", routes=pfs_routes, feedback_token=pfs_feedback_token) return pfs_routes, pfs_feedback_token else: log.warning("Request to Pathfinding Service was not successful, " "falling back to internal routing.") return ( get_best_routes_internal( chain_state=chain_state, token_network_address=token_network_address, from_address=from_address, to_address=to_address, amount=amount, previous_address=previous_address, ), None, )
def start_neighbours_healthcheck(self): for neighbour in views.all_neighbour_nodes(self.wal.state_manager.current_state): if neighbour != ConnectionManager.BOOTSTRAP_ADDR: self.start_health_check_for(neighbour)