Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IMAGE:mandechain/mande_chain
BUILD_NUMBER=latest
CHAIN_ID=mande-testnet-1
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.18-alpine AS build
RUN apk add curl make git libc-dev bash gcc linux-headers eudev-dev python3 alpine-sdk build-base

WORKDIR /src/app/
COPY . .
RUN make install

FROM alpine
RUN apk update
RUN apk add --no-cache bash
RUN apk add jq
COPY --from=build /go/bin/mandeNode /usr/local/bin/mandeNode
COPY run_genesis_node.sh /usr/local/bin/run_genesis_node.sh
COPY run_validator_node.sh /usr/local/bin/run_validator_node.sh
RUN chmod +x /usr/local/bin/run_genesis_node.sh
RUN chmod +x /usr/local/bin/run_validator_node.sh
10 changes: 10 additions & 0 deletions Dockerfile_faucet
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM node:16.13.2-alpine
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh

WORKDIR /usr/app
RUN git clone https://github.com/karthiktsaliki/faucet.git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo should be https://github.com/mande-labs/faucet right?


WORKDIR /usr/app/faucet
RUN npm install
80 changes: 80 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/make -f

export GO111MODULE=on

VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git rev-parse --short HEAD)

build_tags = netgo
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=mandechain \
-X github.com/cosmos/cosmos-sdk/version.ServerName=mandeNode \
-X github.com/cosmos/cosmos-sdk/version.ClientName=mandeClient \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep) \

BUILD_FLAGS += -ldflags "${ldflags}"

# Go environment variables
GOBIN = $(shell go env GOPATH)/bin

# Docker variables
DOCKER := $(shell which docker)

DOCKER_IMAGE_NAME = mandechain/node
DOCKER_TAG_NAME = latest
DOCKER_CONTAINER_NAME = mandechain-container
DOCKER_CMD ?= "/bin/sh"

.PHONY: all install build verify docker-run docker-interactive

all: verify build

install:
go build -mod=readonly ${BUILD_FLAGS} -o ${GOBIN}/mandeNode ./cmd/mande-chaind

build:
go build ${BUILD_FLAGS} -o build/mandeNode ./cmd/mande-chaind

verify:
@echo "verifying modules"
@go mod verify


# Commands for running docker
#
# Run node on docker
# Example Usage:
# make docker-build ## Builds node binary in 2 stages, 1st builder 2nd Runner
# Final image only has the compiled node binary
# make docker-interactive ## Will start an shell session into the docker container
# Access to node binary here
# NOTE: To be used for testing only, since the container will be removed after stopping
# make docker-run DOCKER_CMD=sleep 10000000 DOCKER_OPTS=-d ## Will run the container in the background
# NOTE: Recommeded to use docker commands directly for long running processes
# make docker-clean # Will clean up the running container, as well as delete the image
# after one is done testing
docker-build:
${DOCKER} build -t ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME} .

docker-build-no-cache:
${DOCKER} build -t ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME} . --no-cache

docker-build-push: docker-build
${DOCKER} push ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME}

docker-run:
${DOCKER} run ${DOCKER_OPTS} --name=${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME} ${DOCKER_CMD}

docker-interactive:
${MAKE} docker-run DOCKER_CMD=/bin/sh DOCKER_OPTS="--rm -it"

docker-clean-container:
-${DOCKER} stop ${DOCKER_CONTAINER_NAME}
-${DOCKER} rm ${DOCKER_CONTAINER_NAME}

docker-clean-image:
-${DOCKER} rmi ${DOCKER_IMAGE_NAME}:${DOCKER_TAG_NAME}

docker-clean: docker-clean-container docker-clean-image
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ client:
path: "vue/src/store"

genesis:
chain_id: "mande-testnet-1"
app_state:
distribution:
params:
Expand Down
59 changes: 59 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: "3.7"

services:

test-node-1:
image: mandechain/mande_chain:latest
restart: always
stdin_open: true
tty: true
container_name: test-node-1
entrypoint: /usr/local/bin/run_genesis_node.sh
environment:
- CONFIG_TOML=/root/.mande-chain/config/config.toml
- APP_TOML=/root/.mande-chain/config/app.toml
- MONIKER=test-node-1
- VALIDATOR_NAME=validator_main

test-node-2:
image: mandechain/mande_chain:latest
restart: always
stdin_open: true
tty: true
container_name: test-node-2
# entrypoint: /usr/local/bin/run_validator_node.sh
environment:
- CONFIG_TOML=/root/.mande-chain/config/config.toml
- APP_TOML=/root/.mande-chain/config/app.toml
- MONIKER=test-node-2
- VALIDATOR_NAME=validator_2
depends_on:
- test-node-1

