Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.6.0-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Aug 3, 2021
2 parents 51f1971 + 47694e5 commit b0e2400
Show file tree
Hide file tree
Showing 98 changed files with 11,140 additions and 2,827 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ db/*.go @arnaubennassar
db/historydb @arnaubennassar
db/migrations @arnaubennassar
db/l2db @arnaubennassar
txselector/ @arnaubennassar
etherscan/ @ARR552
priceupdater/ @ARR552
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
.idea/
tmp/
.stamp.*
.vscode/
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ archives:
- LICENSE
- cmd/heznode/README.md
- cmd/heznode/cfg.api.toml
- cmd/heznode/cfg.buidler.toml
- cmd/heznode/cfg.builder.toml

checksum:
name_template: 'checksums.txt'
Expand Down
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,51 @@ stop-database-container:
## exec: Run given command. e.g; make exec run="go test ./..."
exec:
$(GOENVVARS) $(run)

## install: Install the heznode cli as a service in coord mode
install:
echo " > Installing heznode as a service"
echo " > Checking requirements"
ifneq ("$(wildcard $(dist/heznode))","")
echo " - heznode file found!"
else
echo " - heznode file not found!"
echo " - please, run make build before make install!"
test -f ./dist/heznode
endif
ifneq ("$(wildcard $(cmd/heznode/cfg.builder.toml))","")
echo " - config template found!"
else
echo " - config template not found!"
echo " - please, check the !"
test -f ./cmd/heznode/cfg.builder.toml
endif
echo " > Copying hez binary to /usr/local/bin"
cp dist/heznode /usr/local/bin/heznode
echo " > Copying config file to /etc/hermez"
mkdir -p /etc/hermez
cp cmd/heznode/cfg.builder.toml /etc/hermez/config.toml
echo " > Registering as a service"
touch /etc/systemd/system/heznode.service
echo "[Unit]" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "Description=Hermez Node" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "After=postgresql.service" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "StartLimitBurst=5" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "StartLimitIntervalSec=60" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "[Service]" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "Type=simple" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "Restart=always" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "RestartSec=1" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "ExecStart=/usr/local/bin/heznode run --mode coord --cfg /etc/hermez/config.toml" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "KillMode=process" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "StandardOutput=append:/var/log/hermez-node.log" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "StandardError=append:/var/log/hermez-node.log" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "[Install]" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "WantedBy=multi-user.target" | tee -a /etc/systemd/system/heznode.service > /dev/null
echo "" | tee -a /etc/systemd/system/heznode.service > /dev/null
systemctl daemon-reload
echo " > Service is ready. Please update the configs at /etc/hermez/config.toml"
echo " > You can use the service with service heznode status|start|stop"
echo " Bye."
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ ./dist/heznode_<LOCAL_OS>_amd64/heznode version

### Run

First you must edit the default/template config file into [cmd/heznode/cfg.buidler.toml](cmd/heznode/cfg.buidler.toml),
First you must edit the default/template config file into [cmd/heznode/cfg.buidler.toml](cmd/heznode/cfg.builder.toml),
there are more information about the config file into [cmd/heznode/README.md](cmd/heznode/README.md)

After setting the config, you can build and run the Hermez Node as a synchronizer:
Expand All @@ -44,7 +44,7 @@ $ make run-node
Or build and run as a coordinator, and also passing the config file from other location:

```shell
$ MODE=sync CONFIG=cmd/heznode/cfg.buidler.toml make run-node
$ MODE=sync CONFIG=cmd/heznode/cfg.builder.toml make run-node
```

To check the useful make commands:
Expand All @@ -53,6 +53,33 @@ To check the useful make commands:
$ make help
```


### Run as a service

```shell
$ sudo make install
```

After, update the config file manually at `/etc/hermez/config.toml`

```shell
$ sudo service heznode start
```

To check status

```shell
$ sudo service heznode status
```

To stop

```shell
$ sudo service heznode stop
```

If you just kill the process systemd will restart without asking.

### Unit testing

Running the unit tests requires a connection to a PostgreSQL database. You can
Expand Down
248 changes: 248 additions & 0 deletions SETUP_NODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Set up Hermez Nede

This tutorial will help you to set up an Hermez Node and run as sync mode.

## Golang

- [ ] [Install](https://golang.org/doc/install#install) Golang
- [ ] [Create a](https://golang.org/doc/gopath_code#GOPATH) GOPATH environment
- [ ] Set GOPATH/bin into PATH machine

```command
export PATH=$PATH:$GOPATH/bin
```

## Go-Ethereum

- [ ] Clone [GETH](https://github.com/ethereum/go-ethereum) project and do a `make all` command into project folder.
- Need to have `gcc` on PATH.

On Ubuntu/Debian you need install `build-essential`

```command
sudo apt-get update
sudo apt-get install build-essential
```

- [ ] Add `build/bin` on PATH, after `make install` command inside of GETH
folder.

```command
export GETH_PATH=$GOPATH/src/github.com/ethereum/go-ethereum/
export PATH=$PATH:$GETH_PATH/build/bin
```

- [ ] Run the GETH

Enter in a empty folder (really) and you can run:

```command
nohup geth --goerli --cache 4096 --http --http.addr INTERNAL_IP
--http.corsdomain *--http.vhosts* --http.api
"admin,eth,debug,miner,net,txpool,personal,web3" --ws --ws.addr INTERNAL_IP
--graphql --graphql.corsdomain *--graphql.vhosts* --vmdebug --metrics >
~/temp/logs/geth-logs.log &
```

- [ ] Wait the geth command finished to move to next step.

## PostgreSQL

- [ ] [Install](https://www.postgresql.org/download/) PostgreSQL
- [ ] Create a PostgreSQL User called `hermez` to project.

```command
createuser --interactive
```

- [ ] Create a database

```command
createdb hermez-db
```

- [ ] Create a password to `hermez` user created at step 2

```command
ALTER USER hermez WITH PASSWORD 'Your#Password';
```

- [ ] Test connection on localhost with all steps made until now

```command
psql --host=localhost --dbname=hermez-db --username=hermez
```

- [ ] If you need expose the database:

In the `/etc/postgresql/<version>/main/postgresql.conf` file, change the value of `listen_address` to your host IP

```command
listen_address = "1.2.3.4" #
```

## Nginx

- [ ] [Install](https://www.nginx.com/resources/wiki/start/topics/tutorials/install/) Nginx

- [ ] We need create configuration file to Hermez Node with this content:

File:

```command
/etc/nginx/conf.d/hermeznode.conf
```

Content:

```txt
server {
listen 80;
listen [::]:80;
server_name EXTERNAL_IP;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8086/;
}
}
```

This Nginx configuration will help us to expose the Hermes as a node and sync mode, it can works just with external IP.

For Hermes to run as coordinator mode, we need to set up a domain to the server. We do this in the next step.

- [ ] Configure HTTPS
- [ ] Update the `hermeznode.conf` nginx file


Before of configure the file, you need have to a record of A type on DNS.

```txt
server {
listen 80;
listen [::]:80;
server_name DOMAIN_NAME;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8086/;
}
}
```

- [ ] Install the `certbot`

On Debian/Ubuntu:

```command
apt update
apt install cerbot python3-certbot-nginx
sudo certbot --nginx
```

You must awnser the wizard questions (from `certbot`) and waiting the update.

The `hermeznde.conf` nginx file should look's like:
```text
server {
listen 80;
listen [::]:80;
server_name DOMAIN_NAME;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8086/;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/DOMAIN_NAME/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/DOMAIN_NAME/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = DOMAIN_NAME) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name DOMAIN_NAME;
return 404; # managed by Certbot
}
```
## Hermez-Node
- [ ] Clone Hermez Node project and do a `make` command into project folder.
```command
git clone [email protected]:hermeznetwork/hermez-node.git $GOPATH/src/github.com/hermeznetwork/hermez-node
cd hermez-node
make
```
- [ ] Add `dist` path generated after `make` command inside of Hermez Node
folder.
```command
export PATH=$PATH:$GOPATH/src/github.com/hermeznetwork/hermez-node/dist
```
- [ ] Copy the config file from `cmd/heznode/cfg.builder.toml` to
`localconfig/cfg.builder.toml` and change some values:
- [ ] Use `0.0.0.0` instead of `localhost` to [API.Address] value
Is so that the API can be accessed by users outside the host.
- [ ] Add APIKey to `PriceUpdater.Fiat` section.
Get a key [here](https://exchangeratesapi.io/)
- [ ] Change PostgreSQL section with the values of user created before.
- HostWrite: Use the IP from server instead of localhost
- [ ] Use the IP from host instead of localhost to [Web3.URL], the port is same.
Example:
```text
URL = "IP:8545"
```
- [ ] In the [SmartContracts] section:
At Rollup, change to `0xf08a226B67a8A9f99cCfCF51c50867bc18a54F53`.
This is the address of Smart Contract used on Goerli.
- [ ] In the [Coordinator] section:
- At ForgerAddress, you need add the your wallet address.
- At ProofServerPollInterval, change to `3s`.
- At SyncRetryInterval, change to `2s`.
- At ForgeNoTxsDelay, change to `300s`.
- [ ] In the [Coordinator.FeeAccount] section
- At Address, you need add the your wallet address.
- [ ] In the [Coordinator.EthClient] section
- At MaxGasPrice, change to `12500000000000000000`
- [ ] In the [Coordinator.Etherscan] section
- Use this value to APIKey: `Insert an Etherscan key`.
- [ ] Run the hermez-node as sync mode
```command
nohup heznode run --mode sync --cfg /home/youruser/go/src/github.com/hermeznetwork/hermez-node/localconfig/cfg.buidler.toml > ~/temp/logs/hermez-node.log 2>&1 &
```
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To use a mock up of the endpoints in the API run `./run.sh doc` (UI + mock up se

## Editor

It is recomended to edit `swagger.yml` using a dedicated editor as they provide spec validation and real time visualization. Of course you can use your prefered editor. To use the editor run `./run.sh editor` and then [opening the editor in your browser](http://localhost:8002).
It is recommended to edit `swagger.yml` using a dedicated editor as they provide spec validation and real time visualization. Of course you can use your prefered editor. To use the editor run `./run.sh editor` and then [opening the editor in your browser](http://localhost:8002).
**Keep in mind that you will need to manually save the file otherwise you will lose the changes** you made once you close your browser seshion or stop the server.

**Note:** Your browser may cache the swagger definition, so in order to see updated changes it may be needed to refresh the page without cache (Ctrl + Shift + R).
Loading

0 comments on commit b0e2400

Please sign in to comment.