Skip to content
Merged
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
116 changes: 67 additions & 49 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func New(
if gigaExecutorConfig.OCCEnabled {
logger.Info("benchmark: Giga Executor with OCC is ENABLED - using new EVM execution path with parallel execution")
} else {
logger.Info("benchmark: Giga Executor (evmone-based) is ENABLED - using new EVM execution path (sequential)")
logger.Info("benchmark: Giga Executor is ENABLED - using new EVM execution path (sequential)")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unrelated fix

}
} else {
logger.Info("benchmark: Giga Executor is DISABLED - using default GETH interpreter")
Expand Down Expand Up @@ -1546,71 +1546,89 @@ func (app *App) ProcessTXsWithOCCV2(ctx sdk.Context, txs [][]byte, typedTxs []sd
func (app *App) ProcessTXsWithOCCGiga(ctx sdk.Context, txs [][]byte, typedTxs []sdk.Tx) ([]*abci.ExecTxResult, sdk.Context) {
evmEntries := make([]*sdk.DeliverTxEntry, 0, len(txs))
v2Entries := make([]*sdk.DeliverTxEntry, 0, len(txs))
firstCosmosSeen := false
for txIndex, tx := range txs {
if app.GetEVMMsg(typedTxs[txIndex]) != nil {
if firstCosmosSeen {
ctx.Logger().Error("Giga OCC cannot execute block due to tx ordering, falling back to V2")
// Oops! This isn't "all EVM txs, then all Cosmos txs" - we need to fallback to V2.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we add a log here if this isn't expected? (like if the ordering is supposed to be all evm then cosmos)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to do that, but the ordering isn't currently unexpected, because the mempool ordering change will only go live with 6.4.0. It'll only become unexpected when validators are running 6.4.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(Done.)

return app.ProcessTXsWithOCCV2(ctx, txs, typedTxs)
}

evmEntries = append(evmEntries, app.GetDeliverTxEntry(ctx, txIndex, tx, typedTxs[txIndex]))
} else {
if !firstCosmosSeen {
firstCosmosSeen = true
}
v2Entries = append(v2Entries, app.GetDeliverTxEntry(ctx, txIndex, tx, typedTxs[txIndex]))
}
}

// Run EVM txs against a cache so we can discard all changes on fallback.
evmCtx, evmCache := app.CacheContext(ctx)
var evmBatchResult []abci.ResponseDeliverTx
fallbackToV2 := false

// Cache block-level constants (identical for all txs in this block).
// Must use evmCtx (not ctx) because giga KV stores are registered in CacheContext.
cache, cacheErr := newGigaBlockCache(evmCtx, &app.GigaEvmKeeper)
if cacheErr != nil {
ctx.Logger().Error("failed to build giga block cache", "error", cacheErr, "height", ctx.BlockHeight())
return nil, ctx
}
if len(evmEntries) > 0 {
// Run EVM txs against a cache so we can discard all changes on fallback.
evmCtx, evmCache := app.CacheContext(ctx)

// Create OCC scheduler with giga executor deliverTx capturing the cache.
evmScheduler := tasks.NewScheduler(
app.ConcurrencyWorkers(),
app.TracingInfo,
app.makeGigaDeliverTx(cache),
)
// Cache block-level constants (identical for all txs in this block).
// Must use evmCtx (not ctx) because giga KV stores are registered in CacheContext.
cache, cacheErr := newGigaBlockCache(evmCtx, &app.GigaEvmKeeper)
if cacheErr != nil {
ctx.Logger().Error("failed to build giga block cache", "error", cacheErr, "height", ctx.BlockHeight())
return nil, ctx
}

evmBatchResult, evmSchedErr := evmScheduler.ProcessAll(evmCtx, evmEntries)
if evmSchedErr != nil {
// TODO: DeliverTxBatch panics in this case
// TODO: detect if it was interop, and use v2 if so
ctx.Logger().Error("benchmark OCC scheduler error (EVM txs)", "error", evmSchedErr, "height", ctx.BlockHeight(), "txCount", len(evmEntries))
return nil, ctx
}
// Create OCC scheduler with giga executor deliverTx capturing the cache.
evmScheduler := tasks.NewScheduler(
app.ConcurrencyWorkers(),
app.TracingInfo,
app.makeGigaDeliverTx(cache),
)

fallbackToV2 := false
for _, r := range evmBatchResult {
if r.Code == gigautils.GigaAbortCode && r.Codespace == gigautils.GigaAbortCodespace {
fallbackToV2 = true
break
var evmSchedErr error
evmBatchResult, evmSchedErr = evmScheduler.ProcessAll(evmCtx, evmEntries)
if evmSchedErr != nil {
ctx.Logger().Error("benchmark OCC scheduler error (EVM txs)", "error", evmSchedErr, "height", ctx.BlockHeight(), "txCount", len(evmEntries))
return nil, ctx
}
}

if fallbackToV2 {
metrics.IncrGigaFallbackToV2Counter()
// Discard all EVM changes by skipping cache writes, then re-run all txs via DeliverTx.
evmBatchResult = nil
v2Entries = make([]*sdk.DeliverTxEntry, len(txs))
for txIndex, tx := range txs {
v2Entries[txIndex] = app.GetDeliverTxEntry(ctx, txIndex, tx, typedTxs[txIndex])
for _, r := range evmBatchResult {
if r.Code == gigautils.GigaAbortCode && r.Codespace == gigautils.GigaAbortCodespace {
fallbackToV2 = true
break
}
}

if fallbackToV2 {
metrics.IncrGigaFallbackToV2Counter()
// Discard all EVM changes by skipping cache writes, then re-run all txs via DeliverTx.
evmBatchResult = nil
v2Entries = make([]*sdk.DeliverTxEntry, len(txs))
for txIndex, tx := range txs {
v2Entries[txIndex] = app.GetDeliverTxEntry(ctx, txIndex, tx, typedTxs[txIndex])
}
} else {
// Commit EVM cache to main store before processing non-EVM txs.
evmCache.Write()
evmCtx.GigaMultiStore().WriteGiga()
}
} else {
// Commit EVM cache to main store before processing non-EVM txs.
evmCache.Write()
evmCtx.GigaMultiStore().WriteGiga()
}

v2Scheduler := tasks.NewScheduler(
app.ConcurrencyWorkers(),
app.TracingInfo,
app.DeliverTx,
)
v2BatchResult, v2SchedErr := v2Scheduler.ProcessAll(ctx, v2Entries)
if v2SchedErr != nil {
ctx.Logger().Error("benchmark OCC scheduler error", "error", v2SchedErr, "height", ctx.BlockHeight(), "txCount", len(v2Entries))
return nil, ctx
var v2BatchResult []abci.ResponseDeliverTx

if len(v2Entries) > 0 {
v2Scheduler := tasks.NewScheduler(
app.ConcurrencyWorkers(),
app.TracingInfo,
app.DeliverTx,
)
var v2SchedErr error
v2BatchResult, v2SchedErr = v2Scheduler.ProcessAll(ctx, v2Entries)
if v2SchedErr != nil {
ctx.Logger().Error("benchmark OCC scheduler error", "error", v2SchedErr, "height", ctx.BlockHeight(), "txCount", len(v2Entries))
return nil, ctx
}
}

execResults := make([]*abci.ExecTxResult, 0, len(evmBatchResult)+len(v2BatchResult))
Expand Down
Loading