Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: local dev environment #1554

Merged
merged 5 commits into from
May 21, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

* [#1554](https://github.com/osmosis-labs/osmosis/pull/1554) local dev environment
* [#1535](https://github.com/osmosis-labs/osmosis/pull/1535) upgrade wasmd to v0.27.0.rc3-osmo and ibc-go to v3
* [#1435] `x/tokenfactory` create denom fee for spam resistance
* [#1429] solver for multi-asset CFMM
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COPY --from=build /osmosis/build/osmosisd /bin/osmosisd
ENV HOME /osmosis
WORKDIR $HOME

EXPOSE 26656
EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ format:
### Localnet ###
###############################################################################

localnet-keys:
. tests/localosmosis/keys.sh

localnet-build:
@docker build -t local:osmosis -f tests/localosmosis/Dockerfile .

localnet-start:
@docker-compose -f tests/localosmosis/docker-compose.yml up

localnet-remove:
@docker-compose -f tests/localosmosis/docker-compose.yml down

.PHONY: all build-linux install format lint \
go-mod-cache draw-deps clean build build-contract-tests-hooks \
Expand Down
51 changes: 51 additions & 0 deletions tests/localosmosis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# syntax=docker/dockerfile:1

# --------------------------------------------------------
# Build
# --------------------------------------------------------

FROM golang:1.18.2-alpine3.15 as build

RUN set -eux; apk add --no-cache ca-certificates build-base;
RUN apk add git
# Needed by github.com/zondax/hid
RUN apk add linux-headers

WORKDIR /osmosis
COPY . /osmosis


# CosmWasm: see https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479

# CosmWasm: copy the right library according to architecture. The final location will be found by the linker flag `-lwasmvm_muslc`
RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a

RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build

# --------------------------------------------------------
# Runner
# --------------------------------------------------------

FROM alpine

COPY --from=build /osmosis/build/osmosisd /bin/osmosisd
COPY /tests/localosmosis/setup.sh /setup.sh

ENV HOME /osmosis
WORKDIR $HOME
RUN apk update
RUN apk add jq
RUN apk add moreutils
RUN rm -rf /var/cache/apk/*
RUN chmod +x /setup.sh
RUN /setup.sh
Copy link
Member

Choose a reason for hiding this comment

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

One little improvement could be not to run this script during the docker build phase but running as an entrypoint script of the docker container.

In this way we can avoid rebuilding the image if we want to modify a parameter of the genesis.
Building takes 1-2 mins while running the script should be in the order of seconds

The way to do that would be to modifying the Dockerfile like this:

...
WORKDIR $HOME
RUN apk update \
 && apk add jq \
 && rm -rf /var/cache/apk/*
RUN chmod +x /setup.sh

# Remove the RUN /setup

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

ENTRYPOINT ["/setup.sh"]
CMD ["osmosisd", "start"]

And in the setup.sh:

#!/usr/bin/env sh
set -eu

<STANDARD CONTENT>

exec "$@" 

The exec part will execute the CMD part of the Dockerfile after is has executed the script

Copy link
Member Author

Choose a reason for hiding this comment

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

The only problem with this is the user would be recreating the genesis process on every start right? This process should only be done once at compilation time I think, and if the user wanted to modify a genesis param, they are probably better off recompiling anyway right?

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317

ENTRYPOINT ["osmosisd"]
CMD ["start"]
38 changes: 38 additions & 0 deletions tests/localosmosis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# LocalOsmosis

You can now quickly test your changes to Osmosis with just a few commands:

1. Make any change to the osmosis code that you want to test

2. From the Osmosis home folder, run `make localnet-build`
- This compiles all your changes to docker image called local:osmosis (~60 seconds)

3. Once complete, run `make localnet-start`
- You will now be running a local network with your changes!

4. To add your validator wallet and 9 other preloaded wallets automatically, run `make localnet-keys`
- These keys are added to your --keyring-backend test
- If the keys are already on your keyring, you will get an "Error: aborted"
- Ensure you use the name of the account as listed in the table below, as well as ensure you append the `--keyring-backend test` to your txs
- Example: `osmosisd tx bank send lo-test2 osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks --keyring-backend test --chain-id localosmosis`

5. To remove all block history and start from scratch, run `make localnet-remove`

## Accounts

LocalOsmosis is pre-configured with one validator and 9 accounts with ION and OSMO balances.


| Account | Address | Mnemonic |
| --------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| lo-val | `osmo1phaxpevm5wecex2jyaqty2a4v02qj7qmlmzk5a`<br/>`osmovaloper1phaxpevm5wecex2jyaqty2a4v02qj7qm9v24r6` | `satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn` |
| lo-test1 | `osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks` | `notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius` |
| lo-test2 | `osmo18s5lynnmx37hq4wlrw9gdn68sg2uxp5rgk26vv` | `quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty` |
| lo-test3 | `osmo1qwexv7c6sm95lwhzn9027vyu2ccneaqad4w8ka` | `symbol force gallery make bulk round subway violin worry mixture penalty kingdom boring survey tool fringe patrol sausage hard admit remember broken alien absorb` |
| lo-test4 | `osmo14hcxlnwlqtq75ttaxf674vk6mafspg8xwgnn53` | `bounce success option birth apple portion aunt rural episode solution hockey pencil lend session cause hedgehog slender journey system canvas decorate razor catch empty` |
| lo-test5 | `osmo12rr534cer5c0vj53eq4y32lcwguyy7nndt0u2t` | `second render cat sing soup reward cluster island bench diet lumber grocery repeat balcony perfect diesel stumble piano distance caught occur example ozone loyal` |
| lo-test6 | `osmo1nt33cjd5auzh36syym6azgc8tve0jlvklnq7jq` | `spatial forest elevator battle also spoon fun skirt flight initial nasty transfer glory palm drama gossip remove fan joke shove label dune debate quick` |
| lo-test7 | `osmo10qfrpash5g2vk3hppvu45x0g860czur8ff5yx0` | `noble width taxi input there patrol clown public spell aunt wish punch moment will misery eight excess arena pen turtle minimum grain vague inmate` |
| lo-test8 | `osmo1f4tvsdukfwh6s9swrc24gkuz23tp8pd3e9r5fa` | `cream sport mango believe inhale text fish rely elegant below earth april wall rug ritual blossom cherry detail length blind digital proof identify ride` |
| lo-test9 | `osmo1myv43sqgnj5sm4zl98ftl45af9cfzk7nhjxjqh` | `index light average senior silent limit usual local involve delay update rack cause inmate wall render magnet common feature laundry exact casual resource hundred` |
| lo-test10 | `osmo14gs9zqh8m49yy9kscjqu9h72exyf295afg6kgk` | `prefer forget visit mistake mixture feel eyebrow autumn shop pair address airport diesel street pass vague innocent poem method awful require hurry unhappy shoulder` |
14 changes: 14 additions & 0 deletions tests/localosmosis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"

services:
osmosisd:
image: local:osmosis
user: "root:root"
command:
- start
- --rpc.laddr=tcp://0.0.0.0:26657
ports:
- "26657:26657"
- "1317:1317"
- "9090:9090"
- "9091:9091"
13 changes: 13 additions & 0 deletions tests/localosmosis/keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

echo "satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn" | osmosisd keys add lo-val --recover --keyring-backend test
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
echo "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" | osmosisd keys add lo-test1 --recover --keyring-backend test
echo "quality vacuum heart guard buzz spike sight swarm shove special gym robust assume sudden deposit grid alcohol choice devote leader tilt noodle tide penalty" | osmosisd keys add lo-test2 --recover --keyring-backend test
echo "symbol force gallery make bulk round subway violin worry mixture penalty kingdom boring survey tool fringe patrol sausage hard admit remember broken alien absorb" | osmosisd keys add lo-test3 --recover --keyring-backend test
echo "bounce success option birth apple portion aunt rural episode solution hockey pencil lend session cause hedgehog slender journey system canvas decorate razor catch empty" | osmosisd keys add lo-test4 --recover --keyring-backend test
echo "second render cat sing soup reward cluster island bench diet lumber grocery repeat balcony perfect diesel stumble piano distance caught occur example ozone loyal" | osmosisd keys add lo-test5 --recover --keyring-backend test
echo "spatial forest elevator battle also spoon fun skirt flight initial nasty transfer glory palm drama gossip remove fan joke shove label dune debate quick" | osmosisd keys add lo-test6 --recover --keyring-backend test
echo "noble width taxi input there patrol clown public spell aunt wish punch moment will misery eight excess arena pen turtle minimum grain vague inmate" | osmosisd keys add lo-test7 --recover --keyring-backend test
echo "cream sport mango believe inhale text fish rely elegant below earth april wall rug ritual blossom cherry detail length blind digital proof identify ride" | osmosisd keys add lo-test8 --recover --keyring-backend test
echo "index light average senior silent limit usual local involve delay update rack cause inmate wall render magnet common feature laundry exact casual resource hundred" | osmosisd keys add lo-test9 --recover --keyring-backend test
echo "prefer forget visit mistake mixture feel eyebrow autumn shop pair address airport diesel street pass vague innocent poem method awful require hurry unhappy shoulder" | osmosisd keys add lo-test10 --recover --keyring-backend test
46 changes: 46 additions & 0 deletions tests/localosmosis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# change staking denom to uosmo
osmosisd init --chain-id=localosmosis val
echo "satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn" | osmosisd keys add val --recover --keyring-backend=test
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
osmosisd add-genesis-account osmo1phaxpevm5wecex2jyaqty2a4v02qj7qmlmzk5a 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo18s5lynnmx37hq4wlrw9gdn68sg2uxp5rgk26vv 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo1qwexv7c6sm95lwhzn9027vyu2ccneaqad4w8ka 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo14hcxlnwlqtq75ttaxf674vk6mafspg8xwgnn53 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo12rr534cer5c0vj53eq4y32lcwguyy7nndt0u2t 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo1nt33cjd5auzh36syym6azgc8tve0jlvklnq7jq 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo10qfrpash5g2vk3hppvu45x0g860czur8ff5yx0 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo1f4tvsdukfwh6s9swrc24gkuz23tp8pd3e9r5fa 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo1myv43sqgnj5sm4zl98ftl45af9cfzk7nhjxjqh 100000000000uosmo,100000000000uion
osmosisd add-genesis-account osmo14gs9zqh8m49yy9kscjqu9h72exyf295afg6kgk 100000000000uosmo,100000000000uion
osmosisd gentx val 500000000uosmo --keyring-backend=test --chain-id=localosmosis
osmosisd collect-gentxs
# update staking genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["unbonding_time"]="240s"' | sponge $HOME/.osmosisd/config/genesis.json
# update crisis variable to uosmo
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
# udpate gov genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
# update epochs genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["epochs"]["epochs"][1]["duration"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json
# update poolincentives genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][0]="120s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][1]="180s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][2]="240s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["params"]["minted_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
# update incentives genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][0]="1s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][1]="120s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][2]="180s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][3]="240s"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["params"]["distr_epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json
# update mint genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json
# update gamm genesis
cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gamm"]["params"]["pool_creation_fee"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json
# remove seeds
sed -i.bak -E 's#^(seeds[[:space:]]+=[[:space:]]+).*$#\1""#' ~/.osmosisd/config/config.toml