Skip to content

Commit

Permalink
[Tooling, Code Health] refactor: split Makefile into multiple files (#…
Browse files Browse the repository at this point in the history
…816)

## Summary

The Makefile has gotten quite large ([1185
LoC](https://github.com/pokt-network/poktroll/blob/main/Makefile#L1185)).
This PR splits the makefile into multiple files, focusing on large
groups of targets and groups related to on-chain state or local/devnets:
- warnings.mk
- todos.mk
- checks.mk
- tests.mk
- localnet.mk
- testnet.mk
- params.mk
- applications.mk
- suppliers.mk
- gateways.mk
- session.mk
- claims.mk

## Issue

- Reaction to friction experienced while working on #799

## Type of change

Select one or more from the following:

- [ ] New feature, functionality or library
- [ ] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [x] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [x] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [x] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable
  • Loading branch information
bryanchriswhite authored Sep 16, 2024
1 parent 14a9b89 commit ac3b324
Show file tree
Hide file tree
Showing 15 changed files with 789 additions and 785 deletions.
802 changes: 17 additions & 785 deletions Makefile

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions makefiles/applications.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
####################
### Applications ###
####################

.PHONY: app_list
app_list: ## List all the staked applications
poktrolld --home=$(POKTROLLD_HOME) q application list-application --node $(POCKET_NODE)

.PHONY: app_stake
app_stake: ## Stake tokens for the application specified (must specify the APP and SERVICES env vars)
poktrolld --home=$(POKTROLLD_HOME) tx application stake-application -y --config $(POKTROLLD_HOME)/config/$(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_stake
app1_stake: ## Stake app1 (also staked in genesis)
APP=app1 SERVICES=application1_stake_config.yaml make app_stake

.PHONY: app2_stake
app2_stake: ## Stake app2
APP=app2 SERVICES=application2_stake_config.yaml make app_stake

.PHONY: app3_stake
app3_stake: ## Stake app3
APP=app3 SERVICES=application3_stake_config.yaml make app_stake

.PHONY: app_unstake
app_unstake: ## Unstake an application (must specify the APP env var)
poktrolld --home=$(POKTROLLD_HOME) tx application unstake-application -y --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_unstake
app1_unstake: ## Unstake app1
APP=app1 make app_unstake

.PHONY: app2_unstake
app2_unstake: ## Unstake app2
APP=app2 make app_unstake

.PHONY: app3_unstake
app3_unstake: ## Unstake app3
APP=app3 make app_unstake

.PHONY: app_delegate
app_delegate: ## Delegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
poktrolld --home=$(POKTROLLD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_delegate_gateway1
app1_delegate_gateway1: ## Delegate trust to gateway1
GATEWAY1=$$(make poktrolld_addr ACC_NAME=gateway1) && \
APP=app1 GATEWAY_ADDR=$$GATEWAY1 make app_delegate

.PHONY: app2_delegate_gateway2
app2_delegate_gateway2: ## Delegate trust to gateway2
GATEWAY2=$$(make poktrolld_addr ACC_NAME=gateway2) && \
APP=app2 GATEWAY_ADDR=$$GATEWAY2 make app_delegate

.PHONY: app3_delegate_gateway3
app3_delegate_gateway3: ## Delegate trust to gateway3
GATEWAY3=$$(make poktrolld_addr ACC_NAME=gateway3) && \
APP=app3 GATEWAY_ADDR=$$GATEWAY3 make app_delegate

.PHONY: app_undelegate
app_undelegate: ## Undelegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
poktrolld --home=$(POKTROLLD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_undelegate_gateway1
app1_undelegate_gateway1: ## Undelegate trust to gateway1
GATEWAY1=$$(make poktrolld_addr ACC_NAME=gateway1) && \
APP=app1 GATEWAY_ADDR=$$GATEWAY1 make app_undelegate

.PHONY: app2_undelegate_gateway2
app2_undelegate_gateway2: ## Undelegate trust to gateway2
GATEWAY2=$$(make poktrolld_addr ACC_NAME=gateway2) && \
APP=app2 GATEWAY_ADDR=$$GATEWAY2 make app_undelegate

.PHONY: app3_undelegate_gateway3
app3_undelegate_gateway3: ## Undelegate trust to gateway3
GATEWAY3=$$(make poktrolld_addr ACC_NAME=gateway3) && \
APP=app3 GATEWAY_ADDR=$$GATEWAY3 make app_undelegate
155 changes: 155 additions & 0 deletions makefiles/checks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
##############
### Checks ###
##############

# TODO_DOCUMENT: All of the `check_` helpers can be installed differently depending
# on the user's OS and environment.
# NB: For mac users, you may need to install with the proper linkers: https://github.com/golang/go/issues/65940

.PHONY: check_go_version
# Internal helper target - check go version
check_go_version:
@# Extract the version number from the `go version` command.
@GO_VERSION=$$(go version | cut -d " " -f 3 | cut -c 3-) && \
MAJOR_VERSION=$$(echo $$GO_VERSION | cut -d "." -f 1) && \
MINOR_VERSION=$$(echo $$GO_VERSION | cut -d "." -f 2) && \
\
if [ "$$MAJOR_VERSION" -ne 1 ] || [ "$$MINOR_VERSION" -le 20 ] ; then \
echo "Invalid Go version. Expected 1.21.x or newer but found $$GO_VERSION"; \
exit 1; \
fi

.PHONY: check_ignite_version
# Internal helper target - check ignite version
check_ignite_version:
@version=$$(ignite version 2>/dev/null | grep 'Ignite CLI version:' | awk '{print $$4}') ; \
if [ "$$(printf "v28\n$$version" | sort -V | head -n1)" != "v28" ]; then \
echo "Error: Version $$version is less than v28. Exiting with error." ; \
exit 1 ; \
fi

.PHONY: check_mockgen
# Internal helper target- Check if mockgen is installed
check_mockgen:
{ \
if ( ! ( command -v mockgen >/dev/null )); then \
echo "Seems like you don't have `mockgen` installed. Please visit https://github.com/golang/mock#installation and follow the instructions to install `mockgen` before continuing"; \
exit 1; \
fi; \
}


.PHONY: check_act
# Internal helper target - check if `act` is installed
check_act:
{ \
if ( ! ( command -v act >/dev/null )); then \
echo "Seems like you don't have `act` installed. Please visit https://github.com/nektos/act before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_gh
# Internal helper target - check if `gh` is installed
check_gh:
{ \
if ( ! ( command -v gh >/dev/null )); then \
echo "Seems like you don't have `gh` installed. Please visit https://cli.github.com/ before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_docker
# Internal helper target - check if docker is installed
check_docker:
{ \
if ( ! ( command -v docker >/dev/null && (docker compose version >/dev/null || command -v docker-compose >/dev/null) )); then \
echo "Seems like you don't have Docker or docker-compose installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi; \
}
.PHONY: check_kind
# Internal helper target - check if kind is installed
check_kind:
@if ! command -v kind >/dev/null 2>&1; then \
echo "kind is not installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi

.PHONY: check_docker_ps
## Internal helper target - checks if Docker is running
check_docker_ps: check_docker
@echo "Checking if Docker is running..."
@docker ps > /dev/null 2>&1 || (echo "Docker is not running. Please start Docker and try again."; exit 1)

.PHONY: check_kind_context
## Internal helper target - checks if the kind-kind context exists and is set
check_kind_context: check_kind
@if ! kubectl config get-contexts | grep -q 'kind-kind'; then \
echo "kind-kind context does not exist. Please create it or switch to it."; \
exit 1; \
fi
@if ! kubectl config current-context | grep -q 'kind-kind'; then \
echo "kind-kind context is not currently set. Use 'kubectl config use-context kind-kind' to set it."; \
exit 1; \
fi


.PHONY: check_godoc
# Internal helper target - check if godoc is installed
check_godoc:
{ \
if ( ! ( command -v godoc >/dev/null )); then \
echo "Seems like you don't have godoc installed. Make sure you install it via 'go install golang.org/x/tools/cmd/godoc@latest' before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_npm
# Internal helper target - check if npm is installed
check_npm:
{ \
if ( ! ( command -v npm >/dev/null )); then \
echo "Seems like you don't have npm installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_jq
# Internal helper target - check if jq is installed
check_jq:
{ \
if ( ! ( command -v jq >/dev/null )); then \
echo "Seems like you don't have jq installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_yq
# Internal helper target - check if `yq` is installed
check_yq:
{ \
if ( ! ( command -v yq >/dev/null )); then \
echo "Seems like you don't have `yq` installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_node
# Internal helper target - check if node is installed
check_node:
{ \
if ( ! ( command -v node >/dev/null )); then \
echo "Seems like you don't have node installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_proto_unstable_marshalers
check_proto_unstable_marshalers: ## Check that all protobuf files have the `stable_marshalers_all` option set to true.
go run ./tools/scripts/protocheck/cmd unstable

.PHONY: fix_proto_unstable_marshalers
fix_proto_unstable_marshalers: ## Ensure the `stable_marshaler_all` option is present on all protobuf files.
go run ./tools/scripts/protocheck/cmd unstable --fix
${MAKE} proto_regen
38 changes: 38 additions & 0 deletions makefiles/claims.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##############
### Claims ###
##############

# These encoded values were generated using the `encodeSessionHeader` helpers in `query_claim_test.go` as dummy values.
ENCODED_SESSION_HEADER = "eyJhcHBsaWNhdGlvbl9hZGRyZXNzIjoicG9rdDFleXJuNDUwa3JoZnpycmVyemd0djd2c3J4bDA5NDN0dXN4azRhayIsInNlcnZpY2UiOnsiaWQiOiJhbnZpbCIsIm5hbWUiOiIifSwic2Vzc2lvbl9zdGFydF9ibG9ja19oZWlnaHQiOiI1Iiwic2Vzc2lvbl9pZCI6InNlc3Npb25faWQxIiwic2Vzc2lvbl9lbmRfYmxvY2tfaGVpZ2h0IjoiOSJ9"
ENCODED_ROOT_HASH = "cm9vdF9oYXNo"
.PHONY: claim_create_dummy
claim_create_dummy: ## Create a dummy claim by supplier1
poktrolld --home=$(POKTROLLD_HOME) tx supplier create-claim \
$(ENCODED_SESSION_HEADER) \
$(ENCODED_ROOT_HASH) \
--from supplier1 --node $(POCKET_NODE)

.PHONY: claims_list
claim_list: ## List all the claims
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --node $(POCKET_NODE)

.PHONY: claims_list_address
claim_list_address: ## List all the claims for a specific address (specified via ADDR variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --supplier-operator-address $(ADDR) --node $(POCKET_NODE)

.PHONY: claims_list_address_supplier1
claim_list_address_supplier1: ## List all the claims for supplier1
SUPPLIER1=$$(make poktrolld_addr ACC_NAME=supplier1) && \
ADDR=$$SUPPLIER1 make claim_list_address

.PHONY: claim_list_height
claim_list_height: ## List all the claims ending at a specific height (specified via HEIGHT variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --session-end-height $(HEIGHT) --node $(POCKET_NODE)

.PHONY: claim_list_height_5
claim_list_height_5: ## List all the claims at height 5
HEIGHT=5 make claim_list_height

.PHONY: claim_list_session
claim_list_session: ## List all the claims ending at a specific session (specified via SESSION variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --session-id $(SESSION) --node $(POCKET_NODE)
39 changes: 39 additions & 0 deletions makefiles/gateways.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
####################
### Gateways ###
####################

.PHONY: gateway_list
gateway_list: ## List all the staked gateways
poktrolld --home=$(POKTROLLD_HOME) q gateway list-gateway --node $(POCKET_NODE)

.PHONY: gateway_stake
gateway_stake: ## Stake tokens for the gateway specified (must specify the gateway env var)
poktrolld --home=$(POKTROLLD_HOME) tx gateway stake-gateway -y --config $(POKTROLLD_HOME)/config/$(STAKE) --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)

.PHONY: gateway1_stake
gateway1_stake: ## Stake gateway1
GATEWAY=gateway1 STAKE=gateway1_stake_config.yaml make gateway_stake

.PHONY: gateway2_stake
gateway2_stake: ## Stake gateway2
GATEWAY=gateway2 STAKE=gateway2_stake_config.yaml make gateway_stake

.PHONY: gateway3_stake
gateway3_stake: ## Stake gateway3
GATEWAY=gateway3 STAKE=gateway3_stake_config.yaml make gateway_stake

.PHONY: gateway_unstake
gateway_unstake: ## Unstake an gateway (must specify the GATEWAY env var)
poktrolld --home=$(POKTROLLD_HOME) tx gateway unstake-gateway -y --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)

.PHONY: gateway1_unstake
gateway1_unstake: ## Unstake gateway1
GATEWAY=gateway1 make gateway_unstake

.PHONY: gateway2_unstake
gateway2_unstake: ## Unstake gateway2
GATEWAY=gateway2 make gateway_unstake

.PHONY: gateway3_unstake
gateway3_unstake: ## Unstake gateway3
GATEWAY=gateway3 make gateway_unstake
31 changes: 31 additions & 0 deletions makefiles/localnet.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
########################
### Localnet Helpers ###
########################

.PHONY: localnet_up
localnet_up: check_docker_ps check_kind_context proto_regen localnet_regenesis ## Starts up a clean localnet
tilt up

.PHONY: localnet_up_quick
localnet_up_quick: check_docker_ps check_kind_context ## Starts up a localnet without regenerating fixtures
tilt up

.PHONY: localnet_down
localnet_down: ## Delete resources created by localnet
tilt down

.PHONY: localnet_regenesis
localnet_regenesis: check_yq warn_message_acc_initialize_pubkeys ## Regenerate the localnet genesis file
# NOTE: intentionally not using --home <dir> flag to avoid overwriting the test keyring
@echo "Initializing chain..."
@set -e
@ignite chain init --skip-proto
AUTH_CONTENT=$$(cat ./tools/scripts/authz/dao_genesis_authorizations.json | jq -r tostring); \
$(SED) -i -E 's!^(\s*)"authorization": (\[\]|null)!\1"authorization": '$$AUTH_CONTENT'!' ${HOME}/.poktroll/config/genesis.json;

@cp -r ${HOME}/.poktroll/keyring-test $(POKTROLLD_HOME)
@cp -r ${HOME}/.poktroll/config $(POKTROLLD_HOME)/

.PHONY: cosmovisor_start_node
cosmovisor_start_node: # Starts the node using cosmovisor that waits for an upgrade plan
bash tools/scripts/upgrades/cosmovisor-start-node.sh
Loading

0 comments on commit ac3b324

Please sign in to comment.