Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server/v2): refactor the server/v2 events #21785

Merged
merged 11 commits into from
Sep 18, 2024
Merged
2 changes: 1 addition & 1 deletion collections/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
// decoders and encoders to and from schema values and raw kv-store bytes.
type collectionSchemaCodec struct {
coll Collection
objectType schema.ObjectType
objectType schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectType

Check failure on line 107 in collections/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the undefined type schema.StateObjectType.

The static analysis tools indicate that schema.StateObjectType is undefined. This change would cause compilation errors.

Please ensure that schema.StateObjectType is properly defined and imported before using it as the type for the objectType field.

Tools
GitHub Check: tests (03)

[failure] 107-107:
undefined: schema.StateObjectType

GitHub Check: tests (02)

[failure] 107-107:
undefined: schema.StateObjectType

GitHub Check: tests (01)

[failure] 107-107:
undefined: schema.StateObjectType

GitHub Check: tests (00)

[failure] 107-107:
undefined: schema.StateObjectType

GitHub Check: dependency-review

[failure] 107-107:
undefined: schema.StateObjectType

GitHub Check: golangci-lint

[failure] 107-107:
undefined: schema.StateObjectType

keyDecoder func([]byte) (any, error)
valueDecoder func([]byte) (any, error)
}
Expand Down
2 changes: 2 additions & 0 deletions collections/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ require (
)

replace cosmossdk.io/core/testing => ../core/testing

replace cosmossdk.io/schema => ../schema
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this in a separate PR? I'm pretty sure this replace has a global effect on all go.mod's in the SDK. Instead if needed we can tag schema and then update collections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we need a new tag of schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BlockStage is not included in the schema v2.0, after new tag of schema, and also need to tag the core module, maybe alpah3 ??? cc: @julienrbrt

Copy link
Member

@julienrbrt julienrbrt Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure let's have alpha.3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tagging schema @julienrbrt !

2 changes: 0 additions & 2 deletions collections/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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/schema v0.2.0 h1:UH5CR1DqUq8yP+5Np8PbvG4YX0zAUsTN2Qk6yThmfMk=
cosmossdk.io/schema v0.2.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=
Expand Down
12 changes: 6 additions & 6 deletions collections/indexing.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
collectionLookup *btree.Map[string, *collectionSchemaCodec]
}

