# Polygon Validator Participation Analyzer

The script checks the involvement of specific validator addresses on the Polygon network, identifying the blocks in which these addresses did not sign and keeping track of how many times each address acted as the proposer. The results are saved in a file named "results.txt."

```bash
import requests

def extract_validator_addresses(block, address):
    url = f"https://heimdall-api.polygon.technology/blocks/{block}"

    
    response = requests.get(url)

   
    if response.status_code == 200:
        
        data = response.json()

        
        if 'last_commit' in data['block']:
            
            proposer_address = data['block']['header'].get('proposer_address')
            precommits = data['block']['last_commit'].get('precommits', [])

            
            validator_addresses = [commit.get('validator_address') for commit in precommits if commit]

    
            if address in validator_addresses or address == proposer_address:
                return address, True, proposer_address
            else:
                return address, False, proposer_address
        else:
            print(f"No commit data in Block {block}.")
            return address, False, None
    else:
        
        print(f"Failed request for Block {block}. Response code: {response.status_code}")
        return address, False, None

initial_block = 16378652
final_block = 16379652

with open("addresses.txt", "r") as file:
    addresses_file = [line.strip() for line in file]


addresses_not_signing = []
addresses_proposer_count = {}

for block in range(initial_block, final_block + 1):
    for address in addresses_file:
        _, signed, proposer_address = extract_validator_addresses(block, address)
        if not signed:
            addresses_not_signing.append({"address": address, "block": block, "proposer_address": proposer_address})
          
            if proposer_address in addresses_proposer_count:
                addresses_proposer_count[proposer_address] += 1
            else:
                addresses_proposer_count[proposer_address] = 1


addresses_not_signing = sorted(addresses_not_signing, key=lambda x: x['block'])


with open("results.txt", "w") as result_file:
    result_file.write("Addresses not signing blocks, sorted by block:\n")
    for item in addresses_not_signing:
        result_file.write(f"Address: {item['address']}, Block: {item['block']}, Proposer Address: {item['proposer_address'] if item['proposer_address'] is not None else 'None'}\n")

    result_file.write("\nTotal times each address proposed:\n")
    for address, count in addresses_proposer_count.items():
        result_file.write(f"Address: {address}, Total Proposals: {count}\n")

print("Results saved in results.txt")
```

\
addresses.txt

Python and Requests Installation:

Make sure you have Python installed on your system. Open the terminal or command prompt. Execute the following command to install the `requests` library:

```bash
pip install requests
```

Script Execution:

Save the Python script (`Your_script.py`) in the directory of your choice. Place a file named "addresses.txt" in the same directory as the script, containing the addresses of the validators.

Run the Script:

In the terminal or command prompt, navigate to the directory where the script is located. Execute the script using the following command:

```bash
python3 your_script.py
```

Results:

The script will process the blocks and generate a file named "results.txt" in the same directory as the script. Ensure that the "addresses.txt" file is present in the same directory as the script to ensure proper script functionality.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stakepool.dev.br/polygon/scripts/polygon-validator-participation-analyzer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
