Skip to content

Commit

Permalink
feat(server/v2): refactor the server/v2 events (#21785)
Browse files Browse the repository at this point in the history
(cherry picked from commit 01212de)

# Conflicts:
#	client/v2/go.mod
#	client/v2/go.sum
#	collections/collections.go
#	collections/go.mod
#	collections/go.sum
#	collections/indexing.go
#	go.mod
#	go.sum
#	runtime/v2/go.mod
#	runtime/v2/go.sum
#	server/v2/cometbft/go.mod
#	server/v2/cometbft/go.sum
#	server/v2/go.mod
#	server/v2/go.sum
#	server/v2/stf/core_event_service.go
#	server/v2/stf/go.mod
#	server/v2/stf/go.sum
#	server/v2/stf/stf.go
#	server/v2/streaming/utils.go
#	simapp/go.mod
#	simapp/go.sum
#	simapp/v2/go.mod
#	simapp/v2/go.sum
#	tests/go.mod
#	tests/go.sum
#	x/accounts/defaults/base/go.mod
#	x/accounts/defaults/base/go.sum
#	x/accounts/defaults/lockup/go.mod
#	x/accounts/defaults/lockup/go.sum
#	x/accounts/defaults/multisig/go.mod
#	x/accounts/defaults/multisig/go.sum
#	x/accounts/go.mod
#	x/accounts/go.sum
#	x/authz/go.mod
#	x/authz/go.sum
#	x/bank/go.mod
#	x/bank/go.sum
#	x/circuit/go.mod
#	x/circuit/go.sum
#	x/consensus/go.mod
#	x/consensus/go.sum
#	x/distribution/go.mod
#	x/distribution/go.sum
#	x/epochs/go.mod
#	x/epochs/go.sum
#	x/evidence/go.mod
#	x/evidence/go.sum
#	x/feegrant/go.mod
#	x/feegrant/go.sum
#	x/gov/go.mod
#	x/gov/go.sum
#	x/group/go.mod
#	x/group/go.sum
#	x/mint/go.mod
#	x/mint/go.sum
#	x/nft/go.mod
#	x/nft/go.sum
#	x/params/go.mod
#	x/params/go.sum
#	x/protocolpool/go.mod
#	x/protocolpool/go.sum
#	x/slashing/go.mod
#	x/slashing/go.sum
#	x/staking/go.mod
#	x/staking/go.sum
#	x/upgrade/go.mod
#	x/upgrade/go.sum
  • Loading branch information
cool-develope authored and mergify[bot] committed Sep 18, 2024
1 parent e42e270 commit 5797783
Show file tree
Hide file tree
Showing 71 changed files with 2,870 additions and 66 deletions.
10 changes: 10 additions & 0 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ module cosmossdk.io/client/v2
go 1.23.1

require (
<<<<<<< HEAD
cosmossdk.io/api v0.8.0
cosmossdk.io/core v1.0.0-alpha.2 // main
=======
cosmossdk.io/api v0.7.5
cosmossdk.io/core v1.0.0-alpha.3
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
cosmossdk.io/depinject v1.0.0
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
Expand All @@ -27,8 +32,13 @@ require (
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0
<<<<<<< HEAD
cosmossdk.io/schema v0.2.0 // indirect
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6 // indirect
=======
cosmossdk.io/schema v0.3.0 // indirect
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
12 changes: 12 additions & 0 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88e
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc=
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=
<<<<<<< HEAD
cosmossdk.io/api v0.7.3-0.20240815194237-858ec2fcb897 h1:YV9M+9pClbzPncO5XMSc3kIgDWjb7DdZ/DtURaWqle8=
cosmossdk.io/api v0.7.3-0.20240815194237-858ec2fcb897/go.mod h1:oqpDMZQpEgSo0Cm4F+0yxoC9UQbo/SlodZR4zeOqBsE=
cosmossdk.io/collections v0.4.1-0.20240802064046-23fac2f1b8ab h1:E/IWad76v1Nc4Atswaccpt7twJ0VwHkbY94/PhmZfTo=
Expand All @@ -12,6 +13,12 @@ cosmossdk.io/core v1.0.0-alpha.2 h1:epU0Xwces4Rgl5bMhHHkXGaGDcyucNGlC/JDH+Suckg=
cosmossdk.io/core v1.0.0-alpha.2/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90=
cosmossdk.io/core/testing v0.0.0-20240913164418-aaf72f20c10b h1:uEMbr7Hdpz0fU+GXU6mSN2vgoQnr66WYUpRuiba2aEk=
cosmossdk.io/core/testing v0.0.0-20240913164418-aaf72f20c10b/go.mod h1:FllCSj/ZYskfb982HKqBSISO8DkBY4Euqq768HSFz68=
=======
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.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA=
cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY=
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
Expand All @@ -20,10 +27,15 @@ cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
<<<<<<< HEAD
cosmossdk.io/schema v0.2.0 h1:UH5CR1DqUq8yP+5Np8PbvG4YX0zAUsTN2Qk6yThmfMk=
cosmossdk.io/schema v0.2.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214 h1:UUW0+2UgbDwQ452o2aw4DrVSWmowcad7DB7Vln+N94I=
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214/go.mod h1:ct8HATr+s48YYTRXEyP3HF33v9qEVWHMxwOL8P/v4iQ=
=======
cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c=
cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o=
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg=
cosmossdk.io/x/tx v0.13.4-0.20240918094839-0c8ad9d2c64b h1:FyLcX6eZh9c4FqWla3pXubLIIVlndfQohvf+IcXg99M=
Expand Down
178 changes: 178 additions & 0 deletions collections/collections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package collections

import (
"context"
"errors"
"io"
"math"

"cosmossdk.io/collections/codec"
"cosmossdk.io/schema"
)

var (
// ErrNotFound is returned when the provided key is not present in the StorageProvider.
ErrNotFound = errors.New("collections: not found")
// ErrEncoding is returned when something fails during key or value encoding/decoding.
ErrEncoding = codec.ErrEncoding
// ErrConflict is returned when there are conflicts, for example in UniqueIndex.
ErrConflict = errors.New("collections: conflict")
)

// KEYS

var (
// Uint16Key can be used to encode uint16 keys. Encoding is big endian to retain ordering.
Uint16Key = codec.NewUint16Key[uint16]()
// Uint32Key can be used to encode uint32 keys. Encoding is big endian to retain ordering.
Uint32Key = codec.NewUint32Key[uint32]()
// Uint64Key can be used to encode uint64 keys. Encoding is big endian to retain ordering.
Uint64Key = codec.NewUint64Key[uint64]()
// Int32Key can be used to encode int32 keys. Encoding retains ordering by toggling the MSB.
Int32Key = codec.NewInt32Key[int32]()
// Int64Key can be used to encode int64 keys. Encoding retains ordering by toggling the MSB.
Int64Key = codec.NewInt64Key[int64]()
// StringKey can be used to encode string keys. The encoding just converts the string
// to bytes.
// Non-terminality in multipart keys is handled by appending the StringDelimiter,
// this means that a string key when used as the non final part of a multipart key cannot
// contain the StringDelimiter.
// Lexicographical ordering is retained both in non and multipart keys.
StringKey = codec.NewStringKeyCodec[string]()
// BytesKey can be used to encode bytes keys. The encoding will just use
// the provided bytes.
// When used as the non-terminal part of a multipart key, we prefix the bytes key
// with a single byte representing the length of the key. This means two things:
// 1. When used in multipart keys the length can be at maximum 255 (max number that
// can be represented with a single byte).
// 2. When used in multipart keys the lexicographical ordering is lost due to the
// length prefixing.
// JSON encoding represents a bytes key as a hex encoded string.
BytesKey = codec.NewBytesKey[[]byte]()
// BoolKey can be used to encode booleans. It uses a single byte to represent the boolean.
// 0x0 is used to represent false, and 0x1 is used to represent true.
BoolKey = codec.NewBoolKey[bool]()
)

// VALUES

var (
// BoolValue implements a ValueCodec for bool.
BoolValue = codec.KeyToValueCodec(BoolKey)
// Uint16Value implements a ValueCodec for uint16.
Uint16Value = codec.KeyToValueCodec(Uint16Key)
// Uint32Value implements a ValueCodec for uint32.
Uint32Value = codec.KeyToValueCodec(Uint32Key)
// Uint64Value implements a ValueCodec for uint64.
Uint64Value = codec.KeyToValueCodec(Uint64Key)
// Int32Value implements a ValueCodec for int32.
Int32Value = codec.KeyToValueCodec(Int32Key)
// Int64Value implements a ValueCodec for int64.
Int64Value = codec.KeyToValueCodec(Int64Key)
// StringValue implements a ValueCodec for string.
StringValue = codec.KeyToValueCodec(StringKey)
// BytesValue implements a ValueCodec for bytes.
BytesValue = codec.KeyToValueCodec(BytesKey)
)

// Collection is the interface that all collections implement. It will eventually
// include methods for importing/exporting genesis data and schema
// reflection for clients.
// NOTE: Unstable.
type Collection interface {
// GetName is the unique name of the collection within a schema. It must
// match format specified by NameRegex.
GetName() string

// GetPrefix is the unique prefix of the collection within a schema.
GetPrefix() []byte

// ValueCodec returns the codec used to encode/decode values of the collection.
ValueCodec() codec.UntypedValueCodec

genesisHandler

// collectionSchemaCodec returns the schema codec for this collection.
schemaCodec() (*collectionSchemaCodec, error)

// isSecondaryIndex indicates that this collection represents a secondary index
// in the schema and should be excluded from the module's user facing schema.
isSecondaryIndex() bool
}

// collectionSchemaCodec maps a collection to a schema object type and provides
// decoders and encoders to and from schema values and raw kv-store bytes.
type collectionSchemaCodec struct {
coll Collection
objectType schema.StateObjectType
keyDecoder func([]byte) (any, error)
valueDecoder func([]byte) (any, error)
}

// Prefix defines a segregation bytes namespace for specific collections objects.
type Prefix []byte

// Bytes returns the raw Prefix bytes.
func (n Prefix) Bytes() []byte { return n }

// NewPrefix returns a Prefix given the provided namespace identifier.
// In the same module, no prefixes should share the same starting bytes
// meaning that having two namespaces whose bytes representation is:
// p1 := []byte("prefix")
// p2 := []byte("prefix1")
// yields to iterations of p1 overlapping over p2.
// If a numeric prefix is provided, it must be between 0 and 255 (uint8).
// If out of bounds this function will panic.
// Reason for which this function is constrained to `int` instead of `uint8` is for
// API ergonomics, golang's type inference will infer int properly but not uint8
// meaning that developers would need to write NewPrefix(uint8(number)) for numeric
// prefixes.
func NewPrefix[T interface{ int | string | []byte }](identifier T) Prefix {
i := any(identifier)
var prefix []byte
switch c := i.(type) {
case int:
if c > math.MaxUint8 || c < 0 {
panic("invalid integer prefix value: must be between 0 and 255")
}
prefix = []byte{uint8(c)}
case string:
prefix = []byte(c)
case []byte:
identifierCopy := make([]byte, len(c))
copy(identifierCopy, c)
prefix = identifierCopy
}
return prefix
}

var _ Collection = (*collectionImpl[string, string])(nil)

// collectionImpl wraps a Map and implements Collection. This properly splits
// the generic and untyped Collection interface from the typed Map, which every
// collection builds on.
type collectionImpl[K, V any] struct {
m Map[K, V]
}

func (c collectionImpl[K, V]) ValueCodec() codec.UntypedValueCodec {
return codec.NewUntypedValueCodec(c.m.vc)
}

func (c collectionImpl[K, V]) GetName() string { return c.m.name }

func (c collectionImpl[K, V]) GetPrefix() []byte { return NewPrefix(c.m.prefix) }

func (c collectionImpl[K, V]) validateGenesis(r io.Reader) error { return c.m.validateGenesis(r) }

func (c collectionImpl[K, V]) importGenesis(ctx context.Context, r io.Reader) error {
return c.m.importGenesis(ctx, r)
}

func (c collectionImpl[K, V]) exportGenesis(ctx context.Context, w io.Writer) error {
return c.m.exportGenesis(ctx, w)
}

func (c collectionImpl[K, V]) defaultGenesis(w io.Writer) error { return c.m.defaultGenesis(w) }

func (c collectionImpl[K, V]) isSecondaryIndex() bool { return c.m.isSecondaryIndex }
20 changes: 20 additions & 0 deletions collections/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module cosmossdk.io/collections

go 1.23

require (
cosmossdk.io/core v1.0.0-alpha.3
cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000
cosmossdk.io/schema v0.3.0
github.com/stretchr/testify v1.9.0
github.com/tidwall/btree v1.7.0
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
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace cosmossdk.io/core/testing => ../core/testing
18 changes: 18 additions & 0 deletions collections/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA=
cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY=
cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c=
cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
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/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.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=
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=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
Loading

0 comments on commit 5797783

Please sign in to comment.