Skip to content

Commit

Permalink
Problem: versiondb version mismatch related fixes are not backported (#…
Browse files Browse the repository at this point in the history
…1306)

* Problem: memiavl rootmulti store access map concurrently (#1302)

* Problem: memiavl rootmulti store access map concurrently

Solution:
- code refactoring

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

---------

Signed-off-by: yihuang <[email protected]>

* mod tidy

* Problem: versiondb lag behind when os reboot (#1304)

* Problem: versiondb lag behind when os reboot

Closes: #1301

Solution:
- do fsync when writing versiondb

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

* relax version checking

* changelog

---------

Signed-off-by: yihuang <[email protected]>

* fix lint

---------

Signed-off-by: yihuang <[email protected]>
Co-authored-by: yihuang <[email protected]>
  • Loading branch information
mmsqe and yihuang authored Jan 30, 2024
1 parent b0af3db commit c12016e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

- [#1241](https://github.com/crypto-org-chain/cronos/pull/1241) Improve parallelization of memiavl restoration.
- [#1302](https://github.com/crypto-org-chain/cronos/pull/1302) Fix concurrent map access in rootmulti store.
- [#1304](https://github.com/crypto-org-chain/cronos/pull/1304) Write versiondb with fsync, and relax the version requirement on startup.

### State Machine Breaking

Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ func New(
if qms != nil {
v1 := qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 != v2 {
tmos.Exit(fmt.Sprintf("versiondb lastest version %d don't match iavl latest version %d", v1, v2))
if v1 > 0 && v1 < v2 {
// try to prevent gap being created in versiondb
tmos.Exit(fmt.Sprintf("versiondb version %d lag behind iavl version %d", v1, v2))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-rc.0
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-proto v1.0.0-beta.1
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807104542-537257060180
github.com/cosmos/gogoproto v1.4.8
github.com/cosmos/ibc-go/v6 v6.2.0
Expand All @@ -19,11 +20,9 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/linxGnu/grocksdb v1.8.0
github.com/peggyjv/gravity-bridge/module/v2 v2.0.0-20220420162017-838c0d25e974
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.3
github.com/tendermint/tendermint v0.34.29
github.com/tendermint/tm-db v0.6.7
Expand Down Expand Up @@ -73,7 +72,6 @@ require (
github.com/cometbft/cometbft-db v0.8.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/iavl v0.19.6 // indirect
github.com/cosmos/ibc-go/v5 v5.2.1 // indirect
Expand Down Expand Up @@ -158,6 +156,7 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand All @@ -175,6 +174,7 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.14.0 // indirect
github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
4 changes: 4 additions & 0 deletions store/memiavlstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func New(tree *memiavl.Tree, logger log.Logger) *Store {
return &Store{tree: tree, logger: logger}
}

func (st *Store) SetTree(tree *memiavl.Tree) {
st.tree = tree
}

func (st *Store) Commit() types.CommitID {
panic("memiavl store is not supposed to be committed alone")
}
Expand Down
7 changes: 2 additions & 5 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ func (rs *Store) Commit() types.CommitID {
panic(err)
}

// the underlying memiavl tree might be reloaded, reload the store as well.
// the underlying memiavl tree might be reloaded, update the tree.
for key := range rs.stores {
store := rs.stores[key]
if store.GetStoreType() == types.StoreTypeIAVL {
rs.stores[key], err = rs.loadCommitStoreFromParams(rs.db, key, rs.storesParams[key])
if err != nil {
panic(fmt.Errorf("inconsistent store map, store %s not found", key.Name()))
}
store.(*memiavlstore.Store).SetTree(rs.db.TreeByName(key.Name()))
}
}

Expand Down
11 changes: 8 additions & 3 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ var (

_ versiondb.VersionStore = Store{}

defaultWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultReadOpts = grocksdb.NewDefaultReadOptions()
defaultWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultSyncWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultReadOpts = grocksdb.NewDefaultReadOptions()
)

func init() {
defaultSyncWriteOpts.SetSync(true)
}

type Store struct {
db *grocksdb.DB
cfHandle *grocksdb.ColumnFamilyHandle
Expand Down Expand Up @@ -77,7 +82,7 @@ func (s Store) PutAtVersion(version int64, changeSet []types.StoreKVPair) error
}
}

return s.db.Write(defaultWriteOpts, batch)
return s.db.Write(defaultSyncWriteOpts, batch)
}

func (s Store) GetAtVersionSlice(storeKey string, key []byte, version *int64) (*grocksdb.Slice, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/cronos/keeper/mock/ibckeeper_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (i IbcKeeperMock) Transfer(goCtx context.Context, msg *types.MsgTransfer) (
}

func (i IbcKeeperMock) GetDenomTrace(ctx sdk.Context, denomTraceHash tmbytes.HexBytes) (types.DenomTrace, bool) {
if denomTraceHash.String() == "6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865" { //nolint:gosec // test only
if denomTraceHash.String() == "6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865" {
return types.DenomTrace{
Path: "transfer/channel-0",
BaseDenom: "basetcro",
Expand Down

0 comments on commit c12016e

Please sign in to comment.