Skip to content

Commit

Permalink
fix: Fix inactive vals and min stake handling in ConsumerAdditionProp…
Browse files Browse the repository at this point in the history
…osal conversion (#2181)

* Add inactive vals and min stake to Chain struct

* Add allow_inactive_vals and min_stake to consumer chain query result

* Add inactive vals and min stake to consumer chain getter test

* Fix regression

* Revert extra logging changes

* Remove e2e scenario
  • Loading branch information
p-offtermatt authored Aug 28, 2024
1 parent 3084962 commit ccdb89b
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 130 deletions.
5 changes: 5 additions & 0 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ message Chain {
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.
uint64 min_stake = 9;
// Corresponds to whether inactive validators are allowed to validate the consumer chain.
bool allow_inactive_vals = 10;

}

message QueryValidatorConsumerAddrRequest {
Expand Down
15 changes: 11 additions & 4 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ func (tr Chain) submitConsumerAdditionProposal(
"validator_set_cap": %d,
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"allow_inactive_vals": %t,
"min_stake": "%d"
}
],
"metadata": "ipfs://CID",
Expand Down Expand Up @@ -327,6 +329,8 @@ func (tr Chain) submitConsumerAdditionProposal(
action.ValidatorSetCap,
action.Allowlist,
action.Denylist,
action.AllowInactiveVals,
action.MinStake,
action.Deposit)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
Expand Down Expand Up @@ -587,13 +591,14 @@ type SubmitConsumerModificationProposalAction struct {
ValidatorSetCap uint32
Allowlist []string
Denylist []string
AllowInactiveVals bool
MinStake uint64
}

func (tr Chain) submitConsumerModificationProposal(
action SubmitConsumerModificationProposalAction,
verbose bool,
) {

template := `
{
Expand All @@ -609,8 +614,8 @@ func (tr Chain) submitConsumerModificationProposal(
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"min_stake": "0",
"allow_inactive_vals": false
"min_stake": %d,
"allow_inactive_vals": %t
}
],
"metadata": "ipfs://CID",
Expand All @@ -629,6 +634,8 @@ func (tr Chain) submitConsumerModificationProposal(
action.Allowlist,
action.Denylist,
action.Deposit,
action.MinStake,
action.AllowInactiveVals,
)

// #nosec G204 -- bypass unsafe quoting warning (no production code)
Expand Down
6 changes: 6 additions & 0 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain,
strDenylist[i] = addr.String()
}

allowInactiveVals := k.AllowsInactiveValidators(ctx, chainID)

minStake, _ := k.GetMinStake(ctx, chainID)

return types.Chain{
ChainId: chainID,
ClientId: clientID,
Expand All @@ -104,6 +108,8 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain,
ValidatorsPowerCap: validatorsPowerCap,
Allowlist: strAllowlist,
Denylist: strDenylist,
AllowInactiveVals: allowInactiveVals,
MinStake: minStake,
}, nil
}

Expand Down
13 changes: 13 additions & 0 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ func TestGetConsumerChain(t *testing.T) {
{},
}

allowInactiveVals := []bool{true, false, true, false}

minStakes := []math.Int{
math.NewInt(0),
math.NewInt(100),
math.NewInt(200),
math.NewInt(300),
}

expectedGetAllOrder := []types.Chain{}
for i, chainID := range chainIDs {
clientID := fmt.Sprintf("client-%d", len(chainIDs)-i)
Expand All @@ -289,6 +298,8 @@ func TestGetConsumerChain(t *testing.T) {
pk.SetValidatorSetCap(ctx, chainID, validatorSetCaps[i])
pk.SetValidatorsPowerCap(ctx, chainID, validatorPowerCaps[i])
pk.SetMinimumPowerInTopN(ctx, chainID, expectedMinPowerInTopNs[i])
pk.SetInactiveValidatorsAllowed(ctx, chainID, allowInactiveVals[i])
pk.SetMinStake(ctx, chainID, minStakes[i].Uint64())
for _, addr := range allowlists[i] {
pk.SetAllowlist(ctx, chainID, addr)
}
Expand All @@ -315,6 +326,8 @@ func TestGetConsumerChain(t *testing.T) {
ValidatorsPowerCap: validatorPowerCaps[i],
Allowlist: strAllowlist,
Denylist: strDenylist,
AllowInactiveVals: allowInactiveVals[i],
MinStake: minStakes[i].Uint64(),
})
}

Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func (h Hooks) GetConsumerAdditionFromProp(
ValidatorSetCap: sdkMsg.ValidatorSetCap,
Allowlist: sdkMsg.Allowlist,
Denylist: sdkMsg.Denylist,
MinStake: sdkMsg.MinStake,
AllowInactiveVals: sdkMsg.AllowInactiveVals,
}
return proposal, true
}
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 @@ -44,6 +44,8 @@ func (k Keeper) HandleConsumerAdditionProposal(ctx sdk.Context, proposal *types.
ValidatorSetCap: proposal.ValidatorSetCap,
Allowlist: proposal.Allowlist,
Denylist: proposal.Denylist,
MinStake: proposal.MinStake,
AllowInactiveVals: proposal.AllowInactiveVals,
}

return k.HandleLegacyConsumerAdditionProposal(ctx, &p)
Expand Down
Loading

0 comments on commit ccdb89b

Please sign in to comment.