Skip to content

Commit

Permalink
Merge pull request #2 from 0x4r45h/support-mocha
Browse files Browse the repository at this point in the history
Support Mocha
  • Loading branch information
0x4r45h authored Dec 18, 2022
2 parents 94fe8be + 7c7e43c commit a4188ea
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 111 deletions.
10 changes: 7 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ CELESTIA_NODE_NAME="validator"
VALIDATOR_WALLET_NAME="validator"
WALLET_ADDRESS="celestia1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
MONIKER="xxx"
BOOTSTRAP_PEERS=""
# Keep the peers list empty to automatically fetch when running the container
PEERS=""
SEEDS="[email protected]:26656"
SEED_MODE=true
CELESTIA_HOME=="/root/.celestia-app"
EVM_ADDRESS="0x...."
ORCHESTRATOR_ADDRESS="celestia1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

BRIDGE_CORE_GRPC="validator:9090"
BRIDGE_CORE_REMOTE="tcp://validator:26657"
BRIDGE_CORE_IP="tcp://validator"
BRIDGE_KEY_RING_ACC_NAME="my_celes_key.info"
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ copy environment file sample to .env and set your configs, if you don't have a w
```shell
cp .env.sample .env
```
### Build Images
```shell
docker compose pull & docker compose build
```
### Initialize configs
```shell
docker compose run --rm validator init
Expand All @@ -33,25 +37,32 @@ docker compose exec validator /opt/helpers.sh validator:sync-info
docker compose exec validator /opt/helpers.sh validator:connect
```

### Delegate to a Validator
```shell
docker compose exec validator /opt/helpers.sh validator:delegate <celestiavaloper address> <amount>utia
```

## Bridge Node
To run a bridge node alongside your validator, first run the bridge in foreground to initialize required files,a new wallet is generated automatically:
Initialize bridge node
```shell
docker compose up bridge
docker compose run --rm bridge celestia bridge init && docker compose run --rm bridge celestia bridge start
```
#### Using newly generated account
if you want to stick with generated account, write down mnemonic codes somewhere safe, then cancel the process using `ctrl+c` and run it once again, but this time in background:
if you want to stick with generated account, write down mnemonic codes somewhere safe, then run bridge node in background, otherwise if you want to use validator wallet, skip to next part
```shell
docker compose up -d bridge
```
#### Using same wallet as validator for bridge node
open a new terminal, copy keys from validators volume to host, then copy it to the bridges volume
```shell
docker cp celestia-docker-validator-1:/root/.celestia-app/keyring-test ./keys-backup
```
copy keys from validators volume to host, then copy it to the bridges volume
```shell
docker cp ./keys-backup/. celestia-docker-bridge-1:/root/.celestia-bridge/keys/keyring-test
docker run --rm \
-v celestia-docker_celestia-app:/src \
-v celestia-docker_celestia-bridge-node:/dst \
busybox sh -c "cp -a /src/keyring-test /dst/keys/"
```
in `.env` file change `BRIDGE_KEY_RING_ACC_NAME` value same as `VALIDATOR_WALLET_NAME`. kill the foreground bridge process using `ctrl+c` then run a new instance in background
**IMPORTANT** in `.env` file change `BRIDGE_KEY_RING_ACC_NAME` value same as `VALIDATOR_WALLET_NAME`

run bridge node in background
```shell
docker compose up -d bridge
```
Expand Down
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM arashidos/celestia-app:v0.6.0
FROM arashidos/celestia-app:mocha
RUN apk add --no-cache git curl jq
COPY custom-entrypoint.sh /opt/custom-entrypoint.sh
COPY helpers.sh /opt/helpers.sh
Expand Down
152 changes: 75 additions & 77 deletions app/custom-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,38 @@
set -e

