From b3418cf1545378d4b412966b9c33f650141aec04 Mon Sep 17 00:00:00 2001 From: franjoespejo Date: Fri, 2 Feb 2024 12:54:49 +0100 Subject: [PATCH] feat: blockscout support with sc verification (#481) addresses #372 --------- Co-authored-by: franjoespejo --- .github/tests/mix-with-tools-mev.yaml | 1 + .github/tests/mix-with-tools.yaml | 1 + README.md | 1 + main.star | 12 ++- src/blockscout/blockscout_launcher.star | 131 ++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/blockscout/blockscout_launcher.star diff --git a/.github/tests/mix-with-tools-mev.yaml b/.github/tests/mix-with-tools-mev.yaml index d20500b15..51aaccc45 100644 --- a/.github/tests/mix-with-tools-mev.yaml +++ b/.github/tests/mix-with-tools-mev.yaml @@ -21,6 +21,7 @@ additional_services: - goomy_blob - custom_flood - blobscan + - blockscout ethereum_metrics_exporter_enabled: true snooper_enabled: true mev_type: full diff --git a/.github/tests/mix-with-tools.yaml b/.github/tests/mix-with-tools.yaml index 2853d3a18..52afabd67 100644 --- a/.github/tests/mix-with-tools.yaml +++ b/.github/tests/mix-with-tools.yaml @@ -21,5 +21,6 @@ additional_services: - goomy_blob - custom_flood - blobscan + - blockscout ethereum_metrics_exporter_enabled: true snooper_enabled: true diff --git a/README.md b/README.md index 7fb2f0f49..1c5a832cd 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,7 @@ additional_services: - custom_flood - goomy_blob - el_forkmon + - blockscout - beacon_metrics_gazer - dora - full_beaconchain_explorer diff --git a/main.star b/main.star index 9ccb88719..bef06e591 100644 --- a/main.star +++ b/main.star @@ -25,6 +25,7 @@ blobscan = import_module("./src/blobscan/blobscan_launcher.star") full_beaconchain_explorer = import_module( "./src/full_beaconchain/full_beaconchain_launcher.star" ) +blockscout = import_module("./src/blockscout/blockscout_launcher.star") prometheus = import_module("./src/prometheus/prometheus_launcher.star") grafana = import_module("./src/grafana/grafana_launcher.star") mev_boost = import_module("./src/mev/mev_boost/mev_boost_launcher.star") @@ -68,7 +69,6 @@ def run(plan, args={}): static_files.GRAFANA_DASHBOARD_PROVIDERS_CONFIG_TEMPLATE_FILEPATH ) prometheus_additional_metrics_jobs = [] - raw_jwt_secret = read_file(static_files.JWT_PATH_FILEPATH) jwt_file = plan.upload_files( src=static_files.JWT_PATH_FILEPATH, @@ -326,6 +326,12 @@ def run(plan, args={}): beacon_metrics_gazer_prometheus_metrics_job ) plan.print("Successfully launched beacon metrics gazer") + elif additional_service == "blockscout": + plan.print("Launching blockscout") + blockscout_sc_verif_url = blockscout.launch_blockscout( + plan, all_el_client_contexts, persistent + ) + plan.print("Successfully launched blockscout") elif additional_service == "dora": plan.print("Launching dora") dora_config_template = read_file(static_files.DORA_CONFIG_TEMPLATE_FILEPATH) @@ -434,8 +440,12 @@ def run(plan, args={}): user=GRAFANA_USER, password=GRAFANA_PASSWORD, ) + output = struct( grafana_info=grafana_info, + blockscout_sc_verif_url=None + if ("blockscout" in args_with_right_defaults.additional_services) == False + else blockscout_sc_verif_url, all_participants=all_participants, final_genesis_timestamp=final_genesis_timestamp, genesis_validators_root=genesis_validators_root, diff --git a/src/blockscout/blockscout_launcher.star b/src/blockscout/blockscout_launcher.star new file mode 100644 index 000000000..23ce9a366 --- /dev/null +++ b/src/blockscout/blockscout_launcher.star @@ -0,0 +1,131 @@ +shared_utils = import_module("../shared_utils/shared_utils.star") +constants = import_module("../package_io/constants.star") +postgres = import_module("github.com/kurtosis-tech/postgres-package/main.star") + +IMAGE_NAME_BLOCKSCOUT = "blockscout/blockscout:6.0.0" +IMAGE_NAME_BLOCKSCOUT_VERIF = "ghcr.io/blockscout/smart-contract-verifier:v1.6.0" + +SERVICE_NAME_BLOCKSCOUT = "blockscout" + +HTTP_PORT_ID = "http" +HTTP_PORT_NUMBER = 4000 +HTTP_PORT_NUMBER_VERIF = 8050 + +BLOCKSCOUT_MIN_CPU = 100 +BLOCKSCOUT_MAX_CPU = 1000 +BLOCKSCOUT_MIN_MEMORY = 1024 +BLOCKSCOUT_MAX_MEMORY = 2048 + +BLOCKSCOUT_VERIF_MIN_CPU = 10 +BLOCKSCOUT_VERIF_MAX_CPU = 1000 +BLOCKSCOUT_VERIF_MIN_MEMORY = 10 +BLOCKSCOUT_VERIF_MAX_MEMORY = 1024 + +USED_PORTS = { + HTTP_PORT_ID: shared_utils.new_port_spec( + HTTP_PORT_NUMBER, + shared_utils.TCP_PROTOCOL, + shared_utils.HTTP_APPLICATION_PROTOCOL, + ) +} + +VERIF_USED_PORTS = { + HTTP_PORT_ID: shared_utils.new_port_spec( + HTTP_PORT_NUMBER_VERIF, + shared_utils.TCP_PROTOCOL, + shared_utils.HTTP_APPLICATION_PROTOCOL, + ) +} + + +def launch_blockscout(plan, el_client_contexts, persistent): + postgres_output = postgres.run( + plan, + service_name="{}-postgres".format(SERVICE_NAME_BLOCKSCOUT), + database="blockscout", + extra_configs=["max_connections=1000"], + persistent=persistent, + ) + + el_client_context = el_client_contexts[0] + el_client_rpc_url = "http://{}:{}/".format( + el_client_context.ip_addr, el_client_context.rpc_port_num + ) + el_client_name = el_client_context.client_name + + config_verif = get_config_verif() + verif_service_name = "{}-verif".format(SERVICE_NAME_BLOCKSCOUT) + verif_service = plan.add_service(verif_service_name, config_verif) + verif_url = "http://{}:{}/api".format( + verif_service.hostname, verif_service.ports["http"].number + ) + + config_backend = get_config_backend( + postgres_output, el_client_rpc_url, verif_url, el_client_name + ) + blockscout_service = plan.add_service(SERVICE_NAME_BLOCKSCOUT, config_backend) + plan.print(blockscout_service) + + blockscout_url = "http://{}:{}".format( + blockscout_service.hostname, blockscout_service.ports["http"].number + ) + + return blockscout_url + + +def get_config_verif(): + return ServiceConfig( + image=IMAGE_NAME_BLOCKSCOUT_VERIF, + ports=VERIF_USED_PORTS, + env_vars={ + "SMART_CONTRACT_VERIFIER__SERVER__HTTP__ADDR": "0.0.0.0:{}".format( + HTTP_PORT_NUMBER_VERIF + ) + }, + min_cpu=BLOCKSCOUT_VERIF_MIN_CPU, + max_cpu=BLOCKSCOUT_VERIF_MAX_CPU, + min_memory=BLOCKSCOUT_VERIF_MIN_MEMORY, + max_memory=BLOCKSCOUT_VERIF_MAX_MEMORY, + ) + + +def get_config_backend(postgres_output, el_client_rpc_url, verif_url, el_client_name): + database_url = "{protocol}://{user}:{password}@{hostname}:{port}/{database}".format( + protocol="postgresql", + user=postgres_output.user, + password=postgres_output.password, + hostname=postgres_output.service.hostname, + port=postgres_output.port.number, + database=postgres_output.database, + ) + + return ServiceConfig( + image=IMAGE_NAME_BLOCKSCOUT, + ports=USED_PORTS, + cmd=[ + "/bin/sh", + "-c", + 'bin/blockscout eval "Elixir.Explorer.ReleaseTasks.create_and_migrate()" && bin/blockscout start', + ], + env_vars={ + "ETHEREUM_JSONRPC_VARIANT": el_client_name, + "ETHEREUM_JSONRPC_HTTP_URL": el_client_rpc_url, + "ETHEREUM_JSONRPC_TRACE_URL": el_client_rpc_url, + "DATABASE_URL": database_url, + "COIN": "ETH", + "MICROSERVICE_SC_VERIFIER_ENABLED": "true", + "MICROSERVICE_SC_VERIFIER_URL": verif_url, + "MICROSERVICE_SC_VERIFIER_TYPE": "sc_verifier", + "INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER": "true", + "ECTO_USE_SSL": "false", + "NETWORK": "Kurtosis", + "SUBNETWORK": "Kurtosis", + "API_V2_ENABLED": "true", + "PORT": "{}".format(HTTP_PORT_NUMBER), + "SECRET_KEY_BASE": "56NtB48ear7+wMSf0IQuWDAAazhpb31qyc7GiyspBP2vh7t5zlCsF5QDv76chXeN", + }, + min_cpu=BLOCKSCOUT_MIN_CPU, + max_cpu=BLOCKSCOUT_MAX_CPU, + min_memory=BLOCKSCOUT_MIN_MEMORY, + max_memory=BLOCKSCOUT_MAX_MEMORY, + )