Skip to content

Commit

Permalink
events size store param
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 17, 2024
1 parent df7a478 commit 89027ae
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ type BaseConfig struct {
// AppDBBackend defines the type of Database to use for the application and snapshots databases.
// An empty string indicates that the Tendermint config's DBBackend value should be used.
AppDBBackend string `mapstructure:"app-db-backend"`

MaxEventSize int `mapstructure:"max-event-size" json:"max-event-size"`
}

// APIConfig defines the API listener configuration.
Expand Down
8 changes: 7 additions & 1 deletion server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"text/template"

"github.com/cosmos/cosmos-sdk/types"

"github.com/spf13/viper"
)

Expand Down Expand Up @@ -73,7 +75,7 @@ index-events = [{{ range .BaseConfig.IndexEvents }}{{ printf "%q, " . }}{{end}}]
# IavlCacheSize set the size of the iavl tree cache (in number of nodes).
iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }}
# IAVLDisableFastNode enables or disables the fast node feature of IAVL.
# IAVLDisableFastNode enables or disables the fast node feature of IAVL.
# Default is false.
iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }}
Expand All @@ -96,6 +98,9 @@ iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }}
# The fallback is the db_backend value set in Tendermint's config.toml.
app-db-backend = "{{ .BaseConfig.AppDBBackend }}"
# Maximum event size in bytes. 0 means no limit
max-event-size = {{ .BaseConfig.MaxEventSize }}
###############################################################################
### Telemetry Configuration ###
###############################################################################
Expand Down Expand Up @@ -307,6 +312,7 @@ func init() {
func ParseConfig(v *viper.Viper) (*Config, error) {
conf := DefaultConfig()
err := v.Unmarshal(conf)
types.MaxEventSize = conf.BaseConfig.MaxEventSize

return conf, err
}
Expand Down
32 changes: 25 additions & 7 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,43 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
)

var MaxEventSize = int(0)

// ----------------------------------------------------------------------------
// Event Manager
// ----------------------------------------------------------------------------

// EventManager implements a simple wrapper around a slice of Event objects that
// can be emitted from.
type EventManager struct {
events Events
events Events
maxEventSize int // max size of events in bytes. 0 means no limit
}

func NewEventManager() *EventManager {
return &EventManager{EmptyEvents()}
return &EventManager{events: EmptyEvents(), maxEventSize: MaxEventSize}
}

func (em *EventManager) Events() Events { return em.events }

// EmitEvent stores a single Event object.
// Deprecated: Use EmitTypedEvent
func (em *EventManager) EmitEvent(event Event) {
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
return // Omit the event if it exceeds the max size
}
em.events = em.events.AppendEvent(event)
}

// EmitEvents stores a series of Event objects.
// Deprecated: Use EmitTypedEvents
func (em *EventManager) EmitEvents(events Events) {
em.events = em.events.AppendEvents(events)
for _, event := range events {
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
continue // Omit the event if it exceeds the max size
}
em.events = em.events.AppendEvent(event)
}
}

// ABCIEvents returns all stored Event objects as abci.Event objects.
Expand All @@ -56,19 +67,26 @@ func (em *EventManager) EmitTypedEvent(tev proto.Message) error {
return err
}

if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
return nil // Omit the event if it exceeds the max size
}

em.EmitEvent(event)
return nil
}

// EmitTypedEvents takes series of typed events and emit
func (em *EventManager) EmitTypedEvents(tevs ...proto.Message) error {
events := make(Events, len(tevs))
for i, tev := range tevs {
res, err := TypedEventToEvent(tev)
events := make(Events, 0, len(tevs))
for _, tev := range tevs {
event, err := TypedEventToEvent(tev)
if err != nil {
return err
}
events[i] = res
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
continue // Omit the event if it exceeds the max size
}
events = append(events, event)
}

em.EmitEvents(events)
Expand Down

0 comments on commit 89027ae

Please sign in to comment.