chihuahua icon indicating copy to clipboard operation
chihuahua copied to clipboard

Failed to export block

Open albttx opened this issue 1 year ago • 2 comments

On export, we have issue

~ # chihuahuad export --height 10611500 --output-document ~/.chihuahuad/chihuahua_10611500.json
9:12PM INF NOTICE: this could take a long time to migrate IAVL store to fastnode if you enable Fast Node.
 module=server
panic: module ibchooks does not exist

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/types/module.(*Manager).ExportGenesisForModules(_, {{0x3e36098, 0xc00019a000}, {0x3e4a800, 0xc0472b09c0}, {{0x0, 0x0}, {0x0, 0x0}, 0xa1eb2c, ...}, ...}, ...)
        github.com/cosmos/[email protected]/types/module/module.go:393 +0x4c5
github.com/cosmos/cosmos-sdk/types/module.(*Manager).ExportGenesis(...)
        github.com/cosmos/[email protected]/types/module/module.go:382
github.com/ChihuahuaChain/chihuahua/app.(*App).ExportAppStateAndValidators(0xc000d7d100, 0x0, {0x5674e20, 0x0, 0x0}, {0xc001aaf560?, 0x1?, 0x1?})
        github.com/ChihuahuaChain/chihuahua/app/export.go:32 +0x218
github.com/ChihuahuaChain/chihuahua/cmd/chihuahuad/cmd.appExport({0x3e37528, 0xc0016ae0b0}, {0x3e4aec8, 0xc000196020}, {0x0, 0x0}, 0xa1eb2c, 0xf0?, {0x5674e20, 0x0, ...}, ...)
        github.com/ChihuahuaChain/chihuahua/cmd/chihuahuad/cmd/root.go:318 +0x2d4
github.com/cosmos/cosmos-sdk/server.ExportCmd.func1(0xc0014c4c00, {0xc001634280?, 0x0?, 0x4?})
        github.com/cosmos/[email protected]/server/export.go:73 +0x435
github.com/spf13/cobra.(*Command).execute(0xc0014c4c00, {0xc001634240, 0x4, 0x4})
        github.com/spf13/[email protected]/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc00149f500)
        github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        github.com/spf13/[email protected]/command.go:985
github.com/cosmos/cosmos-sdk/server/cmd.Execute(0x22d80a0?, {0x0, 0x0}, {0xc00119e300, 0x11})
        github.com/cosmos/[email protected]/server/cmd/execute.go:32 +0x179
main.main()
        github.com/ChihuahuaChain/chihuahua/cmd/chihuahuad/main.go:15 +0x30

albttx avatar Dec 19 '23 21:12 albttx

Same here. Any news on how to fix or work around it? Without the export it is hard to create Airdrops for stakers.

havaCreator avatar Feb 07 '24 09:02 havaCreator

@havaCreator in the mean time, i used a python script to export the voters

#!/usr/bin/env python3

import json
import requests

RPC_URL="http://localhost:1317"
BLOCK_HEIGHT = "10611900"

def merge_and_sum(dict1, dict2):
    # Create a new dictionary that contains all keys from both dictionaries
    merged_dict = {}

    # Add all keys and values from the first dictionary
    for key, value in dict1.items():
        merged_dict[key] = float(value)

    # Add values from the second dictionary, summing where keys overlap
    for key, value in dict2.items():
        if key in merged_dict:
            merged_dict[key] += float(value)
            print(merged_dict[key])
        else:
            merged_dict[key] = float(value)

    return merged_dict

def get_validators(url):
    endpoint = f"{url}/cosmos/staking/v1beta1/validators"
    response = requests.get(endpoint, params={
        "pagination.limit": 500
    })

    if response.status_code != 200:
        raise Exception(f"Error querying validators: {response.text}")

    data = response.json()
    validators = data.get("validators", [])

    return validators


def get_delegators(url, validator_address, height):
    delegators = {}
    next_key = None

    while True:
        endpoint = f"{url}/cosmos/staking/v1beta1/validators/{validator_address}/delegations"
        params = {
            "height": height,
            "pagination.limit": 1000
        }
        if next_key:
            params["pagination.key"] = next_key
        response = requests.get(endpoint, params=params)

        if response.status_code != 200:
            raise Exception(f"Error querying delegations: {response.text}")

        data = response.json()
        delegations = data.get("delegation_responses", [])
        for delegation in delegations:
            addr = delegation["delegation"]["delegator_address"]
            amount = delegation["delegation"]["shares"]
            delegators[addr] = amount

        pagination = data.get("pagination", {})
        next_key = pagination.get("next_key")

        if not next_key:
            break

    return delegators

# Example usage
try:
    validators = get_validators(RPC_URL)
    delegators = {}
    i = 0
    for validator in validators:
        if validator["status"] != "BOND_STATUS_BONDED":
            continue
        # print(validator["description"]["moniker"], validator["operator_address"])

        val_delegators = get_delegators(RPC_URL, validator["operator_address"], BLOCK_HEIGHT)

        delegators = merge_and_sum(delegators, val_delegators)
        print(delegators)

        json_data = json.dumps(delegators)
        # if i == 1:
        #     break
        i += 1

    json_data = json.dumps(delegators)
    with open(f'data_{BLOCK_HEIGHT}.json', 'w') as file:
        file.write(json_data)
    print("done")

except Exception as e:
    print(str(e))

albttx avatar Feb 07 '24 11:02 albttx