-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 6 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 |
---|---|---|
|
@@ -21,7 +21,17 @@ func WithKeySetUncheckedValue() func(opt *keySetOptions) { | |
} | ||
} | ||
|
||
type keySetOptions struct{ uncheckedValue bool } | ||
// WithKeySetSecondaryIndex changes the behavior of the KeySet to be a secondary index. | ||
func WithKeySetSecondaryIndex() func(opt *keySetOptions) { | ||
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. Does this need to be public? 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. yes, used in |
||
return func(opt *keySetOptions) { | ||
opt.isSecondaryIndex = true | ||
} | ||
} | ||
|
||
type keySetOptions struct { | ||
uncheckedValue bool | ||
isSecondaryIndex bool | ||
} | ||
|
||
// KeySet builds on top of a Map and represents a collection retaining only a set | ||
// of keys and no value. It can be used, for example, in an allow list. | ||
|
@@ -44,7 +54,7 @@ func NewKeySet[K any]( | |
if o.uncheckedValue { | ||
vc = codec.NewAltValueCodec(vc, func(_ []byte) (NoValue, error) { return NoValue{}, nil }) | ||
} | ||
return (KeySet[K])(NewMap(schema, prefix, name, keyCodec, vc)) | ||
return (KeySet[K])(NewMap(schema, prefix, name, keyCodec, vc, withMapSecondaryIndex(o.isSecondaryIndex))) | ||
} | ||
|
||
// Set adds the key to the KeySet. Errors on encoding problems. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ import ( | |
"cosmossdk.io/schema" | ||
) | ||
|
||
type keyCollection interface { | ||
// Keys returns the key fields for the collection. | ||
Keys() []interface{} | ||
} | ||
|
||
// bindKeyParams binds the key to the key columns. | ||
func (tm *objectIndexer) bindKeyParams(key interface{}) ([]interface{}, []string, error) { | ||
n := len(tm.typ.KeyFields) | ||
|
@@ -17,6 +22,9 @@ func (tm *objectIndexer) bindKeyParams(key interface{}) ([]interface{}, []string | |
} else if n == 1 { | ||
return tm.bindParams(tm.typ.KeyFields, []interface{}{key}) | ||
} else { | ||
if kc, ok := key.(keyCollection); ok { | ||
return tm.bindParams(tm.typ.KeyFields, kc.Keys()) | ||
} | ||
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. We shouldn't need to change anything in indexer here. This breaks the schema specification. Instead we need to make sure that pair, triple, etc in collections decode correctly to what schema expects. This would be part of the codec implementation 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. The SchemaCodec method of PairKeyCodec, etc is what needs to be fixed. I didn't complete the encoding/decoding there properly. Apologies that this wasn't clear. |
||
key, ok := key.([]interface{}) | ||
if !ok { | ||
return nil, nil, errors.New("expected key to be a slice") | ||
|
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.
to a JSON string