Skip to content

Conversation

@aaronc
Copy link
Member

@aaronc aaronc commented Aug 8, 2025

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/cronos with 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.

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

integer overflow conversion int32 -> int8
return rs.CacheMultiStore(), nil
}
opts := rs.opts
opts.TargetVersion = uint32(version)

Check failure

Code scanning / gosec

integer overflow conversion uint64 -> uint32 Error

integer overflow conversion int64 -> uint32
opts := rs.opts
opts.CreateIfMissing = true
opts.InitialStores = initialStores
opts.TargetVersion = uint32(version)

Check failure

Code scanning / gosec

integer overflow conversion uint64 -> uint32 Error

integer overflow conversion int64 -> uint32
}

opts := rs.opts
opts.TargetVersion = uint32(target)

Check failure

Code scanning / gosec

integer overflow conversion uint64 -> uint32 Error

integer overflow conversion int64 -> uint32
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

integer overflow conversion int64 -> uint32
Comment on lines +111 to +115
for _, store := range rs.stores {
if store.GetStoreType() != types.StoreTypeIAVL {
_ = store.Commit()
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +123 to +128
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

Iteration over map may be a possible source of non-determinism
Comment on lines +185 to +195
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

Iteration over map may be a possible source of non-determinism
return rs.CacheMultiStore(), nil
}
opts := rs.opts
opts.TargetVersion = uint32(version)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type uint32 without an upper bound check.

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.


Suggested changeset 1
store/cronos/rootmulti/store.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/store/cronos/rootmulti/store.go b/store/cronos/rootmulti/store.go
--- a/store/cronos/rootmulti/store.go
+++ b/store/cronos/rootmulti/store.go
@@ -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)
EOF
@@ -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)
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +216 to +220
for k, store := range rs.stores {
if store.GetStoreType() != types.StoreTypeIAVL {
stores[k] = store
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
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

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
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

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Comment on lines +513 to +518
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

Iteration over map may be a possible source of non-determinism
Comment on lines +638 to +646
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

Iteration over map may be a possible source of non-determinism
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants