Wait until the nodes used for the transfers can see each other.
(
transfers: List[TransferPath], token_address: str, retry_timeout: int
)
| 201 | |
| 202 | |
| 203 | def wait_for_reachable( |
| 204 | transfers: List[TransferPath], token_address: str, retry_timeout: int |
| 205 | ) -> None: |
| 206 | """Wait until the nodes used for the transfers can see each other.""" |
| 207 | |
| 208 | # Deduplicate the URLs for the channels which need reachability testing |
| 209 | channels_not_reachable = set() |
| 210 | for transfer in transfers: |
| 211 | for payer, payee in zip(transfer, transfer[1:]): |
| 212 | channel_url = f"{payer.url}/api/v1/channels/{token_address}/{payee.config.address}" |
| 213 | channels_not_reachable.add(channel_url) |
| 214 | |
| 215 | # Now wait until every reachability constraint is satisfied |
| 216 | while channels_not_reachable: |
| 217 | log.info(f"Waiting for reachability of partner nodes: {channels_not_reachable}") |
| 218 | |
| 219 | for url in channels_not_reachable.copy(): |
| 220 | response = requests.get(url, headers={"Content-Type": "application/json"}) |
| 221 | data = response.json() |
| 222 | |
| 223 | # The return data **may** be `None`, this looks like a race |
| 224 | # condition in the Raiden client REST API. |
| 225 | if data and data.get("network_state") == NetworkState.REACHABLE.value: |
| 226 | channels_not_reachable.remove(url) |
| 227 | |
| 228 | if channels_not_reachable: |
| 229 | gevent.sleep(retry_timeout) |
| 230 | |
| 231 | |
| 232 | def start_and_wait_for_server( |
no test coverage detected