Skip to content

Commit

Permalink
Merge branch 'aleem/378-group-module' of https://github.com/regen-net…
Browse files Browse the repository at this point in the history
…work/regen-ledger into aleem/378-group-module
  • Loading branch information
aleem1314 committed Aug 11, 2022
2 parents a47b11d + bb85dbe commit a3c33fc
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sims-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Sims Nightly
on:
schedule:
# Runs "at 1am every day"
- corn: "0 0 * * *"
- cron: "0 0 * * *"

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
uses: actions/setup-go@v2.1.3
with:
go-version: 1.18
- name: Checkout code
uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v6
id: git_diff
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Checkout code
uses: actions/checkout@v2
- name: run sub-modules test and codecov
run: make test-cover
if: env.GIT_DIFF
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### x/group

#### Added

- [#1340](https://github.com/regen-network/regen-ledger/pull/1340) Add group module

#### Removed
Expand Down
File renamed without changes.
304 changes: 264 additions & 40 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions docs/DOCS_README.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/ledger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ The following wallets currently support Regen Ledger:

Have any questions, comments, or new ideas? The following community channels are the best place to start for technical topics related to Regen Ledger:

- [Regen Network Discord](https://discord.gg/BDcBJu3)
- [Regen Network Discord](https://discord.gg/regen-network)
- [Regen Network Forum](https://forum.regen.network)
4 changes: 2 additions & 2 deletions docs/validators/get-started/install-regen.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ git checkout v1.0.0
*For Hambach Testnet:*

```bash
git checkout v2.0.0
git checkout v4.0.0
```

Build and install the `regen` binary:
Expand Down Expand Up @@ -83,5 +83,5 @@ v1.0.0
*For Hambach Testnet:*

```bash
v2.0.0
v4.0.0
```
230 changes: 230 additions & 0 deletions scripts/testnet_from_export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/usr/bin/env bash
# shellcheck disable=SC2094

set -e

# home is directory path of node home
home=$HOME/.regen

# export is the filepath of the state export
export=$HOME/Downloads/state_export.json

# set script input options
while getopts ":h:e:" option; do
case $option in
h)
home=$OPTARG;;
e)
export=$OPTARG;;
\?)
echo "Error: invalid option"
exit 1
esac
done

# check home directory and confirm removal if exists
if [ -d "$home" ]; then
read -r -p "WARNING: This script will remove $home. Would you like to continue? [y/N] " confirm
case "$confirm" in
[yY][eE][sS]|[yY])
rm -rf "$home"
;;
*)
exit 0
;;
esac
fi

# node_genesis is the node genesis file
node_genesis=$home/config/genesis.json

# tmp_dir is the temporary directory used for
# exported state to be merged into node_genesis
tmp_dir=./tmp

# tmp_genesis is the exported state from a single
# node network started by the new validator
tmp_genesis=$tmp_dir/genesis.json

# chain_id is the chain id
chain_id=$(jq .chain_id "$export")

# bond_denom is the staking token denom
bond_denom=$(jq .app_state.staking.params.bond_denom "$export")

# amount is the amount of tokens to stake (must be
# more than 2/3 of the total amount staked)
amount="1000000000000000"

# tokens is the token amount and denom to stake
tokens=$(echo "${amount}${bond_denom}" | tr -d '"')

# tokens2 is token amount x2 providing a starting balance with amount
tokens2=$(echo "$(( "$amount" + "$amount" ))${bond_denom}" | tr -d '"')

# build binary
make build

# add test key using keyring backend
./build/regen keys add test --home "$home" --keyring-backend test

# create genesis values for validator node
./build/regen init test --chain-id "$chain_id" --home "$home"
./build/regen add-genesis-account test "$tokens2" --home "$home" --keyring-backend test
./build/regen gentx test "$tokens" --chain-id "$chain_id" --home "$home" --keyring-backend test
./build/regen collect-gentxs --home "$home"

# update default denom to bond denom
sed -i "s|\"stake\"|$bond_denom|g" "$node_genesis"

# start node and deliver genesis transaction
./build/regen start --home "$home" --halt-height 1 && wait $!

# create temporary directory
mkdir -p "$tmp_dir"

# copy single node network state to temporary genesis file
./build/regen export --home "$home" > "$tmp_genesis"

# keys are the genesis file key names to update
keys=(
"app_state.auth.accounts"
"app_state.bank.balances"
"app_state.bank.supply"
"app_state.distribution.delegator_starting_infos"
"app_state.distribution.outstanding_rewards"
"app_state.distribution.validator_current_rewards"
"app_state.distribution.validator_historical_rewards"
"app_state.slashing.signing_infos"
"app_state.staking.delegations"
"app_state.staking.last_total_power"
"app_state.staking.last_validator_powers"
"app_state.staking.params.max_validators"
"app_state.staking.validators"
"validators"
)

# copy single node network state to json files
for i in "${!keys[@]}"; do

