Skip to content

Commit ccdb89b

Browse files
authored
fix: Fix inactive vals and min stake handling in ConsumerAdditionProposal 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
1 parent 3084962 commit ccdb89b

File tree

7 files changed

+246
-130
lines changed

7 files changed

+246
-130
lines changed

proto/interchain_security/ccv/provider/v1/query.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ message Chain {
187187
repeated string allowlist = 7;
188188
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
189189
repeated string denylist = 8;
190+
// Corresponds to the minimal amount of (provider chain) stake required to validate on the consumer chain.
191+
uint64 min_stake = 9;
192+
// Corresponds to whether inactive validators are allowed to validate the consumer chain.
193+
bool allow_inactive_vals = 10;
194+
190195
}
191196

192197
message QueryValidatorConsumerAddrRequest {

tests/e2e/actions.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ func (tr Chain) submitConsumerAdditionProposal(
299299
"validator_set_cap": %d,
300300
"allowlist": %s,
301301
"denylist": %s,
302-
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
302+
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
303+
"allow_inactive_vals": %t,
304+
"min_stake": "%d"
303305
}
304306
],
305307
"metadata": "ipfs://CID",
@@ -327,6 +329,8 @@ func (tr Chain) submitConsumerAdditionProposal(
327329
action.ValidatorSetCap,
328330
action.Allowlist,
329331
action.Denylist,
332+
action.AllowInactiveVals,
333+
action.MinStake,
330334
action.Deposit)
331335

332336
//#nosec G204 -- bypass unsafe quoting warning (no production code)
@@ -587,13 +591,14 @@ type SubmitConsumerModificationProposalAction struct {
587591
ValidatorSetCap uint32
588592
Allowlist []string
589593
Denylist []string
594+
AllowInactiveVals bool
595+
MinStake uint64
590596
}
591597

592598
func (tr Chain) submitConsumerModificationProposal(
593599
action SubmitConsumerModificationProposalAction,
594600
verbose bool,
595601
) {
596-
597602
template := `
598603
599604
{
@@ -609,8 +614,8 @@ func (tr Chain) submitConsumerModificationProposal(
609614
"allowlist": %s,
610615
"denylist": %s,
611616
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
612-
"min_stake": "0",
613-
"allow_inactive_vals": false
617+
"min_stake": %d,
618+
"allow_inactive_vals": %t
614619
}
615620
],
616621
"metadata": "ipfs://CID",
@@ -629,6 +634,8 @@ func (tr Chain) submitConsumerModificationProposal(
629634
action.Allowlist,
630635
action.Denylist,
631636
action.Deposit,
637+
action.MinStake,
638+
action.AllowInactiveVals,
632639
)
633640

634641
// #nosec G204 -- bypass unsafe quoting warning (no production code)

x/ccv/provider/keeper/grpc_query.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain,
9595
strDenylist[i] = addr.String()
9696
}
9797

98+
allowInactiveVals := k.AllowsInactiveValidators(ctx, chainID)
99+
100+
minStake, _ := k.GetMinStake(ctx, chainID)
101+
98102
return types.Chain{
99103
ChainId: chainID,
100104
ClientId: clientID,
@@ -104,6 +108,8 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain,
104108
ValidatorsPowerCap: validatorsPowerCap,
105109
Allowlist: strAllowlist,
106110
Denylist: strDenylist,
111+
AllowInactiveVals: allowInactiveVals,
112+
MinStake: minStake,
107113
}, nil
108114
}
109115

x/ccv/provider/keeper/grpc_query_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ func TestGetConsumerChain(t *testing.T) {
280280
{},
281281
}
282282

283+
allowInactiveVals := []bool{true, false, true, false}
284+
285+
minStakes := []math.Int{
286+
math.NewInt(0),
287+
math.NewInt(100),
288+
math.NewInt(200),
289+
math.NewInt(300),
290+
}
291+
283292
expectedGetAllOrder := []types.Chain{}
284293
for i, chainID := range chainIDs {
285294
clientID := fmt.Sprintf("client-%d", len(chainIDs)-i)
@@ -289,6 +298,8 @@ func TestGetConsumerChain(t *testing.T) {
289298
pk.SetValidatorSetCap(ctx, chainID, validatorSetCaps[i])
290299
pk.SetValidatorsPowerCap(ctx, chainID, validatorPowerCaps[i])
291300
pk.SetMinimumPowerInTopN(ctx, chainID, expectedMinPowerInTopNs[i])
301+
pk.SetInactiveValidatorsAllowed(ctx, chainID, allowInactiveVals[i])
302+
pk.SetMinStake(ctx, chainID, minStakes[i].Uint64())
292303
for _, addr := range allowlists[i] {
293304
pk.SetAllowlist(ctx, chainID, addr)
294305
}
@@ -315,6 +326,8 @@ func TestGetConsumerChain(t *testing.T) {
315326
ValidatorsPowerCap: validatorPowerCaps[i],
316327
Allowlist: strAllowlist,
317328
Denylist: strDenylist,
329+
AllowInactiveVals: allowInactiveVals[i],
330+
MinStake: minStakes[i].Uint64(),
318331
})
319332
}
320333

x/ccv/provider/keeper/hooks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ func (h Hooks) GetConsumerAdditionFromProp(
180180
ValidatorSetCap: sdkMsg.ValidatorSetCap,
181181
Allowlist: sdkMsg.Allowlist,
182182
Denylist: sdkMsg.Denylist,
183+
MinStake: sdkMsg.MinStake,
184+
AllowInactiveVals: sdkMsg.AllowInactiveVals,
183185
}
184186
return proposal, true
185187
}

x/ccv/provider/keeper/proposal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func (k Keeper) HandleConsumerAdditionProposal(ctx sdk.Context, proposal *types.
4444
ValidatorSetCap: proposal.ValidatorSetCap,
4545
Allowlist: proposal.Allowlist,
4646
Denylist: proposal.Denylist,
47+
MinStake: proposal.MinStake,
48+
AllowInactiveVals: proposal.AllowInactiveVals,
4749
}
4850

4951
return k.HandleLegacyConsumerAdditionProposal(ctx, &p)

0 commit comments

Comments
 (0)