diff --git a/app/app.go b/app/app.go index db19e0d443..e5175888c4 100644 --- a/app/app.go +++ b/app/app.go @@ -1846,7 +1846,7 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, msg *evmtypes.MsgE ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeterWithMultiplier(ctx)) // Create state DB for this transaction - stateDB := gigaevmstate.NewDBImpl(ctx, &app.GigaEvmKeeper, false) + stateDB := gigaevmstate.NewDBImplWithoutSnapshot(ctx, &app.GigaEvmKeeper, false) defer stateDB.Cleanup() // Get gas pool diff --git a/giga/deps/xevm/state/state.go b/giga/deps/xevm/state/state.go index e57e962221..0c938a3e5f 100644 --- a/giga/deps/xevm/state/state.go +++ b/giga/deps/xevm/state/state.go @@ -23,6 +23,9 @@ func (s *DBImpl) CreateAccount(acc common.Address) { } func (s *DBImpl) GetCommittedState(addr common.Address, hash common.Hash) common.Hash { + if len(s.snapshottedCtxs) == 0 { + return s.getState(s.ctx, addr, hash) + } return s.getState(s.snapshottedCtxs[0], addr, hash) } diff --git a/giga/deps/xevm/state/statedb.go b/giga/deps/xevm/state/statedb.go index eb95116d05..a1c164f835 100644 --- a/giga/deps/xevm/state/statedb.go +++ b/giga/deps/xevm/state/statedb.go @@ -58,6 +58,25 @@ func NewDBImpl(ctx sdk.Context, k EVMKeeper, simulation bool) *DBImpl { return s } +// NewDBImplWithoutSnapshot creates a DBImpl without the initial Snapshot() call. +// Use this only when the caller guarantees that Prepare() (which calls Snapshot) +// will be called before any state reads/writes — e.g. in the OCC executor path +// where core.ApplyMessage always calls Prepare before EVM execution. +// This avoids creating a redundant CacheMultiStore layer. +func NewDBImplWithoutSnapshot(ctx sdk.Context, k EVMKeeper, simulation bool) *DBImpl { + feeCollector, _ := k.GetFeeCollectorAddress(ctx) + return &DBImpl{ + ctx: ctx, + k: k, + snapshottedCtxs: []sdk.Context{}, + coinbaseAddress: GetCoinbaseAddress(ctx.TxIndex()), + simulation: simulation, + tempState: NewTemporaryState(), + journal: []journalEntry{}, + coinbaseEvmAddress: feeCollector, + } +} + func (s *DBImpl) DisableEvents() { s.eventsSuppressed = true } @@ -141,6 +160,9 @@ func (s *DBImpl) flushCtx(ctx sdk.Context) { } func (s *DBImpl) flushEvents(ctx sdk.Context) { + if len(s.snapshottedCtxs) == 0 { + return + } s.snapshottedCtxs[0].EventManager().EmitEvents(ctx.EventManager().Events()) }