Skip to content

Commit

Permalink
fix: added dev tooling and command utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Nov 25, 2024
1 parent da516f2 commit 48d58dd
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
69 changes: 69 additions & 0 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
###
# Find OS and Go environment
# GO contains the Go binary
# FS contains the OS file separator
###
ifeq ($(OS),Windows_NT)
GO := $(shell where go.exe 2> NUL)
FS := "\\"
else
GO := $(shell command -v go 2> /dev/null)
FS := "/"
endif

ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif

###############################################################################
### Functions ###
###############################################################################

go_get = $(if $(findstring Windows_NT,$(OS)),\
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS) ( mkdir $(GITHUBDIR)$(FS)$(1) ) else (cd .) &\
IF NOT EXIST $(GITHUBDIR)$(FS)$(1)$(FS)$(2)$(FS) ( cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2) ) else (cd .) &\
,\
mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
(test ! -d $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && cd $(GITHUBDIR)$(FS)$(1) && git clone https://github.com/$(1)/$(2)) || true &&\
)\
cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)


###############################################################################
### Tools ###
###############################################################################

PREFIX ?= /usr/local
BIN ?= $(PREFIX)/bin
UNAME_S ?= $(shell uname -s)
UNAME_M ?= $(shell uname -m)

GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com

BUF_VERSION ?= 0.11.0

TOOLS_DESTDIR ?= $(GOPATH)/bin
RUNSIM = $(TOOLS_DESTDIR)/runsim

tools: tools-stamp
tools-stamp: runsim
# Create dummy file to satisfy dependency and avoid
# rebuilding when this Makefile target is hit twice
# in a row.
touch $@

# Install the runsim binary
runsim: $(RUNSIM)
$(RUNSIM):
@echo "Installing runsim..."
@go install github.com/cosmos/tools/cmd/[email protected]

tools-clean:
rm -f $(GOLANGCI_LINT) $(RUNSIM)
rm -f tools-stamp

.PHONY: tools-clean runsim
2 changes: 1 addition & 1 deletion contrib/images/simd-dlv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Cosmos-SDK provides you with a local network to bootstrap a chain in your machine, but how does one debug a node or module?

If we start a single node, we won't be able to debug transactions as the machine will be in bootstrapping phase trying to find peers to connect too, that's why we need to start a local network.
If we start a single node, we won't be able to debug transactions as the machine will be in bootstrapping phase trying to find peers to connect too, thats why we need to start a local network.

But the current `localnet-start` does not provide us with debugging tools so that's why there is a different image for debugging a local network, that is to avoid any issues in the future were debugging won't be needed.

Expand Down
55 changes: 55 additions & 0 deletions contrib/localnet_liveness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

CNT=0
ITER=$1
SLEEP=$2
NUMBLOCKS=$3
NODEADDR=$4

if [ -z "$1" ]; then
echo "Need to input number of iterations to run..."
exit 1
fi

if [ -z "$2" ]; then
echo "Need to input number of seconds to sleep between iterations"
exit 1
fi

if [ -z "$3" ]; then
echo "Need to input block height to declare completion..."
exit 1
fi

if [ -z "$4" ]; then
echo "Need to input node address to poll..."
exit 1
fi

docker_containers=( $(docker ps -q -f name=simd --format='{{.Names}}') )

while [ ${CNT} -lt $ITER ]; do
curr_block=$(curl -s $NODEADDR:26657/status | jq -r '.result.sync_info.latest_block_height')

if [ ! -z ${curr_block} ] ; then
echo "Number of Blocks: ${curr_block}"
fi

if [ ! -z ${curr_block} ] && [ ${curr_block} -gt ${NUMBLOCKS} ]; then
echo "Number of blocks reached. Success!"
exit 0
fi

# Emulate network chaos:
#
# Every 10 blocks, pick a random container and restart it.
if ! ((${CNT} % 10)); then
rand_container=${docker_containers["$[RANDOM % ${#docker_containers[@]}]"]};
echo "Restarting random docker container ${rand_container}"
docker restart ${rand_container} &>/dev/null &
fi
let CNT=CNT+1
sleep $SLEEP
done
echo "Timeout reached. Failure!"
exit 1

0 comments on commit 48d58dd

Please sign in to comment.