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
10 changes: 7 additions & 3 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/tasks"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -179,14 +180,17 @@ func (app *App) DeliverTxBatch(ctx sdk.Context, req sdk.DeliverTxBatchRequest) (
}

// avoid overhead for empty batches
scheduler := tasks.NewScheduler(app.ConcurrencyWorkers(), app.TracingInfo, app.DeliverTx)
txRes, err := scheduler.ProcessAll(ctx, req.TxEntries)
scheduler := tasks.NewScheduler(app.ConcurrencyWorkers(), app.TracingInfo, app.Executor)
txRes, stats, err := scheduler.ProcessAll(ctx.Context(), baseapp.TxEntriesToTasks(ctx, req.TxEntries), baseapp.GetMultiVersionStore(ctx))
if err != nil {
ctx.Logger().Error("error while processing scheduler", "err", err)
panic(err)
}
logStats := []interface{}{"height", ctx.BlockHeight()}
logStats = append(logStats, stats...)
ctx.Logger().Info("occ scheduler", logStats...)
for _, tx := range txRes {
responses = append(responses, &sdk.DeliverTxResult{Response: tx})
responses = append(responses, &sdk.DeliverTxResult{Response: *tx})
}

return sdk.DeliverTxBatchResponse{Results: responses}
Expand Down
5 changes: 5 additions & 0 deletions giga/executor/types/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package types

type Hash [32]byte

type Address [20]byte
21 changes: 21 additions & 0 deletions giga/executor/types/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package types

// The interface defines the entrypoints of a transaction execution.
type VM interface {
Create(sender Address, code []byte, gas uint64, value Hash) (ret []byte, contractAddr Address, gasLeft uint64, err error)
Call(sender Address, to Address, input []byte, gas uint64, value Hash) (ret []byte, gasLeft uint64, err error)
}

// The interface defines access to states. These are needed mainly
// for the preprocessing before the VM entrypoints are called (
// e.g. nonce checking/setting, fee charging, value transfer, etc.)
type Storage interface {
GetCode(addr Address) ([]byte, error)
GetState(addr Address, key Hash) (Hash, error)
SetState(addr Address, key Hash, value Hash) error
GetBalance(addr Address) (Hash, error)
SetBalance(addr Address, value Hash) error
GetNonce(addr Address) (uint64, error)
SetNonce(addr Address, nonce uint64) error
// TODO: accesslist setting
}
32 changes: 32 additions & 0 deletions giga/executor/vm/evmc/vm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package evmc

import (
"math"

"github.com/ethereum/evmc/v12/bindings/go/evmc"
"github.com/sei-protocol/sei-chain/giga/executor/types"
)

type VMImpl struct {
hostContext evmc.HostContext
}

func NewVM(hostContext evmc.HostContext) types.VM {
return &VMImpl{hostContext: hostContext}
}

func (v *VMImpl) Create(sender types.Address, code []byte, gas uint64, value types.Hash) (ret []byte, contractAddr types.Address, gasLeft uint64, err error) {
if gas > math.MaxInt64 {
panic("gas overflow")
}
ret, left, _, addr, err := v.hostContext.Call(evmc.Create, evmc.Address{}, evmc.Address(sender), evmc.Hash(value), code, int64(gas), 0, false, evmc.Hash{}, evmc.Address{})
return ret, types.Address(addr), uint64(left), err //nolint:gosec
}

func (v *VMImpl) Call(sender types.Address, to types.Address, input []byte, gas uint64, value types.Hash) (ret []byte, gasLeft uint64, err error) {
if gas > math.MaxInt64 {
panic("gas overflow")
}
ret, left, _, _, err := v.hostContext.Call(evmc.Call, evmc.Address(to), evmc.Address(sender), evmc.Hash(value), input, int64(gas), 0, false, evmc.Hash{}, evmc.Address(to))
return ret, uint64(left), err //nolint:gosec
}
28 changes: 28 additions & 0 deletions giga/executor/vm/geth/vm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package geth

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/holiman/uint256"
"github.com/sei-protocol/sei-chain/giga/executor/types"
)

var _ types.VM = &VMImpl{}

type VMImpl struct {
evm *vm.EVM
}

func NewVM(evm *vm.EVM) types.VM {
return &VMImpl{evm: evm}
}

func (v *VMImpl) Create(sender types.Address, code []byte, gas uint64, value types.Hash) (ret []byte, contractAddr types.Address, gasLeft uint64, err error) {
ret, addr, gasLeft, err := v.evm.Create(common.Address(sender), code, gas, new(uint256.Int).SetBytes(value[:]))
return ret, types.Address(addr), gasLeft, err
}

func (v *VMImpl) Call(sender types.Address, to types.Address, input []byte, gas uint64, value types.Hash) (ret []byte, gasLeft uint64, err error) {
ret, gasLeft, err = v.evm.Call(common.Address(sender), common.Address(to), input, gas, new(uint256.Int).SetBytes(value[:]))
return ret, gasLeft, err
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/ethereum/evmc/v12 v12.1.0
github.com/ethereum/go-ethereum v1.16.1
github.com/go-playground/validator/v10 v10.11.1
github.com/gogo/protobuf v1.3.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ github.com/esimonov/ifshort v1.0.4 h1:6SID4yGWfRae/M7hkVDVVyppy8q/v9OuxNdmjLQStB
github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcHcfgNWTk0=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/evmc/v12 v12.1.0 h1:fUIzJNnXa9VPYx253lDS7L9iBZtP+tlpTdZst5e6Pks=
github.com/ethereum/evmc/v12 v12.1.0/go.mod h1:80jmft01io35nSmrX70bKFR/lncwFuqE90iLLSMyMAE=
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw=
Expand Down
43 changes: 40 additions & 3 deletions sei-cosmos/baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/armon/go-metrics"
"github.com/cosmos/cosmos-sdk/codec"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/store/multiversion"
"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/tasks"
"github.com/cosmos/cosmos-sdk/telemetry"
Expand Down Expand Up @@ -176,14 +177,17 @@ func (app *BaseApp) DeliverTxBatch(ctx sdk.Context, req sdk.DeliverTxBatchReques
}

// avoid overhead for empty batches
scheduler := tasks.NewScheduler(app.concurrencyWorkers, app.TracingInfo, app.DeliverTx)
txRes, err := scheduler.ProcessAll(ctx, req.TxEntries)
scheduler := tasks.NewScheduler(app.concurrencyWorkers, app.TracingInfo, app.Executor)
txRes, stats, err := scheduler.ProcessAll(ctx.Context(), TxEntriesToTasks(ctx, req.TxEntries), GetMultiVersionStore(ctx))
if err != nil {
ctx.Logger().Error("error while processing scheduler", "err", err)
panic(err)
}
logStats := []interface{}{"height", ctx.BlockHeight()}
logStats = append(logStats, stats...)
ctx.Logger().Info("occ scheduler", logStats...)
for _, tx := range txRes {
responses = append(responses, &sdk.DeliverTxResult{Response: tx})
responses = append(responses, &sdk.DeliverTxResult{Response: *tx})
}

return sdk.DeliverTxBatchResponse{Results: responses}
Expand Down Expand Up @@ -1159,3 +1163,36 @@ func (app *BaseApp) GetTxPriorityHint(_ context.Context, req *abci.RequestGetTxP
Priority: priority,
}, nil
}

func (app *BaseApp) Executor(task tasks.SchedulerTask[*abci.ResponseDeliverTx]) *abci.ResponseDeliverTx {
typedTask := task.(*tasks.DeliverTxTask)
resp := app.DeliverTx(typedTask.Ctx, typedTask.Request, typedTask.SdkTx, typedTask.Checksum)
return &resp
}

func TxEntriesToTasks(ctx sdk.Context, entries []*sdk.DeliverTxEntry) []tasks.SchedulerTask[*abci.ResponseDeliverTx] {
allTasks := make([]tasks.SchedulerTask[*abci.ResponseDeliverTx], 0, len(entries))
for _, r := range entries {
task := &tasks.DeliverTxTask{
Ctx: ctx,
Request: r.Request,
SdkTx: r.SdkTx,
Checksum: r.Checksum,
}
task.SetStatus("pending")
task.SetAbsoluteIndex(r.AbsoluteIndex)
task.SetDependencies(map[int]struct{}{})
task.SetTxTracer(r.TxTracer)
allTasks = append(allTasks, task)
}
return allTasks
}

func GetMultiVersionStore(ctx sdk.Context) map[string]multiversion.MultiVersionStore {
mvs := make(map[string]multiversion.MultiVersionStore)
keys := ctx.MultiStore().StoreKeys()
for _, sk := range keys {
mvs[sk.String()] = multiversion.NewMultiVersionStore(ctx.MultiStore().GetKVStore(sk))
}
return mvs
}
Loading
Loading