Skip to content

Commit 5797783

Browse files
cool-developemergify[bot]
authored andcommitted
feat(server/v2): refactor the server/v2 events (#21785)
(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
1 parent e42e270 commit 5797783

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2870
-66
lines changed

client/v2/go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ module cosmossdk.io/client/v2
33
go 1.23.1
44

55
require (
6+
<<<<<<< HEAD
67
cosmossdk.io/api v0.8.0
78
cosmossdk.io/core v1.0.0-alpha.2 // main
9+
=======
10+
cosmossdk.io/api v0.7.5
11+
cosmossdk.io/core v1.0.0-alpha.3
12+
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
813
cosmossdk.io/depinject v1.0.0
914
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
1015
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
@@ -27,8 +32,13 @@ require (
2732
cosmossdk.io/errors v1.0.1 // indirect
2833
cosmossdk.io/log v1.4.1 // indirect
2934
cosmossdk.io/math v1.3.0
35+
<<<<<<< HEAD
3036
cosmossdk.io/schema v0.2.0 // indirect
3137
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6 // indirect
38+
=======
39+
cosmossdk.io/schema v0.3.0 // indirect
40+
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
41+
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
3242
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect
3343
filippo.io/edwards25519 v1.1.0 // indirect
3444
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect

client/v2/go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88e
44
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc=
55
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
66
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
7+
<<<<<<< HEAD
78
cosmossdk.io/api v0.7.3-0.20240815194237-858ec2fcb897 h1:YV9M+9pClbzPncO5XMSc3kIgDWjb7DdZ/DtURaWqle8=
89
cosmossdk.io/api v0.7.3-0.20240815194237-858ec2fcb897/go.mod h1:oqpDMZQpEgSo0Cm4F+0yxoC9UQbo/SlodZR4zeOqBsE=
910
cosmossdk.io/collections v0.4.1-0.20240802064046-23fac2f1b8ab h1:E/IWad76v1Nc4Atswaccpt7twJ0VwHkbY94/PhmZfTo=
@@ -12,6 +13,12 @@ cosmossdk.io/core v1.0.0-alpha.2 h1:epU0Xwces4Rgl5bMhHHkXGaGDcyucNGlC/JDH+Suckg=
1213
cosmossdk.io/core v1.0.0-alpha.2/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90=
1314
cosmossdk.io/core/testing v0.0.0-20240913164418-aaf72f20c10b h1:uEMbr7Hdpz0fU+GXU6mSN2vgoQnr66WYUpRuiba2aEk=
1415
cosmossdk.io/core/testing v0.0.0-20240913164418-aaf72f20c10b/go.mod h1:FllCSj/ZYskfb982HKqBSISO8DkBY4Euqq768HSFz68=
16+
=======
17+
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
18+
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
19+
cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA=
20+
cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY=
21+
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
1522
cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
1623
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
1724
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
@@ -20,10 +27,15 @@ cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
2027
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
2128
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
2229
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
30+
<<<<<<< HEAD
2331
cosmossdk.io/schema v0.2.0 h1:UH5CR1DqUq8yP+5Np8PbvG4YX0zAUsTN2Qk6yThmfMk=
2432
cosmossdk.io/schema v0.2.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
2533
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214 h1:UUW0+2UgbDwQ452o2aw4DrVSWmowcad7DB7Vln+N94I=
2634
cosmossdk.io/store v1.0.0-rc.0.0.20240913190136-3bc707a5a214/go.mod h1:ct8HATr+s48YYTRXEyP3HF33v9qEVWHMxwOL8P/v4iQ=
35+
=======
36+
cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c=
37+
cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
38+
>>>>>>> 01212de2d (feat(server/v2): refactor the server/v2 events (#21785))
2739
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o=
2840
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg=
2941
cosmossdk.io/x/tx v0.13.4-0.20240918094839-0c8ad9d2c64b h1:FyLcX6eZh9c4FqWla3pXubLIIVlndfQohvf+IcXg99M=

collections/collections.go

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package collections
2+
3+
import (
4+
"context"
5+
"errors"
6+
"io"
7+
"math"
8+
9+
"cosmossdk.io/collections/codec"
10+
"cosmossdk.io/schema"
11+
)
12+
13+
var (
14+
// ErrNotFound is returned when the provided key is not present in the StorageProvider.
15+
ErrNotFound = errors.New("collections: not found")
16+
// ErrEncoding is returned when something fails during key or value encoding/decoding.
17+
ErrEncoding = codec.ErrEncoding
18+
// ErrConflict is returned when there are conflicts, for example in UniqueIndex.
19+
ErrConflict = errors.New("collections: conflict")
20+
)
21+
22+
// KEYS
23+
24+
var (
25+
// Uint16Key can be used to encode uint16 keys. Encoding is big endian to retain ordering.
26+
Uint16Key = codec.NewUint16Key[uint16]()
27+
// Uint32Key can be used to encode uint32 keys. Encoding is big endian to retain ordering.
28+
Uint32Key = codec.NewUint32Key[uint32]()
29+
// Uint64Key can be used to encode uint64 keys. Encoding is big endian to retain ordering.
30+
Uint64Key = codec.NewUint64Key[uint64]()
31+
// Int32Key can be used to encode int32 keys. Encoding retains ordering by toggling the MSB.
32+
Int32Key = codec.NewInt32Key[int32]()
33+
// Int64Key can be used to encode int64 keys. Encoding retains ordering by toggling the MSB.
34+
Int64Key = codec.NewInt64Key[int64]()
35+
// StringKey can be used to encode string keys. The encoding just converts the string
36+
// to bytes.
37+
// Non-terminality in multipart keys is handled by appending the StringDelimiter,
38+
// this means that a string key when used as the non final part of a multipart key cannot
39+
// contain the StringDelimiter.
40+
// Lexicographical ordering is retained both in non and multipart keys.
41+
StringKey = codec.NewStringKeyCodec[string]()
42+
// BytesKey can be used to encode bytes keys. The encoding will just use
43+
// the provided bytes.
44+
// When used as the non-terminal part of a multipart key, we prefix the bytes key
45+
// with a single byte representing the length of the key. This means two things:
46+
// 1. When used in multipart keys the length can be at maximum 255 (max number that
47+
// can be represented with a single byte).
48+
// 2. When used in multipart keys the lexicographical ordering is lost due to the
49+
// length prefixing.
50+
// JSON encoding represents a bytes key as a hex encoded string.
51+
BytesKey = codec.NewBytesKey[[]byte]()
52+
// BoolKey can be used to encode booleans. It uses a single byte to represent the boolean.
53+
// 0x0 is used to represent false, and 0x1 is used to represent true.
54+
BoolKey = codec.NewBoolKey[bool]()
55+
)
56+
57+
// VALUES
58+
59+
var (
60+
// BoolValue implements a ValueCodec for bool.
61+
BoolValue = codec.KeyToValueCodec(BoolKey)
62+
// Uint16Value implements a ValueCodec for uint16.
63+
Uint16Value = codec.KeyToValueCodec(Uint16Key)
64+
// Uint32Value implements a ValueCodec for uint32.
65+
Uint32Value = codec.KeyToValueCodec(Uint32Key)
66+
// Uint64Value implements a ValueCodec for uint64.
67+
Uint64Value = codec.KeyToValueCodec(Uint64Key)
68+
// Int32Value implements a ValueCodec for int32.
69+
Int32Value = codec.KeyToValueCodec(Int32Key)
70+
// Int64Value implements a ValueCodec for int64.
71+
Int64Value = codec.KeyToValueCodec(Int64Key)
72+
// StringValue implements a ValueCodec for string.
73+
StringValue = codec.KeyToValueCodec(StringKey)
74+
// BytesValue implements a ValueCodec for bytes.
75+
BytesValue = codec.KeyToValueCodec(BytesKey)
76+
)
77+
78+
// Collection is the interface that all collections implement. It will eventually
79+
// include methods for importing/exporting genesis data and schema
80+
// reflection for clients.
81+
// NOTE: Unstable.
82+
type Collection interface {
83+
// GetName is the unique name of the collection within a schema. It must
84+
// match format specified by NameRegex.
85+
GetName() string
86+
87+
// GetPrefix is the unique prefix of the collection within a schema.
88+
GetPrefix() []byte
89+
90+
// ValueCodec returns the codec used to encode/decode values of the collection.
91+
ValueCodec() codec.UntypedValueCodec
92+
93+
genesisHandler
94+
95+
// collectionSchemaCodec returns the schema codec for this collection.
96+
schemaCodec() (*collectionSchemaCodec, error)
97+
98+
// isSecondaryIndex indicates that this collection represents a secondary index
99+
// in the schema and should be excluded from the module's user facing schema.
100+
isSecondaryIndex() bool
101+
}
102+
103+
// collectionSchemaCodec maps a collection to a schema object type and provides
104+
// decoders and encoders to and from schema values and raw kv-store bytes.
105+
type collectionSchemaCodec struct {
106+
coll Collection
107+
objectType schema.StateObjectType
108+
keyDecoder func([]byte) (any, error)
109+
valueDecoder func([]byte) (any, error)
110+
}
111+
112+
// Prefix defines a segregation bytes namespace for specific collections objects.
113+
type Prefix []byte
114+
115+
// Bytes returns the raw Prefix bytes.
116+
func (n Prefix) Bytes() []byte { return n }
117+
118+
// NewPrefix returns a Prefix given the provided namespace identifier.
119+
// In the same module, no prefixes should share the same starting bytes
120+
// meaning that having two namespaces whose bytes representation is:
121+
// p1 := []byte("prefix")
122+
// p2 := []byte("prefix1")
123+
// yields to iterations of p1 overlapping over p2.
124+
// If a numeric prefix is provided, it must be between 0 and 255 (uint8).
125+
// If out of bounds this function will panic.
126+
// Reason for which this function is constrained to `int` instead of `uint8` is for
127+
// API ergonomics, golang's type inference will infer int properly but not uint8
128+
// meaning that developers would need to write NewPrefix(uint8(number)) for numeric
129+
// prefixes.
130+
func NewPrefix[T interface{ int | string | []byte }](identifier T) Prefix {
131+
i := any(identifier)
132+
var prefix []byte
133+
switch c := i.(type) {
134+
case int:
135+
if c > math.MaxUint8 || c < 0 {
136+
panic("invalid integer prefix value: must be between 0 and 255")
137+
}
138+
prefix = []byte{uint8(c)}
139+
case string:
140+
prefix = []byte(c)
141+
case []byte:
142+
identifierCopy := make([]byte, len(c))
143+
copy(identifierCopy, c)
144+
prefix = identifierCopy
145+
}
146+
return prefix
147+
}
148+
149+
var _ Collection = (*collectionImpl[string, string])(nil)
150+
151+
// collectionImpl wraps a Map and implements Collection. This properly splits
152+
// the generic and untyped Collection interface from the typed Map, which every
153+
// collection builds on.
154+
type collectionImpl[K, V any] struct {
155+
m Map[K, V]
156+
}
157+
158+
func (c collectionImpl[K, V]) ValueCodec() codec.UntypedValueCodec {
159+
return codec.NewUntypedValueCodec(c.m.vc)
160+
}
161+
162+
func (c collectionImpl[K, V]) GetName() string { return c.m.name }
163+
164+
func (c collectionImpl[K, V]) GetPrefix() []byte { return NewPrefix(c.m.prefix) }
165+
166+
func (c collectionImpl[K, V]) validateGenesis(r io.Reader) error { return c.m.validateGenesis(r) }
167+
168+
func (c collectionImpl[K, V]) importGenesis(ctx context.Context, r io.Reader) error {
169+
return c.m.importGenesis(ctx, r)
170+
}
171+
172+
func (c collectionImpl[K, V]) exportGenesis(ctx context.Context, w io.Writer) error {
173+
return c.m.exportGenesis(ctx, w)
174+
}
175+
176+
func (c collectionImpl[K, V]) defaultGenesis(w io.Writer) error { return c.m.defaultGenesis(w) }
177+
178+
func (c collectionImpl[K, V]) isSecondaryIndex() bool { return c.m.isSecondaryIndex }

collections/go.mod

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module cosmossdk.io/collections
2+
3+
go 1.23
4+
5+
require (
6+
cosmossdk.io/core v1.0.0-alpha.3
7+
cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000
8+
cosmossdk.io/schema v0.3.0
9+
github.com/stretchr/testify v1.9.0
10+
github.com/tidwall/btree v1.7.0
11+
pgregory.net/rapid v1.1.0
12+
)
13+
14+
require (
15+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
17+
gopkg.in/yaml.v3 v3.0.1 // indirect
18+
)
19+
20+
replace cosmossdk.io/core/testing => ../core/testing

collections/go.sum

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA=
2+
cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY=
3+
cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c=
4+
cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
5+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
6+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
10+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
12+
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17+
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
18+
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=

0 commit comments

Comments
 (0)