Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jul 23, 2024
1 parent 9a725bf commit b18a580
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 15 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/pre-genesis-transactions-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- run: |
source .venv/bin/activate
poetry run python scripts/merge-pr.py
poetry run python scripts/validate-pr.py
main:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down Expand Up @@ -127,8 +127,6 @@ jobs:
source .venv/bin/activate
poetry run python scripts/merge-pr.py
- uses: stefanzweifel/git-auto-commit-action@v5
with:
token: ${{ secrets.PAT }}

can_enqueue:
needs: [pr-check]
Expand Down
18 changes: 18 additions & 0 deletions genesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Namada Mainnet Genesis files

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla mauris magna, blandit non posuere a, tempor vel nibh. Integer lacinia quam tempor hendrerit porta. Ut quis congue elit.

## Voting power distrubiton

![Voting Power Distribution](../images/validators.png "Voting Power Distribution")

## Validators


- address: `tnam1q8nzq9m5v8upn6jkjsljf25mzf2n9u7qfyc8kwje`
- alias: `Unknown alias`
- commission: `1.0%`
- max commission rate change: `1.0%`
- total voting power: `10000.0`
- email: `[email protected]`
- website: `Unknown website`
Binary file added images/validators.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 143 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
plotly = "^5.22.0"
kaleido = "0.2.1"
jinja2 = "^3.1.4"

[tool.poetry.group.dev.dependencies]
toml = "^0.10.2"
Expand Down
19 changes: 19 additions & 0 deletions scripts/artifacts/README.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Namada Mainnet Genesis files

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla mauris magna, blandit non posuere a, tempor vel nibh. Integer lacinia quam tempor hendrerit porta. Ut quis congue elit.

## Voting power distrubiton

![Voting Power Distribution](../images/validators.png "Voting Power Distribution")

## Validators

{% for validator in validators %}
- address: `{{ validator.address }}`
- alias: `{{ validator.alias or 'Unknown alias' }}`
- commission: `{{ validator.commission_rate }}%`
- max commission rate change: `{{ validator.max_commission_rate_change }}%`
- total voting power: `{{ validator.voting_power }}`
- email: `{{ validator.email }}`
- website: `{{ validator.website or 'Unknown website' }}`
{% endfor %}
80 changes: 79 additions & 1 deletion scripts/rebuild.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
from collections import defaultdict
import glob
import toml
import plotly.graph_objects as go
from jinja2 import Environment, FileSystemLoader

def build_graph(validators):
fig = go.Figure()
fig.add_trace(go.Bar(
x=[validator['address'] for validator in validators],
y=[validator['voting_power'] for validator in validators],
name='validators',
marker_color='indianred',
))

fig.update_layout(xaxis={'categoryorder':'total descending'})
fig.update_xaxes(tickangle=75)

fig.write_image("images/validators.png")


def build_readme(validators):
environment = Environment(loader=FileSystemLoader("scripts/artifacts"))
template = environment.get_template("README.jinja")

content = template.render({"validators": validators})

with open("genesis/README.md", mode="w", encoding="utf-8") as message:
message.write(content)


def read_unsafe_toml(file_path):
try:
return toml.load(open(file_path, "r"))
except Exception as e:
return None


def parse_validators():
validator_files = glob.glob("transactions/*-validator.toml")
bond_files = glob.glob("transactions/*-bond.toml")

bonds = []
target_vp = defaultdict(int)
for file in bond_files:
bonds_toml = read_unsafe_toml(file)
if bonds_toml is None:
continue

for bond in bonds_toml['bond']:
bonds.append({
'source': bond['source'],
'validator': bond['validator'],
'amount': bond['amount'],
})
target_vp[bond['validator']] += float(bond['amount'])

validators = []
for file in validator_files:
validators_toml = read_unsafe_toml(file)
if validators_toml is None:
continue

for validator in validators_toml['validator_account']:
validators.append({
'address': validator['address'],
'commission_rate': float(validator['commission_rate']) * 100,
'max_commission_rate_change': float(validator['max_commission_rate_change']) * 100,
'email': validator['metadata']['email'],
'alias': validator['metadata']['alias'] if 'alias' in validator['metadata'] else None,
'website': validator['metadata']['website'] if 'website' in validator['metadata'] else None,
'voting_power': target_vp[validator['address']] if validator['address'] in target_vp else 0
})

return sorted(validators, key=lambda d: d['voting_power'])

def main():
exit(0)
validators = parse_validators()
build_graph(validators)
build_readme(validators)

if __name__ == "__main__":
main()
File renamed without changes.
10 changes: 0 additions & 10 deletions scripts/validate-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ def get_all_created_files():
return list(map(lambda file_path: file_path.decode(), res.stdout.splitlines()))


def get_alias(changed_files):
alias = changed_files[0].split('/')[1].split('-')[0]
for file in changed_files:
if not alias == file.split('/')[1].split('-')[0]:
return None

return alias


def read_unsafe_toml(file_path):
try:
return toml.load(open(file_path, "r"))
Expand Down Expand Up @@ -163,7 +154,6 @@ def validate_toml(file):
def main():
check_no_deleted_or_modified_files()
changed_files = get_all_created_files()
alias = get_alias(changed_files)

print("Found {} file changed/added.".format(len(changed_files)))

Expand Down

0 comments on commit b18a580

Please sign in to comment.