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

CDN Whitelist #1357

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
target/release/orchestrator
target/release/cdn-broker
target/release/cdn-marshal
target/release/cdn-whitelist
target/release/state-relay-server
target/release/state-prover
target/release/sequencer
Expand Down Expand Up @@ -102,6 +103,7 @@ jobs:
target/release/orchestrator
target/release/cdn-broker
target/release/cdn-marshal
target/release/cdn-whitelist
target/release/state-relay-server
target/release/state-prover
target/release/sequencer
Expand All @@ -121,6 +123,7 @@ jobs:
sequencer-tag: ${{ steps.sequencer.outputs.tags }}
cdn-broker-tag: ${{ steps.cdn-broker.outputs.tags }}
cdn-marshal-tag: ${{ steps.cdn-marshal.outputs.tags }}
cdn-whitelist-tag: ${{ steps.cdn-whitelist.outputs.tags }}
state-relay-server-tag: ${{ steps.state-relay-server.outputs.tags }}
prover-service-tag: ${{ steps.prover-service.outputs.tags }}
orchestrator-tag: ${{ steps.orchestrator.outputs.tags }}
Expand Down Expand Up @@ -176,6 +179,12 @@ jobs:
with:
images: ghcr.io/espressosystems/espresso-sequencer/cdn-marshal

- name: Generate cdn-whitelist docker metadata
uses: docker/metadata-action@v5
id: cdn-whitelist
with:
images: ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist

- name: Generate state-relay-server docker metadata
uses: docker/metadata-action@v5
id: state-relay-server
Expand Down Expand Up @@ -254,6 +263,16 @@ jobs:
tags: ${{ steps.cdn-marshal.outputs.tags }}
labels: ${{ steps.cdn-marshal.outputs.labels }}

- name: Build and push cdn-whitelist docker
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/cdn-whitelist.Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.cdn-whitelist.outputs.tags }}
labels: ${{ steps.cdn-whitelist.outputs.labels }}

- name: Build and push state-relay-server docker
uses: docker/build-push-action@v5
with:
Expand Down Expand Up @@ -352,6 +371,7 @@ jobs:
docker pull ${{ needs.build-dockers.outputs.sequencer-tag }}
docker pull ${{ needs.build-dockers.outputs.cdn-broker-tag }}
docker pull ${{ needs.build-dockers.outputs.cdn-marshal-tag }}
docker pull ${{ needs.build-dockers.outputs.cdn-whitelist-tag }}
docker pull ${{ needs.build-dockers.outputs.state-relay-server-tag }}
docker pull ${{ needs.build-dockers.outputs.prover-service-tag }}
docker pull ${{ needs.build-dockers.outputs.orchestrator-tag }}
Expand All @@ -365,6 +385,7 @@ jobs:
docker tag ${{ needs.build-dockers.outputs.sequencer-tag }} ghcr.io/espressosystems/espresso-sequencer/sequencer:main
docker tag ${{ needs.build-dockers.outputs.cdn-broker-tag }} ghcr.io/espressosystems/espresso-sequencer/cdn-broker:main
docker tag ${{ needs.build-dockers.outputs.cdn-marshal-tag }} ghcr.io/espressosystems/espresso-sequencer/cdn-marshal:main
docker tag ${{ needs.build-dockers.outputs.cdn-whitelist-tag }} ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist:main
docker tag ${{ needs.build-dockers.outputs.state-relay-server-tag }} ghcr.io/espressosystems/espresso-sequencer/state-relay-server:main
docker tag ${{ needs.build-dockers.outputs.prover-service-tag }} ghcr.io/espressosystems/espresso-sequencer/prover-service:main
docker tag ${{ needs.build-dockers.outputs.orchestrator-tag }} ghcr.io/espressosystems/espresso-sequencer/orchestrator:main
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/build_static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/orchestrator
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/cdn-broker
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/cdn-marshal
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/cdn-whitelist
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/state-relay-server
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/state-prover
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/sequencer
Expand Down Expand Up @@ -141,6 +142,13 @@ jobs:
images: ghcr.io/espressosystems/espresso-sequencer/cdn-marshal
flavor: suffix=musl

- name: Generate cdn-whitelist docker metadata
uses: docker/metadata-action@v5
id: cdn-whitelist
with:
images: ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist
flavor: suffix=musl

- name: Generate state-relay-server docker metadata
uses: docker/metadata-action@v5
id: state-relay-server
Expand Down Expand Up @@ -213,6 +221,16 @@ jobs:
tags: ${{ steps.cdn-marshal.outputs.tags }}
labels: ${{ steps.cdn-marshal.outputs.labels }}

- name: Build and push cdn-whitelist docker
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/cdn-whitelist.Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.cdn-whitelist.outputs.tags }}
labels: ${{ steps.cdn-whitelist.outputs.labels }}

- name: Build and push state-relay-server docker
uses: docker/build-push-action@v5
with:
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ services:
keydb:
condition: service_healthy

# A service to whitelist specific public keys for the CDN
cdn-whitelist:
restart: no
environment:
- RUST_LOG
- ESPRESSO_SEQUENCER_ORCHESTRATOR_URL
image: ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist:main
command:
- cdn-whitelist
- -d
- redis://:changemeplease!!@keydb:6379
depends_on:
keydb:
condition: service_healthy
orchestrator:
condition: service_healthy

state-relay-server:
image: ghcr.io/espressosystems/espresso-sequencer/state-relay-server:main
ports:
Expand Down Expand Up @@ -178,6 +195,8 @@ services:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=10
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_BASE_FEE
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand Down Expand Up @@ -220,6 +239,8 @@ services:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=11
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_BASE_FEE
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand Down Expand Up @@ -257,6 +278,8 @@ services:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=12
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_BASE_FEE
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand Down Expand Up @@ -293,6 +316,8 @@ services:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=13
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_BASE_FEE
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand Down Expand Up @@ -329,6 +354,8 @@ services:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=14
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_BASE_FEE
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand Down
15 changes: 15 additions & 0 deletions docker/cdn-whitelist.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ubuntu:jammy

ARG TARGETARCH

RUN apt-get update \
&& apt-get install -y curl libcurl4 wait-for-it tini \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["tini", "--"]

COPY target/$TARGETARCH/release/cdn-whitelist /bin/cdn-whitelist
RUN chmod +x /bin/cdn-whitelist

ENV RUST_LOG="info"

CMD ["cdn-whitelist"]
15 changes: 14 additions & 1 deletion process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ processes:

# The CDN system's main entry point; where users contact first.
marshal_0:
command: cdn-marshal -d "redis://:changeme!@localhost:6379" -b $ESPRESSO_CDN_SERVER_PORT -m 127.0.0.1:9093
command: cdn-marshal
-d "redis://:changeme!@localhost:6379"
-b $ESPRESSO_CDN_SERVER_PORT
-m 127.0.0.1:9093
depends_on:
keydb:
condition: process_healthy
Expand Down Expand Up @@ -321,6 +324,16 @@ processes:
path: /metrics
failure_threshold: 100

cdn-whitelist:
command: cdn-whitelist
-d redis://:changeme!@localhost:6379
-o http://localhost:$ESPRESSO_ORCHESTRATOR_PORT
depends_on:
orchestrator:
condition: process_healthy
keydb:
condition: process_healthy

commitment-task:
command: commitment-task
depends_on:
Expand Down
1 change: 1 addition & 0 deletions scripts/build-docker-images
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export DOCKER_BUILDKIT=1
docker build -t ghcr.io/espressosystems/espresso-sequencer/orchestrator:main -f docker/orchestrator.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/cdn-broker:main -f docker/cdn-broker.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/cdn-marshal:main -f docker/cdn-marshal.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist:main -f docker/cdn-whitelist.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/state-relay-server:main -f docker/state-relay-server.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/prover-service:main -f docker/prover-service.Dockerfile ${WORKDIR}
docker build -t ghcr.io/espressosystems/espresso-sequencer/sequencer:main -f docker/sequencer.Dockerfile ${WORKDIR}
Expand Down
1 change: 1 addition & 0 deletions scripts/build-docker-images-native
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export DOCKER_BUILDKIT=1
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/orchestrator:main -f docker/orchestrator.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/cdn-broker:main -f docker/cdn-broker.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/cdn-marshal:main -f docker/cdn-marshal.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/cdn-whitelist:main -f docker/cdn-whitelist.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/state-relay-server:main -f docker/state-relay-server.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/prover-service:main -f docker/prover-service.Dockerfile ${WORKDIR}
docker build --platform $PLATFORM -t ghcr.io/espressosystems/espresso-sequencer/sequencer:main -f docker/sequencer.Dockerfile ${WORKDIR}
Expand Down
90 changes: 90 additions & 0 deletions sequencer/src/bin/cdn-whitelist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! The whitelist is an adaptor that is able to update the allowed public keys for
//! all brokers. Right now, we do this by asking the orchestrator for the list of
//! allowed public keys. In the future, we will pull the stake table from the L1.

use std::{str::FromStr, sync::Arc};

use anyhow::{Context, Result};
use cdn_broker::reexports::discovery::{DiscoveryClient, Embedded, Redis};
use clap::Parser;
use hotshot_orchestrator::{
client::{OrchestratorClient, ValidatorArgs},
config::NetworkConfig,
};
use hotshot_types::traits::{node_implementation::NodeType, signature_key::SignatureKey};
use sequencer::SeqTypes;
use surf_disco::Url;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
/// Whitelist is a service that updates the allowed public keys for the CDN.
struct Args {
/// The discovery client endpoint (including scheme) to connect to.
/// With the local discovery feature, this is a file path.
/// With the remote (redis) discovery feature, this is a redis URL (e.g. `redis://127.0.0.1:6789`).
#[arg(short, long, env = "ESPRESSO_CDN_WHITELIST_DISCOVERY_ENDPOINT")]
discovery_endpoint: String,

/// The URL the orchestrator is running on. This should be something like `http://localhost:5555`
#[arg(short, long, env = "ESPRESSO_SEQUENCER_ORCHESTRATOR_URL")]
orchestrator_url: String,

/// Whether or not to use the local discovery client
#[arg(short, long)]
local_discovery: bool,
}

#[cfg_attr(async_executor_impl = "tokio", tokio::main)]
#[cfg_attr(async_executor_impl = "async-std", async_std::main)]
async fn main() -> Result<()> {
// Parse the command line arguments
let args = Args::parse();

// Initialize tracing
tracing_subscriber::fmt::init();

// Create a new `OrchestratorClient` from the supplied URL
let orchestrator_client = OrchestratorClient::new(ValidatorArgs {
url: Url::from_str(&args.orchestrator_url).with_context(|| "Invalid URL")?,
advertise_address: None,
network_config_file: None,
});

tracing::info!(
"Waiting for config from orchestrator on {}",
args.orchestrator_url
);

// Attempt to get the config from the orchestrator.
// Loops internally until the config is received.
let config: NetworkConfig<
<SeqTypes as NodeType>::SignatureKey,
<SeqTypes as NodeType>::ElectionConfigType,
> = orchestrator_client.get_config_after_collection().await;

tracing::info!("Received config from orchestrator");

// Extrapolate the state_ver_keys from the config and convert them to a compatible format
let whitelist = config
.config
.known_nodes_with_stake
.iter()
.map(|k| Arc::from(k.stake_table_entry.stake_key.to_bytes()))
.collect();

if args.local_discovery {
<Embedded as DiscoveryClient>::new(args.discovery_endpoint, None)
.await?
.set_whitelist(whitelist)
.await?;
} else {
<Redis as DiscoveryClient>::new(args.discovery_endpoint, None)
.await?
.set_whitelist(whitelist)
.await?;
}

tracing::info!("Posted config to discovery endpoint");

Ok(())
}
Loading