Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add blutgang integration #87

Merged
merged 12 commits into from
Apr 26, 2024
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
yq -Y --in-place '.deploy_cdk_bridge_infra = false' params.yml
yq -Y --in-place '.deploy_zkevm_permissionless_node = false' params.yml
yq -Y --in-place '.deploy_observability = false' params.yml
yq -Y --in-place '.deploy_blutgang = false' params.yml

- name: Deploy L1
run: |
Expand Down Expand Up @@ -166,6 +167,12 @@ jobs:
kurtosis run --enclave cdk-v1 --args-file params.yml .
yq -Y --in-place '.deploy_observability = false' params.yml # reset

- name: Deploy Loadbalancer (blutgang)
run: |
yq -Y --in-place '.deploy_blutgang = true' params.yml
kurtosis run --enclave cdk-v1 --args-file params.yml .
yq -Y --in-place '.deploy_blutgang = false' params.yml # reset

- name: Check that batches are being verified
run: |
timeout_minutes="${CHECK_VERIFIED_BATCHES_TIMEOUT_MINUTES}"
Expand Down
51 changes: 51 additions & 0 deletions cdk_blutgang.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
def run(plan, args):
blutgang_name = "blutgang" + args["deployment_suffix"]
blutgang_config_template = read_file(
src="./templates/blutgang/blutgang-config.toml"
)

zkevm_sequencer_service = plan.get_service(name="zkevm-node-sequencer" + args["deployment_suffix"])
zkevm_sequencer_http_url = "http://{}:{}".format(zkevm_sequencer_service.ip_address, zkevm_sequencer_service.ports["rpc"].number)

zkevm_rpc_service = plan.get_service(name="zkevm-node-rpc" + args["deployment_suffix"])
zkevm_rpc_http_url = "http://{}:{}".format(zkevm_rpc_service.ip_address, zkevm_rpc_service.ports["http-rpc"].number)
zkevm_rpc_ws_url = "ws://{}:{}".format(zkevm_rpc_service.ip_address, zkevm_rpc_service.ports["ws-rpc"].number)

zkevm_rpc_pless_service = plan.get_service(name="zkevm-node-rpc-pless" + args["deployment_suffix"])
zkevm_rpc_pless_http_url = "http://{}:{}".format(zkevm_rpc_pless_service.ip_address, zkevm_rpc_pless_service.ports["http-rpc"].number)
zkevm_rpc_pless_ws_url = "ws://{}:{}".format(zkevm_rpc_pless_service.ip_address, zkevm_rpc_pless_service.ports["ws-rpc"].number)

blutgang_config_artifact = plan.render_templates(
name="blutgang-config-artifact",
config={
"blutgang-config.toml": struct(template=blutgang_config_template, data={
"l2_sequencer_url": zkevm_sequencer_http_url,
"l2_rpc_url": zkevm_rpc_http_url,
"l2_ws_url": zkevm_rpc_ws_url,
"l2_rpc_pless_url": zkevm_rpc_pless_http_url,
"l2_ws_pless_url": zkevm_rpc_pless_ws_url,
} | args)
},
)

blutgang_service_config = ServiceConfig(
image=args["blutgang_image"],
ports={
"http": PortSpec(args["blutgang_rpc_port"], application_protocol="http"),
"admin": PortSpec(args["blutgang_admin_port"], application_protocol="http"),
},
files={
"/etc/blutgang": Directory(
artifact_names=[
blutgang_config_artifact,
]
),
},
cmd=["/app/blutgang", "-c", "/etc/blutgang/blutgang-config.toml"]
)

