Skip to content

Commit 212d2f5

Browse files
committed
add events and logs
1 parent ba19946 commit 212d2f5

File tree

4 files changed

+571
-21
lines changed

4 files changed

+571
-21
lines changed

app/app.go

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import (
8787
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
8888
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
8989
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
90-
"github.com/ethereum/go-ethereum/core"
9190
ethtypes "github.com/ethereum/go-ethereum/core/types"
9291
"github.com/ethereum/go-ethereum/core/vm"
9392
"github.com/ethereum/go-ethereum/ethclient"
@@ -1334,6 +1333,7 @@ func (app *App) ProcessTxsSynchronousGiga(ctx sdk.Context, txs [][]byte, typedTx
13341333

13351334
txResults := make([]*abci.ExecTxResult, len(txs))
13361335
for i, tx := range txs {
1336+
fmt.Println("GIGA WORKING tx", absoluteTxIndices[i])
13371337
ctx = ctx.WithTxIndex(absoluteTxIndices[i])
13381338
evmMsg := app.GetEVMMsg(typedTxs[i])
13391339
// If not an EVM tx, fall back to v2 processing
@@ -1691,7 +1691,14 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
16911691
}, nil
16921692
}
16931693

1694+
// Prepare context for EVM transaction (set infinite gas meter like original flow)
1695+
// Use a fresh EventManager to collect ALL events during this transaction
1696+
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeterWithMultiplier(ctx))
1697+
ctx = ctx.WithTxIndex(txIndex)
1698+
ctx = ctx.WithEventManager(sdk.NewEventManager())
1699+
16941700
// Associate the address if not already associated (same as EVMPreprocessDecorator)
1701+
// This emits address_associated event
16951702
if _, isAssociated := app.EvmKeeper.GetEVMAddress(ctx, seiAddr); !isAssociated {
16961703
associateHelper := helpers.NewAssociationHelper(&app.EvmKeeper, app.BankKeeper, &app.AccountKeeper)
16971704
if err := associateHelper.AssociateAddresses(ctx, seiAddr, sender, pubkey); err != nil {
@@ -1702,11 +1709,7 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
17021709
}
17031710
}
17041711

1705-
// Prepare context for EVM transaction (set infinite gas meter like original flow)
1706-
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeterWithMultiplier(ctx))
1707-
ctx = ctx.WithTxIndex(txIndex)
1708-
1709-
// Create state DB for this transaction
1712+
// Create state DB for this transaction (uses ctx with our EventManager)
17101713
stateDB := evmstate.NewDBImpl(ctx, &app.EvmKeeper, false)
17111714
defer stateDB.Cleanup()
17121715

@@ -1729,7 +1732,8 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
17291732
// Create Giga executor VM
17301733
gigaExecutor := gigaexecutor.NewGethExecutor(*blockCtx, stateDB, cfg, vm.Config{}, gigaprecompiles.AllCustomPrecompilesFailFast)
17311734

1732-
// Execute the transaction through giga VM
1735+
// Execute the transaction with feeCharged=false
1736+
// This allows BuyGas to emit coin_spent events during execution
17331737
execResult, execErr := gigaExecutor.ExecuteTransaction(ethTx, sender, app.EvmKeeper.GetBaseFee(ctx), &gp)
17341738
if execErr != nil {
17351739
return &abci.ExecTxResult{
@@ -1760,18 +1764,7 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
17601764
}
17611765

17621766
// Create core.Message from ethTx for WriteReceipt
1763-
// WriteReceipt needs msg for GasPrice, To, From, Data, Nonce fields
1764-
evmMsg := &core.Message{
1765-
Nonce: ethTx.Nonce(),
1766-
GasLimit: ethTx.Gas(),
1767-
GasPrice: ethTx.GasPrice(),
1768-
GasFeeCap: ethTx.GasFeeCap(),
1769-
GasTipCap: ethTx.GasTipCap(),
1770-
To: ethTx.To(),
1771-
Value: ethTx.Value(),
1772-
Data: ethTx.Data(),
1773-
From: sender,
1774-
}
1767+
evmMsg := app.EvmKeeper.GetEVMMessage(ctx, ethTx, sender)
17751768
receipt, rerr := app.EvmKeeper.WriteReceipt(ctx, stateDB, evmMsg, uint32(ethTx.Type()), ethTx.Hash(), execResult.UsedGas, vmError)
17761769
if rerr != nil {
17771770
return &abci.ExecTxResult{
@@ -1799,12 +1792,30 @@ func (app *App) executeEVMTxWithGigaExecutor(ctx sdk.Context, txIndex int, msg *
17991792
// isn't committed, so we pass the receipt through the response for later processing.
18001793
receiptBytes, _ := receipt.Marshal()
18011794

1795+
// Collect all events from the EventManager
1796+
// In V2, events are structured as: anteEvents + [message:action + msgResult.Events]
1797+
// For Giga, we collect all events and append message:action at the end
1798+
// This ensures all execution events are captured properly
1799+
eventMsgName := sdk.MsgTypeURL(msg)
1800+
allEvents := ctx.EventManager().Events()
1801+
1802+
// Append message:action event at the end
1803+
allEvents = allEvents.AppendEvents(sdk.Events{
1804+
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName)),
1805+
})
1806+
1807+
// Create message log (same format as RunMsgs)
1808+
msgLogs := sdk.ABCIMessageLogs{
1809+
sdk.NewABCIMessageLog(uint32(0), vmError, allEvents),
1810+
}
1811+
18021812
//nolint:gosec // G115: safe, UsedGas won't exceed int64 max
18031813
return &abci.ExecTxResult{
18041814
Code: code,
18051815
Data: receiptBytes,
18061816
GasUsed: int64(execResult.UsedGas),
1807-
Log: vmError,
1817+
Log: strings.TrimSpace(msgLogs.String()),
1818+
Events: sdk.MarkEventsToIndex(allEvents.ToABCIEvents(), app.IndexEvents),
18081819
EvmTxInfo: &abci.EvmTxInfo{
18091820
TxHash: ethTx.Hash().Hex(),
18101821
VmError: vmError,

giga/executor/executor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ func NewGethExecutor(blockCtx vm.BlockContext, stateDB vm.StateDB, chainConfig *
3333
}
3434

3535
func (e *Executor) ExecuteTransaction(tx *types.Transaction, sender common.Address, baseFee *big.Int, gasPool *core.GasPool) (*core.ExecutionResult, error) {
36+
return e.ExecuteTransactionWithOptions(tx, sender, baseFee, gasPool, false, true)
37+
}
38+
39+
// ExecuteTransactionWithOptions executes a transaction with explicit control over fee and nonce handling.
40+
// - feeCharged: if true, assumes gas fee was already charged (skips BuyGas). Use true to match V2 behavior.
41+
// - shouldIncrementNonce: if true, increments the sender's nonce during execution.
42+
func (e *Executor) ExecuteTransactionWithOptions(tx *types.Transaction, sender common.Address, baseFee *big.Int, gasPool *core.GasPool, feeCharged bool, shouldIncrementNonce bool) (*core.ExecutionResult, error) {
3643
message, err := core.TransactionToMessage(tx, &internal.Signer{From: sender}, baseFee)
3744
if err != nil {
3845
return nil, err
3946
}
4047

41-
executionResult, err := core.ApplyMessage(e.evm, message, gasPool)
48+
e.evm.SetTxContext(core.NewEVMTxContext(message))
49+
executionResult, err := core.NewStateTransition(e.evm, message, gasPool, feeCharged, shouldIncrementNonce).Execute()
4250
if err != nil {
4351
return nil, err
4452
}

0 commit comments

Comments
 (0)