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!: make ExportGenesis return proto.Message #12700

Closed
wants to merge 38 commits into from

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Jul 22, 2022

Description

This PR replaces the usage of json.RawMessage for proto.Message in most places where genesis states are being passed.

AppModuleBasic

- DefaultGenesis(codec.JSONCodec) json.RawMessage
+ DefaultGenesis() proto.Message

AppModuleGenesis

- InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate
- ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage
+ InitGenesis(sdk.Context, proto.Message) []abci.ValidatorUpdate
+ ExportGenesis(sdk.Context) proto.Message

Unresolved issues

ModuleManager's still uses map[string]json.RawMessage

I need to figure out how to create a map[string]proto.Message that we can unmarshal values to. Maybe we need to define a new type for this somehow? I need more input on this issue

Closes: #12642


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 API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building 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

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 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
  • manually tested (if applicable)

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.

@codecov
Copy link

codecov bot commented Jul 29, 2022

Codecov Report

Merging #12700 (161ea0e) into main (cb31043) will decrease coverage by 0.00%.
The diff coverage is 55.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12700      +/-   ##
==========================================
- Coverage   56.12%   56.12%   -0.01%     
==========================================
  Files         645      645              
  Lines       54660    54649      -11     
==========================================
- Hits        30680    30670      -10     
- Misses      21505    21506       +1     
+ Partials     2475     2473       -2     
Impacted Files Coverage Δ
simapp/state.go 0.00% <0.00%> (ø)
types/module/simulation.go 0.00% <ø> (ø)
types/utils.go 63.85% <0.00%> (-15.25%) ⬇️
x/feegrant/module/module.go 15.00% <0.00%> (+0.36%) ⬆️
x/params/module.go 20.96% <0.00%> (ø)
x/upgrade/module.go 28.35% <0.00%> (ø)
simapp/test_helpers.go 22.86% <33.33%> (ø)
x/evidence/module.go 45.20% <55.55%> (-0.75%) ⬇️
x/group/module/module.go 51.25% <66.66%> (+0.63%) ⬆️
x/auth/module.go 52.05% <71.42%> (+0.05%) ⬆️
... and 20 more

@alexanderbez
Copy link
Contributor

alexanderbez commented Jul 30, 2022

@marbar3778 should we make a note of something in an upgrading doc?

Great work @facundomedica!

@tac0turtle
Copy link
Member

@marbar3778 should we make a note of something in an upgrading doc?

Yes a short explanation in the upgrading doc is needed

simapp/genesis.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

The cleanup looks great!

types/utils.go Outdated Show resolved Hide resolved
@@ -20,8 +20,8 @@ type AppBuilder struct {

// DefaultGenesis returns a default genesis from the registered
// AppModuleBasic's.
func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage {
return a.app.basicManager.DefaultGenesis(a.app.cdc)
func (a *AppBuilder) DefaultGenesis() map[string]proto.Message {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we break the AppModule interface again once we remove gogoproto?

How hard would it be to use the api/ genesis state today?

Copy link
Member

Choose a reason for hiding this comment

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

pulsar is not production ready from my understanding. We shouldn't force people to use it yet. the interface break is fairly small in the future, if we document then people will be fine with it

simapp/genesis.go Outdated Show resolved Hide resolved
types/module/module.go Outdated Show resolved Hide resolved
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.

LGTM

// to which we then unmarshal the genesis' file JSON into
genType := reflect.TypeOf(m.Modules[moduleName].DefaultGenesis())
if genType == nil {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

I would panic here instead TBH. It's feedback to the app developers that their DefaultGenesis is incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe there were some modules returning empty structs like this: []byte(`{}`) and I translated those to nil. So I'm gonna double check that

Copy link
Member Author

Choose a reason for hiding this comment

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

For example x/auth/vesting and x/upgrade returned this:

func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
	return []byte("{}")
}

@@ -31,8 +31,10 @@
import (
"encoding/json"
"fmt"
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism
Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

This breaks how the orm does genesis. I'm sorry but let's please close

@aaronc
Copy link
Member

aaronc commented Aug 2, 2022

The orm will be unusable with this API change. It relies on raw json being usable. This is not just an API change but removes functionality other code depends on.

If people really want something like this, just have two extension interfaces (current genesis and proto only genesis) and let AppManager type cast.

@facundomedica
Copy link
Member Author

I'm trying out different strategies, so far the main blocker is that 2 of the methods are part of AppModuleBasic:

	DefaultGenesis(codec.JSONCodec) json.RawMessage
	ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error

And these are used everywhere. I think I can make it work but this would disrupt the module pattern described at the top of the types/module.go file :

The module pattern has been broken down by:
 - independent module functionality (AppModuleBasic)
 - inter-dependent module genesis functionality (AppModuleGenesis)
 - inter-dependent module simulation functionality (AppModuleSimulation)
 - inter-dependent module full functionality (AppModule)

@alexanderbez
Copy link
Contributor

I thought we were just defining a new extension interface?

@facundomedica
Copy link
Member Author

I've opened this replacement PR: #12828

@facundomedica facundomedica deleted the facu/import-export-genesis branch August 30, 2022 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can we change ImportGenesis & ExportGenesis to return a proto.Message interface
7 participants