Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
5f917715
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5f917715
编写于
4月 14, 2016
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2454 from karalabe/trace-fix
eth: fix single transaction tracing (run prev mutations)
上级
e50e3bea
53016c12
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
53 deletion
+65
-53
eth/api.go
eth/api.go
+60
-48
rpc/javascript.go
rpc/javascript.go
+5
-5
未找到文件。
eth/api.go
浏览文件 @
5f917715
...
...
@@ -1594,7 +1594,7 @@ type BlockTraceResult struct {
// TraceBlock processes the given block's RLP but does not import the block in to
// the chain.
func
(
api
*
PrivateDebugAPI
)
TraceBlock
(
blockRlp
[]
byte
,
config
vm
.
Config
)
BlockTraceResult
{
func
(
api
*
PrivateDebugAPI
)
TraceBlock
(
blockRlp
[]
byte
,
config
*
vm
.
Config
)
BlockTraceResult
{
var
block
types
.
Block
err
:=
rlp
.
Decode
(
bytes
.
NewReader
(
blockRlp
),
&
block
)
if
err
!=
nil
{
...
...
@@ -1611,7 +1611,7 @@ func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config vm.Config) BlockT
// TraceBlockFromFile loads the block's RLP from the given file name and attempts to
// process it but does not import the block in to the chain.
func
(
api
*
PrivateDebugAPI
)
TraceBlockFromFile
(
file
string
,
config
vm
.
Config
)
BlockTraceResult
{
func
(
api
*
PrivateDebugAPI
)
TraceBlockFromFile
(
file
string
,
config
*
vm
.
Config
)
BlockTraceResult
{
blockRlp
,
err
:=
ioutil
.
ReadFile
(
file
)
if
err
!=
nil
{
return
BlockTraceResult
{
Error
:
fmt
.
Sprintf
(
"could not read file: %v"
,
err
)}
...
...
@@ -1620,7 +1620,7 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config vm.Config) Bl
}
// TraceProcessBlock processes the block by canonical block number.
func
(
api
*
PrivateDebugAPI
)
TraceBlockByNumber
(
number
uint64
,
config
vm
.
Config
)
BlockTraceResult
{
func
(
api
*
PrivateDebugAPI
)
TraceBlockByNumber
(
number
uint64
,
config
*
vm
.
Config
)
BlockTraceResult
{
// Fetch the block that we aim to reprocess
block
:=
api
.
eth
.
BlockChain
()
.
GetBlockByNumber
(
number
)
if
block
==
nil
{
...
...
@@ -1636,7 +1636,7 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config vm.Config)
}
// TraceBlockByHash processes the block by hash.
func
(
api
*
PrivateDebugAPI
)
TraceBlockByHash
(
hash
common
.
Hash
,
config
vm
.
Config
)
BlockTraceResult
{
func
(
api
*
PrivateDebugAPI
)
TraceBlockByHash
(
hash
common
.
Hash
,
config
*
vm
.
Config
)
BlockTraceResult
{
// Fetch the block that we aim to reprocess
block
:=
api
.
eth
.
BlockChain
()
.
GetBlock
(
hash
)
if
block
==
nil
{
...
...
@@ -1664,7 +1664,7 @@ func (t *TraceCollector) AddStructLog(slog vm.StructLog) {
}
// traceBlock processes the given block but does not save the state.
func
(
api
*
PrivateDebugAPI
)
traceBlock
(
block
*
types
.
Block
,
config
vm
.
Config
)
(
bool
,
[]
vm
.
StructLog
,
error
)
{
func
(
api
*
PrivateDebugAPI
)
traceBlock
(
block
*
types
.
Block
,
config
*
vm
.
Config
)
(
bool
,
[]
vm
.
StructLog
,
error
)
{
// Validate and reprocess the block
var
(
blockchain
=
api
.
eth
.
BlockChain
()
...
...
@@ -1672,6 +1672,9 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config vm.Config) (bo
processor
=
blockchain
.
Processor
()
collector
=
&
TraceCollector
{}
)
if
config
==
nil
{
config
=
new
(
vm
.
Config
)
}
config
.
Debug
=
true
// make sure debug is set.
config
.
Logger
.
Collector
=
collector
...
...
@@ -1683,7 +1686,7 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config vm.Config) (bo
return
false
,
collector
.
traces
,
err
}
receipts
,
_
,
usedGas
,
err
:=
processor
.
Process
(
block
,
statedb
,
config
)
receipts
,
_
,
usedGas
,
err
:=
processor
.
Process
(
block
,
statedb
,
*
config
)
if
err
!=
nil
{
return
false
,
collector
.
traces
,
err
}
...
...
@@ -1771,56 +1774,65 @@ func formatError(err error) string {
// TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object.
func
(
s
*
PrivateDebugAPI
)
TraceTransaction
(
txHash
common
.
Hash
,
logger
vm
.
LogConfig
)
(
*
ExecutionResult
,
error
)
{
// Retrieve the tx from the chain
tx
,
_
,
blockIndex
,
_
:=
core
.
GetTransaction
(
s
.
eth
.
ChainDb
(),
txHash
)
func
(
s
*
PrivateDebugAPI
)
TraceTransaction
(
txHash
common
.
Hash
,
logger
*
vm
.
LogConfig
)
(
*
ExecutionResult
,
error
)
{
if
logger
==
nil
{
logger
=
new
(
vm
.
LogConfig
)
}
// Retrieve the tx from the chain and the containing block
tx
,
blockHash
,
_
,
txIndex
:=
core
.
GetTransaction
(
s
.
eth
.
ChainDb
(),
txHash
)
if
tx
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
Transaction not found"
)
return
nil
,
fmt
.
Errorf
(
"
transaction %x not found"
,
txHash
)
}
block
:=
s
.
eth
.
BlockChain
()
.
GetBlockByNumber
(
blockIndex
-
1
)
block
:=
s
.
eth
.
BlockChain
()
.
GetBlock
(
blockHash
)
if
block
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
Unable to retrieve prior block"
)
return
nil
,
fmt
.
Errorf
(
"
block %x not found"
,
blockHash
)
}
// Create the state database
stateDb
,
err
:=
state
.
New
(
block
.
Root
(),
s
.
eth
.
ChainDb
())
if
err
!=
nil
{
return
nil
,
err
// Create the state database to mutate and eventually trace
parent
:=
s
.
eth
.
BlockChain
()
.
GetBlock
(
block
.
ParentHash
())
if
parent
==
nil
{
return
nil
,
fmt
.
Errorf
(
"block parent %x not found"
,
block
.
ParentHash
())
}
txFrom
,
err
:=
tx
.
FromFrontier
()
stateDb
,
err
:=
state
.
New
(
parent
.
Root
(),
s
.
eth
.
ChainDb
())
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Unable to create transaction sender"
)
}
from
:=
stateDb
.
GetOrNewStateObject
(
txFrom
)
msg
:=
callmsg
{
from
:
from
,
to
:
tx
.
To
(),
gas
:
tx
.
Gas
(),
gasPrice
:
tx
.
GasPrice
(),
value
:
tx
.
Value
(),
data
:
tx
.
Data
(),
return
nil
,
err
}
vmenv
:=
core
.
NewEnv
(
stateDb
,
s
.
config
,
s
.
eth
.
BlockChain
(),
msg
,
block
.
Header
(),
vm
.
Config
{
Debug
:
true
,
Logger
:
logger
,
})
gp
:=
new
(
core
.
GasPool
)
.
AddGas
(
block
.
GasLimit
())
ret
,
gas
,
err
:=
core
.
ApplyMessage
(
vmenv
,
msg
,
gp
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error executing transaction %v"
,
err
)
// Mutate the state and trace the selected transaction
for
idx
,
tx
:=
range
block
.
Transactions
()
{
// Assemble the transaction call message
from
,
err
:=
tx
.
FromFrontier
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"sender retrieval failed: %v"
,
err
)
}
msg
:=
callmsg
{
from
:
stateDb
.
GetOrNewStateObject
(
from
),
to
:
tx
.
To
(),
gas
:
tx
.
Gas
(),
gasPrice
:
tx
.
GasPrice
(),
value
:
tx
.
Value
(),
data
:
tx
.
Data
(),
}
// Mutate the state if we haven't reached the tracing transaction yet
if
uint64
(
idx
)
<
txIndex
{
vmenv
:=
core
.
NewEnv
(
stateDb
,
s
.
config
,
s
.
eth
.
BlockChain
(),
msg
,
parent
.
Header
(),
vm
.
Config
{})
_
,
_
,
err
:=
core
.
ApplyMessage
(
vmenv
,
msg
,
new
(
core
.
GasPool
)
.
AddGas
(
tx
.
Gas
()))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"mutation failed: %v"
,
err
)
}
continue
}
// Otherwise trace the transaction and return
vmenv
:=
core
.
NewEnv
(
stateDb
,
s
.
config
,
s
.
eth
.
BlockChain
(),
msg
,
parent
.
Header
(),
vm
.
Config
{
Debug
:
true
,
Logger
:
*
logger
})
ret
,
gas
,
err
:=
core
.
ApplyMessage
(
vmenv
,
msg
,
new
(
core
.
GasPool
)
.
AddGas
(
tx
.
Gas
()))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"tracing failed: %v"
,
err
)
}
return
&
ExecutionResult
{
Gas
:
gas
,
ReturnValue
:
fmt
.
Sprintf
(
"%x"
,
ret
),
StructLogs
:
formatLogs
(
vmenv
.
StructLogs
()),
},
nil
}
return
&
ExecutionResult
{
Gas
:
gas
,
ReturnValue
:
fmt
.
Sprintf
(
"%x"
,
ret
),
StructLogs
:
formatLogs
(
vmenv
.
StructLogs
()),
},
nil
return
nil
,
errors
.
New
(
"database inconsistency"
)
}
func
(
s
*
PublicBlockChainAPI
)
TraceCall
(
args
CallArgs
,
blockNr
rpc
.
BlockNumber
)
(
*
ExecutionResult
,
error
)
{
...
...
rpc/javascript.go
浏览文件 @
5f917715
...
...
@@ -268,22 +268,22 @@ web3._extend({
new web3._extend.Method({
name: 'traceBlock',
call: 'debug_traceBlock',
params:
2
params:
1
}),
new web3._extend.Method({
name: 'traceBlockByFile',
call: 'debug_traceBlockByFile',
params:
2
params:
1
}),
new web3._extend.Method({
name: 'traceBlockByNumber',
call: 'debug_traceBlockByNumber',
params:
2
params:
1
}),
new web3._extend.Method({
name: 'traceBlockByHash',
call: 'debug_traceBlockByHash',
params:
2
params:
1
}),
new web3._extend.Method({
name: 'seedHash',
...
...
@@ -390,7 +390,7 @@ web3._extend({
new web3._extend.Method({
name: 'traceTransaction',
call: 'debug_traceTransaction',
params:
2
params:
1
})
],
properties: []
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录