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

Idan/main/add sequencer deployment tools #1856

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/sequencer/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"chain_id": "0x5",
"eth_fee_token_address": "0x6",
"strk_fee_token_address": "0x7",
"components.batcher.execution_mode": "Disabled",
"components.batcher.local_server_config.#is_none": true,
"components.consensus_manager.execution_mode": "Disabled",
"components.gateway.execution_mode": "Disabled",
"components.http_server.execution_mode": "Disabled",
"components.mempool.execution_mode": "Disabled",
"components.mempool_p2p.execution_mode": "Disabled",
"components.consensus_manager.local_server_config.#is_none": true,
"components.gateway.local_server_config.#is_none": true,
"components.http_server.local_server_config.#is_none": true,
"components.mempool.local_server_config.#is_none": true,
"components.mempool_p2p.local_server_config.#is_none": true,
"components.http_server.remote_server_config.#is_none": true
}
31 changes: 31 additions & 0 deletions deployments/images/sequencer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# syntax = devthefuture/dockerfile-x

INCLUDE deployments/images/base/Dockerfile


# Compile the sequencer_node crate in release mode, ensuring dependencies are locked.
FROM base AS builder
COPY . .
RUN cargo build --release --package starknet_sequencer_node

FROM base AS sequencer

ENV ID=1000
WORKDIR /app
COPY --from=builder /target/release/starknet_sequencer_node /app/target/release/starknet_sequencer_node
COPY config/ config/

# Create a new user "sequencer".
RUN set -ex; \
addgroup --gid ${ID} sequencer; \
adduser --ingroup $(getent group ${ID} | cut -d: -f1) --uid ${ID} --gecos "" --disabled-password --home /app sequencer; \
chown -R sequencer:sequencer /app

# Expose RPC and monitoring ports.
EXPOSE 8080 8081 8082

# Switch to the new user.
USER ${ID}

# Set the entrypoint to use tini to manage the process.
ENTRYPOINT ["tini", "--", "/app/target/release/starknet_sequencer_node"]
1 change: 1 addition & 0 deletions deployments/sequencer/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ verify_ssl = true
cdk8s = "~=2.66.2"
constructs = "~=10.2.70"
jsonschema = "~=4.23.0"
mypy = "*"

[requires]
python_version = "3.10"
57 changes: 56 additions & 1 deletion deployments/sequencer/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 7 additions & 16 deletions deployments/sequencer/config/sequencer.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
from typing import Dict, Any
import os
import json
import jsonschema

ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
CONFIG_DIR = os.path.join(ROOT_DIR, 'config/papyrus/')


class Config():
def __init__(self, schema: Dict[Any, Any], config: Dict[Any, Any]):
self.schema = schema
self.config = config
from services.objects import Config

def get(self):
return self.config

def validate(self):
pass
ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
CONFIG_DIR = os.path.join(ROOT_DIR, 'config/papyrus/')


class SequencerDevConfig(Config):
def __init__(self):
def __init__(self, mount_path: str):
super().__init__(
schema=json.loads(open(os.path.join(CONFIG_DIR, 'default_config.json'), 'r').read()),
config=json.loads(open(os.path.join(CONFIG_DIR, 'presets', 'sepolia_testnet.json'), 'r').read())
)
config=json.loads(open(os.path.join(CONFIG_DIR, 'presets', 'sepolia_testnet.json'), 'r').read()),
mount_path = mount_path
)

def validate(self):
jsonschema.validate(self.config, schema=self.schema)
83 changes: 67 additions & 16 deletions deployments/sequencer/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
#!/usr/bin/env python3

from constructs import Construct
from cdk8s import App, Chart
from typing import Dict, Any
from services.service import Service
import dataclasses

from constructs import Construct # type: ignore
from cdk8s import App, Chart, YamlOutputType # type: ignore
from typing import Dict, Any, Optional

from services.service import Service
from config.sequencer import Config, SequencerDevConfig
from services.objects import (
HealthCheck, ServiceType, Probe, PersistentVolumeClaim, PortMappings
)
from services import defaults


@dataclasses.dataclass
class SystemStructure:
topology: str = "mesh"
replicas: str = "2"
size: str = "small"
config: Config = SequencerDevConfig()
config: Optional[Config] = None

def __post_init__(self):
self.config.validate()


class SequencerNode(Chart):
def __init__(
self,
scope: Construct,
name: str,
namespace: str,
config: Config,
):
super().__init__(
scope, name, disable_resource_name_hashes=True, namespace=namespace
)
self.service = Service(
self,
"sequencer-node",
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.1",
args=["--config_file", "/app/config/sequencer/config.json"],
port_mappings=[
PortMappings(name="http", port=80, container_port=8080),
PortMappings(name="rpc", port=8081, container_port=8081),
PortMappings(name="monitoring", port=8082, container_port=8082)
],
service_type=ServiceType.CLUSTER_IP,
replicas=1,
config=config,
health_check=HealthCheck(
startup_probe=Probe(port=8082, path="/monitoring/nodeVersion", period_seconds=10, failure_threshold=10, timeout_seconds=5),
readiness_probe=Probe(port=8082, path="/monitoring/ready", period_seconds=10, failure_threshold=5, timeout_seconds=5),
liveness_probe=Probe(port=8082, path="/monitoring/alive", period_seconds=10, failure_threshold=5, timeout_seconds=5)
),
pvc=PersistentVolumeClaim(
access_modes=["ReadWriteOnce"],
storage_class_name="premium-rwo",
volume_mode="Filesystem",
storage="256Gi",
mount_path="/data",
read_only=False
)
)


class SequencerSystem(Chart):
def __init__(
self,
Expand All @@ -36,26 +81,32 @@ def __init__(
"mempool",
image="paulbouwer/hello-kubernetes:1.7",
replicas=2,
config=system_structure.config.get(),
config=system_structure.config,
health_check=defaults.health_check
)
self.batcher = Service(self, "batcher", image="ghost", container_port=2368)
self.sequencer_node = Service(
self.batcher = Service(
self,
"sequencer",
image="",
container_port=8082,
startup_probe_path="/monitoring/nodeVersion",
readiness_probe_path="/monitoring/ready",
liveness_probe_path="/monitoring/alive"
"batcher",
image="ghost",
port_mappings=[{"port": 80, "container_port": 2368}],
health_check=defaults.health_check
)


app = App()
app = App(
yaml_output_type=YamlOutputType.FOLDER_PER_CHART_FILE_PER_RESOURCE
)
sequencer_node = SequencerNode(
scope=app,
name="sequencer-node",
namespace="sequencer-node-test",
config=None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config parameter is marked as required in SequencerNode's implementation but is being passed as None here. This will cause runtime errors since SequencerNode uses the config object without null checks. Either make the parameter optional in SequencerNode and add appropriate null handling, or pass a valid config object at instantiation.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

)
a = SequencerSystem(
scope=app,
name="sequencer-system",
namespace="test-namespace",
system_structure=SystemStructure(),
system_structure=SystemStructure(config=SequencerDevConfig(mount_path="/app/config")),
)

app.synth()
Loading
Loading