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

R4R Add security contact to Validator description #4865

Merged
merged 10 commits into from
Aug 12, 2019
1 change: 1 addition & 0 deletions .pending/improvements/modules/_4814-Add-security-c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4814 Add security contact to Validator description
2 changes: 1 addition & 1 deletion simapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestDecodeStakingStore(t *testing.T) {

bondTime := time.Now().UTC()

val := staking.NewValidator(valAddr1, delPk1, staking.NewDescription("test", "test", "test", "test"))
val := staking.NewValidator(valAddr1, delPk1, staking.NewDescription("test", "test", "test", "test", "test"))
del := staking.NewDelegation(delAddr1, valAddr1, sdk.OneDec())
ubd := staking.NewUnbondingDelegation(delAddr1, valAddr1, 15, bondTime, sdk.OneInt())
red := staking.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, sdk.OneInt(), sdk.OneDec())
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 @@ -18,7 +18,7 @@ var (

func TestValidateGenesisMultipleMessages(t *testing.T) {

desc := stakingtypes.NewDescription("testname", "", "", "")
desc := stakingtypes.NewDescription("testname", "", "", "", "")
comm := stakingtypes.CommissionRates{}

msg1 := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
Expand All @@ -35,7 +35,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
}

func TestValidateGenesisBadMessage(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "")
desc := stakingtypes.NewDescription("testname", "", "", "", "")

msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil)

Expand Down
2 changes: 1 addition & 1 deletion x/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ var (
ed25519.GenPrivKey().PubKey(),
}

testDescription = staking.NewDescription("T", "E", "S", "T")
testDescription = staking.NewDescription("T", "E", "S", "T", ">:)")
testCommissionRates = staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
)

Expand Down
2 changes: 1 addition & 1 deletion x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestSlashingMsgs(t *testing.T) {
accs := []auth.Account{acc1}
mock.SetGenesis(mapp, accs)

description := staking.NewDescription("foo_moniker", "", "", "")
description := staking.NewDescription("foo_moniker", "", "", "", "")
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())

createValidatorMsg := staking.NewMsgCreateValidator(
Expand Down
4 changes: 2 additions & 2 deletions x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestStakingMsgs(t *testing.T) {
mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin})

// create validator
description := NewDescription("foo_moniker", "", "", "")
description := NewDescription("foo_moniker", "", "", "", "")
createValidatorMsg := NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(),
)
Expand All @@ -157,7 +157,7 @@ func TestStakingMsgs(t *testing.T) {
mApp.BeginBlock(abci.RequestBeginBlock{Header: header})

// edit the validator
description = NewDescription("bar_moniker", "", "", "")
description = NewDescription("bar_moniker", "", "", "", "")
editValidatorMsg := NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil)

header = abci.Header{Height: mApp.LastBlockHeight() + 1}
Expand Down
9 changes: 5 additions & 4 deletions x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const (
FlagSharesAmount = "shares-amount"
FlagSharesFraction = "shares-fraction"

FlagMoniker = "moniker"
FlagIdentity = "identity"
FlagWebsite = "website"
FlagDetails = "details"
FlagMoniker = "moniker"
FlagIdentity = "identity"
FlagWebsite = "website"
FlagSecurityContact = "security-contact"
FlagDetails = "details"

FlagCommissionRate = "commission-rate"
FlagCommissionMaxRate = "commission-max-rate"
Expand Down
14 changes: 8 additions & 6 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)

valAddr := cliCtx.GetFromAddress()
description := types.Description{
Moniker: viper.GetString(FlagMoniker),
Identity: viper.GetString(FlagIdentity),
Website: viper.GetString(FlagWebsite),
Details: viper.GetString(FlagDetails),
}
description := types.NewDescription(
viper.GetString(FlagMoniker),
viper.GetString(FlagIdentity),
viper.GetString(FlagWebsite),
viper.GetString(FlagSecurityContact),
viper.GetString(FlagDetails),
)

var newRate *sdk.Dec

Expand Down Expand Up @@ -350,6 +351,7 @@ func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr auth.TxBuilder) (
viper.GetString(FlagMoniker),
viper.GetString(FlagIdentity),
viper.GetString(FlagWebsite),
viper.GetString(FlagSecurityContact),
viper.GetString(FlagDetails),
)

Expand Down
8 changes: 4 additions & 4 deletions x/staking/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestInitGenesis(t *testing.T) {
// initialize the validators
validators[0].OperatorAddress = sdk.ValAddress(keep.Addrs[0])
validators[0].ConsPubKey = keep.PKs[0]
validators[0].Description = NewDescription("hoop", "", "", "")
validators[0].Description = NewDescription("hoop", "", "", "", "")
validators[0].Status = sdk.Bonded
validators[0].Tokens = valTokens
validators[0].DelegatorShares = valTokens.ToDec()
validators[1].OperatorAddress = sdk.ValAddress(keep.Addrs[1])
validators[1].ConsPubKey = keep.PKs[1]
validators[1].Description = NewDescription("bloop", "", "", "")
validators[1].Description = NewDescription("bloop", "", "", "", "")
validators[1].Status = sdk.Bonded
validators[1].Tokens = valTokens
validators[1].DelegatorShares = valTokens.ToDec()
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {

for i := range validators {
validators[i] = NewValidator(sdk.ValAddress(keep.Addrs[i]),
keep.PKs[i], NewDescription(fmt.Sprintf("#%d", i), "", "", ""))
keep.PKs[i], NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""))

validators[i].Status = sdk.Bonded

Expand All @@ -102,7 +102,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
func TestValidateGenesis(t *testing.T) {
genValidators1 := make([]types.Validator, 1, 5)
pk := ed25519.GenPrivKey().PubKey()
genValidators1[0] = types.NewValidator(sdk.ValAddress(pk.Address()), pk, types.NewDescription("", "", "", ""))
genValidators1[0] = types.NewValidator(sdk.ValAddress(pk.Address()), pk, types.NewDescription("", "", "", "", ""))
genValidators1[0].Tokens = sdk.OneInt()
genValidators1[0].DelegatorShares = sdk.OneDec()

Expand Down
23 changes: 14 additions & 9 deletions x/staking/simulation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k staking.Keeper) simulati
opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {

denom := k.GetParams(ctx).BondDenom
description := staking.Description{
Moniker: simulation.RandStringOfLength(r, 10),
}
description := staking.NewDescription(
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
)

maxCommission := sdk.NewDecWithPrec(r.Int63n(1000), 3)
commission := staking.NewCommissionRates(
Expand Down Expand Up @@ -67,12 +71,13 @@ func SimulateMsgEditValidator(k staking.Keeper) simulation.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
accs []simulation.Account) (opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {

description := staking.Description{
Moniker: simulation.RandStringOfLength(r, 10),
Identity: simulation.RandStringOfLength(r, 10),
Website: simulation.RandStringOfLength(r, 10),
Details: simulation.RandStringOfLength(r, 10),
}
description := staking.NewDescription(
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
simulation.RandStringOfLength(r, 10),
)

if len(k.GetAllValidators(ctx)) == 0 {
return simulation.NoOpMsg(staking.ModuleName), nil, nil
Expand Down
50 changes: 25 additions & 25 deletions x/staking/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ func TestMsgCreateValidator(t *testing.T) {
commission2 := NewCommissionRates(sdk.NewDec(5), sdk.NewDec(5), sdk.NewDec(5))

tests := []struct {
name, moniker, identity, website, details string
CommissionRates CommissionRates
minSelfDelegation sdk.Int
validatorAddr sdk.ValAddress
pubkey crypto.PubKey
bond sdk.Coin
expectPass bool
name, moniker, identity, website, securityContact, details string
CommissionRates CommissionRates
minSelfDelegation sdk.Int
validatorAddr sdk.ValAddress
pubkey crypto.PubKey
bond sdk.Coin
expectPass bool
}{
{"basic good", "a", "b", "c", "d", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
{"partial description", "", "", "c", "", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
{"empty description", "", "", "", "", commission2, sdk.OneInt(), valAddr1, pk1, coinPos, false},
{"empty address", "a", "b", "c", "d", commission2, sdk.OneInt(), emptyAddr, pk1, coinPos, false},
{"empty pubkey", "a", "b", "c", "d", commission1, sdk.OneInt(), valAddr1, emptyPubkey, coinPos, true},
{"empty bond", "a", "b", "c", "d", commission2, sdk.OneInt(), valAddr1, pk1, coinZero, false},
{"zero min self delegation", "a", "b", "c", "d", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
{"negative min self delegation", "a", "b", "c", "d", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
{"delegation less than min self delegation", "a", "b", "c", "d", commission1, coinPos.Amount.Add(sdk.OneInt()), valAddr1, pk1, coinPos, false},
{"basic good", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
{"partial description", "", "", "c", "", "", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
{"empty description", "", "", "", "", "", commission2, sdk.OneInt(), valAddr1, pk1, coinPos, false},
{"empty address", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), emptyAddr, pk1, coinPos, false},
{"empty pubkey", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, emptyPubkey, coinPos, true},
{"empty bond", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), valAddr1, pk1, coinZero, false},
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
{"delegation less than min self delegation", "a", "b", "c", "d", "e", commission1, coinPos.Amount.Add(sdk.OneInt()), valAddr1, pk1, coinPos, false},
}

for _, tc := range tests {
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details)
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.securityContact, tc.details)
msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description, tc.CommissionRates, tc.minSelfDelegation)
if tc.expectPass {
require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name)
Expand All @@ -53,18 +53,18 @@ func TestMsgCreateValidator(t *testing.T) {
// test ValidateBasic for MsgEditValidator
func TestMsgEditValidator(t *testing.T) {
tests := []struct {
name, moniker, identity, website, details string
validatorAddr sdk.ValAddress
expectPass bool
name, moniker, identity, website, securityContact, details string
validatorAddr sdk.ValAddress
expectPass bool
}{
{"basic good", "a", "b", "c", "d", valAddr1, true},
{"partial description", "", "", "c", "", valAddr1, true},
{"empty description", "", "", "", "", valAddr1, false},
{"empty address", "a", "b", "c", "d", emptyAddr, false},
{"basic good", "a", "b", "c", "d", "e", valAddr1, true},
{"partial description", "", "", "c", "", "", valAddr1, true},
{"empty description", "", "", "", "", "", valAddr1, false},
{"empty address", "a", "b", "c", "d", "e", emptyAddr, false},
}

for _, tc := range tests {
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details)
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.securityContact, tc.details)
newRate := sdk.ZeroDec()
newMinSelfDelegation := sdk.OneInt()

Expand Down
48 changes: 29 additions & 19 deletions x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
// nolint
const (
// TODO: Why can't we just have one string description which can be JSON by convention
MaxMonikerLength = 70
MaxIdentityLength = 3000
MaxWebsiteLength = 140
MaxDetailsLength = 280
MaxMonikerLength = 70
MaxIdentityLength = 3000
MaxWebsiteLength = 140
MaxSecurityContactLength = 140
MaxDetailsLength = 280
)

// Implements Validator interface
Expand Down Expand Up @@ -260,19 +261,21 @@ const DoNotModifyDesc = "[do-not-modify]"

// Description - description fields for a validator
type Description struct {
Moniker string `json:"moniker" yaml:"moniker"` // name
Identity string `json:"identity" yaml:"identity"` // optional identity signature (ex. UPort or Keybase)
Website string `json:"website" yaml:"website"` // optional website link
Details string `json:"details" yaml:"details"` // optional details
Moniker string `json:"moniker" yaml:"moniker"` // name
Identity string `json:"identity" yaml:"identity"` // optional identity signature (ex. UPort or Keybase)
Website string `json:"website" yaml:"website"` // optional website link
SecurityContact string `json:"security_contact" yaml:"security_contact"` // optional security contact info
Details string `json:"details" yaml:"details"` // optional details
}

// NewDescription returns a new Description with the provided values.
func NewDescription(moniker, identity, website, details string) Description {
func NewDescription(moniker, identity, website, securityContact, details string) Description {
return Description{
Moniker: moniker,
Identity: identity,
Website: website,
Details: details,
Moniker: moniker,
Identity: identity,
Website: website,
SecurityContact: securityContact,
Details: details,
}
}

Expand All @@ -288,16 +291,20 @@ func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error)
if d2.Website == DoNotModifyDesc {
d2.Website = d.Website
}
if d2.SecurityContact == DoNotModifyDesc {
d2.SecurityContact = d.SecurityContact
}
if d2.Details == DoNotModifyDesc {
d2.Details = d.Details
}

return Description{
Moniker: d2.Moniker,
Identity: d2.Identity,
Website: d2.Website,
Details: d2.Details,
}.EnsureLength()
return NewDescription(
d2.Moniker,
d2.Identity,
d2.Website,
d2.SecurityContact,
d2.Details,
).EnsureLength()
}

// EnsureLength ensures the length of a validator's description.
Expand All @@ -311,6 +318,9 @@ func (d Description) EnsureLength() (Description, sdk.Error) {
if len(d.Website) > MaxWebsiteLength {
return d, ErrDescriptionLength(DefaultCodespace, "website", len(d.Website), MaxWebsiteLength)
}
if len(d.SecurityContact) > MaxSecurityContactLength {
return d, ErrDescriptionLength(DefaultCodespace, "website", len(d.Website), MaxWebsiteLength)
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
}
if len(d.Details) > MaxDetailsLength {
return d, ErrDescriptionLength(DefaultCodespace, "details", len(d.Details), MaxDetailsLength)
}
Expand Down
1 change: 1 addition & 0 deletions x/staking/types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestValidatorMarshalYAML(t *testing.T) {
moniker: ""
identity: ""
website: ""
security_contact: ""
details: ""
unbondingheight: 0
unbondingcompletiontime: 1970-01-01T00:00:00Z
Expand Down