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

Per-module genesis initialization #714

Merged
merged 3 commits into from
Mar 28, 2018
Merged

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Mar 27, 2018

Work in progress, more tests to come.

@rigelrozanski Thoughts?

@cwgoes cwgoes requested a review from ebuchman as a code owner March 27, 2018 18:06

/* Run only once on chain initialization, should write genesis state to store
or throw an error if some required information was not provided, in which case
the application will panic. */
Copy link
Contributor

Choose a reason for hiding this comment

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

// comment
// like
// this

@codecov
Copy link

codecov bot commented Mar 27, 2018

Codecov Report

Merging #714 into develop will decrease coverage by 0.23%.
The diff coverage is 54.16%.

@@            Coverage Diff             @@
##           develop    #714      +/-   ##
==========================================
- Coverage    64.04%   63.8%   -0.24%     
==========================================
  Files           43      43              
  Lines         2022    2039      +17     
==========================================
+ Hits          1295    1301       +6     
- Misses         615     623       +8     
- Partials       112     115       +3

{
Name: "tester",
Address: pubKey.Address(),
Coins: coins,
},
},
"cool": map[string]string{
"trend": "ice-cold",
},
Copy link
Contributor

@rigelrozanski rigelrozanski Mar 27, 2018

Choose a reason for hiding this comment

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

lcd_test should have nothing to do cool module

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree but must be included for this test to pass until that test refactoring happens.

}
}
return nil
})
Copy link
Contributor

@rigelrozanski rigelrozanski Mar 27, 2018

Choose a reason for hiding this comment

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

This is confusing... we should make a bit simpler - let's breakout this function variable definition to another line before line 244

return nil
}

func (rtr *router) ForEach(f func(string, sdk.Handler, sdk.InitGenesis) error) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need a comment, enable go-metalinter

Copy link
Contributor

Choose a reason for hiding this comment

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

we should make func(string, sdk.Handler, sdk.InitGenesis) error a type

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a different name than ForEach - or better explanation

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of ForEach let's create something called InitModules which performs the loop over all the modules.... if this is possible

return route.h
}
}
return nil
}

func (rtr *router) RouteGenesis(path string) (i sdk.InitGenesis) {
Copy link
Contributor

Choose a reason for hiding this comment

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

high level comment

types.NewGenesisAccount(acc),
},
"cool": map[string]string{
"trend": "ice-cold",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

is there another way than using a map here? I know it's safe

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe fine - what are our options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other option - pass bytestring directly - means we'd have to use printf for variable parameters, though, seems ugly.

@@ -180,7 +180,7 @@ func TestInitChainer(t *testing.T) {

// set initChainer and try again - should see the value
app.SetInitChainer(initChainer)
app.InitChain(abci.RequestInitChain{})
app.InitChain(abci.RequestInitChain{AppStateBytes: []byte("{}")})
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment explaining this change

// TODO Return something intelligent
panic(err)
}
err = app.Router().ForEach(func(r string, _ sdk.Handler, i sdk.InitGenesis) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

should reference a type which is that func(r string, _ sdk.Handler, i sdk.InitGenesis) error

encoded, exists := (*genesisState)[r]
if !exists {
// TODO should this be a Cosmos SDK standard error?
return errors.New(fmt.Sprintf("Expected module genesis information for module %s but it was not present", r))
Copy link
Contributor

Choose a reason for hiding this comment

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

can use fmt.Errorf instead here

if i != nil {
encoded, exists := (*genesisState)[r]
if !exists {
// TODO should this be a Cosmos SDK standard error?
Copy link
Contributor

Choose a reason for hiding this comment

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

yes... let's do it!

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

hecka yeah

@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 27, 2018

@rigelrozanski hecka refactored

Still need to rebase onto keeper-modules though.

@cwgoes cwgoes force-pushed the cwgoes/per-module-genesis branch from 2f1407e to 5dc13d0 Compare March 27, 2018 21:21
@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 27, 2018

Rebased onto #690

@rigelrozanski
Copy link
Contributor

aight yo - merged in - rebase can commence!

@cwgoes cwgoes force-pushed the cwgoes/per-module-genesis branch from 5dc13d0 to cd650b3 Compare March 28, 2018 09:22
@cwgoes cwgoes force-pushed the cwgoes/per-module-genesis branch from cd650b3 to 90304fc Compare March 28, 2018 09:25
@cwgoes
Copy link
Contributor Author

cwgoes commented Mar 28, 2018

Rerebased

All the test changes can be reverted when democoin is separated (#695 (comment))

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

great work!

@rigelrozanski rigelrozanski changed the title WIP: Per-module genesis initialization Per-module genesis initialization Mar 28, 2018
@rigelrozanski rigelrozanski merged commit 144ea05 into develop Mar 28, 2018
@rigelrozanski rigelrozanski deleted the cwgoes/per-module-genesis branch March 28, 2018 16:29
"regexp"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// Router provides handlers for each transaction type.
type Router interface {
AddRoute(r string, h sdk.Handler) (rtr Router)
AddRoute(r string, h sdk.Handler, i sdk.InitGenesis) (rtr Router)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this.

What makes InitGenesis different from BeginBlock and EndBlock that it gets this special treatment ?

See also my thoughts in #559 (which I don't think Jae agrees with, but anyways).

In the absence of doing this, modules should export methods that can be called by the InitChain function that is stitched together by the application and passed to SetInitChain

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem mostly lies routing the correct genesis option to the correct module. I think we want to enforce a basic structure as to how genesis information is passed from the genesis block directly to the module to handle. Right now we simply pass a json.rawmessage contained by a key with the module with the matching name, the module can parse / handle the raw message in arbitrary ways. I don't really see the advantage of customizable global application init genesis method... right now the only reason this is necessary is you are extending the standard account. Anyways let's talk more about this

Copy link
Contributor

Choose a reason for hiding this comment

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

What makes InitGenesis different from BeginBlock and EndBlock that it gets this special treatment ?

we need to route genesis information based on the key provided in genesis. BeginBlock/EndBlock do not need to route custom information - I also assume that BeginBlock/EndBlock handlers may have some interdependence whereas InitGenesis will not

further thoughts? - maybe we should break this out into a discussion issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rigelrozanski Discussion issue: #759

@ebuchman ebuchman mentioned this pull request Mar 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants