Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ type gigaBlockCache struct {
blockCtx vm.BlockContext
chainConfig *ethparams.ChainConfig
baseFee *big.Int

// when true, Cosmos-level events (coin_spent, coin_received, etc.) are
// discarded during giga executor tx execution. EVM logs are unaffected.
suppressCosmosEvents bool
}

func newGigaBlockCache(ctx sdk.Context, keeper *gigaevmkeeper.Keeper) (*gigaBlockCache, error) {
Expand All @@ -340,10 +344,11 @@ func newGigaBlockCache(ctx sdk.Context, keeper *gigaevmkeeper.Keeper) (*gigaBloc
chainConfig := evmtypes.DefaultChainConfig().EthereumConfigWithSstore(chainID, &sstore)
baseFee := keeper.GetBaseFee(ctx)
return &gigaBlockCache{
chainID: chainID,
blockCtx: *blockCtx,
chainConfig: chainConfig,
baseFee: baseFee,
chainID: chainID,
blockCtx: *blockCtx,
chainConfig: chainConfig,
baseFee: baseFee,
suppressCosmosEvents: os.Getenv("GIGA_SUPPRESS_COSMOS_EVENTS") == "true",
}, nil
}

Expand Down Expand Up @@ -1793,6 +1798,9 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, msg *evmtypes.MsgE

// Create state DB for this transaction
stateDB := gigaevmstate.NewDBImpl(ctx, &app.GigaEvmKeeper, false)
if cache.suppressCosmosEvents {
stateDB.SuppressCosmosEvents()
}
defer stateDB.Cleanup()

// Get gas pool (mutated per tx, cannot be cached)
Expand Down
6 changes: 5 additions & 1 deletion giga/deps/xevm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func (s *DBImpl) HasSelfDestructed(acc common.Address) bool {
}

func (s *DBImpl) Snapshot() int {
newCtx := s.ctx.WithMultiStore(s.ctx.MultiStore().CacheMultiStore()).WithEventManager(sdk.NewEventManager())
em := sdk.NewEventManager()
if s.cosmosEventsSuppressed {
em = sdk.NewSuppressedEventManager()
}
newCtx := s.ctx.WithMultiStore(s.ctx.MultiStore().CacheMultiStore()).WithEventManager(em)
s.snapshottedCtxs = append(s.snapshottedCtxs, s.ctx)
s.ctx = newCtx
version := len(s.snapshottedCtxs) - 1
Expand Down
20 changes: 16 additions & 4 deletions giga/deps/xevm/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type DBImpl struct {
// for cases like bank.send_native, we want to suppress transfer events
eventsSuppressed bool

// when true, all Cosmos-level events (coin_spent, coin_received, etc.)
// are discarded. EVM logs are unaffected. Use this on the giga executor
// path where Cosmos events are constructed but never consumed.
cosmosEventsSuppressed bool

logger *tracing.Hooks
}

Expand Down Expand Up @@ -66,6 +71,10 @@ func (s *DBImpl) EnableEvents() {
s.eventsSuppressed = false
}

func (s *DBImpl) SuppressCosmosEvents() {
s.cosmosEventsSuppressed = true
}

func (s *DBImpl) SetLogger(logger *tracing.Hooks) {
s.logger = logger
}
Expand Down Expand Up @@ -112,11 +121,14 @@ func (s *DBImpl) Finalize() (surplus sdk.Int, err error) {
s.clearAccountStateIfDestructed(s.tempState)

s.flushCtxs()
// write all events in order
for i := 1; i < len(s.snapshottedCtxs); i++ {
s.flushEvents(s.snapshottedCtxs[i])
// write all events in order (skip when cosmos events are suppressed —
// the EventManagers are no-ops so there is nothing to consolidate)
if !s.cosmosEventsSuppressed {
for i := 1; i < len(s.snapshottedCtxs); i++ {
s.flushEvents(s.snapshottedCtxs[i])
}
s.flushEvents(s.ctx)
}
s.flushEvents(s.ctx)

surplus = s.tempState.surplus
return
Expand Down
17 changes: 16 additions & 1 deletion sei-cosmos/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
type EventManager struct {
events Events

mtx sync.RWMutex
mtx sync.RWMutex
suppressed bool
}

// Common Event Types and Attributes
Expand All @@ -55,11 +56,22 @@ func NewEventManager() *EventManager {
return &em
}

// NewSuppressedEventManager returns an EventManager that silently discards all
// emitted events. Use this on hot paths where events are constructed but never
// consumed (e.g. the giga executor) to avoid mutex contention, bech32 encoding
// in event attributes, and allocation overhead.
func NewSuppressedEventManager() *EventManager {
return &EventManager{suppressed: true}
}

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.suppressed {
return
}
em.mtx.Lock()
defer em.mtx.Unlock()
em.events = em.events.AppendEvent(event)
Expand All @@ -68,6 +80,9 @@ func (em *EventManager) EmitEvent(event Event) {
// EmitEvents stores a series of Event objects.
// Deprecated: Use EmitTypedEvents
func (em *EventManager) EmitEvents(events Events) {
if em.suppressed {
return
}
em.mtx.Lock()
defer em.mtx.Unlock()
em.events = em.events.AppendEvents(events)
Expand Down
Loading