-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(indexer): the issues during simapp v1 integration #22413
Changes from all commits
2d7f0b6
b6c6da7
b1ccaf9
7b1669c
3a92a77
4a272ee
8a911e3
3b2f303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -311,6 +311,16 @@ func (t tripleKeyCodec[K1, K2, K3]) SchemaCodec() (codec.SchemaCodec[Triple[K1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return codec.SchemaCodec[Triple[K1, K2, K3]]{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fields: []schema.Field{field1, field2, field3}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
ToSchemaType: func(t Triple[K1, K2, K3]) (any, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return []interface{}{t.K1(), t.K2(), t.K3()}, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
FromSchemaType: func(a any) (Triple[K1, K2, K3], error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
aSlice, ok := a.([]interface{}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !ok || len(aSlice) != 3 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return Triple[K1, K2, K3]{}, fmt.Errorf("expected slice of length 3, got %T", a) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return Join3(aSlice[0].(K1), aSlice[1].(K2), aSlice[2].(K3)), nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+317
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add type assertion safety checks to prevent panics The current implementation has unsafe type assertions that could cause runtime panics. Consider adding proper type validation and error handling. Here's a safer implementation: FromSchemaType: func(a any) (Triple[K1, K2, K3], error) {
aSlice, ok := a.([]interface{})
if !ok || len(aSlice) != 3 {
return Triple[K1, K2, K3]{}, fmt.Errorf("expected slice of length 3, got %T", a)
}
+ k1, ok := aSlice[0].(K1)
+ if !ok {
+ return Triple[K1, K2, K3]{}, fmt.Errorf("invalid type for k1: expected %T, got %T", *new(K1), aSlice[0])
+ }
+ k2, ok := aSlice[1].(K2)
+ if !ok {
+ return Triple[K1, K2, K3]{}, fmt.Errorf("invalid type for k2: expected %T, got %T", *new(K2), aSlice[1])
+ }
+ k3, ok := aSlice[2].(K3)
+ if !ok {
+ return Triple[K1, K2, K3]{}, fmt.Errorf("invalid type for k3: expected %T, got %T", *new(K3), aSlice[2])
+ }
- return Join3(aSlice[0].(K1), aSlice[1].(K2), aSlice[2].(K3)), nil
+ return Join3(k1, k2, k3), nil
}, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,15 @@ import ( | |
"fmt" | ||
"io" | ||
|
||
_ "github.com/jackc/pgx/v5/stdlib" // Import and register pgx driver | ||
|
||
clienthelpers "cosmossdk.io/client/v2/helpers" | ||
"cosmossdk.io/core/address" | ||
"cosmossdk.io/core/appmodule" | ||
"cosmossdk.io/core/registry" | ||
corestore "cosmossdk.io/core/store" | ||
"cosmossdk.io/depinject" | ||
_ "cosmossdk.io/indexer/postgres" // register the postgres indexer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Missing required PostgreSQL indexer dependency in go.mod The PostgreSQL indexer is imported and used in the code, but its dependency is not properly declared in go.mod. This could lead to build issues or version inconsistencies.
🔗 Analysis chainLGTM: PostgreSQL indexer import is correctly added. The import of the Postgres indexer module with the blank identifier follows the correct pattern for registering the indexer. Let's verify that the required dependencies are properly declared in go.mod: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that the required PostgreSQL dependencies are declared in go.mod
# Test: Check for pgx dependency
echo "Checking for pgx dependency..."
rg "github.com/jackc/pgx/v5" go.mod
# Test: Check for postgres indexer dependency
echo "Checking for postgres indexer dependency..."
rg "cosmossdk.io/indexer/postgres" go.mod
Length of output: 245 Script: #!/bin/bash
# Let's try a different approach to check the dependencies
# Check the entire go.mod content
echo "=== Checking go.mod content ==="
cat go.mod
# Check if there are any indirect dependencies related to postgres
echo -e "\n=== Checking for any postgres-related dependencies ==="
rg -i "postgres" go.mod
# Check if the indexer package is imported anywhere else
echo -e "\n=== Checking for indexer usage across the codebase ==="
rg "cosmossdk.io/indexer" --type go
Length of output: 10219 |
||
"cosmossdk.io/log" | ||
"cosmossdk.io/x/accounts" | ||
basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, used in
indexes/reverse_pair.go