-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat: support memiavl #25121
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
base: main
Are you sure you want to change the base?
feat: support memiavl #25121
Conversation
| node := &memiavl.ExportNode{ | ||
| Key: item.IAVL.Key, | ||
| Value: item.IAVL.Value, | ||
| Height: int8(item.IAVL.Height), |
Check failure
Code scanning / gosec
integer overflow conversion uint64 -> uint32 Error
| return rs.CacheMultiStore(), nil | ||
| } | ||
| opts := rs.opts | ||
| opts.TargetVersion = uint32(version) |
Check failure
Code scanning / gosec
integer overflow conversion uint64 -> uint32 Error
| opts := rs.opts | ||
| opts.CreateIfMissing = true | ||
| opts.InitialStores = initialStores | ||
| opts.TargetVersion = uint32(version) |
Check failure
Code scanning / gosec
integer overflow conversion uint64 -> uint32 Error
| } | ||
|
|
||
| opts := rs.opts | ||
| opts.TargetVersion = uint32(target) |
Check failure
Code scanning / gosec
integer overflow conversion uint64 -> uint32 Error
| db := rs.db | ||
| if version != rs.lastCommitInfo.Version { | ||
| var err error | ||
| db, err = memiavl.Load(rs.dir, memiavl.Options{TargetVersion: uint32(version), ReadOnly: true}) |
Check failure
Code scanning / gosec
integer overflow conversion uint64 -> uint32 Error
| for _, store := range rs.stores { | ||
| if store.GetStoreType() != types.StoreTypeIAVL { | ||
| _ = store.Commit() | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for key := range rs.stores { | ||
| store := rs.stores[key] | ||
| if store.GetStoreType() == types.StoreTypeIAVL { | ||
| store.(*memiavlstore.Store).SetTree(rs.db.TreeByName(key.Name())) | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for k, v := range rs.stores { | ||
| store := types.CacheWrapper(v) | ||
| if kv, ok := store.(types.KVStore); ok { | ||
| // Wire the listenkv.Store to allow listeners to observe the writes from the cache store, | ||
| // set same listeners on cache store will observe duplicated writes. | ||
| if rs.ListeningEnabled(k) { | ||
| store = listenkv.NewStore(kv, k, rs.listeners[k]) | ||
| } | ||
| } | ||
| stores[k] = store | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| return rs.CacheMultiStore(), nil | ||
| } | ||
| opts := rs.opts | ||
| opts.TargetVersion = uint32(version) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix this issue, we need to ensure that the version value is within the valid range for a uint32 before performing the conversion. This means checking that version is non-negative and does not exceed math.MaxUint32. If the value is out of bounds, the function should return an error indicating that the requested version is invalid. The best place to add this check is immediately before the conversion at line 206 in store/cronos/rootmulti/store.go. We will also need to import the math package if it is not already imported (it is). The error returned should be consistent with the error handling style in the rest of the function.
-
Copy modified lines R206-R208
| @@ -205,2 +205,5 @@ | ||
| opts := rs.opts | ||
| if version < 0 || version > int64(math.MaxUint32) { | ||
| return nil, fmt.Errorf("requested version %d is out of range for uint32", version) | ||
| } | ||
| opts.TargetVersion = uint32(version) |
| for k, store := range rs.stores { | ||
| if store.GetStoreType() != types.StoreTypeIAVL { | ||
| stores[k] = store | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| func (rs *Store) GetStore(key types.StoreKey) types.Store { | ||
| s, ok := rs.stores[key] | ||
| if !ok { | ||
| panic(fmt.Sprintf("store does not exist for key: %s", key.Name())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| func (rs *Store) GetKVStore(key types.StoreKey) types.KVStore { | ||
| s, ok := rs.GetStore(key).(types.KVStore) | ||
| if !ok { | ||
| panic(fmt.Sprintf("store with key %v is not KVStore", key)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| for key := range rs.listeners { | ||
| ls := rs.listeners[key] | ||
| if ls != nil { | ||
| cache = append(cache, ls.PopStateCache()...) | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
| for key := range storeParams { | ||
| typ := storeParams[key].typ | ||
| if typ != types.StoreTypeIAVL && typ != types.StoreTypeTransient { | ||
| extraStoreInfos = append(extraStoreInfos, types.StoreInfo{ | ||
| Name: key.Name(), | ||
| CommitId: types.CommitID{}, | ||
| }) | ||
| } | ||
| } |
Check warning
Code scanning / CodeQL
Iteration over map Warning
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs. |
Description
This PR demonstrates that memiavl integration is possible with minimal work. Effectively, the bulk of this PR is a direct copy of https://github.com/crypto-org-chain/cronos/tree/main/store into
store/cronoswith import paths fixed. Other than that, there is simply some minimal configuration in the server package and memiavl basically works. We could choose to include the cronos specific store stuff directly in the SDK as I have done here, or work on upstreaming the required changes to their repo and just add server configuration to the SDK. Either way it is a small lift.