Skip to content

Commit

Permalink
Problem: slices in ReadOptions is freed by gc while referenced in roc…
Browse files Browse the repository at this point in the history
…ksdb (#1751)

* Problem: no deallocate read options

* doc

* sync deps
  • Loading branch information
mmsqe authored Feb 24, 2025
1 parent e1d336f commit 83a6b18
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#1725](https://github.com/crypto-org-chain/cronos/pull/1725) Include the fix of deadlock when close tree in iavl.
* [#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.

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ require (
replace (
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254
cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224020346-25e0cb78f920
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224030921-39d7b26bbb97
)

replace (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c h1:MOgfS4+F
github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/crypto-org-chain/cometbft v0.0.0-20241106091515-ce418f845d9a h1:0EN1TkzHTAxpgpGaZJY3G7L4jf4+sYnI7FOmBFLCg4U=
github.com/crypto-org-chain/cometbft v0.0.0-20241106091515-ce418f845d9a/go.mod h1:khbgmtxbgwJfMqDmnGY4rl2sQpTdzpPb1f9nqnfpy1o=
github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224020346-25e0cb78f920 h1:T4nlD37kZ2CodSH54l7p/Dg7c56ptMsfDoxndf7bNAM=
github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224020346-25e0cb78f920/go.mod h1:JwwsMeZldLN20b72mmbWPY0EV9rs+v/12hRu1JFttvY=
github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224030921-39d7b26bbb97 h1:Aj5lZUTybx2x4fcHNYqWT4Ih8sql6qZkUFRytqwgcmo=
github.com/crypto-org-chain/cosmos-sdk v0.43.0-beta1.0.20250224030921-39d7b26bbb97/go.mod h1:JwwsMeZldLN20b72mmbWPY0EV9rs+v/12hRu1JFttvY=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254 h1:NEgy0r3otU/O+0OAjMdEhbn4VotQlg+98hHbD7M23wU=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254 h1:JzLOFRiKsDtLJt5h0M0jkEIPDKvFFyja7VEp7gG6O9U=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ schema = 3
version = "v1.0.0-beta.5"
hash = "sha256-Fy/PbsOsd6iq0Njy3DVWK6HqWsogI+MkE8QslHGWyVg="
[mod."github.com/cosmos/cosmos-sdk"]
version = "v0.43.0-beta1.0.20250224020346-25e0cb78f920"
hash = "sha256-Hf+IiBP+kroVm9rSA3RVRFT4mjgOKz13jX334vTL5lA="
version = "v0.43.0-beta1.0.20250224030921-39d7b26bbb97"
hash = "sha256-JVGXvBx9OXnki4fjio/iG1QdclifPxL+YXvaMdVPi5s="
replaced = "github.com/crypto-org-chain/cosmos-sdk"
[mod."github.com/cosmos/go-bip39"]
version = "v1.0.0"
Expand Down
8 changes: 6 additions & 2 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ func (s Store) PutAtVersion(version int64, changeSet []*types.StoreKVPair) error
}

func (s Store) GetAtVersionSlice(storeKey string, key []byte, version *int64) (*grocksdb.Slice, error) {
readOpts := newTSReadOptions(version)
defer readOpts.Destroy()
value, ts, err := s.db.GetCFWithTS(
newTSReadOptions(version),
readOpts,
s.cfHandle,
prependStoreKey(storeKey, key),
)
Expand Down Expand Up @@ -164,7 +166,9 @@ func (s Store) iteratorAtVersion(storeKey string, start, end []byte, version *in
prefix := storePrefix(storeKey)
start, end = iterateWithPrefix(prefix, start, end)

itr := s.db.NewIteratorCF(newTSReadOptions(version), s.cfHandle)
readOpts := newTSReadOptions(version)
defer readOpts.Destroy()
itr := s.db.NewIteratorCF(readOpts, s.cfHandle)
return newRocksDBIterator(itr, prefix, start, end, reverse, s.skipVersionZero), nil
}

Expand Down

0 comments on commit 83a6b18

Please sign in to comment.