You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to debug #8265, I stumbled on a bug that makes it impossible to run CLI & REST queries on a module that was added during an on-chain upgrade.
Here are the steps I've done to reproduce this bug:
Run a chain without a specific module (reports).
Create an on-chain upgrade to add such module.
Wait until the upgrade height comes, and the upgrade is performed.
Try performing a transaction using the newly added module.
Try queries the newly added module.
Everything works properly until point 5. When querying the data the result is always empty (like nothing exists), even if the transaction performed at step 4 is successful.
Specific example
The test I've made is based on the following branches of our project:
riccardo/no-module, which does not have one particular module (reports) installed
$ cosmovisor q reports post 158bc7b14484163dc146a7ff6efdf97d68f04a5dc1552350008f64e1bcc7237d
reports: []
As you can see, the returned reports are empty.
Interesting fact
While trying to sorting this out, I have also discovered that the created report is indeed stored properly, and it looks like there's something wrong with the gRPC queries somehow.
We can see that the report is stored properly because when a report is created, this is the code that is called:
// SaveReport allows to save the given report inside the current context.// It assumes that the given report has already been validated.// If the same report has already been inserted, nothing will be changed.func (kKeeper) SaveReport(ctx sdk.Context, report types.Report) error {
store:=ctx.KVStore(k.storeKey)
key:=types.ReportStoreKey(report.PostId)
// Get the list of reports related to the given postIDreports:=types.MustUnmarshalReports(store.Get(key), k.cdc)
// Append the given reportnewSlice, appended:=types.AppendIfMissing(reports, report)
if!appended {
returnsdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "report already exists")
}
store.Set(key, types.MustMarshalReports(newSlice, k.cdc))
returnnil
}
As you can see, if the same exact report already exists inside the store, an error is returned. So, what I did is I tried creating an exact copy of the first report I created after the upgrade by running the same exact command:
At the same time, this is the method that is called when I try to query the reports associated with a post:
// GetPostReports returns the list of reports associated with the given postID.// If no report is associated with the given postID the function will returns an empty list.func (kKeeper) GetPostReports(ctx sdk.Context, postIDstring) []types.Report {
store:=ctx.KVStore(k.storeKey)
returntypes.MustUnmarshalReports(store.Get(types.ReportStoreKey(postID)), k.cdc)
}
As you can see, this code is also used inside SaveReport, and it returns a non-empty slice. At the same time, when querying the post reports, the returned slice is empty. This is particularly strange.
Note. Please note that I have tested the creation of a report and the query of all the reports associated with a post on a new chain that has such module installed from the beginning. In that case, all the reports were returned properly.
For Admin Use
Not duplicate issue
Appropriate labels applied
Appropriate contributors tagged
Contributor assigned/self-assigned
The text was updated successfully, but these errors were encountered:
Summary of Bug
After an on-chain upgrade, the queries on newly added modules are not working.
Version
v0.40.0-rc6
Steps to Reproduce
While trying to debug #8265, I stumbled on a bug that makes it impossible to run CLI & REST queries on a module that was added during an on-chain upgrade.
Here are the steps I've done to reproduce this bug:
reports
).Everything works properly until point 5. When querying the data the result is always empty (like nothing exists), even if the transaction performed at step 4 is successful.
Specific example
The test I've made is based on the following branches of our project:
riccardo/no-module
, which does not have one particular module (reports
) installedriccardo/with-module
which does have such module installedThe precise steps I've taken are:
Start a chain based on
no-module
and create a post using the following transaction:Post creation transaction
Query the posts to make sure that the post was created properly, and to get its id (which is generated while inserting the post):
Query posts
Submit an upgrade proposal for height
50
so that we can switch the daemon version to be based on thewith-module
branch.Wait until the upgrade has been completed successfully.
Query the posts to make sure that everything is still there:
Query posts
Try creating a post report:
Create post report
Try querying the newly inserted report:
Query the report for the post
As you can see, the returned reports are empty.
Interesting fact
While trying to sorting this out, I have also discovered that the created report is indeed stored properly, and it looks like there's something wrong with the gRPC queries somehow.
We can see that the report is stored properly because when a report is created, this is the code that is called:
As you can see, if the same exact report already exists inside the store, an error is returned. So, what I did is I tried creating an exact copy of the first report I created after the upgrade by running the same exact command:
Create post report
This, as expected, this returned an error:
At the same time, this is the method that is called when I try to query the reports associated with a post:
As you can see, this code is also used inside
SaveReport
, and it returns a non-empty slice. At the same time, when querying the post reports, the returned slice is empty. This is particularly strange.Note. Please note that I have tested the creation of a report and the query of all the reports associated with a post on a new chain that has such module installed from the beginning. In that case, all the reports were returned properly.
For Admin Use
The text was updated successfully, but these errors were encountered: