-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GameOfZones Phase 1: Fix to solve capability initialization #6127
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6127 +/- ##
==========================================
- Coverage 54.64% 54.64% -0.01%
==========================================
Files 443 443
Lines 26655 26657 +2
==========================================
Hits 14566 14566
- Misses 11092 11093 +1
- Partials 997 998 +1 |
@@ -24,6 +24,9 @@ func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { | |||
|
|||
// Context with current {check, deliver}State of the app used by tests. | |||
func (app *BaseApp) NewContext(isCheckTx bool, header abci.Header) sdk.Context { | |||
if header.Height < 0 { |
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 you explain why and when this happens?
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 a hack, it never happens during actual chain execution. But we just pass the height in as -1
in the app initialization so that the NewContext
function goes into this condition instead of the checkTx
or deliverTx
conditions.
This allows us to return a context that has CommitMultiStore directly inside of it, which allows us to write the capabilities directly into the memstore during InitializeAndSeal
The problem before was that we were using the BaseApp.NewContext
with checkTx's multistore. But both checkTx and deliverTx will wrap the multistore in a CacheMultiStore
. So all the writes we made to stores in InitializeAndSeal
were being written to CacheStore. Since we didn't (and couldn't) call Commit before the chain started, these cached writes were simply discarded when the chain started.
We didn't have a way to Write the cacheStore from inside NewApp
. So we had to create a way to return a context that was un-cached, so that we could write directly into memstores and not have to commit afterwards. That's what these changes accomplish
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; that makes sense. It's a bit scary that we didn't actually catch this in testing or even some sort of minimal manual testing of running a network.
In any case, can we at the very least add a simple test case and update the godoc for NewContext
to explain what happens when a negative height is passed?
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.
Agreed on documentation. I also wonder if we should avoid using this negative-height trick entirely, it just seems confusing - maybe we should make a function that allows app.cms
to be accessed directly, but can no longer be called after app.Seal()
or something like that?
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.
Agreed. We should either take that route or create an entirely new separate method that solely uses the cms
(e.g. NewContextFromMultiStore
).
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.
I understand the issue; I think a separate function might be less likely to be misused.
@@ -24,6 +24,9 @@ func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { | |||
|
|||
// Context with current {check, deliver}State of the app used by tests. | |||
func (app *BaseApp) NewContext(isCheckTx bool, header abci.Header) sdk.Context { | |||
if header.Height < 0 { |
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.
Agreed on documentation. I also wonder if we should avoid using this negative-height trick entirely, it just seems confusing - maybe we should make a function that allows app.cms
to be accessed directly, but can no longer be called after app.Seal()
or something like that?
Port @AdityaSripal fix to working branch of SDK
Superceeds: #6126