# simple var
k=${keys[$i]}

# create json file for each state object (some are too large
# to pass directly to jq so we create a file for each)
cat <<< $(jq ".$k" "$tmp_genesis") > "$tmp_dir/$k.json"

done

# overwrite node genesis file with state export
cp "$export" "$node_genesis"

# add single node network state to node genesis file
for i in "${!keys[@]}"; do

# simple var
k=${keys[$i]}

if [ "$k" == "app_state.bank.balances" ]; then

# 1) add balance for validator account

# append balances from single node network state
cat <<< $(jq --argfile v "$tmp_dir/$k.json" '.'"$k"' += $v' "$node_genesis") > "$node_genesis"

# 2) update balance for "bonded tokens pool"

# get account address for "bonded tokens pool"
a1=$(jq "[.app_state.auth.accounts[]|select(.name==\"bonded_tokens_pool\")][0].base_account.address" "$node_genesis")

# get balance amount for "bonded tokens pool"
b1=$(jq "[.${k}[]|select(.address==$a1)][0].coins[]|select(.denom==$bond_denom).amount" "$node_genesis" | tr -d '"')

# add new validator stake amount to balance amount
coins='[{"amount": "'$(( "$b1" + "$amount" ))'", "denom": '$bond_denom'}]'

# create json object for account balance with deleted bond denom balance
json=$(jq '[.'"$k"'[]|select(.address=='"$a1"')][0]|del(.coins[]|select(.denom=='"$bond_denom"'))' "$node_genesis")

# update account balance with updated bond denom balance
json=$(jq '.coins = '"$coins"'' <<< "$json")

# delete old account balance
cat <<< $(jq 'del(.'"$k"'[]|select(.address=='"$a1"'))' "$node_genesis") > "$node_genesis"

# add updated account balance
cat <<< $(jq --argjson v "[$json]" '.'"$k"' += $v' "$node_genesis") > "$node_genesis"

# 3) update balance for "fee collector"

# get account address for "fee collector"
a2=$(jq "[.app_state.auth.accounts[]|select(.name==\"fee_collector\")][0].base_account.address" "$node_genesis")

# TODO: "fee collector" does not have a balance in state exports used when
# testing therefore simply adding the balance in step (1) is sufficient but
# this will need to be updated if "fee collector" has an existing balance

elif [ "$k" == "app_state.bank.supply" ]; then

# get supply amount for bond denom from single node network state
a1=$(jq "[.${k}[]|select(.denom==$bond_denom)][0].amount" "$tmp_genesis" | tr -d '"')

# get supply amount for bond denom from node genesis
a2=$(jq "[.${k}[]|select(.denom==$bond_denom)][0].amount" "$node_genesis" | tr -d '"')

# set new supply for bond denom
ts='[{"amount": "'$(( "$a1" + "$a2" ))'", "denom": '$bond_denom'}]'

# delete supply for bond denom
cat <<< $(jq 'del(.'"$k"'[]|select(.denom=='"$bond_denom"'))' "$node_genesis") > "$node_genesis"

# add updated supply for bond denom
cat <<< $(jq --argjson v "$ts" '.'"$k"' += $v' "$node_genesis") > "$node_genesis"

elif [ "$k" == "app_state.staking.last_total_power" ]; then

# get last total power from single node network state
p1=$(jq ".$k" "$tmp_genesis" | tr -d '"')

# get last total power from state export
p2=$(jq ".$k" "$node_genesis" | tr -d '"')

# set new last total power
tp=$(( "$p1" + "$p2" ))

# update last total power
cat <<< $(jq --arg v "$tp" '.'"$k"' = $v' "$node_genesis") > "$node_genesis"

elif [ "$k" == "app_state.staking.params.max_validators" ]; then

# get max validators from state export
mv=$(jq ".$k" "$node_genesis" | tr -d '"')

# update max validators to include new validator
cat <<< $(jq --arg v "$(( "$mv" + 1 ))" '.'"$k"' = $v' "$node_genesis") > "$node_genesis"

else

# append single node network state values
cat <<< $(jq --argfile v "$tmp_dir/$k.json" '.'"$k"' += $v' "$node_genesis") > "$node_genesis"

fi
done

# remove previous state (but keep validator state)
rm -rf "$home/data/application.db/"
rm -rf "$home/data/blockstore.db/"
rm -rf "$home/data/cs.wal/"
rm -rf "$home/data/evidence.db/"
rm -rf "$home/data/snapshots/"
rm -rf "$home/data/state.db/"
rm -rf "$home/data/tx_index.db/"

# remove temporary directory
rm -rf $tmp_dir

# reduce voting period to 20 seconds
cat <<< $(jq '.app_state.gov.voting_params.voting_period = "20s"' "$node_genesis") > "$node_genesis"

# start node
./build/regen start --home "$home" --fast_sync=false

0 comments on commit a3c33fc

Please sign in to comment.