blobscan_launcher.star 4.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
shared_utils = import_module("../shared_utils/shared_utils.star")
postgres = import_module("github.com/kurtosis-tech/postgres-package/main.star")

WEB_SERVICE_NAME = "blobscan-web"
API_SERVICE_NAME = "blobscan-api"
INDEXER_SERVICE_NAME = "blobscan-indexer"

HTTP_PORT_ID = "http"
WEB_HTTP_PORT_NUMBER = 3000
API_HTTP_PORT_NUMBER = 3001

WEB_PORTS = {
    HTTP_PORT_ID: shared_utils.new_port_spec(
        WEB_HTTP_PORT_NUMBER,
        shared_utils.TCP_PROTOCOL,
        shared_utils.HTTP_APPLICATION_PROTOCOL,
    )
}


API_PORTS = {
    HTTP_PORT_ID: shared_utils.new_port_spec(
        API_HTTP_PORT_NUMBER,
        shared_utils.TCP_PROTOCOL,
        shared_utils.HTTP_APPLICATION_PROTOCOL,
    )
}

ENTRYPOINT_ARGS = ["/bin/sh", "-c"]

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# The min/max CPU/memory that blobscan-indexer can use
INDEX_MIN_CPU = 10
INDEX_MAX_CPU = 1000
INDEX_MIN_MEMORY = 32
INDEX_MAX_MEMORY = 1024

# The min/max CPU/memory that blobscan-api can use
API_MIN_CPU = 100
API_MAX_CPU = 1000
API_MIN_MEMORY = 1024
API_MAX_MEMORY = 2048

# The min/max CPU/memory that blobscan-web can use
WEB_MIN_CPU = 100
WEB_MAX_CPU = 1000
WEB_MIN_MEMORY = 512
WEB_MAX_MEMORY = 2048

# The min/max CPU/memory that postgres can use
POSTGRES_MIN_CPU = 10
POSTGRES_MAX_CPU = 1000
POSTGRES_MIN_MEMORY = 32
POSTGRES_MAX_MEMORY = 1024

55 56 57 58 59 60

def launch_blobscan(
    plan,
    cl_client_contexts,
    el_client_contexts,
    chain_id,
61
    persistent,
62 63 64 65 66 67 68 69
):
    beacon_node_rpc_uri = "http://{0}:{1}".format(
        cl_client_contexts[0].ip_addr, cl_client_contexts[0].http_port_num
    )
    execution_node_rpc_uri = "http://{0}:{1}".format(
        el_client_contexts[0].ip_addr, el_client_contexts[0].rpc_port_num
    )

70
    postgres_output = postgres.run(
71 72 73 74 75 76
        plan,
        service_name="blobscan-postgres",
        min_cpu=POSTGRES_MIN_CPU,
        max_cpu=POSTGRES_MAX_CPU,
        min_memory=POSTGRES_MIN_MEMORY,
        max_memory=POSTGRES_MAX_MEMORY,
77
        persistent=persistent,
78
    )
79 80 81 82 83 84 85
    api_config = get_api_config(postgres_output.url, beacon_node_rpc_uri, chain_id)
    blobscan_config = plan.add_service(API_SERVICE_NAME, api_config)

    blobscan_api_url = "http://{0}:{1}".format(
        blobscan_config.ip_address, blobscan_config.ports[HTTP_PORT_ID].number
    )

86
    web_config = get_web_config(postgres_output.url, beacon_node_rpc_uri, chain_id)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    plan.add_service(WEB_SERVICE_NAME, web_config)

    indexer_config = get_indexer_config(
        beacon_node_rpc_uri, execution_node_rpc_uri, blobscan_api_url
    )
    plan.add_service(INDEXER_SERVICE_NAME, indexer_config)


def get_api_config(database_url, beacon_node_rpc, chain_id):
    IMAGE_NAME = "blossomlabs/blobscan:stable"

    return ServiceConfig(
        image=IMAGE_NAME,
        ports=API_PORTS,
        env_vars={
            "BEACON_NODE_ENDPOINT": beacon_node_rpc,
            "CHAIN_ID": chain_id,
            "DATABASE_URL": database_url,
            "SECRET_KEY": "supersecret",
106
            "BLOBSCAN_API_PORT": str(API_HTTP_PORT_NUMBER),
107 108 109 110 111 112 113 114 115 116 117 118 119
        },
        cmd=["api"],
        ready_conditions=ReadyCondition(
            recipe=GetHttpRequestRecipe(
                port_id="http",
                endpoint="/api/healthcheck",
            ),
            field="code",
            assertion="==",
            target_value=200,
            interval="5s",
            timeout="5s",
        ),
120 121 122 123
        min_cpu=API_MIN_CPU,
        max_cpu=API_MAX_CPU,
        min_memory=API_MIN_MEMORY,
        max_memory=API_MAX_MEMORY,
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    )


def get_web_config(database_url, beacon_node_rpc, chain_id):
    # TODO: https://github.com/kurtosis-tech/kurtosis/issues/1861
    # Configure NEXT_PUBLIC_BEACON_BASE_URL and NEXT_PUBLIC_EXPLORER_BASE env vars
    # once retrieving external URLs from services are supported in Kurtosis.
    IMAGE_NAME = "blossomlabs/blobscan:stable"

    return ServiceConfig(
        image=IMAGE_NAME,
        ports=WEB_PORTS,
        env_vars={
            "DATABASE_URL": database_url,
            "SECRET_KEY": "supersecret",
            "NEXT_PUBLIC_NETWORK_NAME": "kurtosis-devnet",
            "BEACON_NODE_ENDPOINT": beacon_node_rpc,
            "CHAIN_ID": chain_id,
        },
        cmd=["web"],
144 145 146 147
        min_cpu=WEB_MIN_CPU,
        max_cpu=WEB_MAX_CPU,
        min_memory=WEB_MIN_MEMORY,
        max_memory=WEB_MAX_MEMORY,
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    )


def get_indexer_config(beacon_node_rpc, execution_node_rpc, blobscan_api_url):
    IMAGE_NAME = "blossomlabs/blobscan-indexer:master"

    return ServiceConfig(
        image=IMAGE_NAME,
        env_vars={
            "SECRET_KEY": "supersecret",
            "BLOBSCAN_API_ENDPOINT": blobscan_api_url,
            "EXECUTION_NODE_ENDPOINT": execution_node_rpc,
            "BEACON_NODE_ENDPOINT": beacon_node_rpc,
        },
        entrypoint=ENTRYPOINT_ARGS,
        cmd=[" && ".join(["sleep 90", "/app/blob-indexer"])],
164 165 166 167
        min_cpu=INDEX_MIN_CPU,
        max_cpu=INDEX_MAX_CPU,
        min_memory=INDEX_MIN_MEMORY,
        max_memory=INDEX_MAX_MEMORY,
168
    )