func (m moduleDecoder) decodeKV(update schema.KVPairUpdate) ([]schema.ObjectUpdate, error) {
func (m moduleDecoder) decodeKV(update schema.KVPairUpdate) ([]schema.StateObjectUpdate, error) {

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate

Check failure on line 70 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
key := update.Key
ks := string(key)
var cd *collectionSchemaCodec
Expand All @@ -87,32 +87,32 @@
return cd.decodeKVPair(update)
}

func (c collectionSchemaCodec) decodeKVPair(update schema.KVPairUpdate) ([]schema.ObjectUpdate, error) {
func (c collectionSchemaCodec) decodeKVPair(update schema.KVPairUpdate) ([]schema.StateObjectUpdate, error) {

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate

Check failure on line 90 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
// strip prefix
key := update.Key
key = key[len(c.coll.GetPrefix()):]

k, err := c.keyDecoder(key)
if err != nil {
return []schema.ObjectUpdate{
return []schema.StateObjectUpdate{

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate

Check failure on line 97 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
{TypeName: c.coll.GetName()},
}, err
Comment on lines +97 to 99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the compilation error due to undefined type schema.StateObjectUpdate.

The static analysis hints indicate that the type schema.StateObjectUpdate is undefined, causing a compilation error. Please ensure that the schema package is updated to define this type.

Tools
GitHub Check: tests (03)

[failure] 97-97:
undefined: schema.StateObjectUpdate

GitHub Check: tests (02)

[failure] 97-97:
undefined: schema.StateObjectUpdate

GitHub Check: tests (01)

[failure] 97-97:
undefined: schema.StateObjectUpdate

GitHub Check: tests (00)

[failure] 97-97:
undefined: schema.StateObjectUpdate

GitHub Check: dependency-review

[failure] 97-97:
undefined: schema.StateObjectUpdate

GitHub Check: golangci-lint

[failure] 97-97:
undefined: schema.StateObjectUpdate

}

if update.Remove {
return []schema.ObjectUpdate{
return []schema.StateObjectUpdate{

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate

Check failure on line 103 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
{TypeName: c.coll.GetName(), Key: k, Delete: true},
}, nil
Comment on lines +103 to 105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the compilation error due to undefined type schema.StateObjectUpdate.

The static analysis hints indicate that the type schema.StateObjectUpdate is undefined, causing a compilation error. Please ensure that the schema package is updated to define this type.

Tools
GitHub Check: tests (03)

[failure] 103-103:
undefined: schema.StateObjectUpdate

GitHub Check: tests (02)

[failure] 103-103:
undefined: schema.StateObjectUpdate

GitHub Check: tests (01)

[failure] 103-103:
undefined: schema.StateObjectUpdate

GitHub Check: tests (00)

[failure] 103-103:
undefined: schema.StateObjectUpdate

GitHub Check: dependency-review

[failure] 103-103:
undefined: schema.StateObjectUpdate

GitHub Check: golangci-lint

[failure] 103-103:
undefined: schema.StateObjectUpdate

}

v, err := c.valueDecoder(update.Value)
if err != nil {
return []schema.ObjectUpdate{
return []schema.StateObjectUpdate{

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate

Check failure on line 110 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
{TypeName: c.coll.GetName(), Key: k},
}, err
Comment on lines +110 to 112
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the compilation error due to undefined type schema.StateObjectUpdate.

The static analysis hints indicate that the type schema.StateObjectUpdate is undefined, causing a compilation error. Please ensure that the schema package is updated to define this type.

Tools
GitHub Check: tests (03)

[failure] 110-110:
undefined: schema.StateObjectUpdate

GitHub Check: tests (02)

[failure] 110-110:
undefined: schema.StateObjectUpdate

GitHub Check: tests (01)

[failure] 110-110:
undefined: schema.StateObjectUpdate

GitHub Check: tests (00)

[failure] 110-110:
undefined: schema.StateObjectUpdate

GitHub Check: dependency-review

[failure] 110-110:
undefined: schema.StateObjectUpdate

GitHub Check: golangci-lint

[failure] 110-110:
undefined: schema.StateObjectUpdate

}

return []schema.ObjectUpdate{
return []schema.StateObjectUpdate{

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: schema.StateObjectUpdate

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: schema.StateObjectUpdate

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: schema.StateObjectUpdate

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: schema.StateObjectUpdate

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: schema.StateObjectUpdate) (typecheck)

Check failure on line 115 in collections/indexing.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: schema.StateObjectUpdate
{TypeName: c.coll.GetName(), Key: k, Value: v},
}, nil
Comment on lines +115 to 117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the compilation error due to undefined type schema.StateObjectUpdate.

The static analysis hints indicate that the type schema.StateObjectUpdate is undefined, causing a compilation error. Please ensure that the schema package is updated to define this type.

Tools
GitHub Check: tests (03)

[failure] 115-115:
undefined: schema.StateObjectUpdate

GitHub Check: tests (02)

[failure] 115-115:
undefined: schema.StateObjectUpdate

GitHub Check: tests (01)

[failure] 115-115:
undefined: schema.StateObjectUpdate

GitHub Check: tests (00)

[failure] 115-115:
undefined: schema.StateObjectUpdate

GitHub Check: dependency-review

[failure] 115-115:
undefined: schema.StateObjectUpdate

GitHub Check: golangci-lint

[failure] 115-115:
undefined: schema.StateObjectUpdate) (typecheck)

}
Expand Down
5 changes: 4 additions & 1 deletion runtime/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace (

require (
cosmossdk.io/api v0.7.5
cosmossdk.io/core v1.0.0-alpha.2
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892
cosmossdk.io/depinject v1.0.0
cosmossdk.io/log v1.4.1
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000
Expand All @@ -31,6 +31,7 @@ require (
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect
cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/schema v0.2.0 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down Expand Up @@ -85,3 +86,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace cosmossdk.io/schema => ../../schema
4 changes: 2 additions & 2 deletions runtime/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fed
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2/go.mod h1:1+3gJj2NvZ1mTLAtHu+lMhOjGgQPiCKCeo+9MBww0Eo=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 h1:b7EEYTUHmWSBEyISHlHvXbJPqtKiHRuUignL1tsHnNQ=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2/go.mod h1:HqcXMSa5qnNuakaMUo+hWhF51mKbcrZxGl9Vp5EeJXc=
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 v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892 h1:37efyVbbWv9K8EU1XDWTBFAo/O+Q9DZsA/Nx7Z5vTqU=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892/go.mod h1:0rHYboOl/sP+mA9rYJW2qPQSP1u3rLgsYPGT+pTA2jo=
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/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA=
Expand Down
3 changes: 2 additions & 1 deletion server/v2/cometbft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.1
replace (
cosmossdk.io/api => ../../../api
cosmossdk.io/core/testing => ../../../core/testing
cosmossdk.io/schema => ../../../schema
cosmossdk.io/server/v2 => ../
cosmossdk.io/server/v2/appmanager => ../appmanager
cosmossdk.io/server/v2/stf => ../stf
Expand All @@ -19,7 +20,7 @@ replace (

require (
cosmossdk.io/api v0.7.5
cosmossdk.io/core v1.0.0-alpha.2
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.4.1
cosmossdk.io/server/v2 v2.0.0-00010101000000-000000000000
Expand Down
6 changes: 2 additions & 4 deletions server/v2/cometbft/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
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.2 h1:epU0Xwces4Rgl5bMhHHkXGaGDcyucNGlC/JDH+Suckg=
cosmossdk.io/core v1.0.0-alpha.2/go.mod h1:abgLjeFLhtuKIYZWSPlVUgQBrKObO7ULV35KYfexE90=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892 h1:37efyVbbWv9K8EU1XDWTBFAo/O+Q9DZsA/Nx7Z5vTqU=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892/go.mod h1:0rHYboOl/sP+mA9rYJW2qPQSP1u3rLgsYPGT+pTA2jo=
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 @@ -18,8 +18,6 @@ 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=
cosmossdk.io/schema v0.2.0 h1:UH5CR1DqUq8yP+5Np8PbvG4YX0zAUsTN2Qk6yThmfMk=
cosmossdk.io/schema v0.2.0/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=
Expand Down
16 changes: 12 additions & 4 deletions server/v2/cometbft/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ func intoABCIEvents(events []event.Event, indexSet map[string]struct{}) []abci.E
indexAll := len(indexSet) == 0
abciEvents := make([]abci.Event, len(events))
for i, e := range events {
attributes, err := e.Attributes()
if err != nil {
panic(err)
}
abciEvents[i] = abci.Event{
Type: e.Type,
Attributes: make([]abci.EventAttribute, len(e.Attributes)),
Attributes: make([]abci.EventAttribute, len(attributes)),
}

for j, attr := range e.Attributes {
for j, attr := range attributes {
_, index := indexSet[fmt.Sprintf("%s.%s", e.Type, attr.Key)]
abciEvents[i].Attributes[j] = abci.EventAttribute{
Key: attr.Key,
Expand All @@ -148,12 +152,16 @@ func intoABCISimulationResponse(txRes server.TxResult, indexSet map[string]struc
indexAll := len(indexSet) == 0
abciEvents := make([]abci.Event, len(txRes.Events))
for i, e := range txRes.Events {
attributes, err := e.Attributes()
if err != nil {
panic(err)
}
abciEvents[i] = abci.Event{
Type: e.Type,
Attributes: make([]abci.EventAttribute, len(e.Attributes)),
Attributes: make([]abci.EventAttribute, len(attributes)),
}

for j, attr := range e.Attributes {
for j, attr := range attributes {
_, index := indexSet[fmt.Sprintf("%s.%s", e.Type, attr.Key)]
abciEvents[i].Attributes[j] = abci.EventAttribute{
Key: attr.Key,
Expand Down
5 changes: 4 additions & 1 deletion server/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace (

require (
cosmossdk.io/api v0.7.5
cosmossdk.io/core v1.0.0-alpha.2
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892
cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000
cosmossdk.io/log v1.4.1
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -44,6 +44,7 @@ require (

require (
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/schema v0.2.0 // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down Expand Up @@ -111,3 +112,5 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace cosmossdk.io/schema => ../../schema
4 changes: 2 additions & 2 deletions server/v2/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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/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 v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892 h1:37efyVbbWv9K8EU1XDWTBFAo/O+Q9DZsA/Nx7Z5vTqU=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892/go.mod h1:0rHYboOl/sP+mA9rYJW2qPQSP1u3rLgsYPGT+pTA2jo=
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA=
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5/go.mod h1:0CuYKkFHxc1vw2JC+t21THBCALJVROrWVR/3PQ1urpc=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
Expand Down
2 changes: 1 addition & 1 deletion server/v2/stf/core_event_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ func TypedEventToEvent(tev transaction.Msg) (event.Event, error) {

return event.Event{
Type: evtType,
Attributes: attrs,
Attributes: func() ([]event.Attribute, error) { return attrs, nil },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider enhancing the attributes closure for more robust error handling and validation.

The introduction of a closure to encapsulate the attributes allows for deferred execution and the addition of logic without altering the function signature. This is a good approach to make the handling of attributes more flexible.

However, the current implementation doesn't fully leverage the potential benefits of the closure. Consider adding error handling or validation logic within the closure to ensure the attributes are valid and to handle any potential errors gracefully.

For example:

Attributes: func() ([]event.Attribute, error) {
    if err := validateAttributes(attrs); err != nil {
        return nil, err
    }
    return attrs, nil
},

This way, the closure can serve as a centralized point to handle attribute-related errors and validations, making the code more robust and maintainable.

Copy link
Member

@aaronc aaronc Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually wrap all the logic in TypedEventToEvent in this closure so that JSON marshaling is done lazily. Let's do that in a follow up PR though, and merge this.

}, nil
}
5 changes: 4 additions & 1 deletion server/v2/stf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module cosmossdk.io/server/v2/stf
go 1.23

require (
cosmossdk.io/core v1.0.0-alpha.2
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892
cosmossdk.io/schema v0.2.0
github.com/cosmos/gogoproto v1.7.0
github.com/tidwall/btree v1.7.0
)
Expand All @@ -12,3 +13,5 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

replace cosmossdk.io/schema => ../../../schema
4 changes: 2 additions & 2 deletions server/v2/stf/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892 h1:37efyVbbWv9K8EU1XDWTBFAo/O+Q9DZsA/Nx7Z5vTqU=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892/go.mod h1:0rHYboOl/sP+mA9rYJW2qPQSP1u3rLgsYPGT+pTA2jo=
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/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
Expand Down
22 changes: 7 additions & 15 deletions server/v2/stf/stf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"cosmossdk.io/core/server"
"cosmossdk.io/core/store"
"cosmossdk.io/core/transaction"
"cosmossdk.io/schema/appdata"
stfgas "cosmossdk.io/server/v2/stf/gas"
"cosmossdk.io/server/v2/stf/internal"
)
Expand Down Expand Up @@ -338,11 +339,8 @@ func (s STF[T]) preBlock(
return nil, err
}

for i, e := range ctx.events {
ctx.events[i].Attributes = append(
e.Attributes,
event.Attribute{Key: "mode", Value: "PreBlock"},
)
for i := range ctx.events {
ctx.events[i].BlockStage = appdata.PreBlockStage
}

return ctx.events, nil
Expand All @@ -357,11 +355,8 @@ func (s STF[T]) beginBlock(
return nil, err
}

for i, e := range ctx.events {
ctx.events[i].Attributes = append(
e.Attributes,
event.Attribute{Key: "mode", Value: "BeginBlock"},
)
for i := range ctx.events {
ctx.events[i].BlockStage = appdata.BeginBlockStage
}

return ctx.events, nil
Expand All @@ -383,11 +378,8 @@ func (s STF[T]) endBlock(

ctx.events = append(ctx.events, events...)

for i, e := range ctx.events {
ctx.events[i].Attributes = append(
e.Attributes,
event.Attribute{Key: "mode", Value: "BeginBlock"},
)
for i := range ctx.events {
ctx.events[i].BlockStage = appdata.EndBlockStage
}

return ctx.events, valsetUpdates, nil
Expand Down
7 changes: 5 additions & 2 deletions server/v2/streaming/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ func IntoStreamingEvents(events []event.Event) []*Event {
strEvent := &Event{
Type: event.Type,
}

for _, eventValue := range event.Attributes {
attrs, err := event.Attributes()
if err != nil {
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid panicking on errors. Return an error instead to allow graceful error handling.

Panicking on an error is not an ideal error handling strategy as it can lead to unexpected program crashes. Instead of panicking, the function should return an error to allow the caller to handle the error gracefully.

Consider applying this diff to improve the error handling:

-		attrs, err := event.Attributes()
-		if err != nil {
-			panic(err)
-		}
+		attrs, err := event.Attributes()
+		if err != nil {
+			return nil, err
+		}

Also, update the function signature to return an error:

-func IntoStreamingEvents(events []event.Event) []*Event {
+func IntoStreamingEvents(events []event.Event) ([]*Event, error) {

Committable suggestion was skipped due to low confidence.

for _, eventValue := range attrs {
strEvent.Attributes = append(strEvent.Attributes, &EventAttribute{
Key: eventValue.Key,
Value: eventValue.Value,
Expand Down
3 changes: 2 additions & 1 deletion simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.1
require (
cosmossdk.io/api v0.7.5
cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/core v1.0.0-alpha.2
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892
cosmossdk.io/depinject v1.0.0
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
Expand Down Expand Up @@ -246,6 +246,7 @@ require (
replace (
cosmossdk.io/client/v2 => ../../client/v2
cosmossdk.io/collections => ../../collections
cosmossdk.io/schema => ../../schema
cosmossdk.io/tools/confix => ../../tools/confix
cosmossdk.io/x/accounts => ../../x/accounts
cosmossdk.io/x/accounts/defaults/lockup => ../../x/accounts/defaults/lockup
Expand Down
6 changes: 2 additions & 4 deletions simapp/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ 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/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 v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892 h1:37efyVbbWv9K8EU1XDWTBFAo/O+Q9DZsA/Nx7Z5vTqU=
cosmossdk.io/core v1.0.0-alpha.2.0.20240917105208-c9f0e2e4d892/go.mod h1:0rHYboOl/sP+mA9rYJW2qPQSP1u3rLgsYPGT+pTA2jo=
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 @@ -204,8 +204,6 @@ 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=
cosmossdk.io/schema v0.2.0 h1:UH5CR1DqUq8yP+5Np8PbvG4YX0zAUsTN2Qk6yThmfMk=
cosmossdk.io/schema v0.2.0/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=
Expand Down
Loading