Skip to content

Commit

Permalink
ft: update tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul0tripathi committed Jun 18, 2024
1 parent 2d7de23 commit 2c0db83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions entity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewTransactionStorage() *TransactionStorage {
return &TransactionStorage{
txs: make(map[common.Hash]*types.Transaction),
receipts: make(map[common.Hash]*types.Receipt),
traces: make(map[common.Hash]TransactionTraces),
}
}

Expand Down
17 changes: 9 additions & 8 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/holiman/uint256"
"github.com/rahul0tripathi/smelter/config"
"github.com/rahul0tripathi/smelter/entity"
Expand Down Expand Up @@ -57,14 +56,14 @@ func NewExecutor(
func (e *SerialExecutor) CallAndPersist(
ctx context.Context,
tx ethereum.CallMsg,
hooks *tracing.Hooks,
tracer entity.TraceProvider,
overrides entity.StateOverrides,
) (txHash *common.Hash, ret []byte, leftOverGas uint64, err error) {
e.mu.Lock()
defer e.mu.Unlock()

executionDB := statedb.NewDB(ctx, e.db)
chainCfg, evmCfg := e.cfg.ExecutionConfig(hooks)
chainCfg, evmCfg := e.cfg.ExecutionConfig(tracer.Hooks())
if err = executionDB.ApplyOverrides(overrides); err != nil {
return nil, nil, 0, err
}
Expand All @@ -88,7 +87,7 @@ func (e *SerialExecutor) CallAndPersist(
return
}

txHash = e.roll(ctx, tx, leftOverGas, executionDB)
txHash = e.roll(ctx, tx, leftOverGas, executionDB, tracer)
return
}

Expand All @@ -97,6 +96,7 @@ func (e *SerialExecutor) roll(
msg ethereum.CallMsg,
left uint64,
executionDB *statedb.StateDB,
traceProvider entity.TraceProvider,
) *common.Hash {
e.db.ApplyStorage(executionDB.Dirty().GetAccountStorage())
e.db.ApplyState(executionDB.Dirty().GetAccountState())
Expand Down Expand Up @@ -127,6 +127,7 @@ func (e *SerialExecutor) roll(

e.prevBlockHash = hash
e.prevBlockNum = block.Uint64()
e.txn.AddTrace(tx.Hash(), traceProvider.OtterTrace())

txHash := tx.Hash()
return &txHash
Expand All @@ -135,7 +136,7 @@ func (e *SerialExecutor) roll(
func (e *SerialExecutor) Call(
ctx context.Context,
tx ethereum.CallMsg,
hooks *tracing.Hooks,
tracer entity.TraceProvider,
overrides entity.StateOverrides,
) (ret []byte, leftOverGas uint64, err error) {
e.mu.Lock()
Expand All @@ -146,7 +147,7 @@ func (e *SerialExecutor) Call(
return nil, 0, err
}

chainCfg, evmCfg := e.cfg.ExecutionConfig(hooks)
chainCfg, evmCfg := e.cfg.ExecutionConfig(tracer.Hooks())
env := vm.NewEVM(e.cfg.BlockContext(new(big.Int).Add(e.cfg.ForkConfig.ForkBlock, new(big.Int).SetUint64(1)),
new(big.Int),
uint64(time.Now().Unix())),
Expand All @@ -169,7 +170,7 @@ func (e *SerialExecutor) Call(
func (e *SerialExecutor) CallWithDB(
ctx context.Context,
tx ethereum.CallMsg,
hooks *tracing.Hooks,
tracer entity.TraceProvider,
db *fork.DB,
overrides entity.StateOverrides,
) (ret []byte, leftOverGas uint64, err error) {
Expand All @@ -181,7 +182,7 @@ func (e *SerialExecutor) CallWithDB(
return nil, 0, err
}

chainCfg, evmCfg := e.cfg.ExecutionConfig(hooks)
chainCfg, evmCfg := e.cfg.ExecutionConfig(tracer.Hooks())
env := vm.NewEVM(e.cfg.BlockContext(new(big.Int).Add(e.cfg.ForkConfig.ForkBlock, new(big.Int).SetUint64(1)),
new(big.Int),
uint64(time.Now().Unix())),
Expand Down
9 changes: 4 additions & 5 deletions services/eth_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *EthRpc) Call(
call, err := createEthCallMsg(msg)
t := tracer.NewTracer(false)
if block.Uint64() == latest {
ret, _, err := execCtx.Executor.Call(ctx, call, t.Hooks(), entity.StateOverrides{})
ret, _, err := execCtx.Executor.Call(ctx, call, t, entity.StateOverrides{})
if err != nil {
return "0x", err
}
Expand All @@ -198,7 +198,7 @@ func (r *EthRpc) Call(
}

db := fork.NewDB(r.readerAndCaller, r.cfg, storage.Accounts, storage.State)
ret, _, err := execCtx.Executor.CallWithDB(ctx, call, t.Hooks(), db, entity.StateOverrides{})
ret, _, err := execCtx.Executor.CallWithDB(ctx, call, t, db, entity.StateOverrides{})
if err != nil {
return "0x", err
}
Expand Down Expand Up @@ -249,13 +249,12 @@ func (r *EthRpc) SendRawTransaction(
Data: tx.Data(),
}

txHash, _, _, err := execCtx.Executor.CallAndPersist(ctx, msg, t.Hooks(), entity.StateOverrides{})
txHash, _, _, err := execCtx.Executor.CallAndPersist(ctx, msg, t, execCtx.Overrides)
fmt.Println(t.Fmt())
if err != nil {
return "0x", err
}

fmt.Println(t.Fmt())

return txHash.Hex(), nil
}

Expand Down
12 changes: 6 additions & 6 deletions tests/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestExecuteE2E(t *testing.T) {
Data: deposit,
Gas: 30000000,
Value: new(big.Int).SetInt64(6969),
}, stateTracer.Hooks(), map[common.Address]entity.StateOverride{
}, stateTracer, map[common.Address]entity.StateOverride{
sender: {Balance: abi.MaxUint256},
})
require.NoError(t, err, "failed to deposit")
Expand All @@ -63,7 +63,7 @@ func TestExecuteE2E(t *testing.T) {
Data: balanceOfx06,
Gas: 30000000,
Value: new(big.Int).SetInt64(0),
}, stateTracer.Hooks(), nil)
}, stateTracer, nil)
require.NoError(t, err, "failed to read 0x6 balance")
require.Equal(t, new(big.Int).SetBytes(ret).Int64(), int64(6969), "invalid 0x6 balance received pre transfer")

Expand All @@ -76,7 +76,7 @@ func TestExecuteE2E(t *testing.T) {
Data: transferCall,
Gas: 30000000,
Value: new(big.Int).SetInt64(0),
}, stateTracer.Hooks(), map[common.Address]entity.StateOverride{
}, stateTracer, map[common.Address]entity.StateOverride{
sender: {Balance: abi.MaxUint256},
})
require.NoError(t, err, "failed to transfer weth")
Expand All @@ -90,7 +90,7 @@ func TestExecuteE2E(t *testing.T) {
Data: balanceOfx07,
Gas: 30000000,
Value: new(big.Int).SetInt64(0),
}, stateTracer.Hooks(), nil)
}, stateTracer, nil)
require.NoError(t, err, "failed to read 0x7 balance")
require.Equal(t, new(big.Int).SetBytes(ret).Int64(), int64(6967), "invalid 0x7 balance received post transfer")

Expand All @@ -101,7 +101,7 @@ func TestExecuteE2E(t *testing.T) {
Data: balanceOfx06,
Gas: 30000000,
Value: new(big.Int).SetInt64(0),
}, stateTracer.Hooks(), nil)
}, stateTracer, nil)
require.NoError(t, err, "failed to read 0x6 balance")
require.Equal(t, new(big.Int).SetBytes(ret).Int64(), int64(2), "invalid 0x6 balance received post transfer")
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestBlockProduction(t *testing.T) {
Gas: 30000000,
Value: new(big.Int).SetInt64(6969),
}
hash, _, _, err := exec.CallAndPersist(ctx, msg, stateTracer.Hooks(), map[common.Address]entity.StateOverride{
hash, _, _, err := exec.CallAndPersist(ctx, msg, stateTracer, map[common.Address]entity.StateOverride{
sender: {Balance: abi.MaxUint256},
})
require.NoError(t, err, "failed to deposit")
Expand Down

0 comments on commit 2c0db83

Please sign in to comment.