From 4d7171f4bf51caaf2715e151b0c0c83a4978a44d Mon Sep 17 00:00:00 2001 From: Gulshan Yadav Date: Thu, 8 Jan 2026 09:24:26 +0530 Subject: [PATCH] a --- CLAUDE.md | 11 ++++ Dockerfile | 5 +- Dockerfile.explorer | 54 +++++++++++++++---- Dockerfile.faucet | 2 +- apps/synord/src/main.rs | 4 +- crates/synor-mining/src/kheavyhash.rs | 2 +- crates/synor-mining/src/miner.rs | 2 +- crates/synor-storage/benches/storage_bench.rs | 2 +- docker-compose.testnet.yml | 53 +++++++++--------- 9 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..54b3836 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,11 @@ +# INSTRUCTIONS TO FOLLOW + +## ALWAYS DO + +1. Build/deploy changes to Docker Desktop, for all kinds of development environments, for debugging, for testing. Deploy on Docker Desktop, then use the assigned PORTS for the works/needs. +2. Use a unique reserved set of ports for this project. + +## NEVER DO + +1. Never build anything on localhost (local machine) directly without deploying the builds on Docker Desktop. +2. Never use default/varying ports. diff --git a/Dockerfile b/Dockerfile index 47d77cd..1132a45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # ============================================================================= # Stage 1: Build Environment # ============================================================================= -FROM rust:1.75-bookworm AS builder +FROM rust:1.85-bookworm AS builder # Install build dependencies RUN apt-get update && apt-get install -y \ @@ -48,9 +48,6 @@ RUN mkdir -p /data/synor && chown -R synor:synor /data # Copy binary from builder COPY --from=builder /app/target/release/synord /usr/local/bin/synord -# Copy default configuration -COPY --from=builder /app/apps/synord/config/ /etc/synor/ - # Switch to non-root user USER synor diff --git a/Dockerfile.explorer b/Dockerfile.explorer index 71e701b..0454940 100644 --- a/Dockerfile.explorer +++ b/Dockerfile.explorer @@ -1,10 +1,10 @@ -# Synor Block Explorer Backend Dockerfile -# Placeholder for future implementation +# Synor Block Explorer Dockerfile +# Multi-stage build for backend API and frontend # ============================================================================= -# Stage 1: Build Environment +# Stage 1: Build Rust Backend # ============================================================================= -FROM rust:1.75-bookworm AS builder +FROM rust:1.85-bookworm AS backend-builder # Install build dependencies RUN apt-get update && apt-get install -y \ @@ -22,11 +22,25 @@ COPY Cargo.toml Cargo.lock ./ COPY crates/ crates/ COPY apps/ apps/ -# Build (placeholder - explorer app not yet implemented) -# RUN cargo build --release --bin synor-explorer +# Build explorer backend +RUN cargo build --release -p synor-explorer # ============================================================================= -# Stage 2: Runtime Environment (placeholder) +# Stage 2: Build Frontend +# ============================================================================= +FROM node:20-alpine AS frontend-builder + +WORKDIR /app + +# Copy frontend source +COPY apps/explorer-web/package*.json ./ +RUN npm ci + +COPY apps/explorer-web/ ./ +RUN npm run build + +# ============================================================================= +# Stage 3: Runtime Environment # ============================================================================= FROM debian:bookworm-slim AS runtime @@ -40,11 +54,31 @@ RUN apt-get update && apt-get install -y \ # Create non-root user RUN useradd --create-home --shell /bin/bash explorer +# Copy backend binary +COPY --from=backend-builder /app/target/release/synor-explorer /usr/local/bin/synor-explorer + +# Copy frontend build +COPY --from=frontend-builder /app/dist /var/www/explorer + +# Set ownership +RUN chown -R explorer:explorer /var/www/explorer + USER explorer WORKDIR /home/explorer +# Expose ports EXPOSE 3000 -# Placeholder - the explorer backend is not yet implemented -# This Dockerfile serves as a template for future development -CMD ["echo", "Explorer backend not yet implemented. See apps/explorer for implementation details."] +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ + CMD curl -f http://localhost:3000/health || exit 1 + +# Environment variables +ENV SYNOR_RPC_URL=http://localhost:17110 +ENV SYNOR_WS_URL=ws://localhost:17111 +ENV EXPLORER_LISTEN_ADDR=0.0.0.0:3000 +ENV EXPLORER_STATIC_DIR=/var/www/explorer +ENV RUST_LOG=info + +# Default command +ENTRYPOINT ["synor-explorer"] diff --git a/Dockerfile.faucet b/Dockerfile.faucet index dd66e97..63a04ff 100644 --- a/Dockerfile.faucet +++ b/Dockerfile.faucet @@ -4,7 +4,7 @@ # ============================================================================= # Stage 1: Build Environment # ============================================================================= -FROM rust:1.75-bookworm AS builder +FROM rust:1.85-bookworm AS builder # Install build dependencies RUN apt-get update && apt-get install -y \ diff --git a/apps/synord/src/main.rs b/apps/synord/src/main.rs index ec5c7e0..de4a957 100644 --- a/apps/synord/src/main.rs +++ b/apps/synord/src/main.rs @@ -494,7 +494,7 @@ async fn import_blocks( errors += 1; } else { imported += 1; - if imported.is_multiple_of(1000) { + if imported % 1000 == 0 { info!("Imported {} blocks...", imported); } } @@ -586,7 +586,7 @@ async fn export_blocks( writer.write_all(&serialized)?; exported += 1; - if exported.is_multiple_of(1000) { + if exported % 1000 == 0 { info!("Exported {} blocks...", exported); } } diff --git a/crates/synor-mining/src/kheavyhash.rs b/crates/synor-mining/src/kheavyhash.rs index db8b410..1cb7d36 100644 --- a/crates/synor-mining/src/kheavyhash.rs +++ b/crates/synor-mining/src/kheavyhash.rs @@ -166,7 +166,7 @@ impl KHeavyHash { } // Report progress every 10000 hashes - if tried.is_multiple_of(10000) && !callback(tried, nonce) { + if tried % 10000 == 0 && !callback(tried, nonce) { return None; // Cancelled } } diff --git a/crates/synor-mining/src/miner.rs b/crates/synor-mining/src/miner.rs index eed9f31..eba9eb2 100644 --- a/crates/synor-mining/src/miner.rs +++ b/crates/synor-mining/src/miner.rs @@ -282,7 +282,7 @@ impl BlockMiner { nonce = nonce.wrapping_add(1); // Update stats periodically - if hashes.is_multiple_of(10000) { + if hashes % 10000 == 0 { self.hash_counter.fetch_add(10000, Ordering::Relaxed); } } diff --git a/crates/synor-storage/benches/storage_bench.rs b/crates/synor-storage/benches/storage_bench.rs index 17c4434..f80d5d8 100644 --- a/crates/synor-storage/benches/storage_bench.rs +++ b/crates/synor-storage/benches/storage_bench.rs @@ -73,7 +73,7 @@ fn make_utxo(n: u64) -> StoredUtxo { amount: 1_000_000_000 + n * 1000, script_pubkey, block_daa_score: n * 10, - is_coinbase: n.is_multiple_of(10), + is_coinbase: n % 10 == 0, } } diff --git a/docker-compose.testnet.yml b/docker-compose.testnet.yml index 9b48f25..47cfa35 100644 --- a/docker-compose.testnet.yml +++ b/docker-compose.testnet.yml @@ -1,8 +1,6 @@ # Synor Testnet Docker Compose Configuration # Deploys 3 seed nodes for initial testnet bootstrap -version: '3.8' - services: # ========================================================================== # Seed Node 1 (Primary Bootstrap) @@ -15,13 +13,13 @@ services: hostname: seed1 restart: unless-stopped command: - - "--data-dir=/data/synor" - - "--network=testnet" - - "--p2p-addr=0.0.0.0:17511" - - "--rpc-http-addr=0.0.0.0:17110" - - "--rpc-ws-addr=0.0.0.0:17111" - - "--mining-enabled" - - "--log-level=info" + - "run" + - "--p2p-host=0.0.0.0" + - "--p2p-port=17511" + - "--rpc-host=0.0.0.0" + - "--rpc-port=17110" + - "--ws-port=17111" + - "--mine" ports: - "17511:17511" # P2P - "17110:17110" # HTTP RPC @@ -33,9 +31,10 @@ services: ipv4_address: 172.20.0.10 environment: - RUST_LOG=info + - SYNOR_DATA_DIR=/data/synor - SYNOR_NETWORK=testnet healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:17110/health"] + test: ["CMD", "synord", "version"] interval: 30s timeout: 10s retries: 3 @@ -52,14 +51,14 @@ services: hostname: seed2 restart: unless-stopped command: - - "--data-dir=/data/synor" - - "--network=testnet" - - "--p2p-addr=0.0.0.0:17511" - - "--rpc-http-addr=0.0.0.0:17110" - - "--rpc-ws-addr=0.0.0.0:17111" - - "--bootstrap-peers=/ip4/172.20.0.10/tcp/17511" - - "--mining-enabled" - - "--log-level=info" + - "run" + - "--p2p-host=0.0.0.0" + - "--p2p-port=17511" + - "--rpc-host=0.0.0.0" + - "--rpc-port=17110" + - "--ws-port=17111" + - "--seeds=172.20.0.10:17511" + - "--mine" ports: - "17521:17511" # P2P (offset port) - "17120:17110" # HTTP RPC @@ -71,6 +70,7 @@ services: ipv4_address: 172.20.0.11 environment: - RUST_LOG=info + - SYNOR_DATA_DIR=/data/synor - SYNOR_NETWORK=testnet depends_on: seed1: @@ -87,14 +87,14 @@ services: hostname: seed3 restart: unless-stopped command: - - "--data-dir=/data/synor" - - "--network=testnet" - - "--p2p-addr=0.0.0.0:17511" - - "--rpc-http-addr=0.0.0.0:17110" - - "--rpc-ws-addr=0.0.0.0:17111" - - "--bootstrap-peers=/ip4/172.20.0.10/tcp/17511,/ip4/172.20.0.11/tcp/17511" - - "--mining-enabled" - - "--log-level=info" + - "run" + - "--p2p-host=0.0.0.0" + - "--p2p-port=17511" + - "--rpc-host=0.0.0.0" + - "--rpc-port=17110" + - "--ws-port=17111" + - "--seeds=172.20.0.10:17511,172.20.0.11:17511" + - "--mine" ports: - "17531:17511" # P2P (offset port) - "17130:17110" # HTTP RPC @@ -106,6 +106,7 @@ services: ipv4_address: 172.20.0.12 environment: - RUST_LOG=info + - SYNOR_DATA_DIR=/data/synor - SYNOR_NETWORK=testnet depends_on: seed1: