Skip to content

Instantly share code, notes, and snippets.

@Nuttymoon
Last active May 26, 2023 09:44
Show Gist options
  • Save Nuttymoon/89525d14ffc1fc53894bae86f399a6d9 to your computer and use it in GitHub Desktop.
Save Nuttymoon/89525d14ffc1fc53894bae86f399a6d9 to your computer and use it in GitHub Desktop.
Gather Avalanche Subnets stats using Ash CLI
#!/bin/bash
export AVALANCHE_NETWORK="${AVALANCHE_NETWORK:-mainnet-ankr}"
echo "Avalanche Network: $AVALANCHE_NETWORK"
# Get the list of Subnets with at least one blockchain (exclude the Primary Network)
SUBNETS_W_CHAINS=$(
ash avalanche subnet list --json |
jq -r '.[] |
select(.id != "11111111111111111111111111111111LpoYY") |
select((.blockchains | length) > 0) | .id'
)
echo "Subnets with blockchains: $(echo "$SUBNETS_W_CHAINS" | wc -l)"
# Get the list of Subnets with at least one validator
SUBNETS_W_VALIDATORS=$(while read -r s; do
ash avalanche subnet info "$s" --json |
jq "{\"id\": \"$s\", \"validators_count\": (.validators | length), \"type\": .subnetType}"
done <<<"$SUBNETS_W_CHAINS" | jq -sc '.[] | select(.validators_count > 0)')
# Get the number of permissioned Subnets
PERMISSIONED_SUBNETS=$(echo "$SUBNETS_W_VALIDATORS" | jq -s '.[] | select(.type == "Permissioned")' | jq -s 'length')
echo "Subnets with validators: $(echo "$SUBNETS_W_VALIDATORS" | wc -l)"
echo "Permissioned / elastic: $PERMISSIONED_SUBNETS / $(($(echo "$SUBNETS_W_VALIDATORS" | wc -l) - $PERMISSIONED_SUBNETS))"
echo "Total Subnet validators: $(echo "$SUBNETS_W_VALIDATORS" | jq -s '. | map(.validators_count) | add')"
echo "Avg number of validators: $(echo "$SUBNETS_W_VALIDATORS" | jq -s '. | map(.validators_count) | (add / length)')"
@Nuttymoon
Copy link
Author

Nuttymoon commented May 23, 2023

Requirements

Picking the network

You can export AVALANCHE_NETWORK to choose another network (e.g. fuji). It has to be in your Ash config (see Custom configuration).

export AVALANCHE_NETWORK=fuji

Sample output

Avalanche Network: mainnet
Subnets with blockchains: 38
Subnets with validators:  24
Permissioned / elastic:   24 / 0
Total Subnet validators: 151
Avg number of validators: 6.291666666666667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment