Skip to content

Commit

Permalink
Feat/new lavavisor (#5)
Browse files Browse the repository at this point in the history
* Support Lavavisor Pod command
* remove the previous workaround to use Lavavisor inside containers   
* updates  to version v0.32.0
  • Loading branch information
0x4r45h authored Jan 2, 2024
1 parent e6cdcf9 commit 663e325
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 99 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ otherwise **make a backup from newly generated files and keep them safe**
./helpers.sh node:backup
```
---
### A note on running `lavad` commands
Generally, to run any `lavad` commands, prefix it like this:
### A note on running `lavad` and `lavap` commands
Generally, to run any `lavad` or `lavap` commands, prefix it like this:
```bash
docker compose exec [service name] lavad [command args]
docker compose exec [service name] [lavad or lavap] [command args]
```
where service name can be either `validator` or `rpcprovider`. based on which docker-compose.yml file you are working with

for example to test our lava rpc using our own node, inside the rpc provider directory:
```bash
cd providers/lava
docker compose exec rpcprovider lavad test rpcprovider --node tcp://validator:26657 --from foo --endpoints "lava.example.com:443,LAV1"
docker compose exec rpcprovider lavap test rpcprovider --node tcp://validator:26657 --from foo --endpoints "lava.example.com:443,LAV1"
```
---

Expand Down Expand Up @@ -97,12 +97,8 @@ docker compose exec validator /opt/helpers.sh validator:delegate VALOPER_ADDRESS

# Run RPC Providers

### Lavavisor Workaround
The newly released `lavavisor` heavily depends on `systemd` which is not available in containers. so i did some nasty things to achieve something
like `auto-update` feature of `lavavisor`. i explain it shortly :
1. `lavavisor` container which periodically scans for new versions of `lavap` and download if any is available. the binaries are shared amongst all RPC services.
2. a supervisor setup with 2 process for each RPC service. one runs the `lavap` service as normal, and a watcher process, which detects new installed versions of `lavap` and restarts the sibling RPC service accordingly

### Lavavisor
Each RPC container is managed by `lavavisor pod` , so it automatically updates the underlying `lavap` binary

### Run Providers/Consumers
**WARNING** I didn't test Consumer yet. maybe it doesn't work
Expand All @@ -126,7 +122,10 @@ Set desired configs in `rpc.yml` file then run:
docker compose up -d
```
That's it. your rpc provider is up and running, fully isolated from other process. traefik will automatically detect this container and generates a certificate using lets encrypt and
routes all traffic from `RPC_URL` to this container. just don't forget stake lava token your provider.
routes all traffic from `RPC_URL` to this container. just don't forget stake lava token your provider. for example to stake for lava provider :
```shell
docker compose exec rpcprovider lavap --node tcp://validator:26657 tx pairing stake-provider LAV1 50000000000ulava "lava.example.com:443,2" 2 --from ACCOUNT_NAME_HERE --provider-moniker MONIKER_HERE --gas-adjustment 1.5 --gas auto --gas-prices 0.0001ulava
```

To test your provider :
```shell
Expand Down
22 changes: 1 addition & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"
services:
validator:
image: arashidos/lava:v0.23.5
image: ${LAVA_IMAGE:-arashidos/lava:v0.32.0}
env_file:
- .env
restart: unless-stopped
Expand All @@ -19,31 +19,11 @@ services:
networks:
lava:
volumes:
- ./helpers.sh:/opt/helpers.sh
- lava:/root/.lava
lavavisor:
image: arashidos/lava:v0.23.5
env_file:
- .env
restart: unless-stopped
command:
- "update-lavap-version"
logging:
options:
max-size: "12m"
max-file: "5"
networks:
lava:
volumes:
- ./helpers.sh:/opt/helpers.sh
- lava_binaries:/go/bin
volumes:
lava:
external: true
name: lava
lava_binaries:
external: true
name: lava_binaries
networks:
lava:
external: true
Expand Down
23 changes: 11 additions & 12 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@ RUN go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0

ARG CONFIG_REPO_URL=https://github.com/lavanet/lava-config.git
ARG CONFIG_REPO_PATH=lava-config/testnet-2
ARG LAVAD_GENESIS_BIN=https://github.com/lavanet/lava/releases/download/v0.21.1.2/lavad-v0.21.1.2-linux-amd64
ARG LAVA_REPO_URL=https://github.com/lavanet/lava.git
ARG LAVA_REPO_TAG=v0.23.5
ARG LAVA_REPO_TAG=v0.32.0

WORKDIR "/tmp"
RUN git clone $CONFIG_REPO_URL
RUN git clone --branch $LAVA_REPO_TAG $LAVA_REPO_URL
RUN mkdir -p "/tmp/conf_repo" && mv $CONFIG_REPO_PATH/* /tmp/conf_repo

RUN wget -O /tmp/lavad $LAVAD_GENESIS_BIN
WORKDIR "/tmp/lava"
# make all instead of BINs
# install lavad, lavap, lavavisor
RUN make install-all
# Remove the lavad binary to always use latest binary in path cosmovisor/current/bin
RUN rm /go/bin/lavad

#final image
FROM golang:1.21.2-bullseye
RUN apt-get update && apt-get install -y \
jq bash nano git logrotate sed unzip wget curl coreutils inotify-tools supervisor \
jq bash nano git logrotate sed unzip wget curl coreutils \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN mkdir -p "/root/.lava/config" && mkdir -p "/root/.lava/cosmovisor/genesis/bin/"
COPY --from=builder /tmp/conf_repo/default_lavad_config_files/* /root/.lava/config/
COPY --from=builder /tmp/conf_repo/genesis_json/genesis.json /root/.lava/config/genesis.json
COPY --from=builder /go/bin/* /go/bin/
COPY --from=builder /tmp/lavad /root/.lava/cosmovisor/genesis/bin/
COPY --from=builder /go/bin/lavavisor /go/bin/
COPY --from=builder /go/bin/cosmovisor /go/bin/
COPY --from=builder /go/bin/lavad /root/.lava/cosmovisor/genesis/bin/
# a helper wrapper to proxy lavap commands to the latest version of lavap
COPY lavap_latest.sh /bin/lavap
COPY entrypoint.sh /opt/entrypoint.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY watcher.sh /root/watcher.sh
RUN chmod +x /opt/entrypoint.sh /root/.lava/cosmovisor/genesis/bin/lavad /root/watcher.sh
COPY helpers.sh /opt/helpers.sh

RUN chmod +x /opt/entrypoint.sh /root/.lava/cosmovisor/genesis/bin/lavad /bin/lavap
ENV PATH="/root/.lava/cosmovisor/current/bin:$PATH"
WORKDIR "/root"
ENTRYPOINT ["/opt/entrypoint.sh"]
Expand Down
12 changes: 3 additions & 9 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,17 @@ init_function() {
$LAVA_GENESIS_BINARY tendermint show-validator
}

update_lavap() {
while true; do
lavavisor init --log_level debug --auto-download --chain-id $CHAIN_ID --node $LAVA_NODE --directory /go/bin
sleep 300 # every 5min
done
}
main() {
case "$1" in
"init")
init_function
;;
"update-lavap-version")
update_lavap
;;
"start-node")
cosmovisor start --home=/root/.lava --p2p.seeds $SEED_NODE
;;
"start-rpcprovider")
lavavisor pod --chain-id ${CHAIN_ID} --node ${LAVA_NODE} --cmd "lavap ${SERVICE_TYPE} /rpc.yml --geolocation ${GEO_LOCATION} --from ${ACCOUNT_NAME} --log_level ${LOG_LEVEL} --keyring-backend test --chain-id ${CHAIN_ID} --node ${LAVA_NODE}"
;;
*)
exec "$@"
;;
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions docker/lavap_latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e
latest_version=$(ls -v /root/.lavavisor/upgrades/*/lavap 2>/dev/null | tail -n 1)

if [ -z "$latest_version" ]; then
echo "Error: No lavap executable found."
return 1
fi
"$latest_version" "$@"
20 changes: 0 additions & 20 deletions docker/supervisord.conf

This file was deleted.

19 changes: 0 additions & 19 deletions docker/watcher.sh

This file was deleted.

13 changes: 6 additions & 7 deletions providers/lava/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: "3.9"
services:
rpcprovider:
image: arashidos/lava:v0.23.5
image: ${LAVA_IMAGE:-arashidos/lava:v0.32.0}
env_file:
- .env
restart: unless-stopped
command:
- "/usr/bin/supervisord"
- "start-rpcprovider"
labels:
- traefik.enable=true
- traefik.docker.network=public
Expand All @@ -26,15 +26,14 @@ services:
public:
volumes:
- ./rpc.yml:/root/rpc.yml
- lava:/root/.lava
- lava_binaries:/go/bin
- type: volume
source: lava
target: /root/.lava
read_only: true
volumes:
lava:
external: true
name: lava
lava_binaries:
external: true
name: lava_binaries
networks:
lava:
external: true
Expand Down

0 comments on commit 663e325

Please sign in to comment.