Skip to content

Commit

Permalink
ci: Test that rewards work with sovereign -> consumer changeovers
Browse files Browse the repository at this point in the history
  • Loading branch information
fastfadingviolets committed Oct 22, 2024
1 parent 12ae129 commit 441854b
Show file tree
Hide file tree
Showing 16 changed files with 501 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/interchain-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
matrix:
${{fromJson(needs.prepare-matrix.outputs.matrix)}}
fail-fast: false
max-parallel: 10
max-parallel: 3
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions tests/interchain/chainsuite/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ func (c *Chain) GetValidatorHex(ctx context.Context, val int) (string, error) {
}

func getValidatorWallets(ctx context.Context, chain *Chain) ([]ValidatorWallet, error) {
wallets := make([]ValidatorWallet, ValidatorCount)
wallets := make([]ValidatorWallet, len(chain.Validators))
lock := new(sync.Mutex)
eg := new(errgroup.Group)
for i := 0; i < ValidatorCount; i++ {
for i := range chain.Validators {
i := i
eg.Go(func() error {
// This moniker is hardcoded into the chain's genesis process.
Expand Down
137 changes: 37 additions & 100 deletions tests/interchain/chainsuite/chain_ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"go.uber.org/multierr"
"golang.org/x/mod/semver"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
Expand All @@ -29,18 +28,20 @@ import (
type ConsumerBootstrapCb func(ctx context.Context, consumer *cosmos.CosmosChain)

type ConsumerConfig struct {
ChainName string
Version string
Denom string
ShouldCopyProviderKey [ValidatorCount]bool
TopN int
ValidatorSetCap int
ValidatorPowerCap int
AllowInactiveVals bool
MinStake uint64
Allowlist []string
Denylist []string
spec *interchaintest.ChainSpec
ChainName string
Version string
Denom string
ShouldCopyProviderKey [ValidatorCount]bool
TopN int
ValidatorSetCap int
ValidatorPowerCap int
AllowInactiveVals bool
MinStake uint64
Allowlist []string
Denylist []string
InitialHeight uint64
DistributionTransmissionChannel string
Spec *interchaintest.ChainSpec

DuringDepositPeriod ConsumerBootstrapCb
DuringVotingPeriod ConsumerBootstrapCb
Expand Down Expand Up @@ -124,15 +125,16 @@ func (p *Chain) AddConsumerChain(ctx context.Context, relayer *Relayer, config C
}
}

if config.spec == nil {
config.spec = p.DefaultConsumerChainSpec(ctx, chainID, config, spawnTime, proposalWaiter)
}
if semver.Compare(p.GetNode().ICSVersion(ctx), "v4.1.0") > 0 && config.spec.InterchainSecurityConfig.ProviderVerOverride == "" {
config.spec.InterchainSecurityConfig.ProviderVerOverride = "v4.1.0"
defaultSpec := p.DefaultConsumerChainSpec(ctx, chainID, config, spawnTime, proposalWaiter)
config.Spec = MergeChainSpecs(defaultSpec, config.Spec)
providerICS := p.GetNode().ICSVersion(ctx)
if config.Spec.InterchainSecurityConfig.ConsumerVerOverride == "" {
// This will disable the genesis transform
config.Spec.InterchainSecurityConfig.ConsumerVerOverride = providerICS
}
cf := interchaintest.NewBuiltinChainFactory(
GetLogger(ctx),
[]*interchaintest.ChainSpec{config.spec},
[]*interchaintest.ChainSpec{config.Spec},
)
chains, err := cf.Chains(p.GetNode().TestName)
if err != nil {
Expand Down Expand Up @@ -203,7 +205,7 @@ func (p *Chain) AddConsumerChain(ctx context.Context, relayer *Relayer, config C
if err := relayer.StartRelayer(ctx, rep); err != nil {
return nil, err
}
err = connectProviderConsumer(ctx, p, consumer, relayer)
err = relayer.ConnectProviderConsumer(ctx, p, consumer)
if err != nil {
return nil, err
}
Expand All @@ -212,17 +214,22 @@ func (p *Chain) AddConsumerChain(ctx context.Context, relayer *Relayer, config C
}

func (p *Chain) CreateConsumerPermissionless(ctx context.Context, chainID string, config ConsumerConfig, spawnTime time.Time) error {
revisionHeight := config.InitialHeight
if revisionHeight == 0 {
revisionHeight = 1
}
initParams := &providertypes.ConsumerInitializationParameters{
InitialHeight: clienttypes.Height{RevisionNumber: clienttypes.ParseChainID(chainID), RevisionHeight: 1},
InitialHeight: clienttypes.Height{RevisionNumber: clienttypes.ParseChainID(chainID), RevisionHeight: revisionHeight},
SpawnTime: spawnTime,
BlocksPerDistributionTransmission: 1000,
BlocksPerDistributionTransmission: BlocksPerDistribution,
CcvTimeoutPeriod: 2419200000000000,
TransferTimeoutPeriod: 3600000000000,
ConsumerRedistributionFraction: "0.75",
HistoricalEntries: 10000,
UnbondingPeriod: 1728000000000000,
GenesisHash: []byte("Z2VuX2hhc2g="),
BinaryHash: []byte("YmluX2hhc2g="),
DistributionTransmissionChannel: config.DistributionTransmissionChannel,
}
powerShapingParams := &providertypes.PowerShapingParameters{
Top_N: 0,
Expand Down Expand Up @@ -453,83 +460,6 @@ func (p *Chain) DefaultConsumerChainSpec(ctx context.Context, chainID string, co
}
}

func connectProviderConsumer(ctx context.Context, provider *Chain, consumer *Chain, relayer *Relayer) error {
icsPath := relayerICSPathFor(provider, consumer)
rep := GetRelayerExecReporter(ctx)
if err := relayer.GeneratePath(ctx, rep, consumer.Config().ChainID, provider.Config().ChainID, icsPath); err != nil {
return err
}

consumerClients, err := relayer.GetClients(ctx, rep, consumer.Config().ChainID)
if err != nil {
return err
}

var consumerClient *ibc.ClientOutput
for _, client := range consumerClients {
if client.ClientState.ChainID == provider.Config().ChainID {
consumerClient = client
break
}
}
if consumerClient == nil {
return fmt.Errorf("consumer chain %s does not have a client tracking the provider chain %s", consumer.Config().ChainID, provider.Config().ChainID)
}
consumerClientID := consumerClient.ClientID

providerClients, err := relayer.GetClients(ctx, rep, provider.Config().ChainID)
if err != nil {
return err
}

var providerClient *ibc.ClientOutput
for _, client := range providerClients {
if client.ClientState.ChainID == consumer.Config().ChainID {
providerClient = client
break
}
}
if providerClient == nil {
return fmt.Errorf("provider chain %s does not have a client tracking the consumer chain %s for path %s on relayer %s",
provider.Config().ChainID, consumer.Config().ChainID, icsPath, relayer)
}
providerClientID := providerClient.ClientID

if err := relayer.UpdatePath(ctx, rep, icsPath, ibc.PathUpdateOptions{
SrcClientID: &consumerClientID,
DstClientID: &providerClientID,
}); err != nil {
return err
}

if err := relayer.CreateConnections(ctx, rep, icsPath); err != nil {
return err
}

if err := relayer.CreateChannel(ctx, rep, icsPath, ibc.CreateChannelOptions{
SourcePortName: "consumer",
DestPortName: "provider",
Order: ibc.Ordered,
Version: "1",
}); err != nil {
return err
}

tCtx, tCancel := context.WithTimeout(ctx, 30*CommitTimeout)
defer tCancel()
for tCtx.Err() == nil {
var ch *ibc.ChannelOutput
ch, err = relayer.GetTransferChannel(ctx, provider, consumer)
if err == nil && ch != nil {
break
} else if err == nil {
err = fmt.Errorf("channel not found")
}
time.Sleep(CommitTimeout)
}
return err
}

func (p *Chain) SubmitConsumerAdditionProposal(ctx context.Context, chainID string, config ConsumerConfig, spawnTime time.Time) (*proposalWaiter, chan error, error) {
propWaiter := newProposalWaiter()
prop := p.buildConsumerAdditionJSON(chainID, config, spawnTime)
Expand Down Expand Up @@ -577,7 +507,7 @@ func (p *Chain) buildConsumerAdditionJSON(chainID string, config ConsumerConfig,
BinaryHash: []byte("bin_hash"),
SpawnTime: spawnTime,

BlocksPerDistributionTransmission: 1000,
BlocksPerDistributionTransmission: BlocksPerDistribution,
CcvTimeoutPeriod: 2419200000000000,
TransferTimeoutPeriod: 3600000000000,
ConsumerRedistributionFraction: "0.75",
Expand Down Expand Up @@ -646,6 +576,13 @@ func (p *Chain) CheckCCV(ctx context.Context, consumer *Chain, relayer *Relayer,
}
}

if err := relayer.ClearCCVChannel(ctx, p, consumer); err != nil {
return err
}
if err := testutil.WaitForBlocks(ctx, 2, p, consumer); err != nil {
return err
}

tCtx, tCancel := context.WithTimeout(ctx, 15*time.Minute)
defer tCancel()
var retErr error
Expand Down
57 changes: 34 additions & 23 deletions tests/interchain/chainsuite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,44 @@ const (
SlashingWindowConsumer = 20
BlocksPerDistribution = 10
StrideVersion = "v22.0.0"
NeutronVersion = "v3.0.2"
TransferPortID = "transfer"
// This is needed because not every ics image is in the default heighliner registry
HyphaICSRepo = "ghcr.io/hyphacoop/ics"
ICSUidGuid = "1025:1025"
)

func (c SuiteConfig) Merge(other SuiteConfig) SuiteConfig {
if c.ChainSpec == nil {
c.ChainSpec = other.ChainSpec
} else if other.ChainSpec != nil {
c.ChainSpec.ChainConfig = c.ChainSpec.MergeChainSpecConfig(other.ChainSpec.ChainConfig)
if other.ChainSpec.Name != "" {
c.ChainSpec.Name = other.ChainSpec.Name
}
if other.ChainSpec.ChainName != "" {
c.ChainSpec.ChainName = other.ChainSpec.ChainName
}
if other.ChainSpec.Version != "" {
c.ChainSpec.Version = other.ChainSpec.Version
}
if other.ChainSpec.NoHostMount != nil {
c.ChainSpec.NoHostMount = other.ChainSpec.NoHostMount
}
if other.ChainSpec.NumValidators != nil {
c.ChainSpec.NumValidators = other.ChainSpec.NumValidators
}
if other.ChainSpec.NumFullNodes != nil {
c.ChainSpec.NumFullNodes = other.ChainSpec.NumFullNodes
}
func MergeChainSpecs(spec, other *interchaintest.ChainSpec) *interchaintest.ChainSpec {
if spec == nil {
return other
}
if other == nil {
return spec
}
spec.ChainConfig = spec.MergeChainSpecConfig(other.ChainConfig)
if other.Name != "" {
spec.Name = other.Name
}
if other.ChainName != "" {
spec.ChainName = other.ChainName
}
if other.Version != "" {
spec.Version = other.Version
}
if other.NoHostMount != nil {
spec.NoHostMount = other.NoHostMount
}
if other.NumValidators != nil {
spec.NumValidators = other.NumValidators
}
if other.NumFullNodes != nil {
spec.NumFullNodes = other.NumFullNodes
}
return spec
}

func (c SuiteConfig) Merge(other SuiteConfig) SuiteConfig {
c.ChainSpec = MergeChainSpecs(c.ChainSpec, other.ChainSpec)
c.UpgradeOnSetup = other.UpgradeOnSetup
c.CreateRelayer = other.CreateRelayer
c.Scope = other.Scope
Expand Down
Loading

0 comments on commit 441854b

Please sign in to comment.