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

Problem: version mismatch happen occasionally #1759

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [#1724](https://github.com/crypto-org-chain/cronos/pull/1724) Include the fix of nonce management in batch tx in ethermint.
* [#1748](https://github.com/crypto-org-chain/cronos/pull/1748) Query with GetCFWithTS to compare both timestamp and key to avoid run fixdata multiple times.
* (versiondb) [#1751](https://github.com/crypto-org-chain/cronos/pull/1751) Add missing Destroy for read options to properly hold and release options reference.
* [#1759](https://github.com/crypto-org-chain/cronos/pull/1759) Fix version mismatch happen occasionally.

### Improvements

Expand Down
33 changes: 26 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,16 +1041,28 @@ func New(
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
var qmsVersion int64
if app.qms != nil {
qmsVersion = app.qms.LatestVersion()
}

if app.qms != nil {
v1 := app.qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 < v2 {
if qmsVersion == 0 {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}
} else {
// make sure iavl version is not ahead of versiondb version
app.SetStoreLoader(VersionStoreLoader(qmsVersion))

if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}

// still keep the check for safety
iavlVersion := app.LastBlockHeight()
if qmsVersion < iavlVersion {
// try to prevent gap being created in versiondb
tmos.Exit(fmt.Sprintf("versiondb version %d lag behind iavl version %d", v1, v2))
tmos.Exit(fmt.Sprintf("versiondb version %d lag behind iavl version %d", qmsVersion, iavlVersion))
}
}

Expand Down Expand Up @@ -1491,3 +1503,10 @@ func (app *App) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error)

return app.BaseApp.CheckTx(req)
}

// VersionStoreLoader will be used when there's versiondb
func VersionStoreLoader(version int64) baseapp.StoreLoader {
return func(ms storetypes.CommitMultiStore) error {
return ms.LoadVersion(version)
}
}
Loading