Skip to content

Commit f8f0311

Browse files
committed
feat: Giga: support synchronous giga execution of blocks
1 parent bc51c2b commit f8f0311

File tree

5 files changed

+98
-31
lines changed

5 files changed

+98
-31
lines changed

app/app.go

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ import (
104104
evmrpcconfig "github.com/sei-protocol/sei-chain/evmrpc/config"
105105
gigaexecutor "github.com/sei-protocol/sei-chain/giga/executor"
106106
gigaconfig "github.com/sei-protocol/sei-chain/giga/executor/config"
107+
108+
gigaprecompiles "github.com/sei-protocol/sei-chain/giga/executor/precompiles"
109+
gigautils "github.com/sei-protocol/sei-chain/giga/executor/utils"
107110
"github.com/sei-protocol/sei-chain/precompiles"
108111
putils "github.com/sei-protocol/sei-chain/precompiles/utils"
109112
"github.com/sei-protocol/sei-chain/sei-db/state_db/ss"
@@ -1311,13 +1314,37 @@ func (app *App) DeliverTxWithResult(ctx sdk.Context, tx []byte, typedTx sdk.Tx)
13111314
func (app *App) ProcessBlockSynchronous(ctx sdk.Context, txs [][]byte, typedTxs []sdk.Tx, absoluteTxIndices []int) []*abci.ExecTxResult {
13121315
defer metrics.BlockProcessLatency(time.Now(), metrics.SYNCHRONOUS)
13131316

1314-
txResults := []*abci.ExecTxResult{}
1317+
txResults := make([]*abci.ExecTxResult, len(txs))
13151318
for i, tx := range txs {
13161319
ctx = ctx.WithTxIndex(absoluteTxIndices[i])
1317-
res := app.DeliverTxWithResult(ctx, tx, typedTxs[i])
1318-
txResults = append(txResults, res)
1320+
evmMsg := app.GetEVMMsg(typedTxs[i])
1321+
// If not an EVM tx, fall back to v2 processing
1322+
if evmMsg == nil {
1323+
result := app.DeliverTxWithResult(ctx, tx, typedTxs[i])
1324+
txResults[i] = result
1325+
continue
1326+
}
1327+
1328+
// Execute EVM transaction through giga executor
1329+
result, execErr := app.executeEVMTxWithGigaExecutor(ctx, i, evmMsg)
1330+
if execErr != nil {
1331+
// Check if this is a fail-fast error (Cosmos precompile interop detected)
1332+
if gigautils.ShouldExecutionAbort(execErr) {
1333+
res := app.DeliverTxWithResult(ctx, tx, typedTxs[i])
1334+
txResults[i] = res
1335+
continue
1336+
}
1337+
txResults[i] = &abci.ExecTxResult{
1338+
Code: 1,
1339+
Log: fmt.Sprintf("[BUG] giga executor error: %v", execErr),
1340+
}
1341+
continue
1342+
}
1343+
1344+
txResults[i] = result
13191345
metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS)
13201346
}
1347+
13211348
return txResults
13221349
}
13231350

@@ -1363,12 +1390,13 @@ func (app *App) PartitionPrioritizedTxs(_ sdk.Context, txs [][]byte, typedTxs []
13631390

13641391
// ExecuteTxsConcurrently calls the appropriate function for processing transacitons
13651392
func (app *App) ExecuteTxsConcurrently(ctx sdk.Context, txs [][]byte, typedTxs []sdk.Tx, absoluteTxIndices []int) ([]*abci.ExecTxResult, sdk.Context) {
1366-
// TODO after OCC release, remove this check and call ProcessTXsWithOCC directly
1367-
if ctx.IsOCCEnabled() {
1368-
return app.ProcessTXsWithOCC(ctx, txs, typedTxs, absoluteTxIndices)
1393+
// Giga only supports synchronous execution for now
1394+
if app.EvmKeeper.GigaExecutorEnabled || !ctx.IsOCCEnabled() {
1395+
results := app.ProcessBlockSynchronous(ctx, txs, typedTxs, absoluteTxIndices)
1396+
return results, ctx
13691397
}
1370-
results := app.ProcessBlockSynchronous(ctx, txs, typedTxs, absoluteTxIndices)
1371-
return results, ctx
1398+
1399+
return app.ProcessTXsWithOCC(ctx, txs, typedTxs, absoluteTxIndices)
13721400
}
13731401

13741402
func (app *App) GetDeliverTxEntry(ctx sdk.Context, txIndex int, absoluateIndex int, bz []byte, tx sdk.Tx) (res *sdk.DeliverTxEntry) {
@@ -1462,12 +1490,9 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
14621490
}
14631491
}()
14641492

1465-
// Route to Giga Executor when enabled - bypasses Cosmos SDK transaction processing
1466-
if app.EvmKeeper.GigaExecutorEnabled {
1467-
if app.EvmKeeper.GigaOCCEnabled {
1468-
return app.ProcessBlockWithGigaExecutorOCC(ctx, txs, req, lastCommit, simulate)
1469-
}
1470-
return app.ProcessBlockWithGigaExecutor(ctx, txs, req, lastCommit, simulate)
1493+
// TODO: for now Giga OCC calls ProcessBlockWithGigaExecutorOCC, WIP
1494+
if app.EvmKeeper.GigaExecutorEnabled && app.EvmKeeper.GigaOCCEnabled {
1495+
return app.ProcessBlockWithGigaExecutorOCC(ctx, txs, req, lastCommit, simulate)
14711496
}
14721497

14731498
ctx = ctx.WithIsOCCEnabled(app.OccEnabled())
@@ -1530,6 +1555,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
15301555
// ProcessBlockWithGigaExecutor executes block transactions using the Giga executor,
15311556
// bypassing the standard Cosmos SDK transaction processing flow.
15321557
// This is an experimental path for improved EVM throughput.
1558+
// NOTE: This is not currently used in the codebase, but might be in the future.
15331559
func (app *App) ProcessBlockWithGigaExecutor(ctx sdk.Context, txs [][]byte, req BlockProcessRequest, lastCommit abci.CommitInfo, simulate bool) (events []abci.Event, txResults []*abci.ExecTxResult, endBlockResp abci.ResponseEndBlock, err error) {
15341560
// Panic recovery like original ProcessBlock
15351561
defer func() {
@@ -1580,12 +1606,9 @@ func (app *App) ProcessBlockWithGigaExecutor(ctx sdk.Context, txs [][]byte, req
15801606
// Check if this is an EVM transaction
15811607
evmMsg := app.GetEVMMsg(decodedTx)
15821608
if evmMsg == nil {
1583-
// Non-EVM transaction - for now, fall back to standard processing
1584-
// TODO: Handle or reject non-EVM txs in giga mode
1585-
txResults[i] = &abci.ExecTxResult{
1586-
Code: 1,
1587-
Log: "non-EVM transactions not supported in giga executor mode",
1588-
}
1609+
res := app.DeliverTxWithResult(ctx, txBytes, decodedTx)
1610+
// Non-EVM transaction - fall back to standard processing
1611+
txResults[i] = res
15891612
continue
15901613
}
15911614

@@ -1594,9 +1617,15 @@ func (app *App) ProcessBlockWithGigaExecutor(ctx sdk.Context, txs [][]byte, req
15941617
// Execute EVM transaction through giga executor
15951618
result, execErr := app.executeEVMTxWithGigaExecutor(ctx, i, evmMsg)
15961619
if execErr != nil {
1620+
// Check if this is a fail-fast error (Cosmos precompile interop detected)
1621+
if gigautils.ShouldExecutionAbort(execErr) {
1622+
res := app.DeliverTxWithResult(ctx, txBytes, decodedTx)
1623+
txResults[i] = res
1624+
continue
1625+
}
15971626
txResults[i] = &abci.ExecTxResult{
15981627
Code: 1,
1599-
Log: fmt.Sprintf("giga executor error: %v", execErr),
1628+
Log: fmt.Sprintf("[BUG] giga executor error: %v", execErr),
16001629
}
16011630
continue
16021631
}
@@ -1676,8 +1705,8 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
16761705
sstore := app.EvmKeeper.GetParams(ctx).SeiSstoreSetGasEip2200
16771706
cfg := evmtypes.DefaultChainConfig().EthereumConfigWithSstore(app.EvmKeeper.ChainID(ctx), &sstore)
16781707

1679-
// Create Giga executor VM (wraps evmone)
1680-
gigaExecutor := gigaexecutor.NewEvmoneExecutor(*blockCtx, stateDB, cfg, vm.Config{}, app.EvmKeeper.CustomPrecompiles(ctx))
1708+
// Create Giga executor VM
1709+
gigaExecutor := gigaexecutor.NewGethExecutor(*blockCtx, stateDB, cfg, vm.Config{}, gigaprecompiles.AllCustomPrecompilesFailFast)
16811710

16821711
// Execute the transaction through giga VM
16831712
execResult, execErr := gigaExecutor.ExecuteTransaction(ethTx, sender, app.EvmKeeper.GetBaseFee(ctx), &gp)
@@ -1688,6 +1717,12 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
16881717
}, nil
16891718
}
16901719

1720+
// Check if the execution hit a fail-fast precompile (Cosmos interop detected)
1721+
// Return the error to the caller so it can handle accordingly (e.g., fallback to standard execution)
1722+
if execResult.Err != nil && gigautils.ShouldExecutionAbort(execResult.Err) {
1723+
return nil, execResult.Err
1724+
}
1725+
16911726
// Finalize state changes
16921727
_, ferr := stateDB.Finalize()
16931728
if ferr != nil {
@@ -1905,6 +1940,12 @@ func (app *App) gigaDeliverTx(ctx sdk.Context, req abci.RequestDeliverTxV2, tx s
19051940

19061941
result, err := app.executeEVMTxWithGigaExecutor(ctx, ctx.TxIndex(), evmMsg)
19071942
if err != nil {
1943+
// Check if this is a fail-fast error (Cosmos precompile interop detected)
1944+
if gigautils.ShouldExecutionAbort(err) {
1945+
// Transaction requires Cosmos interop - not supported in giga mode
1946+
// TODO: implement fallback to standard execution path
1947+
return abci.ResponseDeliverTx{Code: 1, Log: fmt.Sprintf("giga executor: cosmos interop not supported: %v", err)}
1948+
}
19081949
return abci.ResponseDeliverTx{Code: 1, Log: fmt.Sprintf("giga executor error: %v", err)}
19091950
}
19101951

giga/executor/precompiles/failfast.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package precompiles
22

33
import (
4-
"errors"
4+
"fmt"
55
"math/big"
66

77
"github.com/ethereum/go-ethereum/common"
@@ -38,7 +38,24 @@ var FailFastPrecompileAddresses = []common.Address{
3838
common.HexToAddress(p256.P256VerifyAddress),
3939
}
4040

41-
var ErrInvalidPrecompileCall = errors.New("invalid precompile call")
41+
// InvalidPrecompileCallError is an error type that implements vm.AbortError,
42+
// signaling that execution should abort and this error should propagate
43+
// through the entire call stack.
44+
type InvalidPrecompileCallError struct{}
45+
46+
func (e *InvalidPrecompileCallError) Error() string {
47+
return "invalid precompile call"
48+
}
49+
50+
// IsAbortError implements vm.AbortError interface, signaling that this error
51+
// should propagate through the EVM call stack instead of being swallowed.
52+
func (e *InvalidPrecompileCallError) IsAbortError() bool {
53+
return true
54+
}
55+
56+
// ErrInvalidPrecompileCall is the singleton error instance for invalid precompile calls.
57+
// It implements vm.AbortError to ensure it propagates through the call stack.
58+
var ErrInvalidPrecompileCall error = &InvalidPrecompileCallError{}
4259

4360
type FailFastPrecompile struct{}
4461

@@ -49,6 +66,7 @@ func (p *FailFastPrecompile) RequiredGas(input []byte) uint64 {
4966
}
5067

5168
func (p *FailFastPrecompile) Run(evm *vm.EVM, caller common.Address, callingContract common.Address, input []byte, value *big.Int, readOnly bool, isFromDelegateCall bool, hooks *tracing.Hooks) ([]byte, error) {
69+
fmt.Println("FAILFAST PRECOMPILE CALLED: 52")
5270
return nil, ErrInvalidPrecompileCall
5371
}
5472

giga/executor/utils/errors.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package utils
22

33
import (
4-
"errors"
5-
6-
"github.com/sei-protocol/sei-chain/giga/executor/precompiles"
4+
"github.com/ethereum/go-ethereum/core/vm"
75
)
86

7+
// ShouldExecutionAbort checks if the given error is an AbortError that should
8+
// cause Giga execution to abort and fall back to standard execution.
99
func ShouldExecutionAbort(err error) bool {
10-
return errors.Is(err, precompiles.ErrInvalidPrecompileCall)
10+
if err == nil {
11+
return false
12+
}
13+
if abortErr, ok := err.(vm.AbortError); ok {
14+
return abortErr.IsAbortError()
15+
}
16+
return false
1117
}

go.work

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ use (
55
./sei-cosmos
66
./sei-tendermint
77
)
8+
9+
replace github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.15.8-wip

go.work.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ github.com/schollz/closestmatch v2.1.0+incompatible h1:Uel2GXEpJqOWBrlyI+oY9LTiy
803803
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
804804
github.com/seccomp/libseccomp-golang v0.9.1 h1:NJjM5DNFOs0s3kYE1WUOr6G8V97sdt46rlXTMfXGWBo=
805805
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
806-
github.com/sei-protocol/go-ethereum v1.15.7-sei-15 h1:cK2ZiNo9oWO4LeyRlZYZMILspPq0yoHIJdjLviAxtXE=
807-
github.com/sei-protocol/go-ethereum v1.15.7-sei-15/go.mod h1:+S9k+jFzlyVTNcYGvqFhzN/SFhI6vA+aOY4T5tLSPL0=
806+
github.com/sei-protocol/go-ethereum v1.15.8-wip h1:isUcMF8DkzsrCoYIxlMKAw7bR5rmzJqwWurunv/t/kI=
807+
github.com/sei-protocol/go-ethereum v1.15.8-wip/go.mod h1:+S9k+jFzlyVTNcYGvqFhzN/SFhI6vA+aOY4T5tLSPL0=
808808
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
809809
github.com/shirou/gopsutil/v3 v3.22.9/go.mod h1:bBYl1kjgEJpWpxeHmLI+dVHWtyAwfcmSBLDsp2TNT8A=
810810
github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU=

0 commit comments

Comments
 (0)