Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CNS-short-block-script #1704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scripts/automation_scripts/short_block_proposers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import requests
from datetime import datetime

def fetch_block_data(block_number):
# URL that returns a JSON response
url = 'https://lava.rest.lava.build/cosmos/base/tendermint/v1beta1/blocks/' + block_number

# Fetch the data from the URL
response = requests.get(url)

# Parse the JSON data
json_data = response.json()
block_header = json_data.get("sdk_block").get("header")

height = block_header.get("height")

dt = datetime.strptime(block_header.get("time")[:26] + "Z", "%Y-%m-%dT%H:%M:%S.%fZ")
time = dt.timestamp()

proposer = block_header.get("proposer_address")

return [int(height), float(time), proposer]

stats_before = {}
stats_current = {}
current = fetch_block_data("latest")
for i in range(10000):
print(f"Progress: {i}", end='\r')
before = fetch_block_data(str(current[0]-1))

if current[2] not in stats_current:
stats_current[current[2]] = {"good": 0, "bad": 0}

if before[2] not in stats_before:
stats_before[before[2]] = {"good": 0, "bad": 0}

if current[1] - before[1] < 10:
stats_current[current[2]]["bad"] += 1
stats_before[before[2]]["bad"] += 1
else:
stats_current[current[2]]["good"] += 1
stats_before[before[2]]["good"] += 1

current = before

print(stats_before)
print("---------------------------------------------------------------------")
# print(stats_current)


Loading