From 0483fc5526478519879084062ec6c45d23241fba Mon Sep 17 00:00:00 2001 From: Yohan9206 Date: Sun, 3 Aug 2025 16:19:04 +0300 Subject: [PATCH] working on blockscout --- .github/workflows/deploy-devnet.yml | 103 ++++++++++++++++------------ Dockerfile | 48 ++++++------- OldDfile | 33 +++++++++ docker-compose.yaml | 48 +------------ docker-compose_old.yaml | 64 +++++++++++++++++ hardhat/hardhat.config.js | 23 ++++++- start.sh | 26 +++++++ terraform.tfstate | 9 +++ 8 files changed, 239 insertions(+), 115 deletions(-) create mode 100644 OldDfile create mode 100644 docker-compose_old.yaml create mode 100644 start.sh create mode 100644 terraform.tfstate diff --git a/.github/workflows/deploy-devnet.yml b/.github/workflows/deploy-devnet.yml index 5257193db2..c635309ff8 100644 --- a/.github/workflows/deploy-devnet.yml +++ b/.github/workflows/deploy-devnet.yml @@ -20,7 +20,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 - # capture SHA as an env variables - name: Get short commit SHA id: vars run: echo "COMMIT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV @@ -32,33 +31,9 @@ jobs: run: | docker run -d \ --name $CONTAINER_NAME \ - -p 8545:8545 \ + -p 8545:8545 -p 4000:4000 \ $BASE_IMAGE \ - --dev --http --http.addr 0.0.0.0 --http.vhosts "*" --http.api eth,net,web3,personal - - -# - name: check if curl is installed -# run: docker exec $CONTAINER_NAME which curl - # - name: Wait for Geth RPC to become available - # run: | - # echo "Waiting for Geth RPC to be ready..." - # for i in {1..30}; do - # if docker exec $CONTAINER_NAME curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8545 > /dev/null; then - # echo "Geth RPC is up!" - # break - # fi - # echo "Attempt $i: Not yet ready..." - # sleep 2 - # done - - # if ! docker exec $CONTAINER_NAME curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8545 > /dev/null; then - # echo "❌ Geth RPC did not start within 60 seconds." - # echo "--- Container logs ---" - # docker logs $CONTAINER_NAME - # echo "--- Container status ---" - # docker ps -a - # exit 1 - # fi + /bin/sh /start.sh - name: Set up Node.js uses: actions/setup-node@v3 @@ -69,9 +44,44 @@ jobs: working-directory: ./hardhat run: npm install - - name: Deploy contracts to devnet + - name: Deploy contracts to devnet and capture address working-directory: ./hardhat - run: npx hardhat run scripts/deploy.js --network localhost + run: | + DEPLOY_OUTPUT=$(npx hardhat run scripts/deploy.js --network localhost) + echo "$DEPLOY_OUTPUT" + echo "$DEPLOY_OUTPUT" > deploy.log + echo "CONTRACT_ADDRESS=$(echo \"$DEPLOY_OUTPUT\" | grep -i 'Lock deployed to:' | awk '{ print $NF }')" >> $GITHUB_ENV + + - name: Retry contract verification on Blockscout + working-directory: ./hardhat + run: | + echo "🔍 Verifying contract at $CONTRACT_ADDRESS" + for i in {1..5}; do + npx hardhat verify --network localhost $CONTRACT_ADDRESS && break + echo "Retry $i: Verification failed. Waiting for Blockscout sync..." + sleep 10 + done + + - name: Confirm contract is visible in Blockscout + run: | + echo "Waiting for Blockscout explorer to index contract..." + for i in {1..30}; do + CODE=$(curl -s http://localhost:4000/api \ + -d "module=contract" \ + -d "action=getsourcecode" \ + -d "address=$CONTRACT_ADDRESS" | jq -r '.result[0].SourceCode') + + if [ "$CODE" != "" ] && [ "$CODE" != "null" ]; then + echo "✅ Contract is now visible in Blockscout" + exit 0 + fi + + echo "⏳ Not indexed yet, retrying ($i)..." + sleep 5 + done + + echo "❌ Contract not found in Blockscout after timeout." + exit 1 - name: Commit container with deployed contracts run: | @@ -91,30 +101,33 @@ jobs: run: | docker push $FINAL_IMAGE:latest docker push $FINAL_IMAGE:${{ env.COMMIT_SHA }} - + - name: Run container with predeployed contracts run: | docker run -d \ --name test-node \ - -p 8545:8545 \ + -p 8545:8545 -p 4000:4000 \ $FINAL_IMAGE:latest \ - --dev --http --http.addr 0.0.0.0 --http.vhosts "*" --http.api eth,net,web3,personal - sleep 20 + /bin/sh /start.sh + sleep 20 - # - name: Wait for RPC to be ready - # run: | - # echo "Waiting for devnet to be ready..." - # for i in {1..20}; do - # if curl -s http://localhost:8545 > /dev/null; then - # echo "RPC is ready." - # break - # fi - # sleep 2 - # done + - name: Check Blockscout Explorer + run: | + echo "Waiting for Blockscout..." + for i in {1..30}; do + if curl -s http://localhost:4000 | grep -qi "blockscout"; then + echo "✅ Blockscout UI is up!" + exit 0 + fi + sleep 5 + done + echo "❌ Blockscout did not respond." + docker logs test-node + exit 1 - name: Run Hardhat tests working-directory: ./hardhat - run: npx hardhat test # --network localhost + run: npx hardhat test - name: Stop and remove test container - run: docker rm -f test-node \ No newline at end of file + run: docker rm -f test-node \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index cdc9e2a8bf..1136a98fd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,35 @@ -# Support setting various labels on the final image -ARG COMMIT="" -ARG VERSION="" -ARG BUILDNUM="" +# Base Geth build stage remains the same -# Build Geth in a stock Go builder container -FROM golang:1.24-alpine AS builder +# Additional stage for Blockscout dependencies +FROM hexpm/elixir:1.14.5-erlang-25.3.2.6-alpine-3.18.0 as blockscout-builder -RUN apk add --no-cache gcc musl-dev linux-headers git +RUN apk add --no-cache build-base git curl postgresql-dev inotify-tools npm gcompat -# Get dependencies - will also be cached if we won't change go.mod/go.sum -COPY go.mod /go-ethereum/ -COPY go.sum /go-ethereum/ -RUN cd /go-ethereum && go mod download +# Clone Blockscout source +RUN git clone https://github.com/blockscout/blockscout.git /blockscout -ADD . /go-ethereum -RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth +WORKDIR /blockscout -# Pull Geth into a second stage deploy alpine container +RUN mix local.hex --force && \ + mix local.rebar --force && \ + mix deps.get && \ + mix compile + +RUN mix do ecto.create, ecto.migrate + +RUN mix phx.digest && MIX_ENV=prod mix release + +# Final image FROM alpine:latest -RUN apk add --no-cache ca-certificates +RUN apk add --no-cache ca-certificates libstdc++ postgresql-client su-exec bash curl + COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ +COPY --from=blockscout-builder /blockscout /blockscout -EXPOSE 8545 8546 30303 30303/udp -ENTRYPOINT ["geth", "--dev", "--http", "--http.addr", "0.0.0.0", "--http.vhosts", "*", "--http.api", "eth,net,web3,personal"] +# Custom entrypoint +COPY start.sh /start.sh +RUN chmod +x /start.sh -# Add some metadata labels to help programmatic image consumption -ARG COMMIT="" -ARG VERSION="" -ARG BUILDNUM="" - -LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" +EXPOSE 8545 8546 30303 4000 +ENTRYPOINT ["/bin/sh", "/start.sh"] diff --git a/OldDfile b/OldDfile new file mode 100644 index 0000000000..616cfc28bc --- /dev/null +++ b/OldDfile @@ -0,0 +1,33 @@ +# Support setting various labels on the final image +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +# Build Geth in a stock Go builder container +FROM golang:1.24-alpine AS builder + +RUN apk add --no-cache gcc musl-dev linux-headers git + +# Get dependencies - will also be cached if we won't change go.mod/go.sum +COPY go.mod /go-ethereum/ +COPY go.sum /go-ethereum/ +RUN cd /go-ethereum && go mod download + +ADD . /go-ethereum +RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth + +# Pull Geth into a second stage deploy alpine container +FROM alpine:latest + +RUN apk add --no-cache ca-certificates +COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ + +EXPOSE 8545 8546 30303 30303/udp +ENTRYPOINT ["geth", "--dev", "--http", "--http.addr", "0.0.0.0", "--http.vhosts", "*", "--http.api", "eth,net,web3,personal"] + +# Add some metadata labels to help programmatic image consumption +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index e0aa6bbdaf..7666272bbe 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,55 +8,11 @@ services: - "8545:8545" - "8546:8546" - "30303:30303" + - "4000:4000" volumes: - geth-data:/root/.ethereum restart: unless-stopped - command: [ - "geth", - "--dev", - "--http", - "--http.addr", "0.0.0.0", - "--http.vhosts", "*", - "--http.api", "personal,eth,net,web3,miner", - "--http.corsdomain", "*", - "--ws", - "--ws.addr", "0.0.0.0", - "--ws.api", "personal,eth,net,web3,miner", - "--allow-insecure-unlock", - "--mine", - "--nodiscover" - ] - - # postgres: - # image: postgres:13 - # container_name: blockscout-db - # environment: - # POSTGRES_USER: postgres - # POSTGRES_PASSWORD: postgres - # POSTGRES_DB: blockscout - # ports: - # - "5432:5432" - # volumes: - # - pg-data:/var/lib/postgresql/data - - # blockscout: - # image: blockscout/blockscout:latest - # container_name: blockscout - # depends_on: - # - geth-node - # - postgres - # ports: - # - "4000:4000" - # environment: - # ETHEREUM_JSONRPC_HTTP_URL: http://geth-node:8545 - # DATABASE_URL: postgresql://postgres:postgres@postgres:5432/blockscout - # NETWORK: "Devnet" - # SUBNETWORK: "Geth Dev Mode" - # COIN: "ETH" - # MIX_ENV: "prod" - # PORT: 4000 - # BLOCKSCOUT_HOST: "0.0.0.0" - # restart: unless-stopped + command: ["/bin/sh", "/start.sh"] volumes: geth-data: diff --git a/docker-compose_old.yaml b/docker-compose_old.yaml new file mode 100644 index 0000000000..d2cc0f9f28 --- /dev/null +++ b/docker-compose_old.yaml @@ -0,0 +1,64 @@ +version: '3.8' + +services: + geth-node: + image: yohands/my_first_container + container_name: geth-devnet + ports: + - "8545:8545" + - "8546:8546" + - "30303:30303" + - "4000:4000" + volumes: + - geth-data:/root/.ethereum + restart: unless-stopped + command: [ + "geth", + "--dev", + "--http", + "--http.addr", "0.0.0.0", + "--http.vhosts", "*", + "--http.api", "personal,eth,net,web3,miner", + "--http.corsdomain", "*", + "--ws", + "--ws.addr", "0.0.0.0", + "--ws.api", "personal,eth,net,web3,miner", + "--allow-insecure-unlock", + "--mine", + "--nodiscover" + ] + + # postgres: + # image: postgres:13 + # container_name: blockscout-db + # environment: + # POSTGRES_USER: postgres + # POSTGRES_PASSWORD: postgres + # POSTGRES_DB: blockscout + # ports: + # - "5432:5432" + # volumes: + # - pg-data:/var/lib/postgresql/data + + # blockscout: + # image: blockscout/blockscout:latest + # container_name: blockscout + # depends_on: + # - geth-node + # - postgres + # ports: + # - "4000:4000" + # environment: + # ETHEREUM_JSONRPC_HTTP_URL: http://geth-node:8545 + # DATABASE_URL: postgresql://postgres:postgres@postgres:5432/blockscout + # NETWORK: "Devnet" + # SUBNETWORK: "Geth Dev Mode" + # COIN: "ETH" + # MIX_ENV: "prod" + # PORT: 4000 + # BLOCKSCOUT_HOST: "0.0.0.0" + # restart: unless-stopped + +volumes: + geth-data: + pg-data: \ No newline at end of file diff --git a/hardhat/hardhat.config.js b/hardhat/hardhat.config.js index b63f0c2f2e..85e8af102f 100644 --- a/hardhat/hardhat.config.js +++ b/hardhat/hardhat.config.js @@ -3,4 +3,25 @@ require("@nomicfoundation/hardhat-toolbox"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: "0.8.28", -}; + networks: { + localhost: { + url: "http://127.0.0.1:8545", + chainId: 1337 + } + }, + etherscan: { + apiKey: { + localhost: "abc123" // dummy or optional if not enforced + }, + customChains: [ + { + network: "localhost", + chainId: 1337, + urls: { + apiURL: "http://localhost:4000/api", + browserURL: "http://localhost:4000" + } + } + ] + } +}; \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000000..65f5846279 --- /dev/null +++ b/start.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Start PostgreSQL for Blockscout +docker-entrypoint.sh postgres & + +# Wait for DB to be ready +until pg_isready -h localhost -p 5432; do + echo "Waiting for Postgres..." + sleep 2 +done + +# Start Geth +geth --dev \ + --http --http.addr 0.0.0.0 \ + --http.vhosts "*" --http.api eth,net,web3,personal \ + --ws --ws.addr 0.0.0.0 \ + --allow-insecure-unlock --mine --nodiscover & + +# Start Blockscout +cd /blockscout && \ +DATABASE_URL=postgresql://postgres:postgres@localhost:5432/blockscout \ +ETHEREUM_JSONRPC_HTTP_URL=http://localhost:8545 \ +PORT=4000 \ +MIX_ENV=prod \ +/blockscout/_build/prod/rel/blockscout/bin/blockscout start + +wait \ No newline at end of file diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000000..506cee097c --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,9 @@ +{ + "version": 4, + "terraform_version": "1.12.2", + "serial": 1, + "lineage": "40f0fde9-d9f7-345b-6b37-4ce3b96e72ae", + "outputs": {}, + "resources": [], + "check_results": null +}