From 4bff1855ad7aacb7b26bea020edd72a1dbd38e6f Mon Sep 17 00:00:00 2001 From: Andrew Kirillov Date: Thu, 12 Dec 2024 10:56:06 -0800 Subject: [PATCH] node-support: bootloader, docker: release: build & invoke event export sidecar in bootloader --- docker/release/Dockerfile | 7 +++- node-support/bootloader/src/main.rs | 40 +++++++++++++++---- .../event-export-sidecar/src/event_socket.rs | 6 +-- .../event-export-sidecar/src/hse_client.rs | 6 +-- node-support/event-export-sidecar/src/main.rs | 4 +- workers/job-types/src/event_manager.rs | 1 + 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/docker/release/Dockerfile b/docker/release/Dockerfile index 57bb176e0..7d516eec2 100644 --- a/docker/release/Dockerfile +++ b/docker/release/Dockerfile @@ -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" @@ -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 diff --git a/node-support/bootloader/src/main.rs b/node-support/bootloader/src/main.rs index 019da2305..1de0a9e49 100644 --- a/node-support/bootloader/src/main.rs +++ b/node-support/bootloader/src/main.rs @@ -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 --- // @@ -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"; @@ -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::(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::(ENV_HISTORICAL_STATE_URL)?; + let hse_key = read_env_var::(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(()) } diff --git a/node-support/event-export-sidecar/src/event_socket.rs b/node-support/event-export-sidecar/src/event_socket.rs index 1669b886c..6a6ab0575 100644 --- a/node-support/event-export-sidecar/src/event_socket.rs +++ b/node-support/event-export-sidecar/src/event_socket.rs @@ -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 | @@ -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 { + pub async fn new(url: &Url, hse_client: HistoricalStateClient) -> Result { let path = extract_unix_socket_path(url)?; let socket = Self::establish_socket_connection(&path).await?; Ok(Self { socket, path, hse_client }) diff --git a/node-support/event-export-sidecar/src/hse_client.rs b/node-support/event-export-sidecar/src/hse_client.rs index 369db92b4..83daa570e 100644 --- a/node-support/event-export-sidecar/src/hse_client.rs +++ b/node-support/event-export-sidecar/src/hse_client.rs @@ -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 } @@ -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, diff --git a/node-support/event-export-sidecar/src/main.rs b/node-support/event-export-sidecar/src/main.rs index 549ce5896..393f38825 100644 --- a/node-support/event-export-sidecar/src/main.rs +++ b/node-support/event-export-sidecar/src/main.rs @@ -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}; // ------- @@ -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?; diff --git a/workers/job-types/src/event_manager.rs b/workers/job-types/src/event_manager.rs index ae493f3b4..55123c7c7 100644 --- a/workers/job-types/src/event_manager.rs +++ b/workers/job-types/src/event_manager.rs @@ -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,