CosmWasm / cosmwasm

Framework for building smart contracts in Wasm for the Cosmos SDK
https://www.cosmwasm.com/
Apache License 2.0
1.05k stars 328 forks source link

Module for StakingQuery AllDelegations from a validator perspectives #681

Closed 0xantman closed 2 days ago

0xantman commented 3 years ago

I would like to know if there is a module to query all delegators address delegating to a validator, i can't find it. Currently there is a module to query AllDelegations from a delegator this allow you to check your current delegations.

pub enum StakingQuery {
    BondedDenom {},
    AllDelegations {
        delegator: HumanAddr,
    },
    Delegation {
        delegator: HumanAddr,
        validator: HumanAddr,
    },
    Validators {},
}

But is there an equivalent for the validator to check who is delegating to your validator? like this

pub enum StakingQuery {
    BondedDenom {},
    AllDelegationsFromDelegator {
        delegator: HumanAddr,
    },
    // Adding this one to query from a validator perspectives
    AllDelegationsFromValidator{
        validator: HumanAddr,
    },
    Delegation {
        delegator: HumanAddr,
        validator: HumanAddr,
    },
    Validators {},
}
ethanfrey commented 3 years ago

Thanks for the suggestion. My first impression was it would be an easy add. But after seeing the discord questions, I realized you want to model the staking controls from a validators perspective, so a contract could operate a validator (set commission, etc).

That would require quite a few more endpoints both for messages (set commission, register validator,...) and queries. And frankly I am a bit unsure if it makes sense for a contract to run a validator, because you really need a human (or three) to run the machines anyway, no contract can abstract that away.

I do see a use case to use eg. a multisig contract to control a validator, as it provides an easy way to require multiple signers on chain, and just redispatches the messages. But that would require it to redispatch the custom validator-related staking messages as well...

I think to add some more stargate-related functionality in the 0.14 cosmwasm release and maybe we add this in there. It would be helpful to see a complete use case and motivation to ensure we support this case, and there is a real need we are supporting (not just adding features to add features)

ethanfrey commented 1 year ago

I think we should define this better and in conjunction with https://github.com/CosmWasm/cosmwasm/issues/1154 to better define what exact queries we want to support (and remember to be flexible for eg substrate integration / cw-sdk and not only cosmos sdk)

dimiandre commented 1 year ago

I think we should define this better and in conjunction with #1154 to better define what exact queries we want to support (and remember to be flexible for eg substrate integration / cw-sdk and not only cosmos sdk)

It would be nice to have, I'm also working on a contract that needs this query on Juno

webmaster128 commented 1 year ago

The all delegations for a given validator query is currently not implemented efficiently in Cosmos SDK. And even if it was fast at DB level, do we really want to have a query that returns tens, maybe hundreds of thousands of JSON elements for deseralization in Wasm?

What's your use case @dimiandre? Maybe there are other ways to achieve the goal.

webmaster128 commented 1 year ago

@dimiandre could you please check out https://github.com/CosmWasm/cosmwasm/issues/1521 and let us know which queries are of major importance for you?

chipshort commented 2 days ago

Closing for now, since this is very inefficient in the SDK, is hard to implement correctly and the use-case is not really clear.