Skip to content

Commit

Permalink
Merge pull request #82 from ethstorage/devnetfix
Browse files Browse the repository at this point in the history
Validate miner address and other updates
  • Loading branch information
syntrust authored Nov 19, 2023
2 parents 9636a78 + bb1fda4 commit a463d9d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +32,7 @@ Remember to use the signer's private key (with ETH balance) to replace `<private
## Step 2. Download source code
```sh
# download source code
git clone git@github.com:ethstorage/es-node.git
git clone https://github.com/ethstorage/es-node.git

# go to the repo
cd es-node
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions cmd/es-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func EsNodeInit(ctx *cli.Context) error {
log.Info("Will create data files for storage node")
l1Rpc := readRequiredFlag(ctx, flags.L1NodeAddr.Name)
contract := readRequiredFlag(ctx, flags.StorageL1Contract.Name)
if !common.IsHexAddress(contract) {
return fmt.Errorf("invalid contract address %s", contract)
}

datadir := readRequiredFlag(ctx, flags.DataDir.Name)
encodingType := ethstorage.ENCODE_BLOB_POSEIDON
miner := "0x"
Expand All @@ -178,6 +182,9 @@ func EsNodeInit(ctx *cli.Context) error {
}
if encodingType != ethstorage.NO_ENCODE {
miner = readRequiredFlag(ctx, flags.StorageMiner.Name)
if !common.IsHexAddress(miner) {
return fmt.Errorf("invalid miner address %s", miner)
}
}
shardIndexes := ctx.Int64Slice(shardIndexFlagName)
log.Info("Read flag", "name", shardIndexFlagName, "value", shardIndexes)
Expand Down
41 changes: 35 additions & 6 deletions run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,54 @@
# usage:
# env ES_NODE_STORAGE_MINER=<miner> ES_NODE_SIGNER_PRIVATE_KEY=<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 ] || 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

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

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 -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
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 \
-p 9545:9545 \
-p 9222:9222 \
-p 30305:30305/udp \
-d \
--entrypoint /es-node/run.sh \
$image_name
echo "container $container_name started"
fi
fi
22 changes: 18 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
# env ES_NODE_STORAGE_MINER=<miner> ES_NODE_SIGNER_PRIVATE_KEY=<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 ] || 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

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 "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64"
exit 1
fi

Expand Down Expand Up @@ -55,8 +65,12 @@ 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}"
exit 1
fi
fi

# start es-node
Expand Down

0 comments on commit a463d9d

Please sign in to comment.