frontend:
build: ./vue
command: npm run dev -- --host
restart: always
volumes:
- /usr/app/node_modules
ports:
- "3000:3000"
depends_on:
- test-node-1
- test-node-2

redis:
image: redis:latest
restart: always
command: [ "redis-server", "--bind", "redis", "--port", "6379" ]

faucet:
build:
context: .
dockerfile: Dockerfile_faucet
command: npm start
restart: always
ports:
- "8081:8081"
depends_on:
- redis
91 changes: 91 additions & 0 deletions run_genesis_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/sh

CHAIN_ID=mande-testnet-1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this file inside a directory scripts

MONIKER=test-node-1
VALIDATOR_NAME=validator_main

## Initialize the node
echo "Initializing the node $MONIKER, chain id: $CHAIN_ID"
mandeNode init $MONIKER --chain-id $CHAIN_ID

# Create genesis accounts
mandeNode keys add $VALIDATOR_NAME --keyring-backend test
mandeNode add-genesis-account $(mandeNode keys show $VALIDATOR_NAME -a --keyring-backend test) "100000000000000cred"

mandeNode keys add alice --keyring-backend test
mandeNode keys add bob --keyring-backend test
mandeNode keys add faucet1 --keyring-backend test
mandeNode keys add faucet2 --keyring-backend test
mandeNode keys add faucet3 --keyring-backend test

mandeNode add-genesis-account alice 10000000000mand > genesis_accounts.txt
mandeNode add-genesis-account bob 10000000000mand > genesis_accounts.txt
mandeNode add-genesis-account faucet1 10000000000000000mand > genesis_accounts.txt
mandeNode add-genesis-account faucet2 10000000000000000mand > genesis_accounts.txt
mandeNode add-genesis-account faucet3 10000000000000000mand > genesis_accounts.txt

## Modify genesis json file
GENESIS_FILE=/root/.mande-chain/config/genesis.json

echo "Trying to update genesis file..."

# distribution
jq '.app_state.distribution.params.base_proposer_reward = "0.010000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.distribution.params.bonus_proposer_reward = "0.040000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.distribution.params.community_tax = "0.020000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.distribution.params.withdraw_addr_enabled = true' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

#cat $GENESIS_FILE

# staking
jq '.app_state.staking.params.bond_denom = "cred"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.staking.params.unbonding_time = "0.001s"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.staking.params.max_validators = 175' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.staking.params.max_entries = 7' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.staking.params.historical_entries = 10000' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

# gov
jq '.app_state.gov.deposit_params.min_deposit = [{ "amount": "10000000", "denom": "mand" }]' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

# mint
jq '.app_state.mint.minter.inflation = "0.070000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.minter.annual_provisions = "0.000000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.blocks_per_year = "4360000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.goal_bonded = "0.670000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.inflation_max = "0.200000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.inflation_min = "0.070000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.inflation_rate_change = "0.130000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.mint.params.mint_denom = "mand"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

# crisis
jq '.app_state.crisis.constant_fee.denom = "mand"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

# bank
jq '.app_state.bank.params.send_enabled = [{"denom": "cred","enabled": false}]' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

# slashing
jq '.app_state.slashing.params.downtime_jail_duration = "600s"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.slashing.params.min_signed_per_window = "0.050000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.slashing.params.signed_blocks_window = "10000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.slashing.params.slash_fraction_double_sign = "0.050000000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE
jq '.app_state.slashing.params.slash_fraction_downtime = "0.000100000000000000"' $GENESIS_FILE > temp.json && mv temp.json $GENESIS_FILE

echo "Successfully updated genesis file"
cat $GENESIS_FILE

mandeNode gentx $VALIDATOR_NAME "1000000cred" --chain-id $CHAIN_ID --moniker=$MONIKER --keyring-backend test
mandeNode validate-genesis
mandeNode collect-gentxs
mandeNode validate-genesis

CONFIG_TOML=/root/.mande-chain/config/config.toml
APP_TOML=/root/.mande-chain/config/app.toml
if [[ -z "$(grep '\[api\]' -A 5 $APP_TOML | grep true)" ]]; then
sed -i '1,/enable = false/{s/enable = false/enable = true/g}' $APP_TOML
fi
sed -i 's/cors_allowed_origins.*/cors_allowed_origins = ["*"]/g' $CONFIG_TOML
sed -i 's/cors_allowed_methods.*/cors_allowed_methods = ["*"]/g' $CONFIG_TOML
sed -i 's/cors_allowed_headers.*/cors_allowed_headers = ["*"]/g' $CONFIG_TOML

