-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
types/initgenesis.go
Outdated
|
||
/* 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. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// comment
// like
// this
Codecov Report
@@ 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", | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
baseapp/baseapp.go
Outdated
} | ||
} | ||
return nil | ||
}) |
There was a problem hiding this comment.
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
baseapp/router.go
Outdated
return nil | ||
} | ||
|
||
func (rtr *router) ForEach(f func(string, sdk.Handler, sdk.InitGenesis) error) error { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
baseapp/router.go
Outdated
return route.h | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (rtr *router) RouteGenesis(path string) (i sdk.InitGenesis) { |
There was a problem hiding this comment.
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", | ||
}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
baseapp/baseapp_test.go
Outdated
@@ -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("{}")}) |
There was a problem hiding this comment.
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
baseapp/baseapp.go
Outdated
// TODO Return something intelligent | ||
panic(err) | ||
} | ||
err = app.Router().ForEach(func(r string, _ sdk.Handler, i sdk.InitGenesis) error { |
There was a problem hiding this comment.
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
baseapp/baseapp.go
Outdated
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)) |
There was a problem hiding this comment.
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
baseapp/baseapp.go
Outdated
if i != nil { | ||
encoded, exists := (*genesisState)[r] | ||
if !exists { | ||
// TODO should this be a Cosmos SDK standard error? |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hecka yeah
@rigelrozanski hecka refactored Still need to rebase onto keeper-modules though. |
2f1407e
to
5dc13d0
Compare
Rebased onto #690 |
aight yo - merged in - rebase can commence! |
5dc13d0
to
cd650b3
Compare
cd650b3
to
90304fc
Compare
Rerebased All the test changes can be reverted when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work!
"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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rigelrozanski Discussion issue: #759
Work in progress, more tests to come.
@rigelrozanski Thoughts?