From 45af4b58bdff5827900ea7aecfc3c6c5a27e8e78 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 10:24:14 +0800 Subject: [PATCH 01/14] fix in devnet1 --- Dockerfile | 5 +++++ GUIDE.md | 2 +- cmd/es-node/main.go | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ef4d68f5..fdd00ef0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,11 @@ FROM golang:1.20-alpine as builder RUN apk add --no-cache gcc musl-dev linux-headers +# Get dependencies - will also be cached if we won't change go.mod/go.sum +COPY go.mod /es-node/ +COPY go.sum /es-node/ +RUN cd /es-node && go mod download + ADD . /es-node RUN cd /es-node/cmd/es-node && go build RUN cd /es-node/cmd/es-utils && go build diff --git a/GUIDE.md b/GUIDE.md index 40fb6711..2a627d67 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -32,7 +32,7 @@ Remember to use the signer's private key (with ETH balance) to replace ` Date: Fri, 17 Nov 2023 11:35:44 +0800 Subject: [PATCH 02/14] check env vars and init result --- run.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/run.sh b/run.sh index 25ff6862..18f58295 100644 --- a/run.sh +++ b/run.sh @@ -4,12 +4,32 @@ # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run.sh if [ -z "$ES_NODE_STORAGE_MINER" ]; then - echo "Please provide 'ES_NODE_STORAGE_MINER' as environment variable" + echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then + echo "ES_NODE_STORAGE_MINER should have a length of 42" + exit 1 +fi + +if [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then + echo "ES_NODE_STORAGE_MINER should be prefixed with '0x'" exit 1 fi if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then - echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as environment variable" + echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then + echo "ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" + exit 1 +fi + +if [[ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]]; then + echo "ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" exit 1 fi @@ -55,8 +75,10 @@ es_node_start=" --network devnet \ " # create data file for shard 0 if not yet if [ ! -e $storage_file_0 ]; then - $executable $es_node_init $common_flags - echo "initialized ${storage_file_0}" + if [ $executable $es_node_init $common_flags ]; then + echo "initialized ${storage_file_0} successfully" + else + echo "failed to initialize ${storage_file_0}" fi # start es-node From 3f8d66aaa147f0a9669909992edb5befd5332e86 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 11:43:16 +0800 Subject: [PATCH 03/14] check env vars --- run-docker.sh | 30 ++++++++++++++++++++++++++++++ run.sh | 8 ++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index b0fdc026..8ab32276 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -3,6 +3,36 @@ # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run-docker.sh +if [ -z "$ES_NODE_STORAGE_MINER" ]; then + echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then + echo "Error: ES_NODE_STORAGE_MINER should have a length of 42" + exit 1 +fi + +if [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" + exit 1 +fi + +if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then + echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" + exit 1 +fi + +if [[ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]]; then + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" + exit 1 +fi + container_name="es" image_name="es-node" diff --git a/run.sh b/run.sh index 18f58295..273dc155 100644 --- a/run.sh +++ b/run.sh @@ -9,12 +9,12 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then fi if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then - echo "ES_NODE_STORAGE_MINER should have a length of 42" + echo "Error: ES_NODE_STORAGE_MINER should have a length of 42" exit 1 fi if [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then - echo "ES_NODE_STORAGE_MINER should be prefixed with '0x'" + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" exit 1 fi @@ -24,12 +24,12 @@ if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then fi if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then - echo "ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" exit 1 fi if [[ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]]; then - echo "ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" exit 1 fi From 9e367ec19cfcf68a9c5d5d2285a270fcb6520b96 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 11:46:54 +0800 Subject: [PATCH 04/14] fix --- run-docker.sh | 4 ++-- run.sh | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index 8ab32276..ef5fb054 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -13,7 +13,7 @@ if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then exit 1 fi -if [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then +if [ ! "$ES_NODE_STORAGE_MINER" == 0x* ]; then echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" exit 1 fi @@ -28,7 +28,7 @@ if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then exit 1 fi -if [[ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]]; then +if [ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]; then echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" exit 1 fi diff --git a/run.sh b/run.sh index 273dc155..03177bd1 100644 --- a/run.sh +++ b/run.sh @@ -3,6 +3,7 @@ # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run.sh + if [ -z "$ES_NODE_STORAGE_MINER" ]; then echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" exit 1 @@ -13,7 +14,7 @@ if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then exit 1 fi -if [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then +if [ ! "$ES_NODE_STORAGE_MINER" == 0x* ]; then echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" exit 1 fi @@ -28,7 +29,7 @@ if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then exit 1 fi -if [[ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]]; then +if [ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]; then echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" exit 1 fi From fb24a6c87a476f68c489e1cf3bd230c0ac9925fa Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 11:48:01 +0800 Subject: [PATCH 05/14] fix --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 03177bd1..252763cf 100644 --- a/run.sh +++ b/run.sh @@ -80,6 +80,7 @@ if [ ! -e $storage_file_0 ]; then echo "initialized ${storage_file_0} successfully" else echo "failed to initialize ${storage_file_0}" + fi fi # start es-node From fcfae3d2ef0b0128a173bb4724b5cbf7fbf46899 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 12:06:11 +0800 Subject: [PATCH 06/14] fix --- run-docker.sh | 16 +++------------- run.sh | 17 +++-------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index ef5fb054..a80e5952 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run-docker.sh @@ -8,13 +8,8 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then exit 1 fi -if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then - echo "Error: ES_NODE_STORAGE_MINER should have a length of 42" - exit 1 -fi - -if [ ! "$ES_NODE_STORAGE_MINER" == 0x* ]; then - echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then + echo "Error: ES_NODE_STORAGE_MINER should have a length of 42 and prefixed with '0x" exit 1 fi @@ -28,11 +23,6 @@ if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then exit 1 fi -if [ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]; then - echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" - exit 1 -fi - container_name="es" image_name="es-node" diff --git a/run.sh b/run.sh index 252763cf..fa5c907f 100644 --- a/run.sh +++ b/run.sh @@ -1,21 +1,15 @@ -#!/bin/sh +#!/bin/bash # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run.sh - if [ -z "$ES_NODE_STORAGE_MINER" ]; then echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" exit 1 fi -if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ]; then - echo "Error: ES_NODE_STORAGE_MINER should have a length of 42" - exit 1 -fi - -if [ ! "$ES_NODE_STORAGE_MINER" == 0x* ]; then - echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x'" +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then + echo "Error: ES_NODE_STORAGE_MINER should have a length of 42 and prefixed with '0x" exit 1 fi @@ -29,11 +23,6 @@ if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then exit 1 fi -if [ "$ES_NODE_SIGNER_PRIVATE_KEY" == 0x* ]; then - echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should not be prefixed with '0x'" - exit 1 -fi - # download blob_poseidon.zkey if not yet zkey_file="./ethstorage/prover/snarkjs/blob_poseidon.zkey" if [ ! -e ${zkey_file} ]; then From 07c8a2b0035da1a94cb46338b7bfe63a53ff964b Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 12:07:59 +0800 Subject: [PATCH 07/14] fix --- run-docker.sh | 2 +- run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index a80e5952..f6e2d585 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -9,7 +9,7 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then fi if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then - echo "Error: ES_NODE_STORAGE_MINER should have a length of 42 and prefixed with '0x" + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" exit 1 fi diff --git a/run.sh b/run.sh index fa5c907f..3004425a 100644 --- a/run.sh +++ b/run.sh @@ -9,7 +9,7 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then fi if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then - echo "Error: ES_NODE_STORAGE_MINER should have a length of 42 and prefixed with '0x" + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" exit 1 fi From 9061f1ff0c7142bc441b4dcee938c3b2d9e6e4e8 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 12:10:08 +0800 Subject: [PATCH 08/14] exit if fail init --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 3004425a..69e0a6c3 100644 --- a/run.sh +++ b/run.sh @@ -69,6 +69,7 @@ if [ ! -e $storage_file_0 ]; then echo "initialized ${storage_file_0} successfully" else echo "failed to initialize ${storage_file_0}" + exit 1 fi fi From b6a36be8a23df012a43c3c94790a57b8eb8e3643 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 14:58:40 +0800 Subject: [PATCH 09/14] bash to entrypoint --- run-docker.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/run-docker.sh b/run-docker.sh index f6e2d585..155783a5 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -41,7 +41,16 @@ else echo "image $image_name built" fi # run container in the background - docker run --name $container_name -v ./es-data:/es-node/es-data -e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER -e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY -p 9545:9545 -p 9222:9222 -p 30305:30305/udp -d --entrypoint /es-node/run.sh $image_name + docker run --name $container_name \ + -v ./es-data:/es-node/es-data \ + -e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER \ + -e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY \ + -p 9545:9545 \ + -p 9222:9222 \ + -p 30305:30305/udp \ + -d \ + --entrypoint /bin/bash /es-node/run.sh \ + $image_name echo "container $container_name started" fi fi From 2b5393cac89c70e003b134e261a31dd15c49bd3f Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 15:39:14 +0800 Subject: [PATCH 10/14] use sh --- run-docker.sh | 4 ++-- run.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index 155783a5..69af9e7a 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run-docker.sh @@ -8,7 +8,7 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then exit 1 fi -if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || case $ES_NODE_STORAGE_MINER in 0x*) false;; *) true;; esac; then echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" exit 1 fi diff --git a/run.sh b/run.sh index 69e0a6c3..52c9ca57 100644 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # usage: # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run.sh @@ -8,7 +8,7 @@ if [ -z "$ES_NODE_STORAGE_MINER" ]; then exit 1 fi -if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || [[ ! "$ES_NODE_STORAGE_MINER" == 0x* ]]; then +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || case $ES_NODE_STORAGE_MINER in 0x*) false;; *) true;; esac; then echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" exit 1 fi From fd1d63fada9c154117f654a02cb28d085eb6a29d Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 15:41:43 +0800 Subject: [PATCH 11/14] fix --- run-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-docker.sh b/run-docker.sh index 69af9e7a..d3b51f4d 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -49,7 +49,7 @@ else -p 9222:9222 \ -p 30305:30305/udp \ -d \ - --entrypoint /bin/bash /es-node/run.sh \ + --entrypoint /es-node/run.sh \ $image_name echo "container $container_name started" fi From c83e69d6af2ce1c49649c35c4fa45ebda832ac51 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 16:07:43 +0800 Subject: [PATCH 12/14] fix --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 52c9ca57..5044b5e1 100644 --- a/run.sh +++ b/run.sh @@ -65,7 +65,7 @@ es_node_start=" --network devnet \ " # create data file for shard 0 if not yet if [ ! -e $storage_file_0 ]; then - if [ $executable $es_node_init $common_flags ]; then + if $executable $es_node_init $common_flags ; then echo "initialized ${storage_file_0} successfully" else echo "failed to initialize ${storage_file_0}" From 1126a7ee9bfc6ca27299501ea6e4f969fe7e8139 Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 17 Nov 2023 16:15:23 +0800 Subject: [PATCH 13/14] minor --- GUIDE.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GUIDE.md b/GUIDE.md index 2a627d67..91baec9e 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -19,7 +19,7 @@ For a detailed explanation for es-node please refer to the [README](/README.md). ## System Environment - Ubuntu 20.04+ (has been tested with) - (Optional) Docker 24.0.5+ (would simplify the process) - - (Optional) go 1.20+ and node 16+ (can be installed following the [steps](#1-install-go-120-eg-v1213)) + - (Optional) go 1.20.* (can't be built on Go 1.21 yet) and node 16+ (can be installed following the [steps](#1-install-go-120-eg-v1213)) You can choose [how to run es-node](#step-3-run-es-node) according to your current environment. ## Step 1. Prepare miner and signer account diff --git a/README.md b/README.md index 669f1a6a..a3950806 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ _Note: You need to have some ETH balance in the account of the private key as th #### Environment Please make sure that the following packages are pre-installed. -* go 1.20 or above +* go 1.20.* (can't be built on Go 1.21 yet) * node 16 or above Also, you will need to install `snarkjs` for the generation of zk proof. From bb1fda4444ff92a40c2f4ee6977abfaffb0be129 Mon Sep 17 00:00:00 2001 From: syntrust Date: Sun, 19 Nov 2023 12:14:53 +0800 Subject: [PATCH 14/14] sudo --- run-docker.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/run-docker.sh b/run-docker.sh index d3b51f4d..755673ff 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -27,21 +27,21 @@ container_name="es" image_name="es-node" # check if container is running -if docker ps --format "{{.Names}}" | grep -q "^$container_name$"; then +if sudo docker ps --format "{{.Names}}" | grep -q "^$container_name$"; then echo "container $container_name already started" else # start container if exist - if docker ps -a --format "{{.Names}}" | grep -q "^$container_name$"; then - docker start $container_name + if sudo docker ps -a --format "{{.Names}}" | grep -q "^$container_name$"; then + sudo docker start $container_name echo "container $container_name started" else # build an image if not exist - if ! docker images --format "{{.Repository}}" | grep -q "^$image_name$"; then - docker build -t $image_name . + if ! sudo docker images --format "{{.Repository}}" | grep -q "^$image_name$"; then + sudo docker build -t $image_name . echo "image $image_name built" fi # run container in the background - docker run --name $container_name \ + sudo docker run --name $container_name \ -v ./es-data:/es-node/es-data \ -e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER \ -e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY \