Skip to content

Commit

Permalink
Add minStake and maxRank to proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Jul 16, 2024
1 parent 26842a5 commit fa0a336
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 133 deletions.
8 changes: 8 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ message ConsumerAdditionProposal {
repeated string allowlist = 18;
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
repeated string denylist = 19;
// Corresponds to the minimal amount of (provider chain) stake required to validate on the consumer chain.
int64 min_stake = 20;
// Corresponds to the maximal rank in the provider chain validator set that a validator can have to validate on the consumer chain.
int32 max_rank = 21;
}

// ConsumerRemovalProposal is a governance proposal on the provider chain to
Expand Down Expand Up @@ -156,6 +160,10 @@ message ConsumerModificationProposal {
repeated string allowlist = 7;
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
repeated string denylist = 8;
// Corresponds to the minimal amount of (provider chain) stake required to validate on the consumer chain.
int64 min_stake = 9;
// Corresponds to the maximal rank in the provider chain validator set that a validator can have to validate on the consumer chain.
int32 max_rank = 10;
}


Expand Down
2 changes: 2 additions & 0 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal)

return prop
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/provider/client/legacy_proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ Where proposal.json contains:
proposal.ConsumerRedistributionFraction, proposal.BlocksPerDistributionTransmission,
proposal.DistributionTransmissionChannel, proposal.HistoricalEntries,
proposal.CcvTimeoutPeriod, proposal.TransferTimeoutPeriod, proposal.UnbondingPeriod, proposal.TopN,
proposal.ValidatorsPowerCap, proposal.ValidatorSetCap, proposal.Allowlist, proposal.Denylist)
proposal.ValidatorsPowerCap, proposal.ValidatorSetCap, proposal.Allowlist, proposal.Denylist,
proposal.MinStake, proposal.MaxValidatorRank)

from := clientCtx.GetFromAddress()

Expand Down Expand Up @@ -261,7 +262,7 @@ Where proposal.json contains:

content := types.NewConsumerModificationProposal(
proposal.Title, proposal.Summary, proposal.ChainId, proposal.TopN,
proposal.ValidatorsPowerCap, proposal.ValidatorSetCap, proposal.Allowlist, proposal.Denylist)
proposal.ValidatorsPowerCap, proposal.ValidatorSetCap, proposal.Allowlist, proposal.Denylist, proposal.MinStake, proposal.MaxValidatorRank)

from := clientCtx.GetFromAddress()

Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/client/legacy_proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type ConsumerAdditionProposalJSON struct {
ValidatorSetCap uint32 `json:"validator_set_cap"`
Allowlist []string `json:"allowlist"`
Denylist []string `json:"denylist"`
MinStake int64 `json:"min_stake"`
MaxValidatorRank int32 `json:"max_validator_rank"`
}

type ConsumerAdditionProposalReq struct {
Expand Down Expand Up @@ -172,6 +174,8 @@ type ConsumerModificationProposalJSON struct {
ValidatorSetCap uint32 `json:"validator_set_cap"`
Allowlist []string `json:"allowlist"`
Denylist []string `json:"denylist"`
MinStake int64 `json:"min_stake"`
MaxValidatorRank int32 `json:"max_validator_rank"`

Deposit string `json:"deposit"`
}
Expand Down
16 changes: 16 additions & 0 deletions x/ccv/provider/keeper/legacy_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func TestHandleLegacyConsumerAdditionProposal(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
blockTime: now,
expAppendProp: true,
Expand Down Expand Up @@ -92,6 +94,8 @@ func TestHandleLegacyConsumerAdditionProposal(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
blockTime: now,
expAppendProp: false,
Expand Down Expand Up @@ -282,18 +286,24 @@ func TestHandleConsumerModificationProposal(t *testing.T) {
providerKeeper.SetAllowlist(ctx, chainID, providertypes.NewProviderConsAddress([]byte("allowlistedAddr1")))
providerKeeper.SetAllowlist(ctx, chainID, providertypes.NewProviderConsAddress([]byte("allowlistedAddr2")))
providerKeeper.SetDenylist(ctx, chainID, providertypes.NewProviderConsAddress([]byte("denylistedAddr1")))
providerKeeper.SetMinStake(ctx, chainID, 1000)
providerKeeper.SetMaxValidatorRank(ctx, chainID, 180)

expectedTopN := uint32(75)
expectedValidatorsPowerCap := uint32(67)
expectedValidatorSetCap := uint32(20)
expectedAllowlistedValidator := "cosmosvalcons1wpex7anfv3jhystyv3eq20r35a"
expectedDenylistedValidator := "cosmosvalcons1nx7n5uh0ztxsynn4sje6eyq2ud6rc6klc96w39"
expectedMinStake := 0
expectedMaxValidatorRank := 20
proposal := providertypes.NewConsumerModificationProposal("title", "description", chainID,
expectedTopN,
expectedValidatorsPowerCap,
expectedValidatorSetCap,
[]string{expectedAllowlistedValidator},
[]string{expectedDenylistedValidator},
int64(expectedMinStake),
int32(expectedMaxValidatorRank),
).(*providertypes.ConsumerModificationProposal)

err := providerKeeper.HandleLegacyConsumerModificationProposal(ctx, proposal)
Expand All @@ -315,4 +325,10 @@ func TestHandleConsumerModificationProposal(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(providerKeeper.GetDenyList(ctx, chainID)))
require.Equal(t, providertypes.NewProviderConsAddress(denylistedValidator), providerKeeper.GetDenyList(ctx, chainID)[0])

actualMinStake, _ := providerKeeper.GetMinStake(ctx, chainID)
require.Equal(t, expectedMinStake, actualMinStake)

actualMaxValidatorRank, _ := providerKeeper.GetMaxValidatorRank(ctx, chainID)
require.Equal(t, expectedMaxValidatorRank, actualMaxValidatorRank)
}
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/partial_set_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func createStakingValidatorsAndMocks(ctx sdk.Context, mocks testkeeper.MockedKee
}
// set up mocks
for index, val := range validators {
mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr(ctx, consAddrs[index]).Return(val, nil).AnyTimes()
mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr(ctx, consAddrs[index].Address).Return(val, nil).AnyTimes()
}

return validators, consAddrs
Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) {
k.SetTopN(cachedCtx, prop.ChainId, prop.Top_N)
k.SetValidatorSetCap(cachedCtx, prop.ChainId, prop.ValidatorSetCap)
k.SetValidatorsPowerCap(cachedCtx, prop.ChainId, prop.ValidatorsPowerCap)
k.SetMinStake(cachedCtx, prop.ChainId, prop.MinStake)
k.SetMaxValidatorRank(cachedCtx, prop.ChainId, prop.MaxRank)

for _, address := range prop.Allowlist {
consAddr, err := sdk.ConsAddressFromBech32(address)
Expand Down
16 changes: 16 additions & 0 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func TestHandleConsumerAdditionProposal(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
blockTime: now,
expAppendProp: true,
Expand Down Expand Up @@ -103,6 +105,8 @@ func TestHandleConsumerAdditionProposal(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
blockTime: now,
expAppendProp: false,
Expand Down Expand Up @@ -809,6 +813,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "spawn time passed", "chain2", clienttypes.NewHeight(3, 4), []byte{}, []byte{},
Expand All @@ -825,6 +831,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "spawn time not passed", "chain3", clienttypes.NewHeight(3, 4), []byte{}, []byte{},
Expand All @@ -841,6 +849,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "invalid proposal: chain id already exists", "chain2", clienttypes.NewHeight(4, 5), []byte{}, []byte{},
Expand All @@ -857,6 +867,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "opt-in chain with at least one validator opted in", "chain5", clienttypes.NewHeight(3, 4), []byte{}, []byte{},
Expand All @@ -873,6 +885,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "opt-in chain with no validator opted in", "chain6", clienttypes.NewHeight(3, 4), []byte{}, []byte{},
Expand All @@ -889,6 +903,8 @@ func TestBeginBlockInit(t *testing.T) {
0,
nil,
nil,
0,
0,
).(*providertypes.ConsumerAdditionProposal),
}

Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func TestProviderProposalHandler(t *testing.T) {
0,
nil,
nil,
0,
0,
),
blockTime: hourFromNow, // ctx blocktime is after proposal's spawn time
expValidConsumerAddition: true,
Expand Down
8 changes: 8 additions & 0 deletions x/ccv/provider/types/legacy_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func NewConsumerAdditionProposal(title, description, chainID string,
validatorSetCap uint32,
allowlist []string,
denylist []string,
minStake int64,
maxValidatorRank int32,
) govv1beta1.Content {
return &ConsumerAdditionProposal{
Title: title,
Expand All @@ -79,6 +81,8 @@ func NewConsumerAdditionProposal(title, description, chainID string,
ValidatorSetCap: validatorSetCap,
Allowlist: allowlist,
Denylist: denylist,
MinStake: minStake,
MaxRank: maxValidatorRank,
}
}

Expand Down Expand Up @@ -243,6 +247,8 @@ func NewConsumerModificationProposal(title, description, chainID string,
validatorSetCap uint32,
allowlist []string,
denylist []string,
minStake int64,
maxValidatorRank int32,
) govv1beta1.Content {
return &ConsumerModificationProposal{
Title: title,
Expand All @@ -253,6 +259,8 @@ func NewConsumerModificationProposal(title, description, chainID string,
ValidatorSetCap: validatorSetCap,
Allowlist: allowlist,
Denylist: denylist,
MinStake: minStake,
MaxRank: maxValidatorRank,
}
}

Expand Down
Loading

0 comments on commit fa0a336

Please sign in to comment.