_init_p2p() {
cd $HOME
rm -rf networks
rm -f $HOME/.celestia-app/config/genesis.json
git clone https://github.com/celestiaorg/networks.git
while true; do
# in case you want recover priv_validator_key.json through mnemonics
read -p "Do you want to import a previously created node mnemonics? " yn
case $yn in
[Yy]* ) celestia-appd init "$CELESTIA_NODE_NAME" --chain-id mamaki --recover; break;;
[Nn]* ) celestia-appd init "$CELESTIA_NODE_NAME" --chain-id mamaki; break;;
* ) echo "Please answer yes or no.";;
esac
done
cp $HOME/networks/mamaki/genesis.json $HOME/.celestia-app/config
if [ -z "${BOOTSTRAP_PEERS}" ]; then
BOOTSTRAP_PEERS=$(curl -s https://rpc-mamaki.pops.one/net_info | jq -r '.result.peers[] | .url + ","' | tr -d '\n' | sed 's/.$//')
fi
echo $BOOTSTRAP_PEERS
sed -i.bak -e "s/^bootstrap-peers *=.*/bootstrap-peers = \"$BOOTSTRAP_PEERS\"/" $HOME/.celestia-app/config/config.toml
# Make the node accessible outside of container
sed -i.bak -e "s/^laddr = \"tcp:\/\/127.0.0.1:26657\"/laddr = \"tcp:\/\/0.0.0.0:26657\"/" $HOME/.celestia-app/config/config.toml
# Configure validator mode
sed -i.bak -e "s/^mode *=.*/mode = \"validator\"/" $HOME/.celestia-app/config/config.toml

cd $HOME
rm -rf networks
rm -f $HOME/.celestia-app/config/genesis.json
git clone https://github.com/celestiaorg/networks.git
while true; do
# in case you want recover priv_validator_key.json through mnemonics
read -p "Do you want to import a previously created node mnemonics? " yn
case $yn in
[Yy]*)
celestia-appd init "$CELESTIA_NODE_NAME" --chain-id mocha --recover
break
;;
[Nn]*)
celestia-appd init "$CELESTIA_NODE_NAME" --chain-id mocha
break
;;
*) echo "Please answer yes or no." ;;
esac
done
cp $HOME/networks/mocha/genesis.json $HOME/.celestia-app/config
}
_set_configs() {
if [ -z "${PEERS}" ]; then
# TODO : check the correctness of this with team
PEERS=$(curl -s https://rpc-mocha.pops.one/net_info | jq -r '.result.peers[] | select(.remote_ip | test("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$")) | "\(.node_info.id)@\(.remote_ip):\(.node_info.listen_addr | split(":")[-1])"' | tr '\n' ',' | sed 's/,$//')
fi
sed -i -e 's|^seeds *=.*|seeds = "'$SEEDS'"|; s|^persistent_peers *=.*|persistent_peers = "'$PEERS'"|' $HOME/.celestia-app/config/config.toml
sed -i -e "s/^seed_mode *=.*/seed_mode = \"$SEED_MODE\"/" $HOME/.celestia-app/config/config.toml
# Make the node accessible outside of container
sed -i.bak -e "s/^laddr = \"tcp:\/\/127.0.0.1:26657\"/laddr = \"tcp:\/\/0.0.0.0:26657\"/" $HOME/.celestia-app/config/config.toml
}

_config_pruning() {
PRUNING="custom"
PRUNING_KEEP_RECENT="100"
Expand All @@ -44,74 +51,65 @@ _download_snapshot() {
rm -rf ~/.celestia-app/data
mkdir -p ~/.celestia-app/data
SNAP_NAME=$(curl -s https://snaps.qubelabs.io/celestia/ |
egrep -o ">mamaki.*tar" | tr -d ">")
egrep -o ">mocha.*tar" | tr -d ">")
wget -O - https://snaps.qubelabs.io/celestia/${SNAP_NAME} | tar xf - \
-C ~/.celestia-app/data/
}
_init_wallet() {
celestia-appd config keyring-backend test
while true; do
read -p "Do you want to import a previously created wallet? " yn
case $yn in
[Yy]* ) celestia-appd keys add $VALIDATOR_WALLET_NAME --recover; break;;
[Nn]* ) celestia-appd keys add $VALIDATOR_WALLET_NAME; break;;
* ) echo "Please answer yes or no.";;
esac
done
echo "celesvaloper address : "
celestia-appd keys show $VALIDATOR_WALLET_NAME --bech val -a
}
_get_wallet_balance() {
celestia-appd start > /dev/null 2>&1 &
echo "waiting for connection ..." && sleep 2
celestia-appd query bank balances $WALLET_ADDRESS
}
_validator_connect() {

celestia-appd tx staking create-validator \
--amount=1000000utia \
--pubkey=$(celestia-appd tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=mamaki \
--commission-rate=0.1 \
--commission-max-rate=0.2 \
--commission-max-change-rate=0.01 \
--min-self-delegation=1000000 \
--from=$VALIDATOR_WALLET_NAME \
--keyring-backend=test
celestia-appd config keyring-backend test
while true; do
read -p "Do you want to import a previously created wallet? " yn
case $yn in
[Yy]*)
celestia-appd keys add $VALIDATOR_WALLET_NAME --recover
break
;;
[Nn]*)
celestia-appd keys add $VALIDATOR_WALLET_NAME
break
;;
*) echo "Please answer yes or no." ;;
esac
done
echo "celesvaloper address : "
celestia-appd keys show $VALIDATOR_WALLET_NAME --bech val -a
}

_init() {
_init_p2p
_config_pruning
_init_wallet
while true; do
_init_p2p
_set_configs
_config_pruning
_init_wallet
while true; do
read -p "Did you made a backup from your mnemonic keys? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Please, store it in a safe place then type yes";;
* ) echo "Please answer yes or no.";;
[Yy]*) break ;;
[Nn]*) echo "Please, store it in a safe place then type yes" ;;
*) echo "Please answer yes or no." ;;
esac
done
while true; do
done
while true; do
read -p "Do you want to download the latest snapshot? " yn
case $yn in
[Yy]* ) _download_snapshot; break;;
[Nn]* ) exit ;;
* ) echo "Please answer yes or no.";;
[Yy]*)
_download_snapshot
break
;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done

done

}
if [ "$1" = 'debug' ]; then
trap : TERM INT; sleep infinity & wait
trap : TERM INT
sleep infinity &
wait
elif [ "$1" = 'init' ]; then
_init
elif [ "$1" = 'wallet:balance' ]; then
_get_wallet_balance
elif [ "$1" = 'validator:connect' ]; then
_validator_connect
_init
elif [ "$1" = 'start' ]; then
#always update configs before start to apply changes in .env file
_set_configs
/bin/celestia-appd start
else
/bin/celestia-appd $@
/bin/celestia-appd "$@"
fi
51 changes: 33 additions & 18 deletions app/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,46 @@
set -e

_get_wallet_balance() {
celestia-appd query bank balances $WALLET_ADDRESS
celestia-appd query bank balances $WALLET_ADDRESS
}
_validator_connect() {
# Configure validator mode
sed -i.bak -e "s/^mode *=.*/mode = \"validator\"/" $HOME/.celestia-app/config/config.toml

celestia-appd tx staking create-validator \
--amount=1000000utia \
--pubkey=$(celestia-appd tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=mamaki \
--commission-rate=0.1 \
--commission-max-rate=0.2 \
--commission-max-change-rate=0.01 \
--min-self-delegation=1000000 \
--from=$VALIDATOR_WALLET_NAME \
--keyring-backend=test
celestia-appd tx staking create-validator \
--amount=1000000utia \
--pubkey=$(celestia-appd tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=mocha \
--commission-rate=0.1 \
--gas="auto" \
--gas-adjustment=1.5 \
--fees="1800utia" \
--commission-max-rate=0.2 \
--commission-max-change-rate=0.01 \
--min-self-delegation=1000000 \
--from=$VALIDATOR_WALLET_NAME \
--evm-address=$EVM_ADDRESS \
--orchestrator-address=$ORCHESTRATOR_ADDRESS \
--keyring-backend=test
}
_delegate_to_validator() {
# first argument is celestiavaloper address of validator and second is the amount e.g 1000000utia
celestia-appd tx staking delegate \
$2 $3 \
--chain-id=mocha \
--gas="auto" \
--gas-adjustment=1.5 \
--fees="1800utia" \
--from=$VALIDATOR_WALLET_NAME \
--keyring-backend=test
}

if [ "$1" = 'wallet:balance' ]; then
_get_wallet_balance
elif [ "$1" = 'validator:connect' ]; then
_validator_connect
_validator_connect
elif [ "$1" = 'validator:delegate' ]; then
_delegate_to_validator "$@"
elif [ "$1" = 'validator:sync-info' ]; then
curl -s localhost:26657/status | jq .result | jq .sync_info
curl -s localhost:26657/status | jq .result | jq .sync_info
else
/bin/celestia-appd $@
/bin/celestia-appd "$@"
fi
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ services:
- ./app/helpers.sh:/opt/helpers.sh
- celestia-app:/root/.celestia-app
bridge:
image: arashidos/celestia-node:v0.3.0-rc2
image: ghcr.io/celestiaorg/celestia-node:0.6.0
env_file:
- .env
environment:
- NODE_TYPE=bridge
restart: unless-stopped
command: "celestia bridge start --core.grpc $BRIDGE_CORE_GRPC --core.remote $BRIDGE_CORE_REMOTE --keyring.accname $BRIDGE_KEY_RING_ACC_NAME"
command: "celestia bridge start --core.ip $BRIDGE_CORE_IP --keyring.accname $BRIDGE_KEY_RING_ACC_NAME"
logging:
options:
max-size: "12m"
max-file: "5"
networks:
default:
volumes:
- celestia-bridge-node:/root/.celestia-bridge
- celestia-bridge-node:/root/.celestia-bridge-mocha
volumes:
celestia-app:
celestia-bridge-node:
Expand Down

0 comments on commit a4188ea

Please sign in to comment.