-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3a70ef
commit d5c787f
Showing
15 changed files
with
314 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,52 @@ | ||
FROM rust:1.71-slim-bookworm as builder | ||
LABEL description="STAGE 1: Build" | ||
|
||
# Add files for build | ||
ADD common /serai/common | ||
ADD crypto /serai/crypto | ||
ADD coins /serai/coins | ||
ADD message-queue /serai/message-queue | ||
ADD processor /serai/processor | ||
ADD coordinator /serai/coordinator | ||
ADD substrate /serai/substrate | ||
ADD tests /serai/tests | ||
ADD Cargo.toml /serai | ||
ADD Cargo.lock /serai | ||
ADD AGPL-3.0 /serai | ||
|
||
WORKDIR /serai | ||
|
||
RUN apt update && apt upgrade -y && apt install -y pkg-config clang libssl-dev | ||
|
||
# Add the wasm toolchain | ||
RUN rustup target add wasm32-unknown-unknown | ||
|
||
# Mount the caches and build | ||
RUN --mount=type=cache,target=/root/.cargo \ | ||
--mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git \ | ||
--mount=type=cache,target=/serai/target \ | ||
cd coordinator && \ | ||
cargo build --release --all-features && \ | ||
mkdir /serai/bin && \ | ||
mv /serai/target/release/serai-coordinator /serai/bin | ||
|
||
# Prepare Image | ||
FROM debian:bookworm-slim as image | ||
LABEL description="STAGE 2: Copy and Run" | ||
|
||
# Upgrade packages and install openssl | ||
RUN apt update && apt upgrade -y && apt install -y libssl-dev | ||
|
||
# Switch to a non-root user | ||
RUN useradd --system --create-home --shell /sbin/nologin coordinator | ||
USER coordinator | ||
|
||
WORKDIR /home/coordinator | ||
|
||
# Copy necessary files to run node | ||
COPY --from=builder --chown=processsor /serai/bin/serai-coordinator /bin/ | ||
COPY --from=builder --chown=processsor /serai/AGPL-3.0 . | ||
|
||
# Run coordinator | ||
CMD ["serai-coordinator"] |
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,9 @@ | ||
#!/bin/bash | ||
|
||
export MESSAGE_QUEUE_KEY="0000000000000000000000000000000000000000000000000000000000000000" | ||
export MESSAGE_QUEUE_RPC="http://127.0.0.1:2287" | ||
|
||
export DB_PATH="./coordinator-db" | ||
export SERAI_HOSTNAME="127.0.0.1" | ||
|
||
serai-coordinator |
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,30 @@ | ||
[package] | ||
name = "serai-coordinator-tests" | ||
version = "0.1.0" | ||
description = "Tests for Serai's Coordinator" | ||
license = "AGPL-3.0-only" | ||
repository = "https://github.com/serai-dex/serai/tree/develop/tests/coordinator" | ||
authors = ["Luke Parker <[email protected]>"] | ||
keywords = [] | ||
edition = "2021" | ||
publish = false | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[dependencies] | ||
hex = "0.4" | ||
|
||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["ristretto"] } | ||
|
||
messages = { package = "serai-processor-messages", path = "../../processor/messages" } | ||
|
||
serai-client = { path = "../../substrate/client" } | ||
serai-message-queue = { path = "../../message-queue" } | ||
|
||
tokio = { version = "1", features = ["time"] } | ||
|
||
dockertest = "0.3" | ||
serai-docker-tests = { path = "../docker" } | ||
serai-message-queue-tests = { path = "../message-queue" } |
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 @@ | ||
AGPL-3.0-only license | ||
|
||
Copyright (c) 2023 Luke Parker | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License Version 3 as | ||
published by the Free Software Foundation. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
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,95 @@ | ||
#![allow(clippy::needless_pass_by_ref_mut)] // False positives | ||
|
||
use std::sync::{OnceLock, Mutex}; | ||
|
||
use ciphersuite::{group::ff::PrimeField, Ciphersuite, Ristretto}; | ||
|
||
use serai_client::primitives::NetworkId; | ||
|
||
use dockertest::{PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition}; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
static UNIQUE_ID: OnceLock<Mutex<u16>> = OnceLock::new(); | ||
|
||
pub fn coordinator_instance(message_queue_key: <Ristretto as Ciphersuite>::F) -> Composition { | ||
serai_docker_tests::build("coordinator".to_string()); | ||
|
||
Composition::with_image( | ||
Image::with_repository("serai-dev-coordinator").pull_policy(PullPolicy::Never), | ||
) | ||
.with_env( | ||
[ | ||
("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())), | ||
("DB_PATH".to_string(), "./coordinator-db".to_string()), | ||
] | ||
.into(), | ||
) | ||
} | ||
|
||
pub fn serai_composition(name: &str) -> Composition { | ||
serai_docker_tests::build("serai".to_string()); | ||
|
||
Composition::with_image(Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never)) | ||
.with_cmd(vec![ | ||
"serai-node".to_string(), | ||
"--unsafe-rpc-external".to_string(), | ||
"--rpc-cors".to_string(), | ||
"all".to_string(), | ||
"--chain".to_string(), | ||
"devnet".to_string(), | ||
format!("--{name}"), | ||
]) | ||
} | ||
|
||
pub type Handles = (String, String, String); | ||
pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<Composition>) { | ||
let serai_composition = serai_composition(name); | ||
|
||
let (coord_key, message_queue_keys, message_queue_composition) = | ||
serai_message_queue_tests::instance(); | ||
|
||
let coordinator_composition = coordinator_instance(message_queue_keys[&NetworkId::Bitcoin]); | ||
|
||
// Give every item in this stack a unique ID | ||
// Uses a Mutex as we can't generate a 8-byte random ID without hitting hostname length limits | ||
let unique_id = { | ||
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0)); | ||
let mut unique_id_lock = unique_id_mutex.lock().unwrap(); | ||
let unique_id = hex::encode(unique_id_lock.to_be_bytes()); | ||
*unique_id_lock += 1; | ||
unique_id | ||
}; | ||
|
||
let mut compositions = vec![]; | ||
let mut handles = vec![]; | ||
for composition in [serai_composition, message_queue_composition, coordinator_composition] { | ||
let handle = composition.handle(); | ||
compositions.push( | ||
composition | ||
.with_start_policy(StartPolicy::Strict) | ||
.with_container_name(format!("{handle}-{}", &unique_id)) | ||
.with_log_options(Some(LogOptions { | ||
action: LogAction::Forward, | ||
policy: if handle.contains("coordinator") { | ||
LogPolicy::Always | ||
} else { | ||
LogPolicy::OnError | ||
}, | ||
source: LogSource::Both, | ||
})), | ||
); | ||
handles.push(compositions.last().unwrap().handle()); | ||
} | ||
|
||
let coordinator_composition = compositions.last_mut().unwrap(); | ||
coordinator_composition.inject_container_name(handles.remove(0), "SERAI_HOSTNAME"); | ||
coordinator_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC"); | ||
|
||
( | ||
(compositions[0].handle(), compositions[1].handle(), compositions[2].handle()), | ||
coord_key, | ||
compositions, | ||
) | ||
} |
Oops, something went wrong.