feat: staking config (#10988)
## Description staking config to remove DefaultPowerReduction global. I want to see if this would be accepted as its easier to document and show users how to do this. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
@@ -17,16 +17,3 @@ const (
|
||||
// https://tendermint.com/docs/spec/abci/apps.html#endblock
|
||||
ValidatorUpdateDelay int64 = 1
|
||||
)
|
||||
|
||||
// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power
|
||||
var DefaultPowerReduction = NewIntFromUint64(1000000)
|
||||
|
||||
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
|
||||
func TokensToConsensusPower(tokens Int, powerReduction Int) int64 {
|
||||
return (tokens.Quo(powerReduction)).Int64()
|
||||
}
|
||||
|
||||
// TokensFromConsensusPower - convert input power to tokens
|
||||
func TokensFromConsensusPower(power int64, powerReduction Int) Int {
|
||||
return NewInt(power).Mul(powerReduction)
|
||||
}
|
||||
@@ -335,7 +335,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData
|
||||
|
||||
// a chain must initialize with a non-empty validator set
|
||||
if len(validatorUpdates) == 0 {
|
||||
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction))
|
||||
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction, found in x/staking/types/config.go"))
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
type stakingTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestStakingTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(stakingTestSuite))
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) SetupSuite() {
|
||||
s.T().Parallel()
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) TestTokensToConsensusPower() {
|
||||
s.Require().Equal(int64(0), sdk.TokensToConsensusPower(sdk.NewInt(999_999), sdk.DefaultPowerReduction))
|
||||
s.Require().Equal(int64(1), sdk.TokensToConsensusPower(sdk.NewInt(1_000_000), sdk.DefaultPowerReduction))
|
||||
}
|
||||
Reference in New Issue
Block a user