-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add whitelist for CDN * fmt
- Loading branch information
Showing
8 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |