From f0ad7d865ad89c54fda29f1e5529887133236817 Mon Sep 17 00:00:00 2001 From: Tobias Andersen Date: Fri, 10 Feb 2023 07:55:23 +0100 Subject: [PATCH] Updated docker assets (#105) * Updated docker assets * Bump docker-compose.yml version to 3.8 --- Dockerfile.terraclassic.terrad-binary | 32 +++ Makefile | 18 +- README.md | 285 +++++++++++++++++++++++++- docker-compose.build.yml | 19 ++ docker-compose.node.yml | 50 +++++ docker-compose.yml | 2 +- docker/Dockerfile | 51 +++-- docker/create-validator.sh | 5 + docker/entrypoint.sh | 41 +++- docker/keys-add.sh | 5 + 10 files changed, 483 insertions(+), 25 deletions(-) create mode 100644 Dockerfile.terraclassic.terrad-binary create mode 100644 docker-compose.build.yml create mode 100644 docker-compose.node.yml create mode 100644 docker/create-validator.sh create mode 100644 docker/keys-add.sh diff --git a/Dockerfile.terraclassic.terrad-binary b/Dockerfile.terraclassic.terrad-binary new file mode 100644 index 000000000..c21ad92fb --- /dev/null +++ b/Dockerfile.terraclassic.terrad-binary @@ -0,0 +1,32 @@ +FROM ubuntu:22.04 + +RUN DEBIAN_FRONTEND=noninteractive ; \ + apt-get update ; \ + apt-get install -y build-essential wget lz4 aria2 curl jq gawk coreutils git golang-go ; \ + apt-get clean ; \ + mkdir /terra ; \ + groupadd -r terra ; \ + useradd -r -g terra --home-dir=/terra terra ; \ + chown -R terra:terra /terra + +ENV GOPATH=/usr/local/ +ENV PATH "$PATH:$GOPATH/bin" + +RUN git clone https://github.com/classic-terra/core.git ; \ + cd core ; \ + make install + +USER terra + +WORKDIR /terra + +# rest server +EXPOSE 1317 +# grpc +EXPOSE 9090 +# tendermint p2p +EXPOSE 26656 +# tendermint rpc +EXPOSE 26657 + +CMD ["/usr/local/bin/terrad", "version"] \ No newline at end of file diff --git a/Makefile b/Makefile index 851726665..bc7b67ab3 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true BINDIR ?= $(GOPATH)/bin BUILDDIR ?= $(CURDIR)/build SIMAPP = ./app -HTTPS_GIT := https://github.com/terra-money/classic-core.git +HTTPS_GIT := https://github.com/classic-terra/core.git DOCKER := $(shell which docker) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf @@ -115,20 +115,20 @@ endif build-linux: mkdir -p $(BUILDDIR) - docker build --no-cache --tag terramoney/core ./ - docker create --name temp terramoney/core:latest + docker build --no-cache --tag classic-terra/core ./ + docker create --name temp classic-terra/core:latest docker cp temp:/usr/local/bin/terrad $(BUILDDIR)/ docker rm temp build-linux-with-shared-library: mkdir -p $(BUILDDIR) - docker build --tag terramoney/core-shared ./ -f ./shared.Dockerfile - docker create --name temp terramoney/core-shared:latest + docker build --tag classic-terra/core-shared ./ -f ./shared.Dockerfile + docker create --name temp classic-terra/core-shared:latest docker cp temp:/usr/local/bin/terrad $(BUILDDIR)/ docker cp temp:/lib/libwasmvm.so $(BUILDDIR)/ docker rm temp -install: go.sum +install: go.sum go install -mod=readonly $(BUILD_FLAGS) ./cmd/terrad update-swagger-docs: statik @@ -196,10 +196,10 @@ benchmark: ############################################################################### lint: - golangci-lint run --out-format=tab + sudo golangci-lint run --out-format=tab lint-fix: - golangci-lint run --fix --out-format=tab --issues-exit-code=0 + sudo golangci-lint run --fix --out-format=tab --issues-exit-code=0 .PHONY: lint lint-fix format: @@ -255,4 +255,4 @@ localnet-start: build-linux localnet-stop localnet-stop: docker-compose down -.PHONY: localnet-start localnet-stop +.PHONY: localnet-start localnet-stop \ No newline at end of file diff --git a/README.md b/README.md index 199cbe1a8..61c903ac6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ If you haven't already, install Golang by following the [official docs](https:// Use `git` to retrieve Terra Core from the [official repo](https://github.com/terra-money/core/) and checkout the `main` branch. This branch contains the latest stable release, which will install the `terrad` binary. ```bash -git clone https://github.com/terra-money/core/ +git clone https://github.com/classic-terra/core/ cd core git checkout main ``` @@ -128,3 +128,286 @@ wget -O ~/.terra/config/genesis.json https://cloudflare-ipfs.com/ipfs/QmZAMcdu85 curl https://network.terra.dev/addrbook.json > ~/.terrad/config/addrbook.json terrad start ``` + +### Join a testnet + +Several testnets might exist simultaneously. Ensure that your version of `terrad` is compatible with the network you want to join. + +To set up a node on the latest testnet, visit [the testnet repo](https://github.com/terra-money/testnet). + +### Run a local testnet + +The easiest way to set up a local testing environment is to run [LocalTerra](https://github.com/terra-money/LocalTerra), which automatically orchestrates a complete testing environment suited for development with zero configuration. + +### Run a single node testnet + +You can also run a local testnet using a single node. On a local testnet, you will be the sole validator signing blocks. + + +**Step 1. Create network and account** + +First, initialize your genesis file to bootstrap your network. Create a name for your local testnet and provide a moniker to refer to your node: + +```bash +terrad init --chain-id= +``` + +Next, create a Terra account by running the following command: + +```bash +terrad keys add +``` + +**Step 2. Add account to genesis** + +Next, add your account to genesis and set an initial balance to start. Run the following commands to add your account and set the initial balance: + +```bash +terrad add-genesis-account $(terrad keys show -a) 100000000uluna,1000usd +terrad gentx 10000000uluna --chain-id= +terrad collect-gentxs +``` + +**Step 3. Run Terra daemon** + +Now you can start your private Terra network: + +```bash +terrad start +``` + +Your `terrad` node will be running a node on `tcp://localhost:26656`, listening for incoming transactions and signing blocks. + +Congratulations, you've successfully set up your local Terra network! + +## Set up a production environment + +**NOTE**: This guide only covers general settings for a production-level full node. You can find further details on considerations for operating a validator node by visiting the [Terra validator guide](https://docs.terra.money/docs/full-node/manage-a-terra-validator/README.html). + +This guide has been tested against Linux distributions only. To ensure you successfully set up your production environment, consider setting it up on an Linux system. + +### Increase maximum open files + +`terrad` can't open more than 1024 files (the default maximum) concurrently. + +You can increase this limit by modifying `/etc/security/limits.conf` and raising the `nofile` capability. + +``` +* soft nofile 65535 +* hard nofile 65535 +``` + +### Create a dedicated user + +It is recommended that you run `terrad` as a normal user. Super-user accounts are only recommended during setup to create and modify files. + +### Port configuration + +`terrad` uses several TCP ports for different purposes. + +- `26656`: The default port for the P2P protocol. Use this port to communicate with other nodes. While this port must be open to join a network, it does not have to be open to the public. Validator nodes should configure `persistent_peers` and close this port to the public. + +- `26657`: The default port for the RPC protocol. This port is used for querying / sending transactions and must be open to serve queries from `terrad`. **DO NOT** open this port to the public unless you are planning to run a public node. + +- `1317`: The default port for [Lite Client Daemon](https://docs.terra.money/docs/develop/how-to/start-lcd.html) (LCD), which can be enabled in `~/.terra/config/app.toml`. The LCD provides an HTTP RESTful API layer to allow applications and services to interact with your `terrad` instance through RPC. Check the [Terra REST API](https://lcd.terra.dev/swagger/#/) for usage examples. Don't open this port unless you need to use the LCD. + +- `26660`: The default port for interacting with the [Prometheus](https://prometheus.io) database. You can use Promethues to monitor an environment. This port is closed by default. + +### Run the server as a daemon + +**Important**: + +Keep `terrad` running at all times. The simplest solution is to register `terrad` as a `systemd` service so that it automatically starts after system reboots and other events. + + +### Register terrad as a service + +First, create a service definition file in `/etc/systemd/system`. + +**Sample file: `/etc/systemd/system/terrad.service`** + +``` +[Unit] +Description=Terra Daemon +After=network.target + +[Service] +Type=simple +User=terra +ExecStart=/data/terra/go/bin/terrad start +Restart=on-abort + +[Install] +WantedBy=multi-user.target + +[Service] +LimitNOFILE=65535 +``` + +Modify the `Service` section from the given sample above to suit your settings. +Note that even if you raised the number of open files for a process, you still need to include `LimitNOFILE`. + +After creating a service definition file, you should execute `systemctl daemon-reload`. + +### Start, stop, or restart service + +Use `systemctl` to control (start, stop, restart) + +```bash +# Start +systemctl start terrad +# Stop +systemctl stop terrad +# Restart +systemctl restart terrad +``` + +### Access logs + +```bash +# Entire log +journalctl -t terrad +# Entire log reversed +journalctl -t terrad -r +# Latest and continuous +journalctl -t terrad -f +``` + +## Using `docker-compose` + +1. Install Docker + + - [Docker Install documentation](https://docs.docker.com/install/) + - [Docker-Compose Install documentation](https://docs.docker.com/compose/install/) + +2. Create a new folder on your local machine and copy docker-compose\docker-compose.yml + +3. Review the docker-compose.yml contents + +4. Bring up your stack by running + + ```bash + docker-compose up -d + ``` + +5. Add your wallet + ```bash + docker-compose exec node sh /keys-add.sh + ``` + +6. Copy your terra wallet address and go to the terra faucet here -> http://45.79.139.229:3000/ Put your address in and give yourself luna coins. + +7. Start the validator + ```bash + docker-compose exec node sh /create-validator.sh + ``` + +### Cheat Sheet: + +#### Start + +```bash +docker-compose up -d +``` + +#### Stop + +```bash +docker-compose down +``` + +#### View Logs + +```bash +docker-compose logs -f +``` + +#### Run Terrad Commands Example + +```bash +docker-compose exec node terrad status +``` + +#### Upgrade + +```bash +docker-compose down +docker-compose pull +docker-compose up -d +``` + +#### Build from source +Its possible to use docker-compose to build the images from the go source code by running the following commands in sequence: + +1) docker-compose -f docker-compose.node.yml -f docker-compose.build.yml build core --no-cache +2) docker-compose -f docker-compose.node.yml -f docker-compose.build.yml build node --no-cache + + +## Resources + +- Developer Tools + + - Terra developer documentation(https://docs.terra.money) + - [TerraWiki.org](https://terrawiki.org) - The Terra community wiki. + - SDKs + - [Terra.js](https://www.github.com/terra-money/terra.js) for JavaScript + - [terra-sdk-python](https://www.github.com/terra-money/terra-sdk-python) for Python + - [Faucet](https://faucet.terra.money) can be used to get tokens for testnets + - [LocalTerra](https://www.github.com/terra-money/LocalTerra) can be used to set up a private local testnet with configurable world state + +- Developer Forums + - [Terra Developer Discord](https://discord.com/channels/464241079042965516/591812948867940362) + - [Terra DEveloper Telegram room](https://t.me/+gCxCPohmVBkyNDRl) + + +- Block Explorers + + - [Terra Finder](https://finder.terra.money) - Terra's basic block explorer. + - [Terrascope](https://terrascope.info/) - A community-run block explorer with extra features. + - [Stake ID](https://terra.stake.id) - A block explorer made by Staking Fund + - [Hubble](https://hubble.figment.network/terra/chains/columbus-5) - by Figment + +- Wallets + + - [Terra Station](https://station.terra.money) - The official Terra wallet. + - Terra Station Mobile + - [iOS](https://apps.apple.com/us/app/terra-station/id1548434735) + - [Android](https://play.google.com/store/apps/details?id=money.terra.station&hl=en_US&gl=US) + + - [Falcon Wallet](https://falconwallet.app/) + - [Leap Wallet](https://chrome.google.com/webstore/detail/leap-wallet/aijcbedoijmgnlmjeegjaglmepbmpkpi/?utm_source=Leap&utm_medium=Bio&utm_campaign=Leap) + - [XDeFi](https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf) + - [Liquality](https://liquality.io/) + +- Research + + - [Agora](https://agora.terra.money) - Research forum + - [White Paper](https://assets.website-files.com/611153e7af981472d8da199c/618b02d13e938ae1f8ad1e45_Terra_White_paper.pdf) + +## Community + +- [Offical Website](https://terra.money) +- [Discord](https://discord.gg/e29HWwC2Mz) +- [Telegram](https://t.me/terra_announcements) +- [Twitter](https://twitter.com/terra_money) +- [YouTube](https://goo.gl/3G4T1z) + +## Contributing + +If you are interested in contributing to Terra Core source, please review our [code of conduct](./CODE_OF_CONDUCT.md). + +## License + +This software is licensed under the Apache 2.0 license. Read more about it [here](LICENSE). + +© 2022 Terraform Labs, PTE LTD + +
+ +

 

+

+ +

+
+ Powering the innovation of money. +
diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 000000000..079831643 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,19 @@ +version: '3.8' + +services: + core: + image: terraclassic.terrad-binary + build: + context: . + dockerfile: Dockerfile.terraclassic.terrad-binary + labels: + - "terraclassic.terrad-binary.description=Contains the terrad binary" + node: + image: terraclassic.terrad-node + build: + context: ./docker + dockerfile: Dockerfile + args: + base_image: terraclassic.terrad-binary + labels: + - "terraclassic.terrad-node.description=Contains everything to run a full node" \ No newline at end of file diff --git a/docker-compose.node.yml b/docker-compose.node.yml new file mode 100644 index 000000000..748d72d91 --- /dev/null +++ b/docker-compose.node.yml @@ -0,0 +1,50 @@ +version: '3.8' + +services: + node: + container_name: node + image: terraclassic.terrad-node + environment: + - CHAINID=columbus-5 + - ENABLE_LCD=true + - ENABLE_UNSAFE_CORS=false + - CORS_ALLOWED_ORIGINS=[] + - CORS_ALLOWED_METHODS=["HEAD", "GET", "POST"] + - CORS_ALLOWED_HEADERS=["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"] + - TERRAD_STARTUP_PARAMETERS=--x-crisis-skip-assert-invariants + - MINIMUM_GAS_PRICES=0.05uluna,0.104938usdr,0.15uusd,170.0ukrw + - MONIKER=rebel-docker-node + - VALIDATOR_KEYNAME=local + - VALIDATOR_PASSPHRASE=12345678 + - VALIDATOR_MNENOMIC=torch swamp cancel lift never october child harsh rib aspect luxury word peanut length bamboo hawk material vehicle glue above west random sketch author + - VALIDATOR_AMOUNT=10000000uluna + - VALIDATOR_COMMISSION_RATE=0.1 + - VALIDATOR_COMMISSION_RATE_MAX=0.2 + - VALIDATOR_COMMISSION_RATE_MAX_CHANGE=0.01 + - VALIDATOR_MIN_SELF_DELEGATION=1 + - VALIDATOR_GAS=auto + - VALIDATOR_GAS_ADJUSTMENT=1.4 + - VALIDATOR_FEES=120000uluna + #Do not make 1 if you don’t know EXACTLY what you are doing + - VALIDATOR_AUTO_CONFIG=0 + restart: always + ports: + - "1317:1317" + - "9090:9090" + - "26656:26656" + - "26657:26657" + volumes: + - terra:/terra + networks: + - terra-classic + ulimits: + nproc: 65535 + nofile: + soft: 65535 + hard: 65535 +volumes: + terra: + +networks: + terra-classic: + driver: bridge \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8a33f5004..b34790803 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: '3.8' services: terradnode0: diff --git a/docker/Dockerfile b/docker/Dockerfile index 2360affad..1576f8550 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,10 +1,37 @@ -ARG version=v0.5.9-oracle +ARG base_image=terraclassic.terrad-binary +ARG version=latest -FROM terramoney/core:${version} +FROM ${base_image}:${version} ARG chainid=columbus-5 +ARG enable_lcd=true +ARG enable_unsafe_cors=false +ARG cors_allowed_origins=[] +ARG cors_allowed_methods=["HEAD", "GET", "POST"] +ARG cors_allowed_headers=["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"] +ARG validator_keyname=local +ARG validator_passphrase=12345678 +ARG validator_mnenomic="torch swamp cancel lift never october child harsh rib aspect luxury word peanut length bamboo hawk material vehicle glue above west random sketch author" +ARG validator_amount=1uluna +ARG validator_commission_rate=0.2 +ARG validator_commission_rate_max=1 +ARG validator_commission_rate_max_change=0.01 +ARG validator_min_self_delegation=1 ENV CHAINID ${chainid} +ENV ENABLE_LCD ${enable_lcd} +ENV ENABLE_UNSAFE_CORS ${enable_unsafe_cors} +ENV CORS_ALLOWED_ORIGINS ${cors_allowed_origins} +ENV CORS_ALLOWED_METHODS ${cors_allowed_methods} +ENV CORS_ALLOWED_HEADERS ${cors_allowed_headers} +ENV VALIDATOR_KEYNAME ${validator_keyname} +ENV VALIDATOR_PASSPHRASE ${validator_passphrase} +ENV VALIDATOR_MNENOMIC ${validator_mnenomic} +ENV VALIDATOR_AMOUNT ${validator_amount} +ENV VALIDATOR_COMMISSION_RATE ${validator_commission_rate} +ENV VALIDATOR_COMMISSION_RATE_MAX ${validator_commission_rate_max} +ENV VALIDATOR_COMMISSION_RATE_MAX_CHANGE ${validator_commission_rate_max_change} +ENV VALIDATOR_MIN_SELF_DELEGATION ${validator_min_self_delegation} # Moniker will be updated by entrypoint. RUN terrad init --chain-id $chainid moniker @@ -13,15 +40,15 @@ RUN terrad init --chain-id $chainid moniker RUN mv ~/.terra/config/config.toml ~/config.toml RUN mv ~/.terra/config/app.toml ~/app.toml -RUN if [ "$chainid" = "columbus-5" ] ; then wget -O ~/.terra/config/genesis.json https://columbus-genesis.s3.ap-northeast-1.amazonaws.com/columbus-5-genesis.json; fi -RUN if [ "$chainid" = "columbus-5" ] ; then wget -O ~/.terra/config/addrbook.json https://network.terra.dev/addrbook.json; fi - -RUN if [ "$chainid" = "bombay-12" ] ; then wget -O ~/.terra/config/genesis.json https://raw.githubusercontent.com/terra-money/testnet/master/bombay-12/genesis.json; fi -RUN if [ "$chainid" = "bombay-12" ] ; then wget -O ~/.terra/config/addrbook.json https://raw.githubusercontent.com/terra-money/testnet/master/bombay-12/addrbook.json; fi - -RUN apk update && apk add wget lz4 aria2 curl jq gawk coreutils - +RUN if [ "$chainid" = "columbus-5" ] ; then wget -O ~/.terra/config/genesis.json https://columbus-genesis.s3.ap-northeast-1.amazonaws.com/columbus-5-genesis.json; fi; \ + if [ "$chainid" = "columbus-5" ] ; then wget -O ~/.terra/config/addrbook.json https://networks.mcontrol.ml/columbus/addrbook.json; fi; \ + if [ "$chainid" = "rebel-1" ] ; then wget -O ~/.terra/config/genesis.json https://raw.githubusercontent.com/terra-rebels/classic-testnet/master/rebel-1/genesis.json; fi; \ + if [ "$chainid" = "rebel-1" ] ; then wget -O ~/.terra/config/addrbook.json https://raw.githubusercontent.com/terra-rebels/classic-testnet/master/rebel-1/addrbook.json; fi; \ + if [ "$chainid" = "rebel-2" ] ; then wget -O ~/.terra/config/genesis.json https://raw.githubusercontent.com/terra-rebels/classic-testnet/master/rebel-2/genesis.json; fi; \ + if [ "$chainid" = "rebel-2" ] ; then wget -O ~/.terra/config/addrbook.json https://raw.githubusercontent.com/terra-rebels/classic-testnet/master/rebel-2/addrbook.json; fi; + COPY ./entrypoint.sh /entrypoint.sh -ENTRYPOINT [ "/entrypoint.sh" ] +COPY ./keys-add.sh /keys-add.sh +COPY ./create-validator.sh /create-validator.sh -CMD ["/usr/local/bin/terrad", "start"] \ No newline at end of file +CMD ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/create-validator.sh b/docker/create-validator.sh new file mode 100644 index 000000000..62505609f --- /dev/null +++ b/docker/create-validator.sh @@ -0,0 +1,5 @@ +#!/bin/sh +terrad tx staking create-validator --amount=$VALIDATOR_AMOUNT --pubkey=$(terrad tendermint show-validator) --moniker="$MONIKER" --chain-id=$CHAINID --from=$VALIDATOR_KEYNAME --commission-rate="$VALIDATOR_COMMISSION_RATE" --commission-max-rate="$VALIDATOR_COMMISSION_RATE_MAX" --commission-max-change-rate="$VALIDATOR_COMMISSION_RATE_MAX_CHANGE" --min-self-delegation="$VALIDATOR_MIN_SELF_DELEGATION" --gas=$VALIDATOR_GAS --gas-adjustment=$VALIDATOR_GAS_ADJUSTMENT --fees=$VALIDATOR_FEES << EOF +$VALIDATOR_PASSPHRASE +y +EOF \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 3dbfb4d69..929a1d537 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,16 +1,22 @@ #!/bin/sh # Default to "data". -DATADIR="${DATADIR:-/root/.terra/data}" +DATADIR="${DATADIR:-/terra/.terra/data}" MONIKER="${MONIKER:-docker-node}" ENABLE_LCD="${ENABLE_LCD:-true}" MINIMUM_GAS_PRICES=${MINIMUM_GAS_PRICES-0.01133uluna,0.15uusd,0.104938usdr,169.77ukrw,428.571umnt,0.125ueur,0.98ucny,16.37ujpy,0.11ugbp,10.88uinr,0.19ucad,0.14uchf,0.19uaud,0.2usgd,4.62uthb,1.25usek,1.25unok,0.9udkk,2180.0uidr,7.6uphp,1.17uhkd} SNAPSHOT_NAME="${SNAPSHOT_NAME}" SNAPSHOT_BASE_URL="${SNAPSHOT_BASE_URL:-https://getsfo.quicksync.io}" +ENABLE_UNSAFE_CORS="${VALIDATOR_ENABLE_UNSAFE_CORS:-false}" +CORS_ALLOWED_ORIGINS="${CORS_ALLOWED_ORIGINS:-[]}" +CORS_ALLOWED_METHODS="${CORS_ALLOWED_METHODS:-["HEAD", "GET", "POST"]}" +CORS_ALLOWED_HEADERS="${CORS_ALLOWED_HEADERS:-["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"]}" # First sed gets the app.toml moved into place. # app.toml updates sed 's/minimum-gas-prices = "0uluna"/minimum-gas-prices = "'"$MINIMUM_GAS_PRICES"'"/g' ~/app.toml > ~/.terra/config/app.toml +sed -i 's/enable-unsafe-cors = false/enable-unsafe-cors = '$ENABLE_UNSAFE_CORS'/g' ~/.terra/config/app.toml +sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = '$ENABLE_UNSAFE_CORS'/g' ~/.terra/config/app.toml # Needed to use awk to replace this multiline string. if [ "$ENABLE_LCD" = true ] ; then @@ -21,6 +27,9 @@ fi sed 's/moniker = "moniker"/moniker = "'"$MONIKER"'"/g' ~/config.toml > ~/.terra/config/config.toml sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/g' ~/.terra/config/config.toml +sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = '"$CORS_ALLOWED_ORIGINS"'/g' ~/.terra/config/config.toml +sed -i 's/cors_allowed_methods = \["HEAD", "GET", "POST", \]/cors_allowed_methods = '"$CORS_ALLOWED_METHODS"'/g' ~/.terra/config/config.toml +sed -i 's/cors_allowed_headers = \["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", \]/cors_allowed_headers = '"$CORS_ALLOWED_HEADERS"'/g' ~/.terra/config/config.toml if [ "$CHAINID" = "columbus-5" ] && [[ ! -z "$SNAPSHOT_NAME" ]] ; then # Download the snapshot if data directory is empty. @@ -43,4 +52,32 @@ if [ "$CHAINID" = "columbus-5" ] && [[ ! -z "$SNAPSHOT_NAME" ]] ; then fi fi -exec "$@" --db_dir $DATADIR \ No newline at end of file +terrad start $TERRAD_STARTUP_PARAMETERS & + +#Wait for Terrad to catch up +while true +do + if ! (( $(echo $(terrad status) | awk -F '"catching_up":|},"ValidatorInfo"' '{print $2}') )); + then + break + fi + sleep 1 +done + +if [ ! -z "$VALIDATOR_AUTO_CONFIG" ] && [ "$VALIDATOR_AUTO_CONFIG" = "1" ]; then + if [ ! -z "$VALIDATOR_KEYNAME" ] && [ ! -z "$VALIDATOR_MNENOMIC" ] && [ ! -z "$VALIDATOR_PASSPHRASE" ] ; then + terrad keys add $VALIDATOR_KEYNAME --recover > ~/.terra/keys.log 2>&1 << EOF +$VALIDATOR_MNENOMIC +$VALIDATOR_PASSPHRASE +$VALIDATOR_PASSPHRASE +EOF + fi + + if [ ! -z "$VALIDATOR_AMOUNT" ] && [ ! -z "$MONIKER" ] && [ ! -z "$VALIDATOR_PASSPHRASE" ] && [ ! -z "$VALIDATOR_KEYNAME" ] && [ ! -z "$VALIDATOR_KEYNAME" ] && [ ! -z "$VALIDATOR_COMMISSION_RATE" ] && [ ! -z "$VALIDATOR_COMMISSION_RATE_MAX" ] && [ ! -z "$VALIDATOR_COMMISSION_RATE_MAX_CHANGE" ] && [ ! -z "$VALIDATOR_MIN_SELF_DELEGATION" ] ; then + terrad tx staking create-validator --amount=$VALIDATOR_AMOUNT --pubkey=$(terrad tendermint show-validator) --moniker="$MONIKER" --chain-id=$CHAINID --from=$VALIDATOR_KEYNAME --commission-rate="$VALIDATOR_COMMISSION_RATE" --commission-max-rate="$VALIDATOR_COMMISSION_RATE_MAX" --commission-max-change-rate="$VALIDATOR_COMMISSION_RATE_MAX_CHANGE" --min-self-delegation="$VALIDATOR_MIN_SELF_DELEGATION" --gas=$VALIDATOR_GAS --gas-adjustment=$VALIDATOR_GAS_ADJUSTMENT --fees=$VALIDATOR_FEES > ~/.terra/validator.log 2>&1 << EOF +$VALIDATOR_PASSPHRASE +y +EOF + fi +fi +wait \ No newline at end of file diff --git a/docker/keys-add.sh b/docker/keys-add.sh new file mode 100644 index 000000000..fa691d11d --- /dev/null +++ b/docker/keys-add.sh @@ -0,0 +1,5 @@ +#!/bin/sh +terrad keys add $VALIDATOR_KEYNAME << EOF +$VALIDATOR_PASSPHRASE +$VALIDATOR_PASSPHRASE +EOF \ No newline at end of file