diff --git a/baseapp/abci.go b/baseapp/abci.go index 979089c5c86d..d9921a8e13d5 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -903,8 +903,12 @@ func (app *BaseApp) FinalizeBlock(req *abci.FinalizeBlockRequest) (res *abci.Fin defer func() { // call the streaming service hooks with the FinalizeBlock messages for _, streamingListener := range app.streamingManager.ABCIListeners { - if err := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); err != nil { + if streamErr := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); streamErr != nil { app.logger.Error("ListenFinalizeBlock listening hook failed", "height", req.Height, "err", err) + if app.streamingManager.StopNodeOnErr { + // if StopNodeOnErr is set, we should return the streamErr in order to stop the node + err = streamErr + } } } }() @@ -976,12 +980,12 @@ func (app *BaseApp) Commit() (*abci.CommitResponse, error) { rms.SetCommitHeader(header) } - app.cms.Commit() - resp := &abci.CommitResponse{ RetainHeight: retainHeight, } + app.cms.Commit() + abciListeners := app.streamingManager.ABCIListeners if len(abciListeners) > 0 { ctx := app.finalizeBlockState.Context() @@ -991,6 +995,14 @@ func (app *BaseApp) Commit() (*abci.CommitResponse, error) { for _, abciListener := range abciListeners { if err := abciListener.ListenCommit(ctx, *resp, changeSet); err != nil { app.logger.Error("Commit listening hook failed", "height", blockHeight, "err", err) + if app.streamingManager.StopNodeOnErr { + err = fmt.Errorf("Commit listening hook failed: %w", err) + rollbackErr := app.cms.RollbackToVersion(blockHeight - 1) + if rollbackErr != nil { + return nil, errors.Join(err, rollbackErr) + } + return nil, err + } } } } diff --git a/client/v2/go.mod b/client/v2/go.mod index 4ba6d7b479ed..639fcf32666a 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/client/v2 -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/codec/collections.go b/codec/collections.go index 0137a989e790..3694558ad5c3 100644 --- a/codec/collections.go +++ b/codec/collections.go @@ -1,16 +1,23 @@ package codec import ( + "encoding/json" "fmt" "reflect" + "strings" "github.com/cosmos/gogoproto/proto" gogotypes "github.com/cosmos/gogoproto/types" "google.golang.org/protobuf/encoding/protojson" protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" "cosmossdk.io/collections" collcodec "cosmossdk.io/collections/codec" + "cosmossdk.io/schema" ) // BoolValue implements a ValueCodec that saves the bool value @@ -51,12 +58,17 @@ type protoMessage[T any] interface { proto.Message } +type protoCollValueCodec[T any] interface { + collcodec.HasSchemaCodec[T] + collcodec.ValueCodec[T] +} + // CollValue inits a collections.ValueCodec for a generic gogo protobuf message. func CollValue[T any, PT protoMessage[T]](cdc interface { Marshal(proto.Message) ([]byte, error) Unmarshal([]byte, proto.Message) error }, -) collcodec.ValueCodec[T] { +) protoCollValueCodec[T] { return &collValue[T, PT]{cdc.(Codec), proto.MessageName(PT(new(T)))} } @@ -91,6 +103,139 @@ func (c collValue[T, PT]) ValueType() string { return "github.com/cosmos/gogoproto/" + c.messageName } +func (c collValue[T, PT]) SchemaCodec() (collcodec.SchemaCodec[T], error) { + var ( + t T + pt PT + ) + msgName := proto.MessageName(pt) + desc, err := proto.HybridResolver.FindDescriptorByName(protoreflect.FullName(msgName)) + if err != nil { + return collcodec.SchemaCodec[T]{}, fmt.Errorf("could not find descriptor for %s: %w", msgName, err) + } + schemaFields := protoCols(desc.(protoreflect.MessageDescriptor)) + + kind := schema.KindForGoValue(t) + if err := kind.Validate(); err == nil { + return collcodec.SchemaCodec[T]{ + Fields: []schema.Field{{ + // we don't set any name so that this can be set to a good default by the caller + Name: "", + Kind: kind, + }}, + // these can be nil because T maps directly to a schema value for this kind + ToSchemaType: nil, + FromSchemaType: nil, + }, nil + } else { + return collcodec.SchemaCodec[T]{ + Fields: schemaFields, + ToSchemaType: func(t T) (any, error) { + values := []interface{}{} + msgDesc, ok := desc.(protoreflect.MessageDescriptor) + if !ok { + return nil, fmt.Errorf("expected message descriptor, got %T", desc) + } + + nm := dynamicpb.NewMessage(msgDesc) + bz, err := c.cdc.Marshal(any(&t).(PT)) + if err != nil { + return nil, err + } + + err = c.cdc.Unmarshal(bz, nm) + if err != nil { + return nil, err + } + + for _, field := range schemaFields { + // Find the field descriptor by the Protobuf field name + fieldDesc := msgDesc.Fields().ByName(protoreflect.Name(field.Name)) + if fieldDesc == nil { + return nil, fmt.Errorf("field %q not found in message %s", field.Name, desc.FullName()) + } + + val := nm.ProtoReflect().Get(fieldDesc) + + // if the field is a map or list, we need to convert it to a slice of values + if fieldDesc.IsList() { + repeatedVals := []interface{}{} + list := val.List() + for i := 0; i < list.Len(); i++ { + repeatedVals = append(repeatedVals, list.Get(i).Interface()) + } + values = append(values, repeatedVals) + continue + } + + switch fieldDesc.Kind() { + case protoreflect.BoolKind: + values = append(values, val.Bool()) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, + protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + values = append(values, val.Int()) + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, + protoreflect.Fixed64Kind: + values = append(values, val.Uint()) + case protoreflect.FloatKind, protoreflect.DoubleKind: + values = append(values, val.Float()) + case protoreflect.StringKind: + values = append(values, val.String()) + case protoreflect.BytesKind: + values = append(values, val.Bytes()) + case protoreflect.EnumKind: + // TODO: postgres uses the enum name, not the number + values = append(values, string(fieldDesc.Enum().Values().ByNumber(val.Enum()).Name())) + case protoreflect.MessageKind: + msg := val.Interface().(*dynamicpb.Message) + msgbz, err := c.cdc.Marshal(msg) + if err != nil { + return nil, err + } + + if field.Kind == schema.TimeKind { + // make it a time.Time + ts := ×tamppb.Timestamp{} + err = c.cdc.Unmarshal(msgbz, ts) + if err != nil { + return nil, fmt.Errorf("error unmarshalling timestamp: %w %x %s", err, msgbz, fieldDesc.FullName()) + } + values = append(values, ts.AsTime()) + } else if field.Kind == schema.DurationKind { + // make it a time.Duration + dur := &durationpb.Duration{} + err = c.cdc.Unmarshal(msgbz, dur) + if err != nil { + return nil, fmt.Errorf("error unmarshalling duration: %w", err) + } + values = append(values, dur.AsDuration()) + } else { + // if not a time or duration, just keep it as a JSON object + // we might want to change this to include the entire object as separate fields + bz, err := c.cdc.MarshalJSON(msg) + if err != nil { + return nil, fmt.Errorf("error marshaling message: %w", err) + } + + values = append(values, json.RawMessage(bz)) + } + } + + } + + // if there's only one value, return it directly + if len(values) == 1 { + return values[0], nil + } + return values, nil + }, + FromSchemaType: func(a any) (T, error) { + panic("not implemented") + }, + }, nil + } +} + type protoMessageV2[T any] interface { *T protov2.Message @@ -179,3 +324,101 @@ func (c collInterfaceValue[T]) ValueType() string { var t T return fmt.Sprintf("%T", t) } + +// SchemaCodec returns a schema codec, which will always have a single JSON field +// as there is no way to know in advance the necessary fields for an interface. +func (c collInterfaceValue[T]) SchemaCodec() (collcodec.SchemaCodec[T], error) { + var pt T + + kind := schema.KindForGoValue(pt) + if err := kind.Validate(); err == nil { + return collcodec.SchemaCodec[T]{ + Fields: []schema.Field{{ + // we don't set any name so that this can be set to a good default by the caller + Name: "", + Kind: kind, + }}, + // these can be nil because T maps directly to a schema value for this kind + ToSchemaType: nil, + FromSchemaType: nil, + }, nil + } else { + return collcodec.SchemaCodec[T]{ + Fields: []schema.Field{{ + Name: "value", + Kind: schema.JSONKind, + }}, + ToSchemaType: func(t T) (any, error) { + bz, err := c.codec.MarshalInterfaceJSON(t) + if err != nil { + return nil, err + } + + return json.RawMessage(bz), nil + }, + FromSchemaType: func(a any) (T, error) { + panic("not implemented") + }, + }, nil + } +} + +func protoCols(desc protoreflect.MessageDescriptor) []schema.Field { + nFields := desc.Fields() + cols := make([]schema.Field, 0, nFields.Len()) + for i := 0; i < nFields.Len(); i++ { + f := nFields.Get(i) + cols = append(cols, protoCol(f)) + } + return cols +} + +func protoCol(f protoreflect.FieldDescriptor) schema.Field { + col := schema.Field{Name: string(f.Name())} + if f.IsMap() || f.IsList() { + col.Kind = schema.JSONKind + col.Nullable = true + } else { + switch f.Kind() { + case protoreflect.BoolKind: + col.Kind = schema.BoolKind + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + col.Kind = schema.Int32Kind + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + col.Kind = schema.Int64Kind + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + col.Kind = schema.Int64Kind + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + col.Kind = schema.Uint64Kind + case protoreflect.FloatKind: + col.Kind = schema.Float32Kind + case protoreflect.DoubleKind: + col.Kind = schema.Float64Kind + case protoreflect.StringKind: + col.Kind = schema.StringKind + case protoreflect.BytesKind: + col.Kind = schema.BytesKind + case protoreflect.EnumKind: + // TODO: support enums + col.Kind = schema.EnumKind + // use the full name to avoid collissions + col.ReferencedType = string(f.Enum().FullName()) + col.ReferencedType = strings.ReplaceAll(col.ReferencedType, ".", "_") + case protoreflect.MessageKind: + col.Nullable = true + fullName := f.Message().FullName() + if fullName == "google.protobuf.Timestamp" { + col.Kind = schema.TimeKind + } else if fullName == "google.protobuf.Duration" { + col.Kind = schema.DurationKind + } else { + col.Kind = schema.JSONKind + } + } + if f.HasPresence() { + col.Nullable = true + } + } + + return col +} diff --git a/collections/CHANGELOG.md b/collections/CHANGELOG.md index 844df7e785d8..142263bc5050 100644 --- a/collections/CHANGELOG.md +++ b/collections/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#21090](https://github.com/cosmos/cosmos-sdk/pull/21090) Introduces `Quad`, a composite key with four keys. * [#20704](https://github.com/cosmos/cosmos-sdk/pull/20704) Add `ModuleCodec` method to `Schema` and `HasSchemaCodec` interface in order to support `cosmossdk.io/schema` compatible indexing. * [#20538](https://github.com/cosmos/cosmos-sdk/pull/20538) Add `Nameable` variations to `KeyCodec` and `ValueCodec` to allow for better indexing of `collections` types. +* [#22544](https://github.com/cosmos/cosmos-sdk/pull/22544) Schema's `ModuleCodec` will now also return Enum descriptors to be registered with the indexer. ## [v0.4.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.4.0) diff --git a/collections/go.mod b/collections/go.mod index c6c94e7cbc1d..9ea5cd3f6acf 100644 --- a/collections/go.mod +++ b/collections/go.mod @@ -1,18 +1,22 @@ module cosmossdk.io/collections -go 1.23 +go 1.23.2 require ( cosmossdk.io/core v1.0.0-alpha.6 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/schema v0.3.0 + github.com/cosmos/gogoproto v1.7.0 github.com/stretchr/testify v1.10.0 github.com/tidwall/btree v1.7.0 + google.golang.org/protobuf v1.35.2 pgregory.net/rapid v1.1.0 ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/collections/go.sum b/collections/go.sum index 8966c2815454..7cd741b3ec8e 100644 --- a/collections/go.sum +++ b/collections/go.sum @@ -4,14 +4,22 @@ cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= +github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/collections/indexing.go b/collections/indexing.go index bb039e7be256..8a482c39810f 100644 --- a/collections/indexing.go +++ b/collections/indexing.go @@ -3,9 +3,12 @@ package collections import ( "bytes" "fmt" + "reflect" "strings" + "github.com/cosmos/gogoproto/proto" "github.com/tidwall/btree" + "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/collections/codec" "cosmossdk.io/schema" @@ -46,8 +49,45 @@ func (s Schema) ModuleCodec(opts IndexingOptions) (schema.ModuleCodec, error) { cdc.objectType.RetainDeletions = true } - types = append(types, cdc.objectType) + // this part below is a bit hacky, it will try to convert to a proto.Message + // in order to get any enum types inside of it. + emptyVal, err := coll.ValueCodec().Decode([]byte{}) + if err == nil { + // convert to proto.Message + pt, err := toProtoMessage(emptyVal) + if err == nil { + msgName := proto.MessageName(pt) + desc, err := proto.HybridResolver.FindDescriptorByName(protoreflect.FullName(msgName)) + if err != nil { + return schema.ModuleCodec{}, fmt.Errorf("could not find descriptor for %s: %w", msgName, err) + } + msgDesc := desc.(protoreflect.MessageDescriptor) + + // go through enum descriptors and add them to types + for i := 0; i < msgDesc.Fields().Len(); i++ { + field := msgDesc.Fields().Get(i) + enum := field.Enum() + if enum == nil { + continue + } + + enumType := schema.EnumType{ + Name: strings.ReplaceAll(string(enum.FullName()), ".", "_"), // make it compatible with schema + } + for j := 0; j < enum.Values().Len(); j++ { + val := enum.Values().Get(j) + enumType.Values = append(enumType.Values, schema.EnumValueDefinition{ + Name: string(val.Name()), + Value: int32(val.Number()), + }) + } + types = append(types, enumType) + } + + } + } + types = append(types, cdc.objectType) decoder.collectionLookup.Set(string(coll.GetPrefix()), cdc) } @@ -150,6 +190,11 @@ func (c collectionImpl[K, V]) schemaCodec() (*collectionSchemaCodec, error) { if err != nil { return nil, err } + + if valueDecoder.ToSchemaType == nil { + return x, nil + } + return valueDecoder.ToSchemaType(x) } ensureFieldNames(c.m.vc, "value", res.objectType.ValueFields) @@ -180,3 +225,34 @@ func ensureFieldNames(x any, defaultName string, cols []schema.Field) { cols[i] = col } } + +// toProtoMessage is a helper to convert a value to a proto.Message. +func toProtoMessage(value interface{}) (proto.Message, error) { + if value == nil { + return nil, fmt.Errorf("value is nil") + } + + // Check if the value already implements proto.Message + if msg, ok := value.(proto.Message); ok { + return msg, nil + } + + // Use reflection to handle non-pointer values + v := reflect.ValueOf(value) + if v.Kind() == reflect.Ptr { + // Already a pointer, but doesn't implement proto.Message + return nil, fmt.Errorf("value is a pointer but does not implement proto.Message") + } + + // If not a pointer, create a pointer to the value dynamically + ptr := reflect.New(v.Type()) + ptr.Elem().Set(v) + + // Assert if the pointer implements proto.Message + msg, ok := ptr.Interface().(proto.Message) + if !ok { + return nil, fmt.Errorf("value does not implement proto.Message") + } + + return msg, nil +} diff --git a/collections/protocodec/collections.go b/collections/protocodec/collections.go index 0b6c2c230f6e..f989cddbcd0f 100644 --- a/collections/protocodec/collections.go +++ b/collections/protocodec/collections.go @@ -1,4 +1,4 @@ -package codec +package protocodec import ( "fmt" diff --git a/collections/protocodec/collections_test.go b/collections/protocodec/collections_test.go index f98e3d3d7409..cf2af632f788 100644 --- a/collections/protocodec/collections_test.go +++ b/collections/protocodec/collections_test.go @@ -1,4 +1,4 @@ -package codec_test +package protocodec_test import ( "testing" diff --git a/go.mod b/go.mod index 69eca52df12e..9acd697db8c4 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -go 1.23.1 +go 1.23.2 module github.com/cosmos/cosmos-sdk diff --git a/indexer/postgres/create_table.go b/indexer/postgres/create_table.go index 0f8dc652190e..58a5177fde2d 100644 --- a/indexer/postgres/create_table.go +++ b/indexer/postgres/create_table.go @@ -17,7 +17,7 @@ func (tm *objectIndexer) createTable(ctx context.Context, conn dbConn) error { sqlStr := buf.String() if tm.options.logger != nil { - tm.options.logger.Debug("Creating table %s", "table", tm.tableName(), "sql", sqlStr) + tm.options.logger.Debug("Creating table", "table", tm.tableName(), "sql", sqlStr) } _, err = conn.ExecContext(ctx, sqlStr) return err diff --git a/indexer/postgres/enum.go b/indexer/postgres/enum.go index 62332f67d0e8..10ce2bd13269 100644 --- a/indexer/postgres/enum.go +++ b/indexer/postgres/enum.go @@ -21,6 +21,7 @@ func (m *moduleIndexer) createEnumType(ctx context.Context, conn dbConn, enum sc } } else { // the enum type already exists + // TODO: add a check to ensure the existing enum type matches the expected values, and update it if necessary? return nil } diff --git a/indexer/postgres/listener.go b/indexer/postgres/listener.go index 21d08a736af7..c2e982e2b02f 100644 --- a/indexer/postgres/listener.go +++ b/indexer/postgres/listener.go @@ -22,7 +22,26 @@ func (i *indexerImpl) listener() appdata.Listener { return mm.initializeSchema(i.ctx, i.tx) }, StartBlock: func(data appdata.StartBlockData) error { - _, err := i.tx.Exec("INSERT INTO block (number) VALUES ($1)", data.Height) + var ( + headerBz []byte + err error + ) + + if data.HeaderJSON != nil { + headerBz, err = data.HeaderJSON() + if err != nil { + return err + } + } else if data.HeaderBytes != nil { + headerBz, err = data.HeaderBytes() + if err != nil { + return err + } + } + + // TODO: verify the format of headerBz, otherwise we'll get `ERROR: invalid input syntax for type json (SQLSTATE 22P02)` + _, err = i.tx.Exec("INSERT INTO block (number, header) VALUES ($1, $2)", data.Height, headerBz) + return err }, OnObjectUpdate: func(data appdata.ObjectUpdateData) error { diff --git a/indexer/postgres/tests/testdata/init_schema.txt b/indexer/postgres/tests/testdata/init_schema.txt index 43b91a6a7a83..d188c41c9264 100644 --- a/indexer/postgres/tests/testdata/init_schema.txt +++ b/indexer/postgres/tests/testdata/init_schema.txt @@ -6,7 +6,7 @@ DEBUG: Creating enum type sql: CREATE TYPE "test_my_enum" AS ENUM ('a', 'b', 'c'); DEBUG: Creating enum type sql: CREATE TYPE "test_vote_type" AS ENUM ('yes', 'no', 'abstain'); -DEBUG: Creating table %s +DEBUG: Creating table table: test_all_kinds sql: CREATE TABLE IF NOT EXISTS "test_all_kinds" ( "id" BIGINT NOT NULL, @@ -36,7 +36,7 @@ DEBUG: Creating table %s PRIMARY KEY ("id", "ts_nanos") ); GRANT SELECT ON TABLE "test_all_kinds" TO PUBLIC; -DEBUG: Creating table %s +DEBUG: Creating table table: test_singleton sql: CREATE TABLE IF NOT EXISTS "test_singleton" ( _id INTEGER NOT NULL CHECK (_id = 1), @@ -46,7 +46,7 @@ DEBUG: Creating table %s PRIMARY KEY (_id) ); GRANT SELECT ON TABLE "test_singleton" TO PUBLIC; -DEBUG: Creating table %s +DEBUG: Creating table table: test_vote sql: CREATE TABLE IF NOT EXISTS "test_vote" ( "proposal" BIGINT NOT NULL, diff --git a/indexer/postgres/tests/testdata/init_schema_no_retain_delete.txt b/indexer/postgres/tests/testdata/init_schema_no_retain_delete.txt index 71dfd4d08290..a1adcb0c0c25 100644 --- a/indexer/postgres/tests/testdata/init_schema_no_retain_delete.txt +++ b/indexer/postgres/tests/testdata/init_schema_no_retain_delete.txt @@ -6,7 +6,7 @@ DEBUG: Creating enum type sql: CREATE TYPE "test_my_enum" AS ENUM ('a', 'b', 'c'); DEBUG: Creating enum type sql: CREATE TYPE "test_vote_type" AS ENUM ('yes', 'no', 'abstain'); -DEBUG: Creating table %s +DEBUG: Creating table table: test_all_kinds sql: CREATE TABLE IF NOT EXISTS "test_all_kinds" ( "id" BIGINT NOT NULL, @@ -36,7 +36,7 @@ DEBUG: Creating table %s PRIMARY KEY ("id", "ts_nanos") ); GRANT SELECT ON TABLE "test_all_kinds" TO PUBLIC; -DEBUG: Creating table %s +DEBUG: Creating table table: test_singleton sql: CREATE TABLE IF NOT EXISTS "test_singleton" ( _id INTEGER NOT NULL CHECK (_id = 1), @@ -46,7 +46,7 @@ DEBUG: Creating table %s PRIMARY KEY (_id) ); GRANT SELECT ON TABLE "test_singleton" TO PUBLIC; -DEBUG: Creating table %s +DEBUG: Creating table table: test_vote sql: CREATE TABLE IF NOT EXISTS "test_vote" ( "proposal" BIGINT NOT NULL, diff --git a/math/legacy_dec_test.go b/math/legacy_dec_test.go index 66a971186cff..4f3897a0867e 100644 --- a/math/legacy_dec_test.go +++ b/math/legacy_dec_test.go @@ -632,10 +632,10 @@ func BenchmarkMarshalTo(b *testing.B) { }{ { math.LegacyNewDec(1e8), []byte{ - 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - }, + 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + }, }, {math.LegacyNewDec(0), []byte{0x30}}, } diff --git a/schema/appdata/async.go b/schema/appdata/async.go index b85d0e492e90..d16216b56dd7 100644 --- a/schema/appdata/async.go +++ b/schema/appdata/async.go @@ -46,6 +46,13 @@ func AsyncListener(opts AsyncListenerOptions, listener Listener) Listener { done := ctx.Done() go func() { + defer func() { + close(packetChan) + if opts.DoneWaitGroup != nil { + opts.DoneWaitGroup.Done() + } + }() + if opts.DoneWaitGroup != nil { opts.DoneWaitGroup.Add(1) } @@ -74,10 +81,6 @@ func AsyncListener(opts AsyncListenerOptions, listener Listener) Listener { } case <-done: - close(packetChan) - if opts.DoneWaitGroup != nil { - opts.DoneWaitGroup.Done() - } return } } diff --git a/schema/field.go b/schema/field.go index b2bc76a2e3b6..d76e91b56792 100644 --- a/schema/field.go +++ b/schema/field.go @@ -35,6 +35,10 @@ type Field struct { // Validate validates the field. func (c Field) Validate(typeSet TypeSet) error { // valid name + if c.Name == "" { + return fmt.Errorf("field name cannot be empty, might be missing the named key codec") + } + if !ValidateName(c.Name) { return fmt.Errorf("invalid field name %q", c.Name) } diff --git a/schema/field_test.go b/schema/field_test.go index 0756f5a7ca86..1fa6413b790c 100644 --- a/schema/field_test.go +++ b/schema/field_test.go @@ -27,7 +27,7 @@ func TestField_Validate(t *testing.T) { Name: "", Kind: StringKind, }, - errContains: "invalid field name", + errContains: "name cannot be empty, might be missing the named key codec", }, { name: "invalid kind", diff --git a/schema/state_object.go b/schema/state_object.go index eff8d1f98459..3367d8337b7f 100644 --- a/schema/state_object.go +++ b/schema/state_object.go @@ -53,7 +53,7 @@ func (o StateObjectType) Validate(typeSet TypeSet) error { for _, field := range o.KeyFields { if err := field.Validate(typeSet); err != nil { - return fmt.Errorf("invalid key field %q: %v", field.Name, err) //nolint:errorlint // false positive due to using go1.12 + return fmt.Errorf("invalid key field %q in type %q: %v", field.Name, o.Name, err) //nolint:errorlint // false positive due to using go1.12 } if !field.Kind.ValidKeyKind() { @@ -65,7 +65,7 @@ func (o StateObjectType) Validate(typeSet TypeSet) error { } if fieldNames[field.Name] { - return fmt.Errorf("duplicate field name %q", field.Name) + return fmt.Errorf("duplicate key field name %q for stateObjectType: %s", field.Name, o.Name) } fieldNames[field.Name] = true } @@ -76,7 +76,7 @@ func (o StateObjectType) Validate(typeSet TypeSet) error { } if fieldNames[field.Name] { - return fmt.Errorf("duplicate field name %q", field.Name) + return fmt.Errorf("duplicate field name %q for stateObjectType: %s", field.Name, o.Name) } fieldNames[field.Name] = true } diff --git a/schema/state_object_test.go b/schema/state_object_test.go index 407586dd76e2..03bb402adf46 100644 --- a/schema/state_object_test.go +++ b/schema/state_object_test.go @@ -93,7 +93,7 @@ func TestObjectType_Validate(t *testing.T) { }, }, }, - errContains: "invalid field name", + errContains: "field name cannot be empty, might be missing the named key codec", }, { name: "invalid value field", @@ -105,7 +105,7 @@ func TestObjectType_Validate(t *testing.T) { }, }, }, - errContains: "invalid field name", + errContains: "field name cannot be empty, might be missing the named key codec", }, { name: "no fields", @@ -146,7 +146,7 @@ func TestObjectType_Validate(t *testing.T) { }, }, }, - errContains: "duplicate field name", + errContains: "duplicate key field name \"field1\" for stateObjectType: object1", }, { name: "nullable key field", diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 08759950339c..de0adc9b3ad1 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -1,9 +1,10 @@ module cosmossdk.io/server/v2/cometbft -go 1.23.1 +go 1.23.2 replace ( cosmossdk.io/api => ../../../api + cosmossdk.io/collections => ../../../collections cosmossdk.io/core/testing => ../../../core/testing cosmossdk.io/server/v2 => ../ cosmossdk.io/server/v2/appmanager => ../appmanager diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index 173298ead2e9..dd420b5e2a62 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/depinject v1.1.0 h1:wLan7LG35VM7Yo6ov0jId3RHWCGRhe8E8bsuARorl5E= diff --git a/simapp/go.mod b/simapp/go.mod index b267ed783bb3..7de23fba36bf 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/simapp -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 @@ -252,7 +252,6 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections - cosmossdk.io/indexer/postgres => ../indexer/postgres cosmossdk.io/store => ../store cosmossdk.io/tools/confix => ../tools/confix cosmossdk.io/x/accounts => ../x/accounts @@ -281,6 +280,8 @@ replace ( // Below are the long-lived replace of the SimApp replace ( + cosmossdk.io/indexer/postgres => ../indexer/postgres + cosmossdk.io/schema => ../schema // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // Simapp always use the latest version of the cosmos-sdk diff --git a/simapp/go.sum b/simapp/go.sum index 204a0143b2a6..933a2335c4e8 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -204,9 +204,6 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= -cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index a74d0400734a..83eb8b79cf78 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/simapp/v2 -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/store/cachekv/branch_bench_test.go b/store/cachekv/branch_bench_test.go index 6cb393aa9b43..0001d416585c 100644 --- a/store/cachekv/branch_bench_test.go +++ b/store/cachekv/branch_bench_test.go @@ -74,7 +74,6 @@ func Benchmark_GetSparse(b *testing.B) { var keySink, valueSink any func Benchmark_Iterate(b *testing.B) { - for _, stackSize := range stackSizes { b.Run(fmt.Sprintf("StackSize%d", stackSize), func(b *testing.B) { bs := makeBranchStack(b, stackSize) diff --git a/tests/go.mod b/tests/go.mod index fa985d660cdf..0f64c06e6a15 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -1,6 +1,6 @@ module github.com/cosmos/cosmos-sdk/tests -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/tests/integration/v2/auth/app_test.go b/tests/integration/v2/auth/app_test.go index 01aba394c808..5c3c5a7e95cf 100644 --- a/tests/integration/v2/auth/app_test.go +++ b/tests/integration/v2/auth/app_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "cosmossdk.io/core/router" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" @@ -26,7 +28,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring`` _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring - "github.com/stretchr/testify/require" ) type suite struct { diff --git a/tests/integration/v2/services.go b/tests/integration/v2/services.go index 56dbf63341e5..8cffbc0445ee 100644 --- a/tests/integration/v2/services.go +++ b/tests/integration/v2/services.go @@ -128,8 +128,7 @@ func (e *eventManager) EmitKV(eventType string, attrs ...event.Attribute) error var _ branch.Service = &BranchService{} // custom branch service for integration tests -type BranchService struct { -} +type BranchService struct{} func (bs *BranchService) Execute(ctx context.Context, f func(ctx context.Context) error) error { _, ok := ctx.Value(contextKey).(*integrationContext) diff --git a/types/collections.go b/types/collections.go index df1e27617abb..18ed47ef45d4 100644 --- a/types/collections.go +++ b/types/collections.go @@ -44,7 +44,7 @@ var ( // Deprecated: exists only for state compatibility reasons, should not // be used for new storage keys using time. Please use the time KeyCodec // provided in the collections package. - TimeKey collcodec.KeyCodec[time.Time] = timeKeyCodec{} + TimeKey collcodec.NameableKeyCodec[time.Time] = timeKeyCodec{} // LEUint64Key is a collections KeyCodec that encodes uint64 using little endian. // NOTE: it MUST NOT be used by other modules, distribution relies on this only for @@ -56,7 +56,7 @@ var ( // Deprecated: exists only for state compatibility reasons, should not be // used for new storage keys using []byte. Please use the BytesKey provided // in the collections package. - LengthPrefixedBytesKey collcodec.KeyCodec[[]byte] = lengthPrefixedBytesKey{collections.BytesKey} + LengthPrefixedBytesKey collcodec.NameableKeyCodec[[]byte] = lengthPrefixedBytesKey{collections.BytesKey} ) const ( @@ -139,6 +139,10 @@ func (g lengthPrefixedAddressKey[T]) Size(key T) int { return g.SizeNonTerminal( func (g lengthPrefixedAddressKey[T]) KeyType() string { return "index_key/" + g.KeyCodec.KeyType() } +func (g lengthPrefixedAddressKey[T]) WithName(name string) collcodec.KeyCodec[T] { + return collcodec.NamedKeyCodec[T]{KeyCodec: g, Name: name} +} + // Deprecated: LengthPrefixedAddressKey implements an SDK backwards compatible indexing key encoder // for addresses. // The status quo in the SDK is that address keys are length prefixed even when they're the @@ -148,7 +152,7 @@ func (g lengthPrefixedAddressKey[T]) KeyType() string { return "index_key/" + g. // byte to the string, then when you know when the string part finishes, it's logical that the // part which remains is the address key. In the SDK instead we prepend to the address key its // length too. -func LengthPrefixedAddressKey[T addressUnion](keyCodec collcodec.KeyCodec[T]) collcodec.KeyCodec[T] { +func LengthPrefixedAddressKey[T addressUnion](keyCodec collcodec.KeyCodec[T]) collcodec.NameableKeyCodec[T] { return lengthPrefixedAddressKey[T]{ keyCodec, } @@ -176,6 +180,10 @@ func (g lengthPrefixedBytesKey) KeyType() string { return "index_key/" + g.KeyCodec.KeyType() } +func (g lengthPrefixedBytesKey) WithName(name string) collcodec.KeyCodec[[]byte] { + return collcodec.NamedKeyCodec[[]byte]{KeyCodec: g, Name: name} +} + // Collection Codecs type intValueCodec struct{} @@ -329,6 +337,10 @@ func (t timeKeyCodec) DecodeNonTerminal(buffer []byte) (int, time.Time, error) { } func (t timeKeyCodec) SizeNonTerminal(key time.Time) int { return t.Size(key) } +func (t timeKeyCodec) WithName(name string) collcodec.KeyCodec[time.Time] { + return collcodec.NamedKeyCodec[time.Time]{KeyCodec: t, Name: name} +} + type leUint64Key struct{} func (l leUint64Key) Encode(buffer []byte, key uint64) (int, error) { diff --git a/x/accounts/defaults/base/go.mod b/x/accounts/defaults/base/go.mod index e15b033d6aa5..c4a10bf35e4f 100644 --- a/x/accounts/defaults/base/go.mod +++ b/x/accounts/defaults/base/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/accounts/defaults/base -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/accounts/defaults/lockup/go.mod b/x/accounts/defaults/lockup/go.mod index d61421cb0d4c..4f715b86ccdb 100644 --- a/x/accounts/defaults/lockup/go.mod +++ b/x/accounts/defaults/lockup/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/accounts/defaults/lockup -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/collections v0.4.0 diff --git a/x/accounts/defaults/multisig/go.mod b/x/accounts/defaults/multisig/go.mod index 6a75ddea9db3..e6de34cee263 100644 --- a/x/accounts/defaults/multisig/go.mod +++ b/x/accounts/defaults/multisig/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/accounts/defaults/multisig -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/collections v0.4.0 diff --git a/x/accounts/go.mod b/x/accounts/go.mod index acdfdc692317..3a64b6806dbe 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/accounts -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/auth/module.go b/x/auth/module.go index b959fcde5408..45e845a02527 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -8,10 +8,12 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" + "cosmossdk.io/schema" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -198,3 +200,9 @@ func (AppModule) ProposalMsgsX(weights simsx.WeightSource, reg simsx.Registry) { func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.accountKeeper.Schema) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.accountKeeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/authz/go.mod b/x/authz/go.mod index 6b5471cda55a..fd8811df9912 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/authz -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/bank/go.mod b/x/bank/go.mod index cfa72128365b..78c583d0ad2c 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/bank -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 31620246518e..6eff40e1388d 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -78,10 +78,10 @@ func NewBaseViewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, ak type cdc: cdc, ak: ak, addrCdc: ak.AddressCodec(), - Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey.WithName("supply"), sdk.IntValue), - DenomMetadata: collections.NewMap(sb, types.DenomMetadataPrefix, "denom_metadata", collections.StringKey.WithName("denom_metadata"), codec.CollValue[types.Metadata](cdc)), - SendEnabled: collections.NewMap(sb, types.SendEnabledPrefix, "send_enabled", collections.StringKey.WithName("send_enabled"), codec.BoolValue), // NOTE: we use a bool value which uses protobuf to retain state backwards compat - Balances: collections.NewIndexedMap(sb, types.BalancesPrefix, "balances", collections.NamedPairKeyCodec("address", sdk.AccAddressKey, "balances", collections.StringKey), types.BalanceValueCodec, newBalancesIndexes(sb)), + Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey.WithName("denom"), sdk.IntValue), + DenomMetadata: collections.NewMap(sb, types.DenomMetadataPrefix, "denom_metadata", collections.StringKey.WithName("denom"), codec.CollValue[types.Metadata](cdc)), + SendEnabled: collections.NewMap(sb, types.SendEnabledPrefix, "send_enabled", collections.StringKey.WithName("denom"), codec.BoolValue), // NOTE: we use a bool value which uses protobuf to retain state backwards compat + Balances: collections.NewIndexedMap(sb, types.BalancesPrefix, "balances", collections.NamedPairKeyCodec("address", sdk.AccAddressKey, "denom", collections.StringKey), types.BalanceValueCodec, newBalancesIndexes(sb)), Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), } diff --git a/x/bank/module.go b/x/bank/module.go index f387903c5886..cc459f23b340 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -39,6 +39,7 @@ var ( _ appmodule.HasMigrations = AppModule{} _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} + _ schema.HasModuleCodec = AppModule{} ) // AppModule implements an application module for the bank module. diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 7db82fdd1a4f..476ae25c1236 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/circuit -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -9,6 +9,7 @@ require ( cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e cosmossdk.io/depinject v1.1.0 cosmossdk.io/errors v1.0.1 + cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc github.com/cosmos/cosmos-sdk v0.53.0 github.com/cosmos/gogoproto v1.7.0 @@ -24,7 +25,6 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.5.0 // indirect cosmossdk.io/math v1.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect @@ -177,6 +177,8 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections + cosmossdk.io/schema => ../../schema cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 42b2170efbf4..bbaed15447da 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= @@ -18,8 +16,6 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/circuit/module.go b/x/circuit/module.go index 91645aaee6cc..da69333716bf 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -8,10 +8,12 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" + "cosmossdk.io/schema" "cosmossdk.io/x/circuit/ante" "cosmossdk.io/x/circuit/keeper" "cosmossdk.io/x/circuit/types" @@ -117,3 +119,9 @@ func (am AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error { validator := ante.NewCircuitBreakerDecorator(&am.keeper) return validator.ValidateTx(ctx, tx) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/consensus/go.mod b/x/consensus/go.mod index 51ff28ab91f4..75d9c5c822bb 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/consensus -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -8,6 +8,7 @@ require ( cosmossdk.io/core v1.0.0-alpha.6 cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e cosmossdk.io/depinject v1.1.0 + cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f github.com/cometbft/cometbft/api v1.0.0-rc.1 @@ -27,7 +28,6 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.5.0 // indirect cosmossdk.io/math v1.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect @@ -175,6 +175,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 42b2170efbf4..ff76711e650f 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 28f94270a38e..53858707f9fe 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -26,6 +26,7 @@ type Keeper struct { authority string ParamsStore collections.Item[cmtproto.ConsensusParams] + Schema collections.Schema } var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore @@ -33,11 +34,19 @@ var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore // NewKeeper creates a new Keeper instance. func NewKeeper(cdc codec.BinaryCodec, env appmodule.Environment, authority string) Keeper { sb := collections.NewSchemaBuilder(env.KVStoreService) - return Keeper{ + k := Keeper{ Environment: env, authority: authority, ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)), } + + var err error + k.Schema, err = sb.Build() + if err != nil { + panic(fmt.Sprintf("failed to build schema: %v", err)) + } + + return k } // GetAuthority returns the authority address for the consensus module. diff --git a/x/consensus/module.go b/x/consensus/module.go index 298a80bad428..7a21619980be 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -7,8 +7,10 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/registry" + "cosmossdk.io/schema" "cosmossdk.io/x/consensus/keeper" "cosmossdk.io/x/consensus/types" @@ -96,3 +98,9 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // ConsensusVersion implements HasConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/distribution/go.mod b/x/distribution/go.mod index c65b5e935b4f..c006e8b0d4c7 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/distribution -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -10,6 +10,7 @@ require ( cosmossdk.io/depinject v1.1.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.4.0 + cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 github.com/cosmos/cosmos-proto v1.0.0-beta.5 @@ -29,7 +30,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.5.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index a44285055dd4..2df55c435ca2 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -104,7 +104,12 @@ func NewKeeper( sb, types.DelegatorStartingInfoPrefix, "delegators_starting_info", - collections.PairKeyCodec(sdk.ValAddressKey, sdk.LengthPrefixedAddressKey(sdk.AccAddressKey)), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + collections.NamedPairKeyCodec( + "validator_address", + sdk.ValAddressKey, + "delegator_address", + sdk.LengthPrefixedAddressKey(sdk.AccAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + ), codec.CollValue[types.DelegatorStartingInfo](cdc), ), ValidatorsAccumulatedCommission: collections.NewMap( @@ -126,14 +131,26 @@ func NewKeeper( sb, types.ValidatorHistoricalRewardsPrefix, "validator_historical_rewards", - collections.PairKeyCodec(sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), sdk.LEUint64Key), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + collections.NamedPairKeyCodec( + "validator_address", + sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + "period", + sdk.LEUint64Key, + ), codec.CollValue[types.ValidatorHistoricalRewards](cdc), ), ValidatorSlashEvents: collections.NewMap( sb, types.ValidatorSlashEventPrefix, "validator_slash_events", - collections.TripleKeyCodec(sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), collections.Uint64Key, collections.Uint64Key), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + collections.NamedTripleKeyCodec( + "validator_address", + sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + "height", + collections.Uint64Key, + "period", + collections.Uint64Key, + ), codec.CollValue[types.ValidatorSlashEvent](cdc), ), } diff --git a/x/distribution/module.go b/x/distribution/module.go index eb7de978c6d1..ae1ae85e82c9 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -9,8 +9,10 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/registry" + "cosmossdk.io/schema" "cosmossdk.io/x/distribution/client/cli" "cosmossdk.io/x/distribution/keeper" "cosmossdk.io/x/distribution/simulation" @@ -182,3 +184,9 @@ func (am AppModule) WeightedOperationsX(weights simsx.WeightSource, reg simsx.Re reg.Add(weights.Get("msg_withdraw_delegation_reward", 50), simulation.MsgWithdrawDelegatorRewardFactory(am.keeper, am.stakingKeeper)) reg.Add(weights.Get("msg_withdraw_validator_commission", 50), simulation.MsgWithdrawValidatorCommissionFactory(am.keeper, am.stakingKeeper)) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 1b0ac8e6a480..7772bd62f7bc 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/epochs -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -20,7 +20,7 @@ require ( google.golang.org/grpc v1.68.0 ) -require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect +require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1 // indirect @@ -180,6 +180,8 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections + cosmossdk.io/schema => ../../schema cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 42b2170efbf4..bbaed15447da 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= @@ -18,8 +16,6 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/epochs/module.go b/x/epochs/module.go index 2fba7c0de141..aeb7947b4ec1 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -8,8 +8,10 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/registry" + "cosmossdk.io/schema" "cosmossdk.io/x/epochs/keeper" "cosmossdk.io/x/epochs/simulation" "cosmossdk.io/x/epochs/types" @@ -125,3 +127,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 245dd8888ca9..e03383bc8a39 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/evidence -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -177,6 +177,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 42b2170efbf4..ff76711e650f 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 60c29a96fe9d..d938184417a2 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/feegrant -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/gov/go.mod b/x/gov/go.mod index 5f09e43b1278..78d50b5c9759 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/gov -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/group/go.mod b/x/group/go.mod index c25250fa862e..cbfa558f38df 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/group -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 diff --git a/x/mint/go.mod b/x/mint/go.mod index 25557a8f91ac..268389f83778 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/mint -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -29,7 +29,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect @@ -181,6 +181,8 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections + cosmossdk.io/schema => ../../schema cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/consensus => ../consensus diff --git a/x/mint/go.sum b/x/mint/go.sum index 42b2170efbf4..bbaed15447da 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= @@ -18,8 +16,6 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/mint/module.go b/x/mint/module.go index 52c6324b4a11..fa572bdbc90d 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -8,8 +8,10 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/registry" + "cosmossdk.io/schema" "cosmossdk.io/x/mint/keeper" "cosmossdk.io/x/mint/simulation" "cosmossdk.io/x/mint/types" @@ -165,3 +167,9 @@ func (AppModule) ProposalMsgsX(weights simsx.WeightSource, reg simsx.Registry) { func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/nft/go.mod b/x/nft/go.mod index 8036937ba01a..bbf3c08110d7 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/nft -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -177,6 +177,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/nft/go.sum b/x/nft/go.sum index 42b2170efbf4..ff76711e650f 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/params/go.mod b/x/params/go.mod index f8098096abe5..791a55d7949e 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/params -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 @@ -169,6 +169,7 @@ replace github.com/cosmos/cosmos-sdk => ../.. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/distribution => ../distribution diff --git a/x/params/go.sum b/x/params/go.sum index 31188c0bab68..aac0123354df 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index d4b8a1233cb0..7ef25cc9449e 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/protocolpool -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 @@ -177,6 +177,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 42b2170efbf4..ff76711e650f 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/slashing/go.mod b/x/slashing/go.mod index 96d2578d822f..f247839e8203 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/slashing -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 @@ -178,6 +178,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. // TODO remove post spinning out all modules replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/staking => ../staking diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 7ba2dc64cb49..462fbea83843 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -4,8 +4,6 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= diff --git a/x/staking/go.mod b/x/staking/go.mod index d1fc818bc4a9..43c2c186e5c5 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/staking -go 1.23.1 +go 1.23.2 require ( cosmossdk.io/api v0.7.6 @@ -160,8 +160,9 @@ require ( go.opencensus.io v0.24.0 // indirect ) +require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 + require ( - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect github.com/bytedance/sonic v1.12.4 // indirect github.com/bytedance/sonic/loader v0.2.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index b85bab1bbc8b..876c9ae97df3 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -159,8 +159,10 @@ func NewKeeper( LastTotalPower: collections.NewItem(sb, types.LastTotalPowerKey, "last_total_power", sdk.IntValue), Delegations: collections.NewMap( sb, types.DelegationKey, "delegations", - collections.PairKeyCodec( + collections.NamedPairKeyCodec( + "delegator", sdk.LengthPrefixedAddressKey(sdk.AccAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + "validator_address_key", sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility ), codec.CollValue[types.Delegation](cdc), @@ -168,67 +170,94 @@ func NewKeeper( DelegationsByValidator: collections.NewMap( sb, types.DelegationByValIndexKey, "delegations_by_validator", - collections.PairKeyCodec(sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), sdk.AccAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + collections.NamedPairKeyCodec( + "validator_address", + sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + "delegator", + sdk.AccAddressKey, + ), collections.BytesValue, ), UnbondingID: collections.NewSequence(sb, types.UnbondingIDKey, "unbonding_id"), ValidatorByConsensusAddress: collections.NewMap( sb, types.ValidatorsByConsAddrKey, "validator_by_cons_addr", - sdk.LengthPrefixedAddressKey(sdk.ConsAddressKey), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility + sdk.LengthPrefixedAddressKey(sdk.ConsAddressKey).WithName("cons_address"), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility collcodec.KeyToValueCodec(sdk.ValAddressKey), ), - UnbondingType: collections.NewMap(sb, types.UnbondingTypeKey, "unbonding_type", collections.Uint64Key, collections.Uint64Value), + UnbondingType: collections.NewMap(sb, types.UnbondingTypeKey, "unbonding_type", collections.Uint64Key.WithName("unbonding_id"), collections.Uint64Value), // key format is: 52 | lengthPrefixedBytes(AccAddr) | lengthPrefixedBytes(SrcValAddr) | lengthPrefixedBytes(DstValAddr) Redelegations: collections.NewMap( sb, types.RedelegationKey, "redelegations", - collections.TripleKeyCodec( + collections.NamedTripleKeyCodec( + "delegator", collections.BytesKey, + "src_validator", collections.BytesKey, + "dst_validator", sdk.LengthPrefixedBytesKey, // sdk.LengthPrefixedBytesKey is needed to retain state compatibility ), codec.CollValue[types.Redelegation](cdc), ), - UnbondingIndex: collections.NewMap(sb, types.UnbondingIndexKey, "unbonding_index", collections.Uint64Key, collections.BytesValue), + UnbondingIndex: collections.NewMap(sb, types.UnbondingIndexKey, "unbonding_index", collections.Uint64Key.WithName("index"), collections.BytesValue.WithName("ubd_key")), UnbondingDelegationByValIndex: collections.NewMap( sb, types.UnbondingDelegationByValIndexKey, "unbonding_delegation_by_val_index", - collections.PairKeyCodec(sdk.LengthPrefixedBytesKey, sdk.LengthPrefixedBytesKey), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility + collections.NamedPairKeyCodec( + "validator_address", + sdk.LengthPrefixedBytesKey, + "delegator", + sdk.LengthPrefixedBytesKey, + ), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility collections.BytesValue, ), - UnbondingQueue: collections.NewMap(sb, types.UnbondingQueueKey, "unbonidng_queue", sdk.TimeKey, codec.CollValue[types.DVPairs](cdc)), + UnbondingQueue: collections.NewMap(sb, types.UnbondingQueueKey, "unbonidng_queue", sdk.TimeKey.WithName("unbonding_time"), codec.CollValue[types.DVPairs](cdc)), // key format is: 53 | lengthPrefixedBytes(SrcValAddr) | lengthPrefixedBytes(AccAddr) | lengthPrefixedBytes(DstValAddr) RedelegationsByValSrc: collections.NewMap( sb, types.RedelegationByValSrcIndexKey, "redelegations_by_val_src", - collections.TripleKeyCodec( + collections.NamedTripleKeyCodec( + "src_validator", collections.BytesKey, + "delegator", collections.BytesKey, + "dst_validator", sdk.LengthPrefixedBytesKey, // sdk.LengthPrefixedBytesKey is needed to retain state compatibility ), collections.BytesValue, ), // key format is: 17 | lengthPrefixedBytes(valAddr) | power - LastValidatorPower: collections.NewMap(sb, types.LastValidatorPowerKey, "last_validator_power", sdk.LengthPrefixedBytesKey, codec.CollValue[gogotypes.Int64Value](cdc)), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility + LastValidatorPower: collections.NewMap(sb, types.LastValidatorPowerKey, "last_validator_power", sdk.LengthPrefixedBytesKey.WithName("validator_address"), codec.CollValue[gogotypes.Int64Value](cdc)), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility // key format is: 54 | lengthPrefixedBytes(DstValAddr) | lengthPrefixedBytes(AccAddr) | lengthPrefixedBytes(SrcValAddr) RedelegationsByValDst: collections.NewMap( sb, types.RedelegationByValDstIndexKey, "redelegations_by_val_dst", - collections.TripleKeyCodec( + collections.NamedTripleKeyCodec( + "dst_validator", collections.BytesKey, + "delegator", collections.BytesKey, + "src_validator", sdk.LengthPrefixedBytesKey, // sdk.LengthPrefixedBytesKey is needed to retain state compatibility ), collections.BytesValue, ), - RedelegationQueue: collections.NewMap(sb, types.RedelegationQueueKey, "redelegation_queue", sdk.TimeKey, codec.CollValue[types.DVVTriplets](cdc)), - Validators: collections.NewMap(sb, types.ValidatorsKey, "validators", sdk.LengthPrefixedBytesKey, codec.CollValue[types.Validator](cdc)), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility + RedelegationQueue: collections.NewMap(sb, types.RedelegationQueueKey, "redelegation_queue", sdk.TimeKey.WithName("completion_time"), codec.CollValue[types.DVVTriplets](cdc)), + Validators: collections.NewMap( + sb, + types.ValidatorsKey, + "validators", + sdk.LengthPrefixedBytesKey.WithName("validator_address"), // sdk.LengthPrefixedBytesKey is needed to retain state compatibility + codec.CollValue[types.Validator](cdc), + ), UnbondingDelegations: collections.NewMap( sb, types.UnbondingDelegationKey, "unbonding_delegation", - collections.PairKeyCodec( + collections.NamedPairKeyCodec( + "delegator", collections.BytesKey, + "validator", sdk.LengthPrefixedBytesKey, // sdk.LengthPrefixedBytesKey is needed to retain state compatibility ), codec.CollValue[types.UnbondingDelegation](cdc), @@ -238,9 +267,12 @@ func NewKeeper( ValidatorQueue: collections.NewMap( sb, types.ValidatorQueueKey, "validator_queue", - collections.TripleKeyCodec( + collections.NamedTripleKeyCodec( + "ts_length", collections.Uint64Key, + "timestamp", sdk.TimeKey, + "height", collections.Uint64Key, ), codec.CollValue[types.ValAddresses](cdc), @@ -252,7 +284,11 @@ func NewKeeper( ValidatorConsensusKeyRotationRecordIndexKey: collections.NewKeySet( sb, types.ValidatorConsensusKeyRotationRecordIndexKey, "cons_pub_rotation_index", - collections.PairKeyCodec(collections.BytesKey, sdk.TimeKey), + collections.NamedPairKeyCodec( + "validator_address", + collections.BytesKey, + "time", + sdk.TimeKey), ), // key format is: 103 | time @@ -285,7 +321,11 @@ func NewKeeper( sb, types.ValidatorConsPubKeyRotationHistoryKey, "cons_pub_rotation_history", - collections.PairKeyCodec(collections.BytesKey, collections.Uint64Key), + collections.NamedPairKeyCodec( + "validator_address", + collections.BytesKey, + "height_key", + collections.Uint64Key), codec.CollValue[types.ConsPubKeyRotationHistory](cdc), NewRotationHistoryIndexes(sb), ), diff --git a/x/staking/module.go b/x/staking/module.go index 52b5313ed15b..041906ad1c03 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -9,9 +9,11 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" + "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" "cosmossdk.io/core/registry" "cosmossdk.io/depinject" + "cosmossdk.io/schema" "cosmossdk.io/x/staking/client/cli" "cosmossdk.io/x/staking/keeper" "cosmossdk.io/x/staking/types" @@ -37,6 +39,7 @@ var ( _ appmodule.AppModule = AppModule{} _ appmodule.HasMigrations = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} + _ schema.HasModuleCodec = AppModule{} _ depinject.OnePerModuleType = AppModule{} ) @@ -163,3 +166,9 @@ func (AppModule) ConsensusVersion() uint64 { return consensusVersion } func (am AppModule) EndBlock(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { return am.keeper.EndBlocker(ctx) } + +// ModuleCodec implements schema.HasModuleCodec. +// It allows the indexer to decode the module's KVPairUpdate. +func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) { + return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{}) +} diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 52e853e867c0..ce12fe12e451 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/x/upgrade -go 1.23.1 +go 1.23.3 require ( cosmossdk.io/api v0.7.6 @@ -208,6 +208,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api + cosmossdk.io/collections => ../../collections cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../bank cosmossdk.io/x/gov => ../gov diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 7a901fa02d2f..33caed9ce32c 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -192,8 +192,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs=