()
| 279 | |
| 280 | |
| 281 | def main() -> None: |
| 282 | parser = argparse.ArgumentParser() |
| 283 | parser.add_argument("config") |
| 284 | |
| 285 | args = parser.parse_args() |
| 286 | |
| 287 | with open(args.config, "r") as handler: |
| 288 | config = json.load(handler) |
| 289 | |
| 290 | # validate the endpoints |
| 291 | node_to_endpoint = {} |
| 292 | node_to_address = {} |
| 293 | for node_name, node_info in config["nodes"].items(): |
| 294 | if urlsplit(node_info["endpoint"]).scheme == "": |
| 295 | raise ValueError("'endpoint' must have the protocol defined") |
| 296 | |
| 297 | url_deposit = f"{node_info['endpoint']}/api/{API_VERSION}/address" |
| 298 | result = requests.get(url_deposit).json() |
| 299 | |
| 300 | if result["our_address"] != node_info["address"]: |
| 301 | raise ValueError( |
| 302 | f"Address mismatch, configuration {node_info['address']}, " |
| 303 | f"API response {result['our_address']}" |
| 304 | ) |
| 305 | |
| 306 | node_to_endpoint[node_name] = node_info["endpoint"] |
| 307 | node_to_address[node_name] = node_info["address"] |
| 308 | |
| 309 | nodeaddress_to_channelopenqueue: OpenQueue = defaultdict(list) |
| 310 | nodeaddress_to_channeldepositqueue: DepositQueue = defaultdict(list) |
| 311 | |
| 312 | # Schedule the requests to evenly distribute the load. This is important |
| 313 | # because as of 0.100.5 channel cannot be opened concurrently, by dividing |
| 314 | # the load evenly we make sure the channels are opened as fast as possible. |
| 315 | for token_address, channels_to_open in config["networks"].items(): |
| 316 | for channel in channels_to_open: |
| 317 | node1 = channel["node1"] |
| 318 | node2 = channel["node2"] |
| 319 | |
| 320 | participant1 = node_to_address[node1] |
| 321 | participant2 = node_to_address[node2] |
| 322 | |
| 323 | current_channel1 = channel_details( |
| 324 | node_to_endpoint[node1], token_address, participant2 |
| 325 | ) |
| 326 | current_channel2 = channel_details( |
| 327 | node_to_endpoint[node2], token_address, participant1 |
| 328 | ) |
| 329 | |
| 330 | nodes_are_synchronized = bool(current_channel1) == bool(current_channel2) |
| 331 | msg = ( |
| 332 | f"The channel must exist in both or neither of the nodes.\n" |
| 333 | f"{current_channel1}\n" |
| 334 | f"{current_channel2}" |
| 335 | ) |
| 336 | assert nodes_are_synchronized, msg |
| 337 | |
| 338 | if current_channel1 is None: |
no test coverage detected