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

refactor!: Split out consumer genesis state #1324

Merged
merged 20 commits into from
Oct 13, 2023

Conversation

bermuell
Copy link
Contributor

@bermuell bermuell commented Sep 22, 2023

Description

Closes: #1214

Refacoring shared data between provider and consumer.

Note: This breaks json format used by augmenting Genesis files of consumer chains with consumer genesis content exported from provider chain. Consumer Genesis content exported from a provider chain using major version 1,2 or3 of the provider module needs to be transformed with the transformation command introduced by this PR:

Transform the consumer genesis file from a provider version v1,v2 or v3 to a version supported by this consumer. Result is printed to STDOUT.

Example:
$ <appd> transform /path/to/ccv_consumer_genesis.json

Usage:
  interchain-security-cd genesis transform [genesis-file] [flags]

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • Included the correct type prefix in the PR title
  • Added ! to the type prefix if state-machine breaking change (i.e., requires coordinated upgrade)
  • Confirmed this PR does not introduce changes requiring state migrations, OR migration code has been added to consumer and/or provider modules
  • Targeted the correct branch (see PR Targeting)
  • Provided a link to the relevant issue or specification
  • Followed the guidelines for building SDK modules
  • Included the necessary unit and integration tests
  • Added a changelog entry to CHANGELOG.md
  • Included comments for documenting Go code
  • Updated the relevant documentation or specification
  • Reviewed "Files changed" and left comments if necessary
  • Confirmed all CI checks have passed
  • If this PR is library API breaking, bump the go.mod version string of the repo, and follow through on a new major release for both the consumer and provider

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed this PR does not introduce changes requiring state migrations, OR confirmed migration code has been added to consumer and/or provider modules
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage

@github-actions github-actions bot added C:Testing Assigned automatically by the PR labeler C:x/consumer Assigned automatically by the PR labeler C:x/provider Assigned automatically by the PR labeler C:x/types Assigned automatically by the PR labeler labels Sep 22, 2023
@bermuell bermuell force-pushed the bernd/1214-splitConsumerGenesis branch from 92d02bd to 32ad930 Compare September 22, 2023 13:50
@MSalopek MSalopek assigned bermuell and unassigned MSalopek and shaspitz Sep 22, 2023
@MSalopek
Copy link
Contributor

MSalopek commented Sep 25, 2023

The refactor looks good, thanks for the awesome work!

What is a bit unclear to me is if we should maintain backward compatibility with regards to responses from the consumer-genesis provider query:

interchain-security-pd query provider consumer-genesis <chain-id>

The structure returned by this query is an integral part of starting a consumer chain, so maybe we should address the issue of provider-consumer version compatibility.

This is the scenario I'm trying to solve:

  1. consumer is on the newest version of ICS (ICS@latest)
  2. provider is on an old version of ICS ([email protected])
  3. after spawn_time the consumer_genesis becomes available on the provider
  4. the consumer queries the provider for the consumer_genesis
  5. the consumer cannot parse the consumer_genesis in the format sent by the provider chain when doing interchain-security-pd query provider consumer-genesis <chain-id> since the provider is sending an old version of the genesis

It seems to me that this issue can be solved by parsing the "old" genesis into the "new" genesis:

interchain-security-cd parse-genesis v1 <path_to_v1_genesis>

# output of this cmd is a genesis that the consumer can process (ICS@latest)

If the provider and consumer are on the same ICS version there are no compatibility issues.

@bermuell
Copy link
Contributor Author

bermuell commented Sep 26, 2023

thanks @MSalopek for your comment.
Your scenario is the exactly the one we need to provide a way to deal with it.

I'll look into that and provide migration code for my changes

@shaspitz
Copy link
Contributor

Matija's suggestion of creating a new parsing function sounds solid to me with appropriate docs for the procedure 👍

@bermuell bermuell force-pushed the bernd/1214-splitConsumerGenesis branch 2 times, most recently from 8c2a751 to 6731b7c Compare October 3, 2023 12:29
@bermuell bermuell force-pushed the bernd/1214-splitConsumerGenesis branch 3 times, most recently from ed13e20 to 9d7c31f Compare October 5, 2023 14:53
@bermuell bermuell force-pushed the bernd/1214-splitConsumerGenesis branch from 9d7c31f to 8326811 Compare October 5, 2023 14:59
@bermuell bermuell changed the title refactor! Split out consumer genesis state refactor Split out consumer genesis state Oct 5, 2023
@bermuell bermuell marked this pull request as ready for review October 5, 2023 16:20
@bermuell bermuell requested a review from a team as a code owner October 5, 2023 16:20
//
// Note: this type is only used on consumer side and references shared types with
// provider
message GenesisState {
Copy link
Contributor

Choose a reason for hiding this comment

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

In #1288 we renamed the consumer's GenesisState struct to ConsumerGenesisState, is there a reason why we change it back in this PR?

Copy link
Contributor Author

@bermuell bermuell Oct 6, 2023

Choose a reason for hiding this comment

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

We changed it in the shared type namespace to make it clear that it's consumer related. This type is the result of the split and resides in the consumer namespaces so no need to repeat that in the name. The shared one kept its name

TransformationMap map[string]TransformationCallback
)

// Migration of consumer genesis content as it is exported from a provider version v2
Copy link
Contributor

Choose a reason for hiding this comment

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

Prob need some clarification on the use of "v2" and "v3" here, it seems like the term is applied to both consumer and provider. Are we referring to ICS major versions?

Copy link
Contributor Author

@bermuell bermuell Oct 6, 2023

Choose a reason for hiding this comment

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

Yes this is the major version of ICS modules we refer here.

@bermuell bermuell requested a review from shaspitz October 10, 2023 07:44
@MSalopek
Copy link
Contributor

@bermuell docs are needed for the change to CLI.

@MSalopek MSalopek changed the title refactor Split out consumer genesis state refactor!: Split out consumer genesis state Oct 10, 2023
app/consumer/genesis.go Outdated Show resolved Hide resolved
app/consumer/genesis.go Outdated Show resolved Hide resolved
app/consumer/genesis.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the C:Docs Assigned automatically by the PR labeler label Oct 11, 2023
@bermuell bermuell force-pushed the bernd/1214-splitConsumerGenesis branch from f8b2524 to 6d94ef8 Compare October 11, 2023 09:24
@bermuell bermuell requested a review from sainoe October 11, 2023 15:53
Copy link
Contributor

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

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

LGTM!

cmd := &cobra.Command{
Use: "transform [genesis-file]",
Short: "Transform CCV consumer genesis from an older provider version not supporting current format",
Long: fmt.Sprintf(`Transform the consumer genesis file from a provider version v1,v2 or v3 to a version supported by this consumer. Result is printed to STDOUT.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: perhaps add a strings.TrimSpace() call here

@sainoe sainoe self-requested a review October 13, 2023 13:57
Copy link
Contributor

@sainoe sainoe left a comment

Choose a reason for hiding this comment

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

LGTM! See my comment.

@bermuell bermuell merged commit 946f6ec into main Oct 13, 2023
13 of 15 checks passed
@bermuell bermuell deleted the bernd/1214-splitConsumerGenesis branch October 13, 2023 15:04
MSalopek pushed a commit that referenced this pull request Dec 1, 2023
Refactor consumer genesis state
* Split ConsumerGenesis datatype
* Move other non-shared types to consumer
* fix some protbuf lint issues
* make proto-format
* Rename PrivateConsumerGenesisState to GenesisState
* Fix linter issues
* Correct some proto buf
* Protobuf use deprecated instead of reserved
* Add genesis transformation command to interchain-security-cd
* Remove unused field from test data
* Added some basic checks
* Fix linter warnings
* Added test
* Minor test fixes + lint warnings
* Fix lint warning
* Updated comment
* Addressed comments
* Update docs
* Addressed comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Docs Assigned automatically by the PR labeler C:Testing Assigned automatically by the PR labeler C:x/consumer Assigned automatically by the PR labeler C:x/provider Assigned automatically by the PR labeler C:x/types Assigned automatically by the PR labeler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split out consumer genesis state
4 participants