Skip to content

Commit

Permalink
Fix flagging valset changed
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Mar 25, 2024
1 parent 30b99aa commit 252cc59
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
1 change: 0 additions & 1 deletion tests/mbt/driver/mbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func RunItfTrace(t *testing.T, path string) {
driver.setupConsumer(
chainId,
modelParams,
&initialValSet,
consumerSigners,
nodes,
valNames,
Expand Down
30 changes: 24 additions & 6 deletions tests/mbt/driver/setup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"log"
"testing"
Expand Down Expand Up @@ -444,7 +445,6 @@ func (s *Driver) setupProvider(
func (s *Driver) setupConsumer(
chain string,
params ModelParams,
valSet *cmttypes.ValidatorSet, // the current validator set on the provider chain
signers map[string]cmttypes.PrivValidator, // a map of validator addresses to private validators (signers)
nodes []*cmttypes.Validator, // the list of nodes, even ones that have no voting power initially
valNames []string,
Expand All @@ -454,16 +454,34 @@ func (s *Driver) setupConsumer(
) {
s.t.Logf("Starting consumer %v", chain)

// TODO: reuse the partial set computation logic to compute the initial validator set
// for top N chains
initValUpdates := cmttypes.TM2PB.ValidatorUpdates(valSet)
minPowerToOptIn := s.providerKeeper().ComputeMinPowerToOptIn(s.providerCtx(), s.providerValidatorSet(), uint32(topN))

valSet := s.providerChain().Vals

// Filter out all the validators that do not either a) have power at least minPowerToOptIn, or b) are in the validatorsToOptIn slice
filteredValSet := make([]*cmttypes.Validator, 0)
for _, val := range valSet.Validators {
if val.VotingPower >= minPowerToOptIn && topN > 0 {
filteredValSet = append(filteredValSet, val)
continue
}
for _, optInVal := range validatorsToOptIn {
if bytes.Equal(val.Address, optInVal.Address.Bytes()) {
filteredValSet = append(filteredValSet, val)
break
}
}
}

initValSet := cmttypes.ValidatorSet{Validators: filteredValSet, Proposer: filteredValSet[0]}
initValUpdates := cmttypes.TM2PB.ValidatorUpdates(&initValSet)

// start consumer chains
s.t.Logf("Creating consumer chain %v", chain)
consumerChain := newChain(s.t, params, s.coordinator, icstestingutils.ConsumerAppIniter(initValUpdates), chain, valSet, signers, nodes, valNames)
consumerChain := newChain(s.t, params, s.coordinator, icstestingutils.ConsumerAppIniter(initValUpdates), chain, &initValSet, signers, nodes, valNames)
s.coordinator.Chains[chain] = consumerChain

valUpdates := cmttypes.TM2PB.ValidatorUpdates(valSet)
valUpdates := cmttypes.TM2PB.ValidatorUpdates(&initValSet)

path := s.ConfigureNewPath(consumerChain, providerChain, params, uint32(topN), validatorsToOptIn, valUpdates)
s.simibcs[ChainId(chain)] = simibc.MakeRelayedPath(s.t, path)
Expand Down
2 changes: 1 addition & 1 deletion tests/mbt/model/ccv.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ module ccv {
} else {
// set the validator set changed flag
val newProviderState = currentState.providerState.with(
"consumersWithPowerChangesInThisEpoch", getRunningConsumers(currentState.providerState)
"consumersWithPowerChangesInThisEpoch", getRunningConsumers(currentState.providerState).filter(consumer => currentState.providerState.optedInVals.get(consumer).contains(validator))
)
pure val tmpState = currentState.with(
"providerState", newProviderState
Expand Down
2 changes: 1 addition & 1 deletion tests/mbt/model/ccv_model.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module ccv_model {
pure val unbondingPeriods = chains.mapBy(chain => defUnbondingPeriod)
pure val trustingPeriods = chains.mapBy(chain => defUnbondingPeriod - 1 * Hour)
pure val ccvTimeouts = chains.mapBy(chain => 3 * Week)
pure val epochLength = 3
pure val epochLength = 1

pure val nodes = Set("node1", "node2", "node3", "node4", "node5", "node6", "node7", "node8", "node9", "node10")
// possible consumer addresses that nodes can assign their key to
Expand Down
5 changes: 3 additions & 2 deletions tests/mbt/model/ccv_pss_model.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ module ccv_pss_model {

action OptOut_Deterministic(consumer: Chain, validator: Node): bool = {
val res = OptOut(currentState, consumer, validator)
all {
currentState' = res.newState,
all {
// since we sometimes get expected errors here, we need to rollback to the current state if that is the case
currentState' = if (res.error == "") res.newState else currentState,
trace' = trace.append(
{
...emptyAction,
Expand Down

0 comments on commit 252cc59

Please sign in to comment.