-
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
simapp: use tmjson on InitChainer #7514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/gorilla/mux" | ||
"github.com/rakyll/statik/fs" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
tmjson "github.com/tendermint/tendermint/libs/json" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmos "github.com/tendermint/tendermint/libs/os" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
@@ -450,7 +451,9 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re | |
// InitChainer application update at chain initialization | ||
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { | ||
var genesisState GenesisState | ||
app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) | ||
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { | ||
panic(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouch, can we return an error and handle it somewhere higher, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This must panic (it used to panic too). An error that happens in |
||
} | ||
return app.mm.InitGenesis(ctx, app.appCodec, genesisState) | ||
} | ||
|
||
|
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.
it's a pity that the library does not provide a
MustUnmarshal()
method :(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 see it as an advantage. Panics should be avoided.
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 is the reason for using tmjson here?
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 thought GenesisDoc was marshalled using tmjson on the TM side?
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.
ah wait, i might have read too fast, this is our own GenesisState. So it should be decoded with appCodec.
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.
Proper error handling:
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 +1 this idea, and would even propose more aggressively to only allow Tendermint to panic. It's probably a larger discussion, but if the TM spec would expose some well-defined errors that cause TM to panic, then the SDK (or any state machine) should only return these errors, and contain 0 panic itself.
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.
Two weeks ago I've created an issue to clean the panics wherever possible: #7409
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 agree very much indeed to that. But until we got stuff sorted in Tendermint, there is not much we can do other than
panic()
ing in the SDK.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 generally have been using stdlib encoding/json