Skip to content

Commit

Permalink
node-support: bootloader, docker: release: build & invoke event expor…
Browse files Browse the repository at this point in the history
…t sidecar in bootloader
  • Loading branch information
akirillo committed Dec 12, 2024
1 parent 498ef0e commit 4bff185
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
7 changes: 6 additions & 1 deletion docker/release/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ ARG CARGO_FEATURES="default"
# Build only the dependencies to cache them in this layer
RUN cargo chef cook --release --recipe-path recipe.json --features "$CARGO_FEATURES"

# Build the bootloader
COPY . .

# Build the bootloader
RUN cargo build --release --package bootloader

# Build the snapshot sidecar
RUN cargo build --release --package snapshot-sidecar

# Build the event export sidecar
RUN cargo build --release --package event-export-sidecar

# Build the relayer
RUN cargo build --release --bin renegade-relayer --features "$CARGO_FEATURES"

Expand All @@ -58,6 +62,7 @@ RUN apt-get update && \
# Copy the binaries from the build stage
COPY --from=builder /build/target/release/bootloader /bin/bootloader
COPY --from=builder /build/target/release/snapshot-sidecar /bin/snapshot-sidecar
COPY --from=builder /build/target/release/event-export-sidecar /bin/event-export-sidecar
COPY --from=builder /build/target/release/renegade-relayer /bin/renegade-relayer

# Set the bootloader as the entrypoint
Expand Down
40 changes: 32 additions & 8 deletions node-support/bootloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const ENV_ADMIN_KEY: &str = "ADMIN_API_KEY";
const ENV_FUNDS_MANAGER_URL: &str = "FUNDS_MANAGER_URL";
/// The funds manager api key
const ENV_FUNDS_MANAGER_KEY: &str = "FUNDS_MANAGER_KEY";
/// The historical state engine URL
const ENV_HISTORICAL_STATE_URL: &str = "HISTORICAL_STATE_URL";
/// The historical state engine auth key
const ENV_HISTORICAL_STATE_KEY: &str = "HISTORICAL_STATE_KEY";

// --- Constants --- //

Expand Down Expand Up @@ -82,7 +86,9 @@ const WHITELIST_PATH: &str = "/whitelist.json";
const DEFAULT_AWS_REGION: &str = "us-east-2";

/// The location of the snapshot sidecar binary
const SIDECAR_BIN: &str = "/bin/snapshot-sidecar";
const SNAPSHOT_SIDECAR_BIN: &str = "/bin/snapshot-sidecar";
/// The location of the event export sidecar binary
const EVENT_EXPORT_SIDECAR_BIN: &str = "/bin/event-export-sidecar";
/// The location of the relayer binary
const RELAYER_BIN: &str = "/bin/renegade-relayer";

Expand All @@ -101,24 +107,42 @@ async fn main() -> Result<(), String> {
modify_config(whitelist).await?;
download_snapshot(&s3_client).await?;

// Start both the snapshot sidecar and the relayer
// Start the snapshot sidecar, event export sidecar, and the relayer
let bucket = read_env_var::<String>(ENV_SNAP_BUCKET)?;
let mut sidecar = Command::new(SIDECAR_BIN)
let mut snapshot_sidecar = Command::new(SNAPSHOT_SIDECAR_BIN)
.args(["--config-path", CONFIG_PATH])
.args(["--bucket", &bucket])
.spawn()
.expect("Failed to start snapshot sidecar process");

let hse_url = read_env_var::<String>(ENV_HISTORICAL_STATE_URL)?;
let hse_key = read_env_var::<String>(ENV_HISTORICAL_STATE_KEY)?;
let mut event_export_sidecar = Command::new(EVENT_EXPORT_SIDECAR_BIN)
.args(["--config-path", CONFIG_PATH])
.args(["--hse-url", &hse_url])
.args(["--hse-key", &hse_key])
.spawn()
.expect("Failed to start event export sidecar process");

let mut relayer = Command::new(RELAYER_BIN)
.args(["--config-file", CONFIG_PATH])
.spawn()
.expect("Failed to start relayer process");

let sidecar_result = sidecar.wait();
let snapshot_sidecar_result = snapshot_sidecar.wait();
let event_export_sidecar_result = event_export_sidecar.wait();
let relayer_result = relayer.wait();
let (sidecar_result, relayer_result) = tokio::try_join!(sidecar_result, relayer_result)
.expect("Either snapshot sidecar or relayer process encountered an error");

error!("sidecar exited with: {:?}", sidecar_result);
let (snapshot_sidecar_result, event_export_sidecar_result, relayer_result) = tokio::try_join!(
snapshot_sidecar_result,
event_export_sidecar_result,
relayer_result
)
.expect(
"Either snapshot sidecar, event export sidecar, or relayer process encountered an error",
);

error!("snapshot sidecar exited with: {:?}", snapshot_sidecar_result);
error!("event export sidecar exited with: {:?}", event_export_sidecar_result);
error!("relayer exited with: {:?}", relayer_result);
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions node-support/event-export-sidecar/src/event_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::net::{UnixListener, UnixStream};
use tracing::{error, info, warn};
use url::Url;

use crate::hse_client::HseClient;
use crate::hse_client::HistoricalStateClient;

// -------------
// | Constants |
Expand All @@ -34,12 +34,12 @@ pub struct EventSocket {
path: String,

/// The historical state engine client
hse_client: HseClient,
hse_client: HistoricalStateClient,
}

impl EventSocket {
/// Creates a new event socket from the given URL
pub async fn new(url: &Url, hse_client: HseClient) -> Result<Self, Error> {
pub async fn new(url: &Url, hse_client: HistoricalStateClient) -> Result<Self, Error> {
let path = extract_unix_socket_path(url)?;
let socket = Self::establish_socket_connection(&path).await?;
Ok(Self { socket, path, hse_client })
Expand Down
6 changes: 3 additions & 3 deletions node-support/event-export-sidecar/src/hse_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const EVENT_SUBMISSION_PATH: &str = "/event";
// ----------

/// A client for the historical state engine
pub struct HseClient {
pub struct HistoricalStateClient {
/// The base URL of the historical state engine
base_url: String,
/// The auth key for the historical state engine
auth_key: HmacKey,
}

impl HseClient {
impl HistoricalStateClient {
/// Create a new historical state engine client
pub fn new(base_url: String, auth_key: HmacKey) -> Self {
Self { base_url, auth_key }
Expand All @@ -40,7 +40,7 @@ impl HseClient {
/// Submit an event to the historical state engine
pub async fn submit_event(&self, event: &RelayerEvent) -> Result<(), Error> {
send_authenticated_request(
&format!("{}{}", self.base_url, EVENT_SUBMISSION_PATH),
&self.base_url,
EVENT_SUBMISSION_PATH,
Method::POST,
event,
Expand Down
4 changes: 2 additions & 2 deletions node-support/event-export-sidecar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use common::types::wallet::keychain::HmacKey;
use config::parsing::parse_config_from_file;
use event_socket::EventSocket;
use eyre::Error;
use hse_client::HseClient;
use hse_client::HistoricalStateClient;
use tracing::{info, warn};

// -------
Expand Down Expand Up @@ -52,7 +52,7 @@ async fn main() -> Result<(), Error> {

// Construct HSE client
let hse_key = HmacKey::from_base64_string(&cli.hse_key).expect("invalid hse key");
let hse_client = HseClient::new(cli.hse_url, hse_key);
let hse_client = HistoricalStateClient::new(cli.hse_url, hse_key);

let event_socket =
EventSocket::new(&relayer_config.event_export_url.unwrap(), hse_client).await?;
Expand Down
1 change: 1 addition & 0 deletions workers/job-types/src/event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub struct MatchEvent {

/// A convenience type encapsulating the event data for a single party in a
/// match
#[derive(Clone, Copy)]
pub struct PartyMatchData {
/// The ID of the party's wallet
pub wallet_id: WalletIdentifier,
Expand Down

0 comments on commit 4bff185

Please sign in to comment.