Skip to content

Commit

Permalink
use local-ic tool to start devnet (#429)
Browse files Browse the repository at this point in the history
* use env variable instead of yaml file

* use local-ic to startup local devnet

* lint

* update readme

* edit makefile

* edit makefile

---------

Co-authored-by: themandalore <[email protected]>
  • Loading branch information
akremstudy and themandalore authored Nov 14, 2024
1 parent cefdcfe commit 74f18b9
Show file tree
Hide file tree
Showing 39 changed files with 149 additions and 1,821 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ secrets.yaml
prod-sim

dist/

interchaintest/
heighliner/
54 changes: 34 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,35 @@ lint-folder-fix:
###############################################################################
### Protobuf ###
###############################################################################
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)

protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
protoImage="$(DOCKER)" run -e BUF_CACHE_DIR=/tmp/buf --rm -v "$(CURDIR)":/workspace:rw --user ${CURRENT_UID}:${CURRENT_GID} --workdir /workspace $(protoImageName)

#? proto-all: Run make proto-format proto-lint proto-gen
proto-all: proto-format proto-lint proto-gen
proto-all: proto-format proto-lint proto-gen format

#? proto-gen: Generate Protobuf files
proto-gen:
@go install cosmossdk.io/orm/cmd/[email protected]
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh
@go mod tidy

#? proto-swagger-gen: Generate Protobuf Swagger
proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@$(protoImage) sh ./scripts/protoc-swagger-gen.sh

#? proto-format: Format proto file
proto-format:
@echo "Formatting Protobuf files"
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

#? proto-lint: Lint proto file
proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh

proto-lint:
@$(protoImage) buf lint --error-format=json

#? proto-check-breaking: Check proto file is breaking
proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main

#? proto-update-deps: Update protobuf dependencies
proto-update-deps:
@echo "Updating Protobuf dependencies"
$(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update

.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps
.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking

###############################################################################
### tests ###
Expand Down Expand Up @@ -231,9 +225,13 @@ mock-gen:
$(MAKE) mock-gen-registry
$(MAKE) mock-gen-reporter

.PHONY: mock-gen mock-gen-bridge mock-gen-dispute mock-gen-mint mock-gen-oracle mock-gen-registry mock-gen-reporter mock-gen-daemon

get-heighliner:
git clone https://github.com/strangelove-ventures/heighliner.git
git clone --depth 1 https://github.com/strangelove-ventures/heighliner.git
cd heighliner && go install
@sleep 0.1
@echo ✅ heighliner installed to $(shell which heighliner)

local-image:
ifeq (,$(shell which heighliner))
Expand All @@ -242,4 +240,20 @@ else
heighliner build -c layer --local --dockerfile cosmos --build-target "make install" --binaries "/go/bin/layerd"
endif

.PHONY: mock-gen mock-gen-bridge mock-gen-dispute mock-gen-mint mock-gen-oracle mock-gen-registry mock-gen-reporter mock-gen-daemon
get-localic:
@echo "Installing local-interchain"
git clone --depth 1 https://github.com/strangelove-ventures/interchaintest.git
cd interchaintest/local-interchain && make install
@sleep 0.1
@echo ✅ local-interchain installed $(shell which local-ic)


local-devnet:
ifeq (,$(shell which local-ic))
echo 'local-ic' binary not found. Consider running `make get-localic`
else
echo "Starting local interchain"
cd local_devnet && ICTEST_HOME=. local-ic start layer.json

endif
.PHONY: get-heighliner local-image get-localic local-devnet
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@ For docs on how to join our public testnet go here: [https://docs.tellor.io/lay
- `start_two_chains.sh` (mac environment) sets up two nodes/validators and starts one of them from this script. Then to start the other validator you would run the `start_bill.sh` script

2) Run the selected script from the base layer folder:
`sh ./start_scripts/{selected_script}`

```sh
./start_scripts/{selected_script}
```

## Joining a Running Chain

To find more information please go to the layer_scripts folder.

Here you will find a detailed breakdown for how to join a chain as a node and how to create a new validator for the chain

## Start a local devnet

Run the chain locally in a docker container, powered by [local-ic](https://github.com/strangelove-ventures/interchaintest/tree/main/local-interchain)

```sh
make local-devnet
```

To configure the chain (ie add more validators plus more) edit the json in local_devnet/chains/layer.json

## Tests

To run integration tests:
Expand Down
24 changes: 5 additions & 19 deletions daemons/token_bridge_feed/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"math/big"
"net/http"
"net/url"
"os"
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/spf13/viper"
tokenbridgetypes "github.com/tellor-io/layer/daemons/server/types/token_bridge"
tokenbridge "github.com/tellor-io/layer/daemons/token_bridge_feed/abi"

Expand Down Expand Up @@ -381,31 +381,17 @@ func (c *Client) EncodeReportValue(depositReceipt DepositReceipt) ([]byte, error
}

func (c *Client) getEthRpcUrl() (string, error) {
viper.SetConfigName("secrets")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
ethRpcUrl := viper.GetString("eth_rpc_url")
ethRpcUrl := os.Getenv("ETH_RPC_URL")
if ethRpcUrl == "" {
return "", fmt.Errorf("eth_rpc_url not set")
return "", fmt.Errorf("ETH_RPC_URL not set")
}
return ethRpcUrl, nil
}

func (c *Client) getTokenBridgeContractAddress() (common.Address, error) {
viper.SetConfigName("secrets")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
tokenBridgeContractAddress := viper.GetString("token_bridge_contract")
tokenBridgeContractAddress := os.Getenv("TOKEN_BRIDGE_CONTRACT")
if tokenBridgeContractAddress == "" {
return common.Address{}, fmt.Errorf("token_bridge_contract not set")
return common.Address{}, fmt.Errorf("TOKEN_BRIDGE_CONTRACT not set")
}
return common.HexToAddress(tokenBridgeContractAddress), nil
}
Expand Down
78 changes: 78 additions & 0 deletions local_devnet/chains/layer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"chains": [
{
"name": "layer",
"chain_id": "layer-1",
"denom": "loya",
"binary": "layerd",
"bech32_prefix": "tellor",
"docker_image": {
"repository": "layer",
"version": "local",
"uid-gid": "1025:1025"
},
"gas_prices": "0%DENOM%",
"coin_type": 118,
"trusting_period": "112h",
"gas_adjustment": 2.0,
"number_vals": 4,
"number_node": 0,
"debugging": true,
"block_time": "5000ms",
"host_port_override": {
"26657": "26657",
"1317": "1317",
"9090": "9090"
},
"additional_start_args": [
"--keyring-backend",
"test",
"--key-name",
"validator"
],
"env": [
"ETH_RPC_URL=https://sepolia.infura.io/v3/key",
"TOKEN_BRIDGE_CONTRACT=0x"
],
"config_file_overrides": [
{
"file": "config/config.toml",
"paths": {
"moniker": "localic",
"rpc.cors_allowed_origins": [
"*"
]
}
}
],
"genesis": {
"modify": [
{
"key": "app_state.gov.params.voting_period",
"value": "15s"
},
{
"key": "app_state.gov.params.max_deposit_period",
"value": "15s"
},
{
"key": "app_state.gov.params.min_deposit.0.denom",
"value": "loya"
},
{
"key": "app_state.gov.params.min_deposit.0.amount",
"value": "1"
},
{
"key": "consensus.params.abci.vote_extensions_enable_height",
"value": "1"
}
],
"startup_commands": [
"ls %HOME%",
"%BIN% keys add example-key-after --keyring-backend test --home %HOME%"
]
}
}
]
}
15 changes: 15 additions & 0 deletions local_devnet/configs/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"start_time": 1730826722,
"chains": [
{
"chain_id": "layer-1",
"chain_name": "layer-1",
"rpc_address": "http://0.0.0.0:26657",
"rest_address": "http://0.0.0.0:1317",
"grpc_address": "0.0.0.0:9090",
"p2p_address": "0.0.0.0:62372",
"ibc_paths": []
}
],
"ibc_channels": []
}
Loading

0 comments on commit 74f18b9

Please sign in to comment.