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

[cosmos-sdk](x/staking/delegation) limit voting power logic #19

Closed
Tracked by #5
kien6034 opened this issue Nov 2, 2024 · 0 comments
Closed
Tracked by #5

[cosmos-sdk](x/staking/delegation) limit voting power logic #19

kien6034 opened this issue Nov 2, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@kien6034
Copy link

kien6034 commented Nov 2, 2024

x/staking/keeper/delegation.go/

	if ctx.ChainID() == ColumbusChainID {
		// Get the last Total Power of the validator set
		lastPower := k.GetLastTotalPower(ctx)

		// Get the power of the current validator power
		validatorLastPower := sdk.TokensToConsensusPower(validator.Tokens, k.PowerReduction(ctx))

		// Get the new power of the validator if delegated the bond amount
		validatorNewPower := validatorLastPower + sdk.TokensToConsensusPower(bondAmt, k.PowerReduction(ctx))

		// Compute what the Total Consensus Power would be if this Delegation goes through
		newTotalPower := lastPower.Int64() + sdk.TokensToConsensusPower(bondAmt, k.PowerReduction(ctx))

		// Compute what the new Validator voting power would be in relation to the new total power
		// validatorIncreasedDelegationPercent := float32(validatorNewPower) / float32(newTotalPower)
		validatorIncreasedDelegationPercent := sdk.NewDec(validatorNewPower).QuoInt64(newTotalPower)

		// If Delegations are allowed, and the Delegation would have increased the Validator to over 20% of the staking power, do not allow the Delegation to proceed
		if validatorIncreasedDelegationPercent.GT(sdk.NewDecWithPrec(20, 2)) {
			panic("validator power is over the allowed limit")
		}
	}

Solution

We can introduce the AfterDelegationModifed hooks, which check the validator power < 20%

https://github.com/classic-terra/cosmos-sdk/blob/v0.47.10-terra.1/x/staking/keeper/delegation.go#L731-L733

Commit: 372f6f8

@kien6034 kien6034 added the enhancement New feature or request label Nov 2, 2024
@kien6034 kien6034 self-assigned this Nov 2, 2024
@kien6034 kien6034 changed the title [staking] move validator power limit logic to terrad [cosmos-sdk] x/staking/delegation limit voting power logic Nov 2, 2024
@kien6034 kien6034 changed the title [cosmos-sdk] x/staking/delegation limit voting power logic [cosmos-sdk](x/staking/delegation) limit voting power logic Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants