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(x/gov): add governors #73

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Conversation

giunatale
Copy link
Collaborator

@giunatale giunatale commented Jan 14, 2025

iterating over the work started in #16, this PR adds governors to the x/gov module.

More details can be also read in #16

Only sketching out how the tally would work for now.
Lots of stuff is left undefined but the strategy is the one outlined in https://gist.github.com/giunatale/95e9b43f6e265ba32b29e2769f7b8a37?permalink_comment_id=5067400#gistcomment-5067400 but with the restriction of being able to delegate a percentage of its bonded tokens to at most one governor (https://gist.github.com/giunatale/95e9b43f6e265ba32b29e2769f7b8a37?permalink_comment_id=5187246#gistcomment-5187246)

It assumes that every time someone redelegates, undelegates or adds to its delegations a hook is called to check if there is a governor delegated to in x/gov, and the governor's total shares updated accordingly.
The governor's total shares are a collection of share amounts for different validators.
can only delegate all or nothing to governors now
@giunatale
Copy link
Collaborator Author

since this work was left untouched for a while, we need to give it a final pass to identify potentially missing tests and check test coverage, and add documentation. Ideally we would also want to do some more in depth profiling/benchmarking to assess the performance impact of this addition.

Comment on lines +248 to +254
for _, govInfo := range allGovernors {
governor, _ := k.GetGovernor(ctx, govInfo.Address)

if k.ValidateGovernorMinSelfDelegation(ctx, governor) && len(govInfo.Vote) > 0 {
governorsInfos = append(governorsInfos, govInfo)
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +261 to +266
for valAddrStr, shares := range governor.ValShares {
if val, ok := currValidators[valAddrStr]; ok {
sharesAfterDeductions := shares.Sub(governor.ValSharesDeductions[valAddrStr])
votingPower = votingPower.Add(sharesAfterDeductions.MulInt(val.GetBondedTokens()).Quo(val.GetDelegatorShares()))
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

// GovernanceDelegation queries a delegation
rpc GovernanceDelegation(QueryGovernanceDelegationRequest) returns (QueryGovernanceDelegationResponse) {
option (google.api.http).get = "/atomone/gov/v1/delegations/{delegator_address}";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see singular delegation here, as it will always return a single.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for consistency, the plural is used in other places too (e.g. proposals)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable, then the first one /atomone/gov/v1/governor/{governor_address} should be /atomone/gov/v1/governors/{governor_address} ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also e.g. validator info for a single validator in x/staking is "validators/{validator-address}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable, then the first one /atomone/gov/v1/governor/{governor_address} should be /atomone/gov/v1/governors/{governor_address} ?

yes

tbruyelle and others added 6 commits January 16, 2025 09:57
* add governors adr

* Update docs/architecture/adr-004-governors.md

Co-authored-by: Thomas Bruyelle <[email protected]>

---------

Co-authored-by: Thomas Bruyelle <[email protected]>
* add governors documentation

* add txs in CLI section
The gov module InitGenesis must happen after staking because governors
requires to access the validator delegations.
* perf(x/gov): remove useless bech32 conversion

Accessing `delegation.ValidatorAddress` is similar to calling
`delegation.GetValidatorAddress().String()` but w/o useless conversions.

* perf(x/gov): remove useless address conversion

* perf(x/gov): remove useless bech32 conversion

* perf(x/gov): remove unused active field from GovernorGovInfo

* perf(x/gov): assume vote weight is 1 most of the time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants