Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit d98385c

Browse files
committed
fix geth-utils to use updated tracing logic
1 parent bc7ae85 commit d98385c

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

geth-utils/gethutil/trace.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gethutil
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"math/big"
67

@@ -9,11 +10,11 @@ import (
910
"github.com/ethereum/go-ethereum/core"
1011
"github.com/ethereum/go-ethereum/core/rawdb"
1112
"github.com/ethereum/go-ethereum/core/state"
13+
"github.com/ethereum/go-ethereum/core/tracing"
1214
"github.com/ethereum/go-ethereum/core/types"
1315
"github.com/ethereum/go-ethereum/core/vm"
1416
"github.com/ethereum/go-ethereum/eth/tracers/logger"
1517
"github.com/ethereum/go-ethereum/params"
16-
"github.com/ethereum/go-ethereum/core/tracing"
1718
"github.com/holiman/uint256"
1819
)
1920

@@ -138,11 +139,11 @@ func toBigInt(value *hexutil.Big) *big.Int {
138139

139140
func Trace(config TraceConfig) ([]*ExecutionResult, error) {
140141
chainConfig := params.ChainConfig{
141-
ChainID: toBigInt(config.ChainID),
142-
HomesteadBlock: big.NewInt(0),
143-
DAOForkBlock: big.NewInt(0),
144-
DAOForkSupport: true,
145-
EIP150Block: big.NewInt(0),
142+
ChainID: toBigInt(config.ChainID),
143+
HomesteadBlock: big.NewInt(0),
144+
DAOForkBlock: big.NewInt(0),
145+
DAOForkSupport: true,
146+
EIP150Block: big.NewInt(0),
146147
// EIP150Hash: common.Hash{},
147148
EIP155Block: big.NewInt(0),
148149
EIP158Block: big.NewInt(0),
@@ -154,6 +155,7 @@ func Trace(config TraceConfig) ([]*ExecutionResult, error) {
154155
BerlinBlock: big.NewInt(0),
155156
LondonBlock: big.NewInt(0),
156157
ShanghaiTime: newUint64(0),
158+
CancunTime: newUint64(0),
157159
TerminalTotalDifficulty: big.NewInt(0),
158160
TerminalTotalDifficultyPassed: true,
159161
}
@@ -231,32 +233,35 @@ func Trace(config TraceConfig) ([]*ExecutionResult, error) {
231233
}
232234
stateDB.Finalise(true)
233235

236+
var (
237+
err error
238+
usedGas uint64
239+
raw json.RawMessage
240+
tx types.Transaction
241+
)
242+
234243
// Run the transactions with tracing enabled.
235244
executionResults := make([]*ExecutionResult, len(config.Transactions))
236245
for i, message := range messages {
237246
tracer := logger.NewStructLogger(config.LoggerConfig)
238-
evm := vm.NewEVM(blockCtx, core.NewEVMTxContext(&message), stateDB, &chainConfig, vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true})
247+
evm := vm.NewEVM(blockCtx, vm.TxContext{GasPrice: big.NewInt(0)}, stateDB, &chainConfig, vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true})
239248

240-
result, err := core.ApplyMessage(evm, &message, new(core.GasPool).AddGas(message.GasLimit))
249+
tx = *types.NewTransaction(message.Nonce, *message.To, message.Value, message.GasLimit, message.GasPrice, message.Data)
250+
stateDB.SetTxContext(tx.Hash(), i)
251+
252+
_, err = core.ApplyTransactionWithEVM(&message, &chainConfig, new(core.GasPool).AddGas(message.GasLimit), stateDB, blockCtx.BlockNumber, common.Hash{}, &tx, &usedGas, evm)
241253
if err != nil {
242-
executionResults[i] = &ExecutionResult{
243-
Gas: 0,
244-
Failed: true,
245-
Invalid: true,
246-
ReturnValue: fmt.Sprintf("%v", err),
247-
StructLogs: []StructLogRes{},
248-
}
249-
} else {
250-
stateDB.Finalise(true)
254+
return nil, fmt.Errorf("tracing failed: %w", err)
255+
}
256+
raw, _ = tracer.GetResult()
251257

252-
executionResults[i] = &ExecutionResult{
253-
Gas: result.UsedGas,
254-
Failed: result.Failed(),
255-
Invalid: false,
256-
ReturnValue: fmt.Sprintf("%x", result.ReturnData),
257-
StructLogs: FormatLogs(tracer.StructLogs()),
258-
}
258+
var result ExecutionResult
259+
err = json.Unmarshal(raw, &result)
260+
if err != nil {
261+
return nil, fmt.Errorf("failed to unmarshal result: %w", err)
259262
}
263+
264+
executionResults[i] = &result
260265
}
261266

262267
return executionResults, nil

geth-utils/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,24 @@ require (
2727
github.com/consensys/gnark-crypto v0.12.1 // indirect
2828
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
2929
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
30+
github.com/davecgh/go-spew v1.1.1 // indirect
3031
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
3132
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
3233
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
34+
github.com/fsnotify/fsnotify v1.6.0 // indirect
35+
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
3336
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
3437
github.com/getsentry/sentry-go v0.18.0 // indirect
3538
github.com/go-ole/go-ole v1.3.0 // indirect
3639
github.com/gofrs/flock v0.8.1 // indirect
3740
github.com/gogo/protobuf v1.3.2 // indirect
3841
github.com/golang/protobuf v1.5.4 // indirect
3942
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
43+
github.com/google/uuid v1.3.0 // indirect
4044
github.com/gorilla/websocket v1.4.2 // indirect
4145
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
46+
github.com/huin/goupnp v1.3.0 // indirect
47+
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
4248
github.com/klauspost/compress v1.15.15 // indirect
4349
github.com/kr/pretty v0.3.1 // indirect
4450
github.com/kr/text v0.2.0 // indirect
@@ -54,10 +60,12 @@ require (
5460
github.com/rivo/uniseg v0.2.0 // indirect
5561
github.com/rogpeppe/go-internal v1.9.0 // indirect
5662
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
63+
github.com/status-im/keycard-go v0.2.0 // indirect
5764
github.com/supranational/blst v0.3.11 // indirect
5865
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
5966
github.com/tklauser/go-sysconf v0.3.12 // indirect
6067
github.com/tklauser/numcpus v0.6.1 // indirect
68+
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
6169
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
6270
golang.org/x/mod v0.14.0 // indirect
6371
golang.org/x/sync v0.5.0 // indirect

geth-utils/go.sum

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPx
1616
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
1717
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
1818
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
19+
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
20+
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
1921
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
2022
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2123
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
@@ -50,16 +52,14 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1
5052
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
5153
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
5254
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
53-
github.com/ethereum/go-ethereum v1.13.5-0.20240321125013-14eb8967be7a h1:Es15fA9QPpPGVUhEFyGO/0XVYxoxmlTY1aVwWP62AsU=
54-
github.com/ethereum/go-ethereum v1.13.5-0.20240321125013-14eb8967be7a/go.mod h1:76qJL8YPX5VJfJRVsLcVSbjGg1LOi+EQFNfGGgJ/zCY=
55-
github.com/ethereum/go-ethereum v1.13.5-0.20240322175353-064f37d6f67a h1:DuMBSP5WWrEuwyA5tGgpkfY0xxDfC4G+BCd+FCiKeLA=
56-
github.com/ethereum/go-ethereum v1.13.5-0.20240322175353-064f37d6f67a/go.mod h1:76qJL8YPX5VJfJRVsLcVSbjGg1LOi+EQFNfGGgJ/zCY=
5755
github.com/ethereum/go-ethereum v1.13.5-0.20240402092557-0bd03dbc5597 h1:D5DaLAE5RTaiiJFWn0Z4asA4ULBmt6c/1W0EHMNrg/0=
5856
github.com/ethereum/go-ethereum v1.13.5-0.20240402092557-0bd03dbc5597/go.mod h1:x2gtBG0WHLgY08FE97lfhjtpcR5vcSAZbi34JnrsBbQ=
5957
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6058
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
6159
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
6260
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
61+
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI=
62+
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
6363
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2GihuqhwdILrV+7GJel5lyPV3u1+PgzrWLc0TkE=
6464
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc=
6565
github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0=
@@ -91,14 +91,22 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
9191
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9292
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
9393
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
94+
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
95+
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
9496
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
97+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
98+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9599
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
96100
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
97101
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
98102
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
99103
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
100104
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
101105
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
106+
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
107+
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
108+
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
109+
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
102110
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
103111
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
104112
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
@@ -151,6 +159,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
151159
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
152160
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
153161
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
162+
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
163+
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
154164
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
155165
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
156166
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
@@ -163,6 +173,8 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA
163173
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
164174
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
165175
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
176+
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
177+
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
166178
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
167179
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
168180
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -190,6 +202,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
190202
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
191203
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
192204
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
205+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
193206
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
194207
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
195208
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -203,6 +216,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
203216
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
204217
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
205218
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
219+
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
206220
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
207221
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
208222
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)