Skip to content

Commit

Permalink
feat(x/staking)!: Add metadata field to validator info (#21315)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziscky authored Oct 1, 2024
1 parent 8763d8d commit 814d4cf
Show file tree
Hide file tree
Showing 28 changed files with 2,777 additions and 1,492 deletions.
1,715 changes: 1,209 additions & 506 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions server/v2/api/grpc/gogoreflection/fix_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc {
for id, desc := range proto.RegisteredExtensions(m) { //nolint:staticcheck // keep for backward compatibility
if id == extID {
return &gogoproto.ExtensionDesc{
ExtendedType: desc.ExtendedType,
ExtensionType: desc.ExtensionType,
Field: desc.Field,
Name: desc.Name,
Tag: desc.Tag,
Filename: desc.Filename,
ExtendedType: desc.ExtendedType,
ExtensionType: desc.ExtensionType,
Field: desc.Field,
Name: desc.Name,
Tag: desc.Tag,
Filename: desc.Filename,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func initTestnetFiles(
valStr,
valPubKeys[i],
sdk.NewCoin(args.bondTokenDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewDescription(nodeDirName, "", "", "", "", stakingtypes.Metadata{}),
stakingtypes.NewCommissionRates(math.LegacyOneDec(), math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
)
Expand Down
2 changes: 1 addition & 1 deletion simapp/v2/simdv2/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func initTestnetFiles[T transaction.Tx](
valStr,
valPubKeys[i],
sdk.NewCoin(args.bondTokenDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewDescription(nodeDirName, "", "", "", "", stakingtypes.Metadata{}),
stakingtypes.NewCommissionRates(math.LegacyOneDec(), math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
var (
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
TestProposal = v1beta1.NewTextProposal("Test", "description")
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z", stakingtypes.Metadata{})
TestCommissionRates = stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slashing/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestSlashingMsgs(t *testing.T) {

require.NoError(t, err)

description := stakingtypes.NewDescription("foo_moniker", "", "", "", "")
description := stakingtypes.NewDescription("foo_moniker", "", "", "", "", stakingtypes.Metadata{})
commission := stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())

addrStrVal, err := valaddrCodec.BytesToString(addr1)
Expand Down
41 changes: 33 additions & 8 deletions tests/integration/staking/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package keeper_test

import (
"context"
"fmt"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -214,6 +216,26 @@ func bondTypeGenerator() *rapid.Generator[stakingtypes.BondStatus] {
})
}

func metadataGenerator() *rapid.Generator[stakingtypes.Metadata] {
return rapid.Custom(func(t *rapid.T) stakingtypes.Metadata {
return stakingtypes.Metadata{
ProfilePicUri: generateUri(t),
SocialHandleUris: []string{generateUri(t), generateUri(t)},
}
})
}

func generateUri(t *rapid.T) string {
host := fmt.Sprintf("%s.com", rapid.StringN(5, 250, 255).Draw(t, "host"))
path := rapid.StringN(5, 250, 255).Draw(t, "path")
uri := url.URL{
Scheme: "https",
Host: host,
Path: path,
}
return uri.String()
}

// createValidator creates a validator with random values.
func createValidator(t *testing.T, rt *rapid.T, _ *deterministicFixture) stakingtypes.Validator {
t.Helper()
Expand All @@ -233,6 +255,7 @@ func createValidator(t *testing.T, rt *rapid.T, _ *deterministicFixture) staking
rapid.StringN(5, 250, 255).Draw(rt, "website"),
rapid.StringN(5, 250, 255).Draw(rt, "securityContact"),
rapid.StringN(5, 250, 255).Draw(rt, "details"),
metadataGenerator().Draw(rt, "metadata"),
),
UnbondingHeight: rapid.Int64Min(1).Draw(rt, "unbonding-height"),
UnbondingTime: time.Now().Add(durationGenerator().Draw(rt, "duration")),
Expand Down Expand Up @@ -308,6 +331,7 @@ func getStaticValidator(t *testing.T, f *deterministicFixture) stakingtypes.Vali
"website",
"securityContact",
"details",
stakingtypes.Metadata{},
),
UnbondingHeight: 10,
UnbondingTime: time.Date(2022, 10, 1, 0, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -343,6 +367,7 @@ func getStaticValidator2(t *testing.T, f *deterministicFixture) stakingtypes.Val
"website",
"securityContact",
"details",
stakingtypes.Metadata{},
),
UnbondingHeight: 100132,
UnbondingTime: time.Date(2025, 10, 1, 0, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -408,7 +433,7 @@ func TestGRPCValidator(t *testing.T) {
ValidatorAddr: val.OperatorAddress,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 1915, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 1921, false)
}

func TestGRPCValidators(t *testing.T) {
Expand All @@ -434,7 +459,7 @@ func TestGRPCValidators(t *testing.T) {
getStaticValidator(t, f)
getStaticValidator2(t, f)

testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false)
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2880, false)
}

func TestGRPCValidatorDelegations(t *testing.T) {
Expand Down Expand Up @@ -479,7 +504,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
ValidatorAddr: validator.OperatorAddress,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14610, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14628, false)
}

func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
Expand Down Expand Up @@ -569,7 +594,7 @@ func TestGRPCDelegation(t *testing.T) {
DelegatorAddr: delegator1,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4680, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4686, false)
}

func TestGRPCUnbondingDelegation(t *testing.T) {
Expand Down Expand Up @@ -652,7 +677,7 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
DelegatorAddr: delegator1,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4283, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4289, false)
}

func TestGRPCDelegatorValidator(t *testing.T) {
Expand Down Expand Up @@ -690,7 +715,7 @@ func TestGRPCDelegatorValidator(t *testing.T) {
ValidatorAddr: validator.OperatorAddress,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 3563, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 3569, false)
}

func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
Expand Down Expand Up @@ -772,7 +797,7 @@ func TestGRPCDelegatorValidators(t *testing.T) {
assert.NilError(t, err)

req := &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator1}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 3166, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 3172, false)
}

func TestGRPCPool(t *testing.T) {
Expand Down Expand Up @@ -856,7 +881,7 @@ func TestGRPCRedelegations(t *testing.T) {
DstValidatorAddr: validator2,
}

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 3920, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 3926, false)
}

func TestGRPCParams(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/staking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestInitGenesis(t *testing.T) {
Status: types.Bonded,
Tokens: valTokens,
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
Description: types.NewDescription("hoop", "", "", "", ""),
Description: types.NewDescription("hoop", "", "", "", "", types.Metadata{}),
}
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, bondedVal))

Expand All @@ -67,15 +67,15 @@ func TestInitGenesis(t *testing.T) {
Status: types.Bonded,
Tokens: valTokens,
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
Description: types.NewDescription("hoop", "", "", "", ""),
Description: types.NewDescription("hoop", "", "", "", "", types.Metadata{}),
}
bondedVal2 := types.Validator{
OperatorAddress: sdk.ValAddress(addrs[2]).String(),
ConsensusPubkey: pk2,
Status: types.Bonded,
Tokens: valTokens,
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
Description: types.NewDescription("bloop", "", "", "", ""),
Description: types.NewDescription("bloop", "", "", "", "", types.Metadata{}),
}

// append new bonded validators to the list
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestInitGenesis_PoolsBalanceMismatch(t *testing.T) {
Jailed: false,
Tokens: math.NewInt(10),
DelegatorShares: math.LegacyNewDecFromInt(math.NewInt(10)),
Description: types.NewDescription("bloop", "", "", "", ""),
Description: types.NewDescription("bloop", "", "", "", "", types.Metadata{}),
}

params := types.Params{
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
validators[i], err = types.NewValidator(
sdk.ValAddress(addrs[i]).String(),
PKs[i],
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""),
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", "", types.Metadata{}),
)
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", "", "", "", "", types.Metadata{}))
validator.Status = types.Bonded
assert.NilError(t, err)
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/tx/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,12 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
"staking/create_validator": {
gogo: &stakingtypes.MsgCreateValidator{Pubkey: pubkeyAny},
pulsar: &stakingapi.MsgCreateValidator{
Pubkey: pubkeyAnyPulsar,
Description: &stakingapi.Description{},
Commission: &stakingapi.CommissionRates{},
Value: &v1beta1.Coin{},
Pubkey: pubkeyAnyPulsar,
Description: &stakingapi.Description{
Metadata: &stakingapi.Metadata{},
},
Commission: &stakingapi.CommissionRates{},
Value: &v1beta1.Coin{},
},
},
"staking/msg_cancel_unbonding_delegation_response": {
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) {
sdk.ValAddress(addr).String(),
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewDescription(nodeDirName, "", "", "", "", stakingtypes.Metadata{}),
stakingtypes.NewCommissionRates(commission, sdkmath.LegacyOneDec(), sdkmath.LegacyOneDec()),
sdkmath.OneInt(),
)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/vesting/types/vesting.pb.go

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

2 changes: 1 addition & 1 deletion x/genutil/gentx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
pk2 = priv2.PubKey()
addr1 = sdk.AccAddress(pk1.Address())
addr2 = sdk.AccAddress(pk2.Address())
desc = stakingtypes.NewDescription("testname", "", "", "", "")
desc = stakingtypes.NewDescription("testname", "", "", "", "", stakingtypes.Metadata{})
comm = stakingtypes.CommissionRates{}
)

Expand Down
4 changes: 2 additions & 2 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestNetGenesisState(t *testing.T) {
}

func TestValidateGenesisMultipleMessages(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "", "")
desc := stakingtypes.NewDescription("testname", "", "", "", "", stakingtypes.Metadata{})
comm := stakingtypes.CommissionRates{}
valAc := codectestutil.CodecOptions{}.GetValidatorCodec()

Expand All @@ -66,7 +66,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
}

func TestValidateGenesisBadMessage(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "", "")
desc := stakingtypes.NewDescription("testname", "", "", "", "", stakingtypes.Metadata{})
pk1Addr, err := codectestutil.CodecOptions{}.GetValidatorCodec().BytesToString(pk1.Address())
require.NoError(t, err)
msg1 := stakingtypes.NewMsgEditValidator(pk1Addr, desc, nil, nil)
Expand Down
11 changes: 9 additions & 2 deletions x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#19537](https://github.com/cosmos/cosmos-sdk/pull/19537) Changing `MinCommissionRate` in `MsgUpdateParams` now updates the minimum commission rate for all validators.
* [#20434](https://github.com/cosmos/cosmos-sdk/pull/20434) Add consensus address to validator query response
* [#21315](https://github.com/cosmos/cosmos-sdk/pull/21315) Create metadata type and add metadata field in validator details proto
* Add parsing of `metadata-profile-pic-uri` in `create-validator` JSON.
* Add cli flag: `metadata-profile-pic-uri` to `edit-validator` cmd.

### Improvements

Expand All @@ -42,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#19277](https://github.com/cosmos/cosmos-sdk/pull/19277) Hooks calls on `SetUnbondingDelegationEntry`, `SetRedelegationEntry`, `Slash` and `RemoveValidator` returns errors instead of logging just like other hooks calls.
* [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `IterateBondedValidatorsByPower`, `GetDelegatorBonded`, `Delegate`, `Unbond`, `Slash`, `Jail`, `SlashRedelegation`, `ApplyAndReturnValidatorSetUpdates` methods no longer panics on any kind of errors but instead returns appropriate errors.
* [#18506](https://github.com/cosmos/cosmos-sdk/pull/18506) Detect the length of the ed25519 pubkey in CreateValidator to prevent panic.
* [#21315](https://github.com/cosmos/cosmos-sdk/pull/21315) Add a `Validate` method to the `Description` type that validates the metadata as well as other description details.


### API Breaking Changes
Expand Down Expand Up @@ -96,8 +100,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#17335](https://github.com/cosmos/cosmos-sdk/pull/17335) Remove usage of `"cosmossdk.io/x/staking/types".Infraction_*` in favour of `"cosmossdk.io/api/cosmos/staking/v1beta1".Infraction_` in order to remove dependency between modules on staking
* [#20295](https://github.com/cosmos/cosmos-sdk/pull/20295) `GetValidatorByConsAddr` now returns the Cosmos SDK `cryptotypes.Pubkey` instead of `cometcrypto.Publickey`. The caller is responsible to translate the returned value to the expected type.
* Remove `CmtConsPublicKey()` and `TmConsPublicKey()` from `Validator` interface and as methods on the `Validator` struct.
* [#21480](https://github.com/cosmos/cosmos-sdk/pull/21480) ConsensusKeeper is required to be passed to the keeper.

* [#21480](https://github.com/cosmos/cosmos-sdk/pull/21480) ConsensusKeeper is required to be passed to the keeper.
* [#21315](https://github.com/cosmos/cosmos-sdk/pull/21315) New struct `Metadata` to store extra validator information.
* New field `Metadata` introduced in `types`: `Description`.
* The signature of `NewDescription` has changed to accept an extra argument of type `Metadata`.

### State Breaking changes

* [#18841](https://github.com/cosmos/cosmos-sdk/pull/18841) In a undelegation or redelegation if the shares being left delegated correspond to less than 1 token (in base denom) the entire delegation gets removed.
Expand Down
16 changes: 10 additions & 6 deletions x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const (
FlagSharesAmount = "shares-amount"
FlagSharesFraction = "shares-fraction"

FlagMoniker = "moniker"
FlagEditMoniker = "new-moniker"
FlagIdentity = "identity"
FlagWebsite = "website"
FlagSecurityContact = "security-contact"
FlagDetails = "details"
FlagMoniker = "moniker"
FlagEditMoniker = "new-moniker"
FlagIdentity = "identity"
FlagWebsite = "website"
FlagSecurityContact = "security-contact"
FlagDetails = "details"
FlagMetadataProfilePicUri = "metadata-profile-pic-uri"
FlagMetadataSocialHandleUris = "metadata-social-handle-uris"

FlagCommissionRate = "commission-rate"
FlagCommissionMaxRate = "commission-max-rate"
Expand Down Expand Up @@ -89,6 +91,8 @@ func flagSetDescriptionEdit() *flag.FlagSet {
fs.String(FlagWebsite, types.DoNotModifyDesc, "The validator's (optional) website")
fs.String(FlagSecurityContact, types.DoNotModifyDesc, "The validator's (optional) security contact email")
fs.String(FlagDetails, types.DoNotModifyDesc, "The validator's (optional) details")
fs.String(FlagMetadataProfilePicUri, "", "The validator's profile pic uri")
fs.StringArray(FlagMetadataSocialHandleUris, []string{}, "The validator's social handles uris")

return fs
}
Expand Down
Loading

0 comments on commit 814d4cf

Please sign in to comment.