345 lines
12 KiB
Python
Raw Normal View History

chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
import errno
import json
2023-11-01 14:02:29 +02:00
import os
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
import string
import pytest
import requests
from src.libs.common import delay
from src.libs.custom_logger import get_custom_logger
2023-11-01 14:02:29 +02:00
from tenacity import retry, stop_after_delay, wait_fixed
2023-11-03 17:01:00 +02:00
from src.node.api_clients.rest import REST
2023-11-01 14:02:29 +02:00
from src.node.docker_mananger import DockerManager
from src.env_vars import DOCKER_LOG_DIR
2023-11-01 14:02:29 +02:00
from src.data_storage import DS
logger = get_custom_logger(__name__)
2023-11-01 14:02:29 +02:00
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
def select_private_key(prv_keys, key_id):
for key in prv_keys:
if key.endswith(key_id):
return key
raise ValueError("No matching key was found")
def sanitize_docker_flags(input_flags):
output_flags = {}
for key, value in input_flags.items():
key = key.replace("_", "-")
output_flags[key] = value
return output_flags
@retry(stop=stop_after_delay(120), wait=wait_fixed(0.5), reraise=True)
def rln_credential_store_ready(creds_file_path):
if os.path.exists(creds_file_path):
return True
else:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), creds_file_path)
2023-11-01 14:02:29 +02:00
class WakuNode:
2023-11-01 16:44:42 +02:00
def __init__(self, docker_image, docker_log_prefix=""):
2023-11-01 14:02:29 +02:00
self._image_name = docker_image
self._log_path = os.path.join(DOCKER_LOG_DIR, f"{docker_log_prefix}__{self._image_name.replace('/', '_')}.log")
2023-11-01 14:02:29 +02:00
self._docker_manager = DockerManager(self._image_name)
self._container = None
logger.debug(f"WakuNode instance initialized with log path {self._log_path}")
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def start(self, **kwargs):
logger.debug("Starting Node...")
self._docker_manager.create_network()
2023-11-01 14:02:29 +02:00
self._ext_ip = self._docker_manager.generate_random_ext_ip()
2023-11-03 17:01:00 +02:00
self._ports = self._docker_manager.generate_ports()
self._rest_port = self._ports[0]
self._tcp_port = self._ports[1]
self._websocket_port = self._ports[2]
self._discv5_port = self._ports[3]
self._metrics_port = self._ports[4]
self._api = REST(self._rest_port)
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
self._volumes = []
2023-11-01 14:02:29 +02:00
default_args = {
"listen-address": "0.0.0.0",
2023-11-03 17:01:00 +02:00
"rest": "true",
"rest-admin": "true",
2023-11-01 14:02:29 +02:00
"websocket-support": "true",
"log-level": "TRACE",
"rest-relay-cache-capacity": "100",
"websocket-port": self._websocket_port,
2023-11-03 17:01:00 +02:00
"rest-port": self._rest_port,
"tcp-port": self._tcp_port,
"discv5-udp-port": self._discv5_port,
2023-11-03 17:01:00 +02:00
"rest-address": "0.0.0.0",
2023-11-01 14:02:29 +02:00
"nat": f"extip:{self._ext_ip}",
"peer-exchange": "true",
"discv5-discovery": "true",
"cluster-id": "0",
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
"rln-creds-id": None,
"rln-creds-source": None,
2023-11-01 14:02:29 +02:00
}
if self.is_gowaku():
2023-11-01 14:02:29 +02:00
go_waku_args = {
"min-relay-peers-to-publish": "1",
2023-11-01 14:02:29 +02:00
"log-level": "DEBUG",
"rest-filter-cache-capacity": "50",
2023-11-01 14:02:29 +02:00
}
default_args.update(go_waku_args)
elif self.is_nwaku():
nwaku_args = {
"metrics-server": "true",
"metrics-server-address": "0.0.0.0",
"metrics-server-port": self._metrics_port,
"metrics-logging": "true",
}
default_args.update(nwaku_args)
else:
raise NotImplementedError("Not implemented for this node type")
2023-11-01 14:02:29 +02:00
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
default_args.update(sanitize_docker_flags(kwargs))
rln_args, rln_creds_set, keystore_path = self.parse_rln_credentials(default_args, False)
del default_args["rln-creds-id"]
del default_args["rln-creds-source"]
if rln_creds_set:
rln_credential_store_ready(keystore_path)
default_args.update(rln_args)
else:
logger.info(f"RLN credentials not set or credential store not available, starting without RLN")
self._container = self._docker_manager.start_container(
self._docker_manager.image, self._ports, default_args, self._log_path, self._ext_ip, self._volumes
)
2023-11-01 14:02:29 +02:00
logger.debug(f"Started container from image {self._image_name}. REST: {self._rest_port}")
2023-11-01 14:02:29 +02:00
DS.waku_nodes.append(self)
delay(1) # if we fire requests to soon after starting the node will sometimes fail to start correctly
2023-11-01 14:02:29 +02:00
try:
2023-11-03 17:01:00 +02:00
self.ensure_ready()
except Exception as ex:
logger.error(f"REST service did not become ready in time: {ex}")
2023-11-01 14:02:29 +02:00
raise
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
@retry(stop=stop_after_delay(250), wait=wait_fixed(0.1), reraise=True)
def register_rln(self, **kwargs):
logger.debug("Registering RLN credentials...")
self._docker_manager.create_network()
self._ext_ip = self._docker_manager.generate_random_ext_ip()
self._ports = self._docker_manager.generate_ports()
self._rest_port = self._ports[0]
self._api = REST(self._rest_port)
self._volumes = []
default_args = {
"rln-creds-id": None,
"rln-creds-source": None,
}
default_args.update(sanitize_docker_flags(kwargs))
rln_args, rln_creds_set, keystore_path = self.parse_rln_credentials(default_args, True)
if rln_creds_set:
self._container = self._docker_manager.start_container(
self._docker_manager.image, self._ports, rln_args, self._log_path, self._ext_ip, self._volumes
)
logger.debug(f"Executed container from image {self._image_name}. REST: {self._rest_port} to register RLN")
logger.debug(f"Waiting for keystore {keystore_path}")
try:
rln_credential_store_ready(keystore_path)
except Exception as ex:
logger.error(f"File {keystore_path} with RLN credentials did not become available in time {ex}")
raise
else:
logger.warn("RLN credentials not set, no action performed")
2023-11-01 14:02:29 +02:00
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def stop(self):
if self._container:
logger.debug(f"Stopping container with id {self._container.short_id}")
2023-11-01 14:02:29 +02:00
self._container.stop()
self._container = None
2023-11-01 14:02:29 +02:00
logger.debug("Container stopped.")
def restart(self):
if self._container:
logger.debug(f"Restarting container with id {self._container.short_id}")
self._container.restart()
def pause(self):
if self._container:
logger.debug(f"Pausing container with id {self._container.short_id}")
self._container.pause()
def unpause(self):
if self._container:
logger.debug(f"Unpause container with id {self._container.short_id}")
self._container.unpause()
@retry(stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True)
2023-11-03 17:01:00 +02:00
def ensure_ready(self):
self.info_response = self.info()
logger.info("REST service is ready !!")
2023-11-01 14:02:29 +02:00
def get_enr_uri(self):
try:
return self.info_response["enrUri"]
except Exception as ex:
raise AttributeError(f"Could not find enrUri in the info call because of error: {str(ex)}")
def get_multiaddr_with_id(self):
addresses = self.info_response.get("listenAddresses", [])
ws_address = next((addr for addr in addresses if "/ws" not in addr), None)
if ws_address:
identifier = ws_address.split("/p2p/")[-1]
new_address = f"/ip4/{self._ext_ip}/tcp/{self._tcp_port}/p2p/{identifier}"
return new_address
else:
raise AttributeError("No '/ws' address found")
2023-11-01 14:02:29 +02:00
def info(self):
2023-11-03 17:01:00 +02:00
return self._api.info()
2023-11-01 14:02:29 +02:00
def get_peers(self):
return self._api.get_peers()
def add_peers(self, peers):
return self._api.add_peers(peers)
def set_relay_subscriptions(self, pubsub_topics):
return self._api.set_relay_subscriptions(pubsub_topics)
2023-11-01 14:02:29 +02:00
def set_relay_auto_subscriptions(self, content_topics):
return self._api.set_relay_auto_subscriptions(content_topics)
def delete_relay_subscriptions(self, pubsub_topics):
return self._api.delete_relay_subscriptions(pubsub_topics)
def delete_relay_auto_subscriptions(self, content_topics):
return self._api.delete_relay_auto_subscriptions(content_topics)
def send_relay_message(self, message, pubsub_topic):
return self._api.send_relay_message(message, pubsub_topic)
def send_relay_auto_message(self, message):
return self._api.send_relay_auto_message(message)
def get_relay_messages(self, pubsub_topic):
return self._api.get_relay_messages(pubsub_topic)
def get_relay_auto_messages(self, content_topic):
return self._api.get_relay_auto_messages(content_topic)
def set_filter_subscriptions(self, subscription):
return self._api.set_filter_subscriptions(subscription)
def update_filter_subscriptions(self, subscription):
return self._api.update_filter_subscriptions(subscription)
2023-11-01 14:02:29 +02:00
def delete_filter_subscriptions(self, subscription):
return self._api.delete_filter_subscriptions(subscription)
def delete_all_filter_subscriptions(self, request_id):
return self._api.delete_all_filter_subscriptions(request_id)
def ping_filter_subscriptions(self, request_id):
return self._api.ping_filter_subscriptions(request_id)
def get_filter_messages(self, content_topic, pubsub_topic=None):
return self._api.get_filter_messages(content_topic, pubsub_topic)
def get_metrics(self):
if self.is_nwaku():
metrics = requests.get(f"http://localhost:{self._metrics_port}/metrics")
metrics.raise_for_status()
return metrics.content.decode("utf-8")
else:
pytest.skip(f"This method doesn't exist for node {self.type()}")
@property
def image(self):
return self._image_name
def type(self):
if self.is_nwaku():
return "nwaku"
elif self.is_gowaku():
return "gowaku"
else:
raise ValueError("Unknown node type!!!")
def is_nwaku(self):
return "nwaku" in self.image
def is_gowaku(self):
return "go-waku" in self.image
chore: RLN registration support (#16) * chore: parameters and volumes for RLN relay * chore: add startup test for RLN * fix: remove redundant rln_enabled from WakuNode * fix: - and _ magic in rln parameters * fix: key 'eth_testnet_key' -> 'eth_client_private_key' * fix: rln-register_only -> rln-register-only * fix: use extend instead of append for the volumes list * fix: use absolute path for the volumes names - mark volumes shared across containers * fix: remove :z attr from volumes * fix: remove filename from volume path * fix: remove request for ENR * test: plain RLN registration * fix: remove subscribe * fix: remove ENR related params * test: add run_container func to Docker Mananger * fix: remove run_container func from Docker Mananger - no need for exec * fix: pass exec commands instead of specialized docker exec func * fix: exclude RLN arguments from others * fix: separate RLN volumes by implementation * test: registration with nwaku * test: registration over existing credentials * test: add RLN Relay node startup * test: RLN credentials reuse for relay node startup * fix: clean up unnecessary commands * fix: clean up unnecessary commands for non RLN relay too * test: regression by sending one valid message * fix: add forgotten call to get enr_uri * fix: check RLN credentials set properly * fix: parenthesis in eval expression * fix: better check for RLN credentials * fix: update to new flags - gowaku - separate private key for go/nwaku * test: register RLN * fix: RLN credentials check * fix: remove enable rln-relay flag from registration * test: reorder commands to check go-waku registration * fix: restructure if statements for RLN registration * fix: different set of flag for RLN registration and operation * fix: forgotten "eth" in eth-contract-address * fix: remove redundant None from get_env_var call * fix: refactor rln credentials parsing from start function * fix: missed second return value * test: call to parse_rln_credentials * fix: remove redundant self in call to parse_rln_credentials * fix: remove rln related values if not valid * fix: refactored to accept multiple private keys - JSON source for RLN credentials - removed go-waku support for RLN * test: register RLN with 2 nwaku nodes * fix: missing open file, key errors * fix: return effective keystore_path * fix: cleanup unused env variables * fix: cleanup unused env variables from relay * fix: wait longer for credentials file to be written to disk * test: remove waiting for credentials file to be written to disk * fix: add select_private_key() * fix: merge parse_rln_credentials and parse_rln_registration_credentials * test: wait for filesystem cache * test: try with os.sync to flush cache * test: stop container to clear cache * fix: 15 sec wait + stop container to clear cache * test: RLN registration test with fixture and cred file check * test: added allure.step - RLN registration for single node - corresponding test to register all keys * fix: f-strings in the test * fix: sync naming for register_main_rln_relay_nodes * fix: add WARN message to log unset and expected RLN credentials * fix: pytest.skip added to exit tests when non nwaku image is used * fix: swap NODE2 for DEFAULT_NWAKU * fix: let rln_credential_store_ready to raise exception for retry * fix: let register_rln to raise exception too, when credential fine still not available * fix: remove container stop * fix: tune down retry timeouts * fix: remove unnecessary f-string * test: reduce unnecessary variables init * test: undo reduce unnecessary variables init * test: increase timeout for rln_credential_store_ready * test: refactor kwargs handling into sanitize_docker_flags * fix: created RLN registration check - changed rln_credential_store_ready to function * fix: delete unnecessary ports from register_rln init * fix: remove wait for registration entirely * test: RLN_CREDENTIALS env var example * fix: check_rln_registration to raise exception * fix: use f-string at check_rln_registration * fix: add gen_step_id function * fix: RLN_CREDENTIALS as loaded from .env * fix: RLN_CREDENTIALS example, skipping test if not set * test: RLN with actions * fix: tune up RLN timeouts for Github runners * test: filesystem write to / * fix: change RLN data to be stored at working directory * fix: catch exception instead of "if not" - print out container log * fix: wrap logs into debug msg * fix: print log file * fix: remove additional logging * fix: exit RLN cred parsing sooner when not used - delete proper keys from default_args * fix: Allure report * fix: Discord notifications * fix: remove f-string * fix: delete test workflow
2024-02-13 22:01:30 +08:00
def parse_rln_credentials(self, default_args, is_registration):
rln_args = {}
keystore_path = None
rln_creds_source = default_args["rln-creds-source"]
selected_id = default_args["rln-creds-id"]
if rln_creds_source is None or selected_id is None:
logger.debug(f"RLN credentials were not set")
return rln_args, False, keystore_path
imported_creds = json.loads(rln_creds_source)
if len(imported_creds) < 4 or any(value is None for value in imported_creds.values()):
logger.warn(f"One or more of required RLN credentials were not set properly")
return rln_args, False, keystore_path
eth_private_key = select_private_key(imported_creds, selected_id)
current_working_directory = os.getcwd()
if self.is_nwaku():
if is_registration:
rln_args.update(
{
"generateRlnKeystore": None,
"--execute": None,
}
)
else:
rln_args.update(
{
"rln-relay": "true",
}
)
rln_args.update(
{
"rln-relay-cred-path": "/keystore/keystore.json",
"rln-relay-cred-password": imported_creds["rln-relay-cred-password"],
"rln-relay-eth-client-address": imported_creds["rln-relay-eth-client-address"],
"rln-relay-eth-contract-address": imported_creds["rln-relay-eth-contract-address"],
"rln-relay-eth-private-key": imported_creds[eth_private_key],
}
)
keystore_path = current_working_directory + "/keystore_" + selected_id + "/keystore.json"
self._volumes.extend(
[
current_working_directory + "/rln_tree_" + selected_id + ":/etc/rln_tree",
current_working_directory + "/keystore_" + selected_id + ":/keystore",
]
)
else:
raise NotImplementedError("Not implemented for type other than Nim Waku ")
return rln_args, True, keystore_path