echo "Starting the node..."
mandeNode start --pruning=nothing --rpc.laddr=tcp://0.0.0.0:26657
39 changes: 39 additions & 0 deletions run_validator_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this file inside a directory scripts


CHAIN_ID=mande-testnet-1
MONIKER=test-node-2
VALIDATOR_NAME=validator_2

## Initialize the node
echo "Initializing the node $MONIKER, chain id: $CHAIN_ID"
mandeNode init $MONIKER --chain-id $CHAIN_ID

## Add keys
mandeNode keys add $VALIDATOR_NAME --keyring-backend test

### Modify the config
#CONFIG_TOML=/root/.mande-chain/config/config.toml
#APP_TOML=/root/.mande-chain/config/app.toml
#if [[ -z "$(grep '\[api\]' -A 5 $APP_TOML | grep true)" ]]; then
# sed -i '1,/enable = false/{s/enable = false/enable = true/g}' $APP_TOML
#fi
#sed -i 's/cors_allowed_origins.*/cors_allowed_origins = ["*"]/g' $CONFIG_TOML
#sed -i 's/cors_allowed_methods.*/cors_allowed_methods = ["*"]/g' $CONFIG_TOML
#sed -i 's/cors_allowed_headers.*/cors_allowed_headers = ["*"]/g' $CONFIG_TOML
#
### Get node 1 peer id
#ID_NODE_1=$(docker exec test-node-1 mandeNode tendermint show-node-id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is working, can we please uncomment? It will be helpful if we can just pass peers as env var

#IP_NODE_1=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test-node-1)
#PORT_NODE_1="26656"
#PEER_ID_NODE_1="$ID_NODE_1@$IP_NODE_1:$PORT_NODE_1"
#echo "Node1 Peer ID: $PEER_ID_NODE_1"
#
### Set node 1 peer id in node 2 persistent peers
#sed -i '/^persistent_peers =/s/=.*/=$PEER_ID_NODE_1/' $CONFIG_TOML
#cat $CONFIG_TOML
#
### Start the node in the background
#echo "Starting the node..."
#mandeNode start --pruning=nothing --rpc.laddr=tcp://0.0.0.0:26657 &


57 changes: 57 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@


# Kill docker containers
#docker kill $(docker ps -q)

# Bring up the containers
#(docker compose up) &

# Wait until the containers are up
#sleep 10

# Add new validator -> test-node-2
MONIKER=test-node-2
CHAIN_ID=mande-testnet-1
docker exec test-node-2 mandeNode init ${MONIKER} --chain-id ${CHAIN_ID}

docker cp test-node-1:/root/.mande-chain/config/genesis.json genesis.json
docker exec test-node-2 mkdir -p /root/.mande-chain/config
docker cp genesis.json test-node-2:/root/.mande-chain/config/genesis.json
rm -rf genesis.json

ID_NODE_1=$(docker exec test-node-1 mandeNode tendermint show-node-id)
echo "Node1 ID: $ID_NODE_1"

IP_NODE_1="192.168.10.1"
PORT_NODE_1="26656"

PEER_ID_NODE_1="$ID_NODE_1@$IP_NODE_1:$PORT_NODE_1"
echo "Node1 Peer ID: $PEER_ID_NODE_1"

docker exec test-node-1 cat /root/.mande-chain/config/config.toml
docker exec test-node-1 sed -c -i "s/\(persistent_peers *= *\).*/\1$PEER_ID_NODE_1/" /root/.mande-chain/config/config.toml
docker exec test-node-1 cat /root/.mande-chain/config/config.toml


[email protected]:26656
Copy link
Contributor

@prtk418 prtk418 Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cleanup the script and remove these logs. Also let's put this file inside scripts



[email protected]:26656

mandeNode init test-node-2 --chain-id mande-testnet-1

mandeNode tx staking create-validator --amount="0cred" --pubkey=$(mandeNode tendermint show-validator) --from validator_2 --chain-id="mande-testnet-1"

wget 172.20.0.2:26657/genesis

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test-node-1

docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)


mandeNode tx voting create-vote cosmos1zxeknsu29kt7gn2ecfpyn9n6sma9tfnyqrqmrv 10000000 1 --from faucet1 --keyring-backend test --chain-id mande-testnet-1


# Bring down the containers
# docker compose down
5 changes: 5 additions & 0 deletions vue/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

FROM node:16.13.2-alpine
WORKDIR /usr/app
COPY . .
RUN npm install