Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Aug 28, 2024
1 parent 8aedb09 commit 975d583
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 4 deletions.
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 tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ var stepChoices = map[string]StepChoice{
description: "tests the behaviour of inactive validators with a top N = 100 chain and when max_validators is smaller than the total number of validators",
testConfig: InactiveValsExtraValsTestCfg,
},
"inactive-vals-topN-100": {
name: "inactive-vals-topN-100",
steps: stepsInactiveValsTopN100(),
description: "tests the behaviour of inactive validators with a top N = 100 chain",
testConfig: InactiveValsExtraValsTestCfg,
},
}

func getTestCaseUsageString() string {
Expand Down
179 changes: 179 additions & 0 deletions tests/e2e/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,182 @@ func stepsInactiveValsTopNReproduce() []Step {
},
}
}

func stepsInactiveValsTopN100() []Step {
alice_power := uint(30)
bob_power := uint(29)
carol_power := uint(20)
david_power := uint(10)
eve_power := uint(7)
fred_power := uint(4)

return []Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: alice_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: bob_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: carol_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("david"), Stake: david_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("eve"), Stake: eve_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("fred"), Stake: fred_power * 1000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): alice_power,
ValidatorID("bob"): bob_power,
ValidatorID("carol"): carol_power,
ValidatorID("david"): david_power,
ValidatorID("eve"): 0, // max provider consensus validators is 4, so eve and fred are at 0 power
ValidatorID("fred"): 0,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): alice_power * 1000000,
ValidatorID("bob"): bob_power * 1000000,
ValidatorID("carol"): carol_power * 1000000,
ValidatorID("david"): david_power * 1000000,
ValidatorID("eve"): eve_power * 1000000,
ValidatorID("fred"): fred_power * 1000000,
},
},
},
},
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 100,
AllowInactiveVals: true,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
},
},
},
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob"), ValidatorID("carol"), ValidatorID("david"), ValidatorID("eve")},
Vote: []string{"yes", "yes", "yes", "yes", "yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)),
},
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
ValidatorID("david"): {"consu"},
ValidatorID("eve"): {},
ValidatorID("fred"): {},
},
},
},
},
{
Action: StartConsumerChainAction{
ConsumerChain: ChainID("consu"),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: alice_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: bob_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: carol_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("david"), Stake: david_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("eve"), Stake: eve_power * 1000000, Allocation: 10000000000},
{Id: ValidatorID("fred"), Stake: fred_power * 1000000, Allocation: 10000000000},
},
// For consumers that're launching with the provider being on an earlier version
// of ICS before the soft opt-out threshold was introduced, we need to set the
// soft opt-out threshold to 0.05 in the consumer genesis to ensure that the
// consumer binary doesn't panic. Sdk requires that all params are set to valid
// values from the genesis file.
GenesisChanges: ".app_state.ccvconsumer.params.soft_opt_out_threshold = \"0.05\"",
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): alice_power,
ValidatorID("bob"): bob_power,
ValidatorID("carol"): carol_power,
ValidatorID("david"): david_power,
ValidatorID("eve"): 0,
ValidatorID("fred"): 0,
},
},
},
},
{
Action: AddIbcConnectionAction{
ChainA: ChainID("consu"),
ChainB: ChainID("provi"),
ClientA: 0,
ClientB: 0,
},
State: State{},
},
{
Action: AddIbcChannelAction{
ChainA: ChainID("consu"),
ChainB: ChainID("provi"),
ConnectionA: 0,
PortA: "consumer",
PortB: "provider",
Order: "ordered",
},
State: State{},
},
{
// opt in eve, since she is not forced to validate by the top N = 100
Action: OptInAction{
Chain: ChainID("consu"),
Validator: ValidatorID("eve"),
},
State: State{},
},
{
Action: RelayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID("consu"),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): alice_power,
ValidatorID("bob"): bob_power,
ValidatorID("carol"): carol_power,
ValidatorID("david"): david_power,
ValidatorID("eve"): eve_power, // eve is opted in
ValidatorID("fred"): 0,
},
},
},
},
}
}
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
7 changes: 7 additions & 0 deletions x/ccv/provider/keeper/partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func (k Keeper) FulfillsMinStake(ctx sdk.Context, chainID string, providerAddr t

// ComputeNextValidators computes the validators for the upcoming epoch based on the currently `bondedValidators`.
func (k Keeper) ComputeNextValidators(ctx sdk.Context, chainID string, bondedValidators []stakingtypes.Validator) []types.ConsensusValidator {
k.Logger(ctx).Info("Computing next validators", "chainID", chainID, "bondedValidators", bondedValidators)
// sort the bonded validators by number of staked tokens in descending order
sort.Slice(bondedValidators, func(i, j int) bool {
return bondedValidators[i].GetBondedTokens().GT(bondedValidators[j].GetBondedTokens())
Expand All @@ -342,6 +343,7 @@ func (k Keeper) ComputeNextValidators(ctx sdk.Context, chainID string, bondedVal
// since those are the ones that participate in consensus
allowInactiveVals := k.AllowsInactiveValidators(ctx, chainID)
if !allowInactiveVals {
k.Logger(ctx).Info("Inactive validators are not allowed", "chainID", chainID)
// only leave the first MaxProviderConsensusValidators bonded validators
maxProviderConsensusVals := k.GetMaxProviderConsensusValidators(ctx)
if len(bondedValidators) > int(maxProviderConsensusVals) {
Expand All @@ -354,6 +356,11 @@ func (k Keeper) ComputeNextValidators(ctx sdk.Context, chainID string, bondedVal
return k.CanValidateChain(ctx, chainID, providerAddr) && k.FulfillsMinStake(ctx, chainID, providerAddr)
})

k.Logger(ctx).Info("Next validators after filter", "chainID", chainID, "nextValidators", nextValidators)

nextValidators = k.CapValidatorSet(ctx, chainID, nextValidators)

k.Logger(ctx).Info("Next validators after capping validator set", "chainID", chainID, "nextValidators", nextValidators)

return k.CapValidatorsPower(ctx, chainID, nextValidators)
}
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

0 comments on commit 975d583

Please sign in to comment.