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

simapp: rename MakeEncodingConfig to MakeTestEncodingConfig #7681

Merged
merged 3 commits into from
Oct 27, 2020

Conversation

robert-zaremba
Copy link
Collaborator

@robert-zaremba robert-zaremba commented Oct 26, 2020

Description

Temporal solution for #7642

Refactoring MakeEncodingConfig is a bigger work. For the Stargate release we want to make it clear to the users that this method is rather internal and deprecated to use in their apps.


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 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.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

+ Adding DEPRECATED attribute.
@@ -34,7 +34,7 @@ var (
},
}

encodingConfig = simapp.MakeEncodingConfig()
encodingConfig = simapp.MakeTestEncodingConfig()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any idea how we should update this README file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seams that the MakeTestEncodingConfig is needed to users who want to use cli.

Copy link
Member

Choose a reason for hiding this comment

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

No it shouldn't be. Not sure why this is here.

Copy link
Member

Choose a reason for hiding this comment

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

That example code needs to be rewritten to not use EncodingConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No it shouldn't be. Not sure why this is here.

Another point that this task is useful ;)

@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #7681 into master will not change coverage.
The diff coverage is 73.07%.

@@           Coverage Diff           @@
##           master    #7681   +/-   ##
=======================================
  Coverage   54.14%   54.14%           
=======================================
  Files         611      611           
  Lines       38558    38558           
=======================================
  Hits        20876    20876           
  Misses      15550    15550           
  Partials     2132     2132           

@@ -38,7 +38,7 @@ import (
// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := simapp.MakeEncodingConfig()
encodingConfig := simapp.MakeTestEncodingConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is hte line being referenced in the documentation at server/README.md. I know that "simapp" in generally is mainly for testing purposes, but it seems strange to call this MakeTestEncodingConfig here, when from what I understand users will mostly be copying a lot of simapp/simd code into their own application when building their own chains.

Perhaps its fine if we have a better strategy for users than looking at simapp/ code when bootstrapping their own app.

@aaronc when you said that we shouldint depend on EncodingConfig at all in the server/README.md, what do you suggest we do here instead? explicitly do all the interface registry stuff here in this function to make it super clear ?

Copy link
Contributor

Choose a reason for hiding this comment

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

MakeTestEncodingConfig is just the wrong name for this function I'd say. What was the rationale in the first place?

Copy link
Member

@aaronc aaronc Oct 27, 2020

Choose a reason for hiding this comment

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

It's just for switching between amino and protobuf builds.

I don't think simapp is intended to be a reference for apps. The tutorial is for that. Simd was only added during stargate work for testing it was never intended as a reference.

If we want to make simapp a reference for apps we should pull out all the legacy stuff and fully deprecate amino support which will allow EncodingConfig to go away.

Apps should just create a codec and register interfaces as needed. There is a reason why EncodingConfig is in simapp and not part of the SDK proper.

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes sense to me, thanks. Yet IMHO the MakeTestEncodingConfig name does not suggest anything like that and MakeEncodingConfig seems still the best name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alessio - please check the referenced issue: #7642

I'm open for a better name suggestions. As stated in this PR, it's a temporal solution to make it clear for the users that they shouldn't use this method.

@@ -432,7 +432,7 @@ func NewSimApp(
// simapp. It is useful for tests and clients who do not want to construct the
// full simapp
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
config := MakeEncodingConfig()
config := MakeTestEncodingConfig()
Copy link
Contributor

@amaury1093 amaury1093 Oct 27, 2020

Choose a reason for hiding this comment

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

Suggested change
config := MakeTestEncodingConfig()
config := simappparams.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(config.Amino)
std.RegisterInterfaces(config.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(config.Amino)
ModuleBasics.RegisterInterfaces(config.InterfaceRegistry)

How about:

  1. Move simapp/encoding.go to testutil/encoding.go (That's where it really belongs)
  2. Make the above change (as per simapp: rename MakeEncodingConfig to MakeTestEncodingConfig #7681 (comment), "Apps should just create a codec and register interfaces as needed.")

Advantages:

  • MakeTestEncodingConfig lives in testutil, which makes sense.
  • For users looking at simapp as a reference implementation, they will do registration directly in NewSimApp as above. This imports MakeEncodingConfig from ./params, which is okay.

Disadvantages:

  • We write twice the registration (once for tests, once for reference). It's only executed once though).

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach! 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what we want to do in #7642. This PR, as noted in the description, is a temporal solution for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact what we want to do in #7642 is to hide the MakeTestEncodingConfig in a private method, and use app.AppCodecs outside.

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

I think this change is still an improvement. It's not perfect, but "perfect" requires a way bigger refactoring. So I'm okay to merge this now.

@robert-zaremba robert-zaremba added T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine). A:automerge Automatically merge PR once all prerequisites pass. labels Oct 27, 2020
@mergify mergify bot merged commit 9bd42ac into master Oct 27, 2020
@mergify mergify bot deleted the robert/makeencodingconfig branch October 27, 2020 11:33
clevinson pushed a commit that referenced this pull request Oct 29, 2020
* simapp: rename MakeEncodingConfig to MakeTestEncodingConfig

* Updating the Changelog

+ Adding DEPRECATED attribute.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
)

* simapp: rename MakeEncodingConfig to MakeTestEncodingConfig

* Updating the Changelog

+ Adding DEPRECATED attribute.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants