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: Add consensus address to validator query response #20434

Merged
merged 35 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2463cec
Add consensus address to validator query response
lucaslopezf May 21, 2024
625865e
proto files
lucaslopezf May 21, 2024
c09ed0a
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf May 21, 2024
1d7cb9a
Changelog and linter
lucaslopezf May 21, 2024
424b463
Add address codec to validator
lucaslopezf May 23, 2024
de54dad
linting issues
lucaslopezf May 24, 2024
2a6c01f
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf May 24, 2024
3f9ecd0
minor change
lucaslopezf May 24, 2024
b17271c
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf May 24, 2024
edcce4d
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf May 27, 2024
428a4b5
Add validators migration
lucaslopezf May 30, 2024
00fd6d0
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf May 30, 2024
7cf677d
minor fix
lucaslopezf May 30, 2024
8c727b7
Add consensus address to query and delete it from Validator
lucaslopezf Jun 12, 2024
6a8d0ff
fix go mod
lucaslopezf Jun 12, 2024
cd433e7
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 12, 2024
da97cd2
tests
lucaslopezf Jun 12, 2024
0cdaa92
linting issues
lucaslopezf Jun 12, 2024
3fcbe1e
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 12, 2024
f279a5d
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 12, 2024
157dbd6
Update x/staking/keeper/grpc_query.go
lucaslopezf Jun 13, 2024
9338222
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 13, 2024
af8202f
minor changes
lucaslopezf Jun 13, 2024
9c0621b
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 13, 2024
c162fbe
add annotations fields
lucaslopezf Jun 13, 2024
677d04d
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 13, 2024
82dd520
Update x/staking/proto/cosmos/staking/v1beta1/query.proto
lucaslopezf Jun 17, 2024
9bb7568
Update x/staking/proto/cosmos/staking/v1beta1/query.proto
lucaslopezf Jun 17, 2024
f97f074
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 17, 2024
3e18086
minor change
lucaslopezf Jun 17, 2024
8c8502a
make validators query backward compatible
lucaslopezf Jun 19, 2024
79b3c98
minor change
lucaslopezf Jun 19, 2024
009d532
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 19, 2024
de98c7e
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 20, 2024
f50bcaa
Merge branch 'main' into lucas/add-cons-address-to-validator
lucaslopezf Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
}

// setup staking validator
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
assert.NilError(t, err)
commission := stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyOneDec(), math.LegacyOneDec())
validator, err = validator.SetInitialCommission(commission)
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"cosmossdk.io/x/gov/types/v1beta1"
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -41,11 +42,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
pks := simtestutil.CreateTestPubKeys(5)

val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{})
val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
assert.NilError(t, err)
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{})
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
assert.NilError(t, err)
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{})
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
assert.NilError(t, err)

assert.NilError(t, f.stakingKeeper.SetValidator(f.ctx, val1))
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/staking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"cosmossdk.io/x/staking"
"cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -196,6 +197,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
sdk.ValAddress(addrs[i]).String(),
PKs[i],
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""),
addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
)
assert.NilError(t, err)
validators[i].Status = types.Bonded
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
delegatorAddr := addrs[1]

// setup a new validator with bonded status
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", ""))
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", ""), address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator.Status = types.Bonded
assert.NilError(t, err)
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"cosmossdk.io/x/staking/testutil"
"cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,7 +21,7 @@ import (

func newMonikerValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
tb.Helper()
v, err := types.NewValidator(operator.String(), pubKey, types.Description{Moniker: moniker})
v, err := types.NewValidator(operator.String(), pubKey, types.Description{Moniker: moniker}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
assert.NilError(tb, err)
return v
}
Expand Down
3 changes: 1 addition & 2 deletions tests/sims/distribution/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ func (suite *SimTestSuite) getTestingValidator(accounts []simtypes.Account, comm
account := accounts[n]
valPubKey := account.PubKey
valAddr := sdk.ValAddress(account.PubKey.Address().Bytes())
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.
Description{})
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{}, address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
require.NoError(err)
validator, err = validator.SetInitialCommission(commission)
require.NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion tests/sims/slashing/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -207,7 +208,7 @@ func getTestingValidator(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, a
account := accounts[n]
valPubKey := account.ConsKey.PubKey()
valAddr := sdk.ValAddress(account.PubKey.Address().Bytes())
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
if err != nil {
return stakingtypes.Validator{}, fmt.Errorf("failed to create validator: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
valAddr2 := sdk.ValAddress(valConsAddr2)
valAddr2Str, err := cdcOpts.GetValidatorCodec().BytesToString(valAddr2)
require.NoError(t, err)
val2, err := stakingtypes.NewValidator(valAddr2Str, valConsPk1, stakingtypes.Description{})
val2, err := stakingtypes.NewValidator(valAddr2Str, valConsPk1, stakingtypes.Description{}, address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
require.NoError(t, err)
val2.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDec(0))
stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk2)).Return(val2, nil).AnyTimes()
Expand Down
3 changes: 2 additions & 1 deletion x/distribution/testutil/staking_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"cosmossdk.io/x/distribution/keeper"
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func CreateValidator(pk cryptotypes.PubKey, operator string, stake math.Int) (stakingtypes.Validator, error) {
val, err := stakingtypes.NewValidator(operator, pk, stakingtypes.Description{Moniker: "TestValidator"})
val, err := stakingtypes.NewValidator(operator, pk, stakingtypes.Description{Moniker: "TestValidator"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
Fixed Show fixed Hide fixed
val.Tokens = stake
val.DelegatorShares = math.LegacyNewDecFromInt(val.Tokens)
return val, err
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -27,7 +28,7 @@ func (s *KeeperTestSuite) TestAfterValidatorCreatedOrRemoved() {

addStr, err := s.stakingKeeper.ValidatorAddressCodec().BytesToString(addr)
require.NoError(err)
validator, err := stakingtypes.NewValidator(addStr, pubKey, stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(addStr, pubKey, stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
require.NoError(err)

s.stakingKeeper.EXPECT().Validator(ctx, valAddr).Return(validator, nil)
Expand Down
10 changes: 5 additions & 5 deletions x/slashing/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *KeeperTestSuite) TestUnjail() {
valStr, err := s.stakingKeeper.ValidatorAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
s.Require().NoError(err)

s.stakingKeeper.EXPECT().Validator(s.ctx, valAddr).Return(val, nil)
Expand Down Expand Up @@ -214,7 +214,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = false
Expand Down Expand Up @@ -249,7 +249,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = true
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *KeeperTestSuite) TestUnjail() {
addrStr, err := ac.BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = true
Expand Down Expand Up @@ -319,7 +319,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)

Expand Down
Loading
Loading