Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update E2E infra to support more than 2 chains #6524

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Jun 6, 2024

Description

This PR removes a lot of the ChainA/ChainB assumptions within our E2Es to allow for tests with more than 2 chains to be spun up.

Note: this is not exhaustive, there are still some helper/utility functions that assume a 2 chain environment. This PR enables N chains to be created, and for them to be linked via connections/channels by the relayer.

A stub test has been added which verifies that this works, and can be reworked as part of the transfer forwarding work.

closes: #6242


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Copy link
Contributor

coderabbitai bot commented Jun 6, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.


relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions(), func(options *testsuite.ChainOptions) {
// copy all values of existing chains and tweak to make unique to new chain.
chainCSpec := *options.ChainSpecs[0] // nolint
Copy link
Contributor Author

@chatton chatton Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was complaining about copying a lock, I think we can ignore since we'll be refactoring this entire test later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering about this API to set up chains. Rather than having to do this manipulation of the options, couldn't we simply have a couple of configs that we could use (two-chain, three-chain, whatever) where we use two-chain by default and we can just have something like s.UseTestConfig(testsuite.ThreeChainConfig). It would make the intent a little clearer (and shorter). I guess it depends how much we will use different configs, but just an idea.

(This is more on side of this PR, just wanted to write it while I had it in mind...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a nice idea, I think we can do something similar to where we have s.TransferChannelOptions(). The 3rd chain will likely be the same in every test that needs it, so we can default to 2. Then provide a standard default for the 3 chain setup.

@chatton chatton marked this pull request as ready for review June 6, 2024 14:52
@chatton chatton changed the title Update E2E infra to support more than 2 chains [DONT REVIEW] Update E2E infra to support more than 2 chains Jun 6, 2024
@chatton chatton changed the title [DONT REVIEW] Update E2E infra to support more than 2 chains Update E2E infra to support more than 2 chains Jun 6, 2024
@chatton chatton requested a review from gjermundgaraba as a code owner June 11, 2024 08:20

relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions(), func(options *testsuite.ChainOptions) {
// copy all values of existing chains and tweak to make unique to new chain.
chainCSpec := *options.ChainSpecs[0] // nolint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering about this API to set up chains. Rather than having to do this manipulation of the options, couldn't we simply have a couple of configs that we could use (two-chain, three-chain, whatever) where we use two-chain by default and we can just have something like s.UseTestConfig(testsuite.ThreeChainConfig). It would make the intent a little clearer (and shorter). I guess it depends how much we will use different configs, but just an idea.

(This is more on side of this PR, just wanted to write it while I had it in mind...)

@chatton
Copy link
Contributor Author

chatton commented Jun 11, 2024

@gjermundgaraba I created a re-usable function ThreeChainSetup that can be passed in like

relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions(), testsuite.ThreeChainSetup())

How does this look to you?

@gjermundgaraba
Copy link
Contributor

@gjermundgaraba I created a re-usable function ThreeChainSetup that can be passed in like

relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, s.TransferChannelOptions(), testsuite.ThreeChainSetup())

How does this look to you?

Yeah, that reads much better :)

@chatton
Copy link
Contributor Author

chatton commented Jun 11, 2024

the new way broke the setup, looking into it now

@chatton chatton added the priority PRs that need prompt reviews label Jun 11, 2024
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, thanks @chatton for updating this flow! Happy with the changes and we can iterate as needed

@@ -240,8 +292,9 @@ func (s *E2ETestSuite) GetPathName(idx int64) string {
}

// generatePath generates the path name using the test suites name
func (s *E2ETestSuite) generatePath(ctx context.Context, ibcrelayer ibc.Relayer) string {
chainA, chainB := s.GetChains()
func (s *E2ETestSuite) generatePath(ctx context.Context, ibcrelayer ibc.Relayer, chainAIdx, chainBIdx int) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update godoc? The idea here is that if we want to generate a path between chainA and chainC, we provide the args 0, 2?

@@ -143,13 +131,76 @@ func (s *E2ETestSuite) GetRelayerUsers(ctx context.Context, chainOpts ...ChainOp
// with E2ETestSuite.StartRelayer if needed.
// This should be called at the start of every test, unless fine grained control is required.
func (s *E2ETestSuite) SetupChainsRelayerAndChannel(ctx context.Context, channelOpts func(*ibc.CreateChannelOptions), chainSpecOpts ...ChainOptionConfiguration) (ibc.Relayer, ibc.ChannelOutput) {
chainA, chainB := s.GetChains(chainSpecOpts...)
r := s.ConfigureRelayer(ctx, chainA, chainB, channelOpts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need the ConfigureRelayer function if its contents have been moved here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need it for now as it's used in the wasm tests here

This can be refactored in a follow up I think.

channelOptions := ibc.DefaultChannelOpts()
// For now, set the version to the latest transfer module version
// DefaultChannelOpts uses V1 at the moment
channelOptions.Version = transfertypes.V2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous code path handled backwards compatibility, this is still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, will pull in those changes here

Comment on lines +192 to +196
var chainHeighters []test.ChainHeighter
for _, c := range chains {
chainHeighters = append(chainHeighters, c)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are chain heighters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a type defined in interchain test which is an argument for the WaitForBlocks function. the ibc.Chain interface implemnts the ChainHeighter interface, however it does not seem to be possible to pass in a list of ibc.Chain.

For example this is valid

s.Require().NoError(test.WaitForBlocks(ctx, 10, chains[0], chains[1]), "failed to wait for blocks")

but this in invalid

s.Require().NoError(test.WaitForBlocks(ctx, 10, chains...), "failed to wait for blocks")

A conversion to the interface seems to be required for variable argument functions.

testsuite.E2ETestSuite
}

// TODO: replace this with actual tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

ctx := context.TODO()
t := s.T()

// TODO: note the ThreeChainSetup fn needs to be passed to TransferChannelOptions since it calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Comment on lines +670 to +686
func defaultChannelOpts(chains []ibc.Chain) ibc.CreateChannelOptions {
channelOptions := ibc.DefaultChannelOpts()
channelOptions.Version = determineDefaultTransferVersion(chains)
return channelOptions
}

// determineDefaultTransferVersion determines the version of transfer that should be used with an arbitrary number of chains.
// the default is V2, but if any chain does not support V2, then V1 is used.
func determineDefaultTransferVersion(chains []ibc.Chain) string {
for _, chain := range chains {
chainVersion := chain.Config().Images[0].Version
if !testvalues.ICS20v2FeatureReleases.IsSupported(chainVersion) {
return transfertypes.V1
}
}
return transfertypes.V2
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code which determines the default transfer v2 version to account for multiple chains. I think this reads a lot nicer and is easier to reason about.

cc @colin-axner

Comment on lines +350 to +351
chains := s.GetAllChains()
chainA, chainB := chains[0], chains[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this still equivalent to s.GetChains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think I refactored this to remove get chains then actually re-added it to cause less disruption in existing tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, idea is to completely rm afterwards? Fine with that approach, the flow of GetAllChains and then grabbing what you need serves as a guide of how many chains you'll use.

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wizardly as always! fine to address minor things in follow ups!

Copy link

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
11 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@chatton chatton added this pull request to the merge queue Jun 12, 2024
Merged via the queue into main with commit 2b887d7 Jun 12, 2024
87 of 89 checks passed
@chatton chatton deleted the cian/issue#6242-update-e2e-infrastructure-to-be-able-to-spin-up-3-or-more-chains branch June 12, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update e2e infrastructure to be able to spin up 3 or more chains
4 participants