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/staking)!: Add metadata field to validator info #21315

Merged
merged 47 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
455084d
feat(staking/validator): add metadata field to validator detail proto
ziscky Aug 15, 2024
79f694e
feat(staking/validator): protogen
ziscky Aug 15, 2024
65c95fb
feat(staking/validator): update NewDescription to update metadata
ziscky Aug 15, 2024
1a4717d
feat(staking/validator): use the new Description.IsEmpty()
ziscky Aug 15, 2024
3282d5e
feat(staking/validator): update cli to parse metadata
ziscky Aug 15, 2024
83f6327
test(staking/validator): update tests
ziscky Aug 15, 2024
1d4d236
feat(staking/validator): add metadata to create validator sim
ziscky Aug 15, 2024
fbb892f
feat(staking/validator): protogen
ziscky Aug 15, 2024
809a84d
feat(staking/validator): update metadata type to struct
ziscky Aug 22, 2024
6b3de76
feat(staking/validator): update metadata type to struct
ziscky Aug 22, 2024
14eaff9
feat(staking/validator): refactor metadata type
ziscky Aug 22, 2024
a81a3d2
feat(staking/validator): update metadata to object
ziscky Aug 22, 2024
33ca14a
feat(staking/validator): refactor metadata type
ziscky Aug 22, 2024
ca43238
feat(staking/validator): add fn to generate rand uris
ziscky Aug 27, 2024
4337306
feat(staking/validator): update sims
ziscky Aug 27, 2024
e927d50
test(staking/validator): update integration tests
ziscky Aug 27, 2024
fcc82a0
feat(staking/validator): merge main
ziscky Aug 27, 2024
839d578
fix(staking/validator): update metadata flags to accept each metadata…
ziscky Aug 28, 2024
2ebe2a9
test(staking/validator): update tests
ziscky Aug 28, 2024
97b5613
test(staking/validator): update expected gas
ziscky Aug 28, 2024
4d442ed
test(staking/validator): use md generator
ziscky Aug 28, 2024
ba8bc39
feat(staking/validator): update cli arg for profile pic
ziscky Aug 28, 2024
5493969
chore(staking/validator): changelog
ziscky Aug 28, 2024
e403ee3
fix(staking/validator): formatting
ziscky Aug 28, 2024
0befe0c
feat(staking/validator): merge main
ziscky Aug 28, 2024
3df3149
feat(staking/validator): move RandUriOfLength to staking module
ziscky Aug 28, 2024
97e84a9
fix(staking/validator): check DoNotModifyDesc for profile pic uri
ziscky Aug 28, 2024
107cd23
fix(staking/validator): move RandUriOfLength to staking module
ziscky Aug 28, 2024
2478f44
chore(staking/validator): update changelog
ziscky Aug 28, 2024
f77f60b
Merge branch 'main' into ziscky/9988-staking-validator-metadata
ziscky Aug 29, 2024
5e5c817
fix(staking/validator): make rand uri fn more concise
ziscky Aug 30, 2024
4317ac2
test(staking/validator): add test for rand uri fn
ziscky Aug 30, 2024
85d42b0
feat(staking/validator): add social handles field
ziscky Aug 30, 2024
c817001
feat(staking/validator): add IsEmpty() method to Description
ziscky Aug 30, 2024
b742425
feat(staking/validator): add social handles parsing to cli
ziscky Aug 30, 2024
c522e24
test(staking/validator): update sims and tests to include social handles
ziscky Aug 30, 2024
75c9b57
chore(staking/validator): changelog
ziscky Sep 5, 2024
0d3db0a
feat(staking/validator): merge main
ziscky Sep 5, 2024
1ac2085
chore(staking/validator): changelog
ziscky Sep 13, 2024
e651b3c
chore(staking/validator): merge main
ziscky Sep 13, 2024
4631ad1
chore(staking/validator): lint fix
ziscky Sep 21, 2024
a5fc0fe
chore(staking/validator): merge main
ziscky Sep 21, 2024
05bea00
chore(staking/validator): lint fix
ziscky Sep 21, 2024
c894be1
feat(staking/validator): add fn to generate random SocialHandleURIs
ziscky Sep 21, 2024
1862040
feat(staking/validator): add fn to generate random SocialHandleURIs
ziscky Sep 21, 2024
25986ca
chore(staking/validator): lint fix
ziscky Sep 21, 2024
8ac40a0
chore(staking/validator): lint fix
ziscky Sep 21, 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
1,559 changes: 1,063 additions & 496 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func initTestnetFiles(
valStr,
valPubKeys[i],
sdk.NewCoin(args.bondTokenDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewDescription(nodeDirName, "", "", "", "", stakingtypes.Metadata{}),
ziscky marked this conversation as resolved.
Show resolved Hide resolved
stakingtypes.NewCommissionRates(math.LegacyOneDec(), math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
)
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,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/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
1 change: 1 addition & 0 deletions x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
FlagWebsite = "website"
FlagSecurityContact = "security-contact"
FlagDetails = "details"
FlagMetadata = "metadata"

FlagCommissionRate = "commission-rate"
FlagCommissionMaxRate = "commission-max-rate"
Expand Down
28 changes: 27 additions & 1 deletion x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"encoding/json"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -72,6 +73,7 @@ Where validator.json contains:
"website": "validator's (optional) website",
"security": "validator's (optional) security contact email",
"details": "validator's (optional) details",
"metadata": {"profile-pic": "link to profile picture"},
"commission-rate": "0.1",
"commission-max-rate": "0.2",
"commission-max-change-rate": "0.01",
Expand Down Expand Up @@ -129,7 +131,16 @@ func NewEditValidatorCmd() *cobra.Command {
website, _ := cmd.Flags().GetString(FlagWebsite)
security, _ := cmd.Flags().GetString(FlagSecurityContact)
details, _ := cmd.Flags().GetString(FlagDetails)
description := types.NewDescription(moniker, identity, website, security, details)
metadataString, _ := cmd.Flags().GetString(FlagMetadata)

var metadata types.Metadata
if metadataString != "" {
if err := json.Unmarshal([]byte(metadataString), &metadata); err != nil {
return err
}
}

description := types.NewDescription(moniker, identity, website, security, details, metadata)

var newRate *math.LegacyDec

Expand Down Expand Up @@ -183,6 +194,7 @@ func newBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *fl
val.Website,
val.Security,
val.Details,
val.Metadata,
)

valStr, err := valAc.BytesToString(sdk.ValAddress(valAddr))
Expand Down Expand Up @@ -263,6 +275,7 @@ type TxCreateValidatorConfig struct {
SecurityContact string
Details string
Identity string
Metadata types.Metadata
}

func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey cryptotypes.PubKey) (TxCreateValidatorConfig, error) {
Expand Down Expand Up @@ -302,6 +315,17 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c
return c, err
}

metadataString, err := flagSet.GetString(FlagMetadata)
if err != nil {
return c, err
}
var metadata types.Metadata
if metadataString != "" {
if err := json.Unmarshal([]byte(metadataString), &metadata); err != nil {
return c, err
}
}

c.Amount, err = flagSet.GetString(FlagAmount)
if err != nil {
return c, err
Expand Down Expand Up @@ -338,6 +362,7 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c
c.SecurityContact = securityContact
c.Details = details
c.Identity = identity
c.Metadata = metadata
c.ChainID = chainID
c.Moniker = moniker

Expand Down Expand Up @@ -379,6 +404,7 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC
config.Website,
config.SecurityContact,
config.Details,
config.Metadata,
)

// get the initial validator commission parameters
Expand Down
3 changes: 3 additions & 0 deletions x/staking/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type validator struct {
Website string
Security string
Details string
Metadata types.Metadata
CommissionRates types.CommissionRates
MinSelfDelegation math.Int
}
Expand All @@ -37,6 +38,7 @@ func parseAndValidateValidatorJSON(cdc codec.Codec, path string) (validator, err
Website string `json:"website,omitempty"`
Security string `json:"security,omitempty"`
Details string `json:"details,omitempty"`
Metadata types.Metadata `json:"metadata,omitempty"`
CommissionRate string `json:"commission-rate"`
CommissionMaxRate string `json:"commission-max-rate"`
CommissionMaxChange string `json:"commission-max-change-rate"`
Expand Down Expand Up @@ -95,6 +97,7 @@ func parseAndValidateValidatorJSON(cdc codec.Codec, path string) (validator, err
Website: v.Website,
Security: v.Security,
Details: v.Details,
Metadata: v.Metadata,
CommissionRates: commissionRates,
MinSelfDelegation: minSelfDelegation,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali
)
}

if _, err := msg.Description.EnsureLength(); err != nil {
if _, err := msg.Description.Validate(); err != nil {
return nil, err
}

Expand Down
19 changes: 17 additions & 2 deletions x/staking/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ deps:
repository: cosmos-proto
commit: 04467658e59e44bbb22fe568206e1f70
digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 05419252bcc241ea8023acf1ed4cadc5
digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5
- remote: buf.build
owner: cosmos
repository: gogo-proto
Expand All @@ -19,5 +24,15 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
commit: 8bc2c51e08c447cd8886cdea48a73e14
digest: shake256:a969155953a5cedc5b2df5b42c368f2bc66ff8ce1804bc96e0f14ff2ee8a893687963058909df844d1643cdbc98ff099d2daa6bc9f9f5b8886c49afdc60e19af
- remote: buf.build
owner: protocolbuffers
repository: wellknowntypes
commit: 657250e6a39648cbb169d079a60bd9ba
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
- remote: buf.build
owner: tendermint
repository: tendermint
commit: 33ed361a90514289beabf3189e1d7665
digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d
27 changes: 19 additions & 8 deletions x/staking/proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
syntax = "proto3";
package cosmos.staking.v1beta1;

import "amino/amino.proto";
import "cometbft/abci/v1/types.proto";
import "cometbft/types/v1/types.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "amino/amino.proto";
import "cometbft/types/v1/types.proto";
import "cometbft/abci/v1/types.proto";

option go_package = "cosmossdk.io/x/staking/types";

// HistoricalInfo contains header and validator information for a given block.
Expand Down Expand Up @@ -79,6 +78,16 @@ message Description {
string security_contact = 4;
// details define other optional details.
string details = 5;
// metadata defines extra information about the validator.
Metadata metadata = 6 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// Metadata defines extra information about the validator.
message Metadata {
option (gogoproto.equal) = true;

// profile_pic_uri defines a link to the validator profile picture.
string profile_pic_uri = 1;
ziscky marked this conversation as resolved.
Show resolved Hide resolved
}

// Validator defines a validator, together with the total amount of the
Expand Down Expand Up @@ -221,7 +230,8 @@ message UnbondingDelegation {
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
// entries are the unbonding delegation entries.
repeated UnbondingDelegationEntry entries = 3
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; // unbonding delegation entries
[(gogoproto.nullable) = false,
(amino.dont_omitempty) = true]; // unbonding delegation entries
}

// UnbondingDelegationEntry defines an unbonding object with relevant metadata.
Expand Down Expand Up @@ -294,7 +304,8 @@ message Redelegation {
string validator_dst_address = 3 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
// entries are the redelegation entries.
repeated RedelegationEntry entries = 4
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; // redelegation entries
[(gogoproto.nullable) = false,
(amino.dont_omitempty) = true]; // redelegation entries
}

// Params defines the parameters for the x/staking module.
Expand Down
6 changes: 6 additions & 0 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func SimulateMsgCreateValidator(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 10),
types.Metadata{
ProfilePicUri: simtypes.RandStringOfLength(r, 10),
},
)

maxCommission := math.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 0, 100)), 2)
Expand Down Expand Up @@ -277,6 +280,9 @@ func SimulateMsgEditValidator(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 10),
types.Metadata{
ProfilePicUri: simtypes.RandStringOfLength(r, 10),
},
)

msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil)
Expand Down
Loading
Loading