Skip to content

Commit

Permalink
Compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Dec 19, 2024
1 parent c92e338 commit 196bb16
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 86 deletions.
11 changes: 10 additions & 1 deletion .deploy/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/usr/bin/env bash

docker build -t ghcr.io/gnosisguild/ciphernode:mytest -f ./packages/ciphernode/Dockerfile .
# Enable BuildKit
export DOCKER_BUILDKIT=1

mkdir -p /tmp/docker-cache

time docker buildx build \
--cache-from=type=local,src=/tmp/docker-cache \
--cache-to=type=local,dest=/tmp/docker-cache \
--load \
-t ghcr.io/gnosisguild/ciphernode -f ./packages/ciphernode/Dockerfile .
29 changes: 24 additions & 5 deletions .deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#!/usr/bin/env bash

if [ ! -f "./.deploy/.env" ]; then
echo "Environment file ./.deploy/.env not found!"
exit 1
fi
wait_ready() {
local stack_name="$1"
until [ "$(docker stack services $stack_name --format '{{.Replicas}}' | awk -F'/' '$1 != $2')" = "" ]; do
printf "."
sleep 1
done
echo -ne "\r\033[K"
echo "Stack $stack_name is ready!"
}

docker stack deploy -c .deploy/docker-compose.yml enclave-stack --detach=false
wait_removed() {
local stack_name="$1"
while docker stack ps $stack_name >/dev/null 2>&1; do
printf "."
sleep 1
done
echo -ne "\r\033[K"
echo "Stack $stack_name is removed"
}

stack_name=${1:-enclave}
docker stack rm $stack_name
wait_removed $stack_name
docker stack deploy -c docker-compose.yml --prune $stack_name
wait_ready $stack_name
22 changes: 13 additions & 9 deletions .deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
cn1:
image: ghcr.io/gnosisguild/ciphernode:20241210-44aac5b0
image: ghcr.io/gnosisguild/ciphernode:latest
volumes:
- ./cn1.yaml:/home/ciphernode/.config/enclave/config.yaml:ro
- cn1-data:/home/ciphernode/.local/share/enclave
Expand All @@ -14,9 +14,11 @@ services:
ADDRESS: "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E"
QUIC_PORT: 9091
ports:
- "9091:9091"
- "9091:9091/udp"
- "9091:9091/tcp"
deploy:
replicas: 1
endpoint_mode: dnsrr
update_config:
parallelism: 1
order: stop-first
Expand All @@ -27,7 +29,7 @@ services:
- global-network

cn2:
image: ghcr.io/gnosisguild/ciphernode:20241210-44aac5b0
image: ghcr.io/gnosisguild/ciphernode:latest
depends_on:
- cn1
volumes:
Expand All @@ -43,7 +45,8 @@ services:
ADDRESS: "0xdD2FD4581271e230360230F9337D5c0430Bf44C0"
QUIC_PORT: 9092
ports:
- "9092:9092"
- "9092:9092/udp"
- "9092:9092/tcp"
deploy:
replicas: 1
update_config:
Expand All @@ -56,7 +59,7 @@ services:
- global-network

cn3:
image: ghcr.io/gnosisguild/ciphernode:20241210-44aac5b0
image: ghcr.io/gnosisguild/ciphernode:latest
depends_on:
- cn1
volumes:
Expand All @@ -72,7 +75,8 @@ services:
ADDRESS: "0x2546BcD3c84621e976D8185a91A922aE77ECEc30"
QUIC_PORT: 9093
ports:
- "9093:9093"
- "9093:9093/udp"
- "9093:9093/tcp"
deploy:
replicas: 1
update_config:
Expand All @@ -85,7 +89,7 @@ services:
- global-network

aggregator:
image: ghcr.io/gnosisguild/ciphernode:20241210-44aac5b0
image: ghcr.io/gnosisguild/ciphernode:latest
depends_on:
- cn1
volumes:
Expand All @@ -101,8 +105,8 @@ services:
ADDRESS: "0x8626a6940E2eb28930eFb4CeF49B2d1F2C9C1199"
QUIC_PORT: 9094
ports:
- "9094:9094"

- "9094:9094/udp"
- "9094:9094/tcp"
deploy:
replicas: 1
update_config:
Expand Down
31 changes: 31 additions & 0 deletions packages/ciphernode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ciphernode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bs58 = "0.5.1"
base64 = "0.22.1"
clap = { version = "4.5.17", features = ["derive"] }
cipher = { path = "./cipher" }
compile-time = "0.2.0"
dirs = "5.0.1"
data = { path = "./data" }
shellexpand = "3.1.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/ciphernode/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tracing = { workspace = true }
tracing-subscriber = { workspace = true }
zeroize = { workspace = true }
phf = { version = "0.11", features = ["macros"] }
compile-time = { workspace = true }
rand = { workspace = true }
petname = "2.0.2"

[build-dependencies]
serde_json = { workspace = true }
13 changes: 13 additions & 0 deletions packages/ciphernode/enclave/src/compile_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use petname::{Generator, Petnames};
use rand::rngs::StdRng;
use rand::SeedableRng;

static COMPILE_ID: u64 = compile_time::unix!();

/// Generate a unique compilation ID for the build based on the time of compilation
pub fn generate_id() -> String {
let mut rng = StdRng::seed_from_u64(COMPILE_ID);
Petnames::small()
.generate(&mut rng, 3, "_")
.unwrap_or("default-name".to_owned())
}
7 changes: 6 additions & 1 deletion packages/ciphernode/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use clap::Parser;
use commands::{aggregator, init, net, password, start, wallet, Commands};
use config::load_config;
use enclave_core::{get_tag, set_tag};
use tracing::instrument;
use tracing::{info, instrument};
use tracing_subscriber::EnvFilter;

pub mod commands;
mod compile_id;

const OWO: &str = r#"
___ ___ ___ ___ ___
Expand Down Expand Up @@ -85,6 +87,9 @@ pub async fn main() {
// .with_env_filter("[app{id=cn4}]=info")
// .with_env_filter("[app{id=ag}]=info")
.init();

info!("COMPILATION ID: '{}'", compile_id::generate_id());

let cli = Cli::parse();

// Set the tag for all future traces
Expand Down
20 changes: 14 additions & 6 deletions packages/ciphernode/net/src/bin/p2p_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use net::correlation_id::CorrelationId;
use net::events::{NetworkPeerCommand, NetworkPeerEvent};
use net::NetworkPeer;
use std::time::Duration;
use std::{collections::HashSet, env, process};
Expand All @@ -19,7 +21,7 @@ async fn main() -> Result<()> {
.with(tracing_subscriber::fmt::layer())
.init();
let name = env::args().nth(1).expect("need name");

let topic = "test-topic";
println!("{} starting up", name);

let udp_port = env::var("QUIC_PORT")
Expand All @@ -42,7 +44,7 @@ async fn main() -> Result<()> {

// Extract input and outputs
let tx = peer.tx();
let mut rx = peer.rx().unwrap();
let mut rx = peer.rx();

let router_task = tokio::spawn({
let name = name.clone();
Expand All @@ -60,7 +62,12 @@ async fn main() -> Result<()> {

// Send our message first
println!("{} sending message", name);
tx.send(name.as_bytes().to_vec()).await?;
tx.send(NetworkPeerCommand::GossipPublish {
correlation_id: CorrelationId::new(),
topic: topic.to_string(),
data: name.as_bytes().to_vec(),
})
.await?;
println!("{} message sent", name);

let expected: HashSet<String> = vec![
Expand All @@ -79,16 +86,17 @@ async fn main() -> Result<()> {
// Wrap the message receiving loop in a timeout
let receive_result = timeout(Duration::from_secs(10), async {
while received != expected {
if let Some(msg) = rx.recv().await {
match String::from_utf8(msg) {
match rx.recv().await? {
NetworkPeerEvent::GossipData(msg) => match String::from_utf8(msg) {
Ok(msg) => {
if !received.contains(&msg) {
println!("{} received '{}'", name, msg);
received.insert(msg);
}
}
Err(e) => println!("{} received invalid UTF8: {}", name, e),
}
},
_ => (),
}
}
Ok::<(), anyhow::Error>(())
Expand Down
24 changes: 24 additions & 0 deletions packages/ciphernode/net/src/correlation_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{
fmt::Display,
sync::atomic::{AtomicUsize, Ordering},
};

static NEXT_CORRELATION_ID: AtomicUsize = AtomicUsize::new(1);

#[derive(Debug,Clone)]
pub struct CorrelationId {
id: usize,
}

impl CorrelationId {
pub fn new() -> Self {
let id = NEXT_CORRELATION_ID.fetch_add(1, Ordering::SeqCst);
Self { id }
}
}

impl Display for CorrelationId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.id)
}
}
Loading

0 comments on commit 196bb16

Please sign in to comment.