From 252cc59e7a5dcac38f6dfe74b3991fbbde84d984 Mon Sep 17 00:00:00 2001
From: Philip Offtermatt
Date: Mon, 25 Mar 2024 14:23:24 +0100
Subject: [PATCH 1/2] Fix flagging valset changed
---
tests/mbt/driver/mbt_test.go | 1 -
tests/mbt/driver/setup.go | 30 ++++++++++++++++++++++++------
tests/mbt/model/ccv.qnt | 2 +-
tests/mbt/model/ccv_model.qnt | 2 +-
tests/mbt/model/ccv_pss_model.qnt | 5 +++--
5 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/tests/mbt/driver/mbt_test.go b/tests/mbt/driver/mbt_test.go
index c48538b300..0e65d36a7e 100644
--- a/tests/mbt/driver/mbt_test.go
+++ b/tests/mbt/driver/mbt_test.go
@@ -350,7 +350,6 @@ func RunItfTrace(t *testing.T, path string) {
driver.setupConsumer(
chainId,
modelParams,
- &initialValSet,
consumerSigners,
nodes,
valNames,
diff --git a/tests/mbt/driver/setup.go b/tests/mbt/driver/setup.go
index ff0fd744f5..fe2f281190 100644
--- a/tests/mbt/driver/setup.go
+++ b/tests/mbt/driver/setup.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"encoding/json"
"log"
"testing"
@@ -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,
@@ -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)
diff --git a/tests/mbt/model/ccv.qnt b/tests/mbt/model/ccv.qnt
index 9f95abf1df..cd6a42ce52 100644
--- a/tests/mbt/model/ccv.qnt
+++ b/tests/mbt/model/ccv.qnt
@@ -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
diff --git a/tests/mbt/model/ccv_model.qnt b/tests/mbt/model/ccv_model.qnt
index 4bb368ae3f..4c95738947 100644
--- a/tests/mbt/model/ccv_model.qnt
+++ b/tests/mbt/model/ccv_model.qnt
@@ -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
diff --git a/tests/mbt/model/ccv_pss_model.qnt b/tests/mbt/model/ccv_pss_model.qnt
index d2911a0989..a2ff82af3e 100644
--- a/tests/mbt/model/ccv_pss_model.qnt
+++ b/tests/mbt/model/ccv_pss_model.qnt
@@ -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,
From 3f73ba264a9fc27e1a8cc6e568028b396070a272 Mon Sep 17 00:00:00 2001
From: Philip Offtermatt
Date: Mon, 25 Mar 2024 16:20:54 +0100
Subject: [PATCH 2/2] Fix setup
---
tests/mbt/driver/setup.go | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/tests/mbt/driver/setup.go b/tests/mbt/driver/setup.go
index fe2f281190..a2a8d00944 100644
--- a/tests/mbt/driver/setup.go
+++ b/tests/mbt/driver/setup.go
@@ -14,6 +14,8 @@ import (
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/stretchr/testify/require"
+ ce "github.com/cometbft/cometbft/crypto/encoding"
+
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -375,10 +377,6 @@ func (s *Driver) ConfigureNewPath(consumerChain, providerChain *ibctesting.TestC
stakingValidators = append(stakingValidators, v)
}
- considerAll := func(validator stakingtypes.Validator) bool { return true }
- nextValidators := s.providerKeeper().ComputeNextEpochConsumerValSet(s.providerCtx(), string(consumerChainId), stakingValidators, considerAll)
- s.providerKeeper().SetConsumerValSet(s.providerCtx(), string(consumerChainId), nextValidators)
-
err = s.providerKeeper().SetConsumerGenesis(
providerChain.GetContext(),
string(consumerChainId),
@@ -395,6 +393,11 @@ func (s *Driver) ConfigureNewPath(consumerChain, providerChain *ibctesting.TestC
s.providerKeeper().HandleOptIn(s.providerCtx(), consumerChain.ChainID, *addr, nil)
}
+ nextValidators := s.providerKeeper().ComputeNextEpochConsumerValSet(s.providerCtx(), string(consumerChainId), stakingValidators, func(validator stakingtypes.Validator) bool {
+ return s.providerKeeper().ShouldConsiderOnlyOptIn(s.providerCtx(), string(consumerChainId), validator)
+ })
+ s.providerKeeper().SetConsumerValSet(s.providerCtx(), string(consumerChainId), nextValidators)
+
// Client ID is set in InitGenesis and we treat it as a black box. So
// must query it to use it with the endpoint.
clientID, _ := s.consumerKeeper(consumerChainId).GetProviderClientID(s.ctx(consumerChainId))
@@ -482,6 +485,18 @@ func (s *Driver) setupConsumer(
s.coordinator.Chains[chain] = consumerChain
valUpdates := cmttypes.TM2PB.ValidatorUpdates(&initValSet)
+ consumerVals := make([]providertypes.ConsumerValidator, len(initValSet.Validators))
+ for i, val := range initValSet.Validators {
+ pk, err := ce.PubKeyToProto(val.PubKey)
+ require.NoError(s.t, err)
+
+ consumerVals[i] = providertypes.ConsumerValidator{
+ ProviderConsAddr: val.Address,
+ Power: val.VotingPower,
+ ConsumerPublicKey: &pk,
+ }
+ }
+ s.providerKeeper().SetConsumerValSet(s.providerCtx(), chain, consumerVals)
path := s.ConfigureNewPath(consumerChain, providerChain, params, uint32(topN), validatorsToOptIn, valUpdates)
s.simibcs[ChainId(chain)] = simibc.MakeRelayedPath(s.t, path)