plan.add_service(
name=blutgang_name,
config=blutgang_service_config,
description="Starting blutgang service",
)
14 changes: 13 additions & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cdk_central_environment_package = import_module("./cdk_central_environment.star"
cdk_bridge_infra_package = import_module("./cdk_bridge_infra.star")
zkevm_permissionless_node_package = import_module("./zkevm_permissionless_node.star")
observability_package = import_module("./observability.star")

blutgang_package = import_module("./cdk_blutgang.star")

def run(
plan,
Expand All @@ -16,6 +16,7 @@ def run(
deploy_cdk_central_environment=True,
deploy_zkevm_permissionless_node=True,
deploy_observability=True,
deploy_blutgang=True,
args={
"deployment_suffix": "-001",
"zkevm_prover_image": "hermeznetwork/zkevm-prover:v6.0.0",
Expand Down Expand Up @@ -102,6 +103,9 @@ def run(
"zkevm_aggregator_host": "zkevm-node-aggregator-001",
"genesis_file": "templates/permissionless-node/genesis.json",
"polycli_version": "v0.1.42",
"blutgang_image": "makemake1337/blutgang:latest",
"blutgang_rpc_port": "55555",
"blutgang_admin_port": "55556",
},
):
"""Deploy a Polygon CDK Devnet with various configurable options.
Expand Down Expand Up @@ -187,3 +191,11 @@ def run(
observability_package.run(plan, observability_args)
else:
plan.print("Skipping the deployment of the observability stack")

# Deploy blutgang for caching
if deploy_blutgang:
plan.print("Deploying blutgang")
blutgang_args = dict(args)
blutgang_package.run(plan, blutgang_args)
else:
plan.print("Skipping the deployment of blutgang")
9 changes: 9 additions & 0 deletions params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ deploy_zkevm_permissionless_node: true
# Deploy observability stack.
deploy_observability: true

# Deploy eth loadbalancer (blutgang).
deploy_blutgang: true

args:
# Suffix appended to service names.
# Note: It should be a string.
Expand Down Expand Up @@ -180,3 +183,9 @@ args:

## Tools versions
polycli_version: v0.1.42

## blutgang configuration.
blutgang_image: makemake1337/blutgang:0.3.5

blutgang_rpc_port: 55555
blutgang_admin_port: 55556
86 changes: 86 additions & 0 deletions templates/blutgang/blutgang-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Config for blutgang goes here
[blutgang]
# Clear the cache DB on startup
do_clear = true
# Where to bind blutgang to
address = "0.0.0.0:{{.blutgang_rpc_port}}"
# Moving average length for the latency
ma_length = 100
# Sort RPCs by latency on startup. Recommended to leave on.
sort_on_startup = true
# Enable health checking
health_check = true
# Enable content type header checking. Set this to `true` if you want
# Blutgang to be JSON-RPC compliant.
header_check = true
# Acceptable time to wait for a response in ms
ttl = 30
# How many times to retry a request before giving up
max_retries = 32
# Block time in ms, used as a sanity check when not receiving subscriptions
expected_block_time = 20000
# Time between health checks in ms
health_check_ttl = 400
# Supress the health check running info messages
supress_rpc_check = false

# Note: the admin namespace contains volatile functions and
# should not be exposed publicly.
[admin]
# Enable the admin namespace
enabled = true
# Address for the admin RPC
address = "0.0.0.0:{{.blutgang_admin_port}}"
# Only allow read-only methods
# Recommended `true` unless you 100% need write methods
readonly = true
# Enable the use of JWT for auth
# Should be on if exposing to the internet
jwt = false
# jwt token
key = ""

# Sled config
# Sled is the database we use for our cache, for more info check their docs
[sled]
# Path to db
db_path = "./blutgang-cache"
# sled mode. Can be HighThroughput/LowSpace
mode = "HighThroughput"
# Cache size in bytes.
cache_capacity = 1000000000
# Use zstd compression. Reduces size 60-70%,
# and increases CPU and latency by around 10% for db writes and 2% for reads.
# If storage constrained, it's fine to have it be on.
compression = false
# Print DB profile when dropped. Doesn't do anything for now.
print_profile = false
# Frequency of flushes in ms
flush_every_ms = 240

# Add separate RPCs as TOML tables
# DO NOT name an rpc `blutgang`, `admin`, or `sled`

[sequencer]
url = "{{.l2_sequencer_url}}"
# ws_url = "{{.l2_sequencer_ws_url}}"
# The maximum amount of time we can use this rpc in a row.
max_consecutive = 150
# Max amount of queries per second.
max_per_second = 200

[rpc]
url = "{{.l2_rpc_url}}"
ws_url = "{{.l2_ws_url}}"
# The maximum amount of time we can use this rpc in a row.
max_consecutive = 150
# Max amount of queries per second.
max_per_second = 200

[rpcpless]
url = "{{.l2_rpc_pless_url}}"
ws_url = "{{.l2_ws_pless_url}}"
# The maximum amount of time we can use this rpc in a row.
max_consecutive = 150
# Max amount of queries per second.
max_per_second = 200
Loading