Skip to content

Commit

Permalink
chore: Easily run localnet (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar authored Jul 21, 2023
1 parent d6c5cf4 commit ede09d0
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
.vscode/

dist/
data/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Contains bug fixes.
Contains all the PRs that improved the code without changing the behaviours.
-->

## [Unreleased]

### Added

- [#419](https://github.com/archway-network/archway/pull/419) - Easily run localnet via make


## [v2.0.0]

### Added
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,17 @@ check-vuln-deps:
go-mod-cache draw-deps clean build format \
test test-all test-build test-cover test-unit test-race \
test-sim-import-export \

###############################################################################
### Run Localnet ###
###############################################################################

# Run a new localnet
run:
./scripts/localnet.sh

# Continue the existing localnet
run-continue:
./scripts/localnet.sh continue

.PHONY: localnet run-continue
119 changes: 119 additions & 0 deletions scripts/localnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/sh

# Console log text colour
red=`tput setaf 9`
green=`tput setaf 10`
blue=`tput setaf 12`
reset=`tput sgr0`

echo_info () {
echo "${blue}"
echo "$1"
echo "${reset}"
}

echo_error () {
echo "${red}"
echo "$1"
echo "${reset}"
}

echo_success () {
echo "${green}"
echo "$1"
echo "${reset}"
}

# Set localnet settings
BINARY=./build/archwayd
CHAIN_ID=localnet-1
CHAIN_DIR=./data
VALIDATOR_MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
DEVELOPER_MNEMONIC="friend excite rough reopen cover wheel spoon convince island path clean monkey play snow number walnut pull lock shoot hurry dream divide concert discover"
USER_MNEMONIC="any giant turtle pioneer frequent frown harvest ancient episode junior vocal rent shrimp icon idle echo suspect clean cage eternal sample post heavy enough"
GENESIS_COINS=1000000000000000000000000000000000000stake

setup_chain () {
# Stop archwayd if it is already running
if pgrep -x "$BINARY" >/dev/null; then
echo_error "Terminating $BINARY..."
killall archwayd
fi

# Remove previous data
echo_info "Removing previous chain data from $CHAIN_DIR/$CHAIN_ID..."
rm -rf $CHAIN_DIR/$CHAIN_ID


# Initialize archwayd with "localnet-1" chain id
echo_info "Initializing $CHAIN_ID..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID init test --chain-id=$CHAIN_ID; then
echo_success "Successfully initialized $CHAIN_ID"
else
echo_error "Failed to initialize $CHAIN_ID"
fi

# Modify config for development
config="$CHAIN_DIR/$CHAIN_ID/config/config.toml"
if [ "$(uname)" = "Linux" ]; then
sed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config
else
sed -i '' "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config
fi
# modify genesis params for localnet ease of use
genesis="$CHAIN_DIR/$CHAIN_ID/config/genesis.json"
# x/gov params change
# reduce voting period to 2 minutes
contents="$(jq '.app_state.gov.voting_params.voting_period = "120s"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov voting period to 120 seconds"
# reduce minimum deposit amount to 10stake
contents="$(jq '.app_state.gov.deposit_params.min_deposit[0].amount = "10"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov proposal min deposit amount to 10 stake"
# reduce deposit period to 20seconds
contents="$(jq '.app_state.gov.deposit_params.max_deposit_period = "20s"' $genesis)" && echo "${contents}" > $genesis
echo_info "Set x/gov proposal max deposit period to 20 seconds"


# Adding users
echo_info "Adding genesis accounts..."
echo_info "1. validator"
echo $VALIDATOR_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add validator --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show validator --keyring-backend test -a) $GENESIS_COINS
echo_info "2. developer"
echo $DEVELOPER_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add developer --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show developer --keyring-backend test -a) $GENESIS_COINS
echo_info "3. user"
echo $USER_MNEMONIC | $BINARY --home $CHAIN_DIR/$CHAIN_ID keys add user --recover --keyring-backend test
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $($BINARY --home $CHAIN_DIR/$CHAIN_ID keys show user --keyring-backend test -a) $GENESIS_COINS


# Creating gentx
echo_info "Creating gentx for validator..."
$BINARY --home $CHAIN_DIR/$CHAIN_ID gentx validator 100000000000000000000000stake --chain-id $CHAIN_ID --fees 950000000000000000000stake --keyring-backend test


# Collecting gentx
echo_info "Collecting gentx..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi


# Validating genesis
echo_info "Validating genesis..."
if $BINARY --home $CHAIN_DIR/$CHAIN_ID validate-genesis; then
echo_success "Successfully validated genesis"
else
echo_error "Failed to validate genesis"
fi
}

if [ "$1" != "continue" ] ;then
setup_chain
fi

# Starting chain
echo_info "Starting chain..."
$BINARY --home $CHAIN_DIR/$CHAIN_ID start
Empty file removed test_genesis.sh
Empty file.

0 comments on commit ede09d0

Please sign in to comment.