From 1fad9c15de5685959cc0d1ff40267ff89682e72b Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Thu, 4 Jan 2024 15:07:06 +0200 Subject: [PATCH] Build DSN docker images --- .dockerignore | 7 ++- .github/workflows/kernel.yml | 101 ++++++++++++++++++++++++++++++++ .github/workflows/sequencer.yml | 50 ++++++++++++++++ Cargo.lock | 13 ---- Cargo.toml | 1 - Makefile | 7 +++ docker/sequencer/Dockerfile | 19 ++++++ docker/sequencer/entrypoint.sh | 31 ++++++++++ executor/Cargo.toml | 17 ------ executor/build.rs | 4 -- executor/proto/executor.proto | 13 ---- executor/src/client.rs | 31 ---------- executor/src/main.rs | 21 ------- executor/src/server.rs | 36 ------------ sequencer/src/main.rs | 4 +- 15 files changed, 216 insertions(+), 139 deletions(-) create mode 100644 .github/workflows/kernel.yml create mode 100644 .github/workflows/sequencer.yml create mode 100644 docker/sequencer/entrypoint.sh delete mode 100644 executor/Cargo.toml delete mode 100644 executor/build.rs delete mode 100644 executor/proto/executor.proto delete mode 100644 executor/src/client.rs delete mode 100644 executor/src/main.rs delete mode 100644 executor/src/server.rs diff --git a/.dockerignore b/.dockerignore index 9f97022..7d3c5b8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,6 @@ -target/ \ No newline at end of file +target/ +benchmark/ +bin/ +.tezos-client/ +.db/ +.git/ \ No newline at end of file diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml new file mode 100644 index 0000000..547eba5 --- /dev/null +++ b/.github/workflows/kernel.yml @@ -0,0 +1,101 @@ +name: Build & deploy DSN kernel + +on: + push: + branches: + - 'master' + tags: + - '*.*.*' + pull_request: + branches: + - 'master' + +jobs: + build: + name: Build and push docker images + runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + DOCKER_REGISTRY: ghcr.io + DOCKER_IMAGE_BASE: ${{ github.repository_owner }} + outputs: + operator: ${{ steps.meta-dsn-operator.outputs.tags }} + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to the registry + uses: docker/login-action@v1 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: DSN operator tags & labels + id: meta-dsn-operator + uses: docker/metadata-action@v3 + with: + images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_BASE }}/operator + + - name: DSN operator build & push + uses: docker/build-push-action@v2 + with: + context: . + file: build/kernel/Dockerfile + build-args: | + OCTEZ_TAG=v17.1 + OCTEZ_PROTO=PtNairob + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.meta-dsn-operator.outputs.tags }} + labels: ${{ steps.meta-dsn-operator.outputs.labels }} + + deploy: + if: (github.event_name == 'pull_request' && github.event.pull_request.draft == false) || (github.event_name == 'push' && github.ref == 'refs/heads/master') + name: Deploy DSN kernel to testnet + needs: build + runs-on: ubuntu-latest + env: + NETWORK: nairobinet + steps: + - name: Deploy rollup + run: docker run -v "/var/run/docker.sock":"/var/run/docker.sock" -e NETWORK=${{ env.NETWORK }} -e OPERATOR_KEY=${{ secrets.OPERATOR_KEY }} ${{ needs.build.outputs.operator }} deploy_rollup | tee originate.out + + - name: Extract rollup address + run: | + ROLLUP_ADDRESS=$(cat originate.out | grep -oE "sr1[a-zA-Z0-9]{33}" | uniq | tr -d '\n') + echo "ROLLUP_ADDRESS=$ROLLUP_ADDRESS" >> $GITHUB_ENV + + - name: Update PR with the deployment link + if: github.event_name == 'pull_request' + uses: edumserrano/find-create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: '' + comment-author: 'github-actions[bot]' + body: | + + Deployed at [${{ env.ROLLUP_ADDRESS }}](https://${{ env.NETWORK }}.tzkt.io/${{ env.ROLLUP_ADDRESS }}) + edit-mode: replace + reactions: rocket + + - name: Create GitHub deployment + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: altinukshini/deployment-action@releases/v1 + id: deployment + with: + token: "${{ github.token }}" + environment: ${{ env.NETWORK }} + + - name: Update deployment status + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: altinukshini/deployment-status@releases/v1 + with: + token: "${{ github.token }}" + state: "success" + environment_url: https://${{ env.NETWORK }}.tzkt.io/${{ env.ROLLUP_ADDRESS }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} \ No newline at end of file diff --git a/.github/workflows/sequencer.yml b/.github/workflows/sequencer.yml new file mode 100644 index 0000000..e830267 --- /dev/null +++ b/.github/workflows/sequencer.yml @@ -0,0 +1,50 @@ +name: Build DSN nodes + +on: + push: + branches: + - 'master' + tags: + - '*.*.*' + pull_request: + branches: + - 'master' + +jobs: + build: + name: Build and push docker images + runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + DOCKER_REGISTRY: ghcr.io + DOCKER_IMAGE_BASE: ${{ github.repository_owner }} + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to the registry + uses: docker/login-action@v1 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: DSN image tags & labels + id: meta-sequencer + uses: docker/metadata-action@v3 + with: + images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_BASE }}/sequencer + + - name: DSN image build & push + uses: docker/build-push-action@v2 + with: + context: . + file: build/sequencer/Dockerfile + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.meta-sequencer.outputs.tags }} + labels: ${{ steps.meta-sequencer.outputs.labels }} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5a5c497..d0bb108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2192,19 +2192,6 @@ dependencies = [ "pin-project-lite 0.2.13", ] -[[package]] -name = "executor" -version = "0.1.0" -dependencies = [ - "async-trait", - "clap", - "prost", - "protobuf-src", - "tokio", - "tonic", - "tonic-build", -] - [[package]] name = "eyre" version = "0.6.11" diff --git a/Cargo.toml b/Cargo.toml index 59abec8..508829b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ members = [ "crates/worker", "crates/pre-block", - "executor", "launcher", "playground", "kernel", diff --git a/Makefile b/Makefile index 553870b..027f8c3 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ image-operator: --build-arg OCTEZ_PROTO=$(OCTEZ_PROTO) \ . +image-sequencer: + docker build -t dsn/sequencer --file ./docker/sequencer/Dockerfile . + run-operator: $(MAKE) build-operator $(MAKE) image-operator OCTEZ_TAG=$(OCTEZ_TAG) OCTEZ_PROTO=$(OCTEZ_PROTO) @@ -61,3 +64,7 @@ run-operator: run-sequencer: $(MAKE) build-sequencer RUST_LOG=info ./target/debug/sequencer + +run-consensus: + cargo build --package launcher + ./target/debug/launcher \ No newline at end of file diff --git a/docker/sequencer/Dockerfile b/docker/sequencer/Dockerfile index e69de29..e0557ca 100644 --- a/docker/sequencer/Dockerfile +++ b/docker/sequencer/Dockerfile @@ -0,0 +1,19 @@ +FROM rust:1.73-bullseye AS builder +ARG PROFILE=release +WORKDIR /build +RUN apt-get update && apt-get install -y cmake clang +COPY . ./ +RUN cargo build --profile ${PROFILE} --bin narwhal-node +RUN cargo build --profile ${PROFILE} --bin sequencer + +FROM debian:bullseye-slim AS runtime +# Use jemalloc as memory allocator +RUN apt-get update && apt-get install -y libjemalloc-dev +ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so +ARG PROFILE=release +COPY --from=builder build/target/${PROFILE}/narwhal-node /usr/bin/narwhal-node +COPY --from=builder build/target/${PROFILE}/sequencer /usr/bin/sequencer +COPY ./launcher/defaults/* /narwhal/ +COPY ./docker/sequencer/entrypoint.sh . +RUN chmod +x entrypoint.sh && ln ./entrypoint.sh /usr/bin/narwhal +ENTRYPOINT [ "./entrypoint.sh" ] \ No newline at end of file diff --git a/docker/sequencer/entrypoint.sh b/docker/sequencer/entrypoint.sh new file mode 100644 index 0000000..ff92e44 --- /dev/null +++ b/docker/sequencer/entrypoint.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2023 Baking Bad +# +# SPDX-License-Identifier: MIT + +set -e + +NARWHAL_NODE_BIN="/usr/bin/narwhal-node" + +if [ -z "$VALIDATOR_ID" ]; then + echo "VALIDATOR_ID is not set" + exit 1 +fi + +LOG_LEVEL=${LOG_LEVEL:="-v"} +PRIMARY_KEYS_PATH=${KEYS_PATH:="/narwhal/primary-$VALIDATOR_ID.key"} +PRIMARY_NETWORK_KEYS_PATH=${KEYS_PATH:="/narwhal/primary-network-$VALIDATOR_ID.key"} +WORKER_NETWORK_KEYS_PATH=${KEYS_PATH:="/narwhal/worker-network-$VALIDATOR_ID.key"} +COMMITTEE_PATH=${COMMITTEE_PATH:="/narwhal/committee.json"} +WORKERS_PATH=${WORKERS_PATH:="/narwhal/workers.json"} +DATA_PATH=${DATA_PATH:="/data"} + +$NARWHAL_NODE_BIN $LOG_LEVEL run-comb \ +--primary-keys $PRIMARY_KEYS_PATH \ +--primary-network-keys $PRIMARY_NETWORK_KEYS_PATH \ +--worker-keys $WORKER_NETWORK_KEYS_PATH \ +--committee $COMMITTEE_PATH \ +--workers $WORKERS_PATH \ +--primary-store "$DATA_PATH/primary-store-$VALIDATOR_ID" \ +--worker-store "$DATA_PATH/worker-store-$VALIDATOR_ID" \ No newline at end of file diff --git a/executor/Cargo.toml b/executor/Cargo.toml deleted file mode 100644 index 53908b3..0000000 --- a/executor/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "executor" -edition = "2021" -version.workspace = true - -[dependencies] -async-trait.workspace = true -clap.workspace = true -prost.workspace = true -tokio = { workspace = true, features = ["rt-multi-thread"] } -tonic.workspace = true - -[target.'cfg(not(target_env = "msvc"))'.build-dependencies] -protobuf-src.workspace = true - -[build-dependencies] -tonic-build.workspace = true diff --git a/executor/build.rs b/executor/build.rs deleted file mode 100644 index 897c277..0000000 --- a/executor/build.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() -> Result<(), Box> { - tonic_build::compile_protos("proto/executor.proto")?; - Ok(()) -} diff --git a/executor/proto/executor.proto b/executor/proto/executor.proto deleted file mode 100644 index 31591cb..0000000 --- a/executor/proto/executor.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package executor; - -message OkMessage {} - -message PayloadMessage { - repeated bytes transactions = 1; -} - -service ExecutorService { - rpc Execute(PayloadMessage) returns (OkMessage) {} -} diff --git a/executor/src/client.rs b/executor/src/client.rs deleted file mode 100644 index 65ab775..0000000 --- a/executor/src/client.rs +++ /dev/null @@ -1,31 +0,0 @@ -use tonic::transport::Channel; - -mod executor { - tonic::include_proto!("executor"); -} -use executor::executor_service_client::ExecutorServiceClient; -use executor::PayloadMessage; - -/// Simple client for interaction with Executor gRPC server -/// Example of use -/// ```rust,ignore -/// let mut client = ExecutorClient::connect("http://127.0.0.1:5000".to_string()).await.unwrap(); -/// client.execute(vec![vec![]]).await.unwrap(); -/// ``` -pub struct ExecutorClient { - client: ExecutorServiceClient -} - -impl ExecutorClient { - /// Connects to the executor gRPC server at the specified endpoint (e.g. `http://127.0.0.1:5000`) - pub async fn connect(endpoint: String) -> Result> { - let client = ExecutorServiceClient::connect(endpoint).await?; - Ok(ExecutorClient {client}) - } - - /// Sends a batch of transactions to the executor - pub async fn execute(&mut self, transactions: Vec>) -> Result<(), Box> { - self.client.execute(PayloadMessage{transactions}).await?; - Ok(()) - } -} \ No newline at end of file diff --git a/executor/src/main.rs b/executor/src/main.rs deleted file mode 100644 index 2de69cd..0000000 --- a/executor/src/main.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clap::Parser; -use std::net::SocketAddr; - -mod server; -use server::run_executor_server; - -/// Simple executor server, emulating EVM node -#[derive(Parser)] -#[command(author, version, about)] -struct Args { - /// Socket address to bind - #[arg(short, long, default_value_t=("127.0.0.1:54321".parse()).unwrap())] - address: SocketAddr, -} - -#[tokio::main] -async fn main() -> Result<(), Box> { - let args = Args::parse(); - println!("Running executor server at {}", args.address); - run_executor_server(args.address).await -} diff --git a/executor/src/server.rs b/executor/src/server.rs deleted file mode 100644 index f927701..0000000 --- a/executor/src/server.rs +++ /dev/null @@ -1,36 +0,0 @@ -use async_trait::async_trait; -use std::net::SocketAddr; -use std::time::Duration; -use tonic::{transport::Server, Request, Response, Status}; - -mod executor { - tonic::include_proto!("executor"); -} -use executor::executor_service_server::{ExecutorService, ExecutorServiceServer}; -use executor::{OkMessage, PayloadMessage}; - -struct ExecutorServiceImpl; - -#[async_trait] -impl ExecutorService for ExecutorServiceImpl { - async fn execute( - &self, - preblock: Request, - ) -> Result, Status> { - println!( - "Preblock with {} txs received", - preblock.into_inner().transactions.iter().count() - ); - std::thread::sleep(Duration::from_millis(500)); - println!("Preblock executed"); - Ok(Response::new(OkMessage {})) - } -} - -pub async fn run_executor_server(addr: SocketAddr) -> Result<(), Box> { - Server::builder() - .add_service(ExecutorServiceServer::new(ExecutorServiceImpl {})) - .serve(addr) - .await?; - Ok(()) -} diff --git a/sequencer/src/main.rs b/sequencer/src/main.rs index abb919f..d80601b 100644 --- a/sequencer/src/main.rs +++ b/sequencer/src/main.rs @@ -151,10 +151,10 @@ struct Args { #[arg(long, default_value_t = String::from("http://localhost:8932"))] rollup_node_url: String, - #[arg(long, default_value_t = String::from("http://localhost:9090"))] + #[arg(long, default_value_t = String::from("http://localhost:64013"))] worker_node_url: String, - #[arg(long, default_value_t = String::from("http://localhost:9091"))] + #[arg(long, default_value_t = String::from("http://localhost:64011"))] primary_node_url: String, #[arg(long, default_value_t = String::from("0.0.0.0"))]