good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
d20238c2
Commit
d20238c2
authored
Aug 24, 2016
by
Nick Johnson
Browse files
Options
Downloads
Patches
Plain Diff
internal/ethapi: Improve tracer error reporting and serialization
parent
4ce83bf5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/ethapi/tracer.go
+24
-9
24 additions, 9 deletions
internal/ethapi/tracer.go
internal/ethapi/tracer_test.go
+2
-2
2 additions, 2 deletions
internal/ethapi/tracer_test.go
with
26 additions
and
11 deletions
internal/ethapi/tracer.go
+
24
−
9
View file @
d20238c2
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
ethapi
package
ethapi
import
(
import
(
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -55,6 +56,11 @@ func (ocw *opCodeWrapper) isPush() bool {
...
@@ -55,6 +56,11 @@ func (ocw *opCodeWrapper) isPush() bool {
return
ocw
.
op
.
IsPush
()
return
ocw
.
op
.
IsPush
()
}
}
// MarshalJSON serializes the opcode as JSON
func
(
ocw
*
opCodeWrapper
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
ocw
.
op
.
String
())
}
// toValue returns an otto.Value for the opCodeWrapper
// toValue returns an otto.Value for the opCodeWrapper
func
(
ocw
*
opCodeWrapper
)
toValue
(
vm
*
otto
.
Otto
)
otto
.
Value
{
func
(
ocw
*
opCodeWrapper
)
toValue
(
vm
*
otto
.
Otto
)
otto
.
Value
{
value
,
_
:=
vm
.
ToValue
(
ocw
)
value
,
_
:=
vm
.
ToValue
(
ocw
)
...
@@ -165,8 +171,6 @@ type JavascriptTracer struct {
...
@@ -165,8 +171,6 @@ type JavascriptTracer struct {
traceobj
*
otto
.
Object
// User-supplied object to call
traceobj
*
otto
.
Object
// User-supplied object to call
log
map
[
string
]
interface
{}
// (Reusable) map for the `log` arg to `step`
log
map
[
string
]
interface
{}
// (Reusable) map for the `log` arg to `step`
logvalue
otto
.
Value
// JS view of `log`
logvalue
otto
.
Value
// JS view of `log`
opcode
*
opCodeWrapper
// Wrapper around the opcode
opcodevalue
otto
.
Value
// JS view of 'opcode'
memory
*
memoryWrapper
// Wrapper around the VM memory
memory
*
memoryWrapper
// Wrapper around the VM memory
memvalue
otto
.
Value
// JS view of `memory`
memvalue
otto
.
Value
// JS view of `memory`
stack
*
stackWrapper
// Wrapper around the VM stack
stack
*
stackWrapper
// Wrapper around the VM stack
...
@@ -213,7 +217,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
...
@@ -213,7 +217,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
logvalue
,
_
:=
vm
.
ToValue
(
log
)
logvalue
,
_
:=
vm
.
ToValue
(
log
)
// Create persistent wrappers for memory and stack
// Create persistent wrappers for memory and stack
opcode
:=
&
opCodeWrapper
{}
mem
:=
&
memoryWrapper
{}
mem
:=
&
memoryWrapper
{}
stack
:=
&
stackWrapper
{}
stack
:=
&
stackWrapper
{}
db
:=
&
dbWrapper
{}
db
:=
&
dbWrapper
{}
...
@@ -223,8 +226,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
...
@@ -223,8 +226,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
traceobj
:
jstracer
,
traceobj
:
jstracer
,
log
:
log
,
log
:
log
,
logvalue
:
logvalue
,
logvalue
:
logvalue
,
opcode
:
opcode
,
opcodevalue
:
opcode
.
toValue
(
vm
),
memory
:
mem
,
memory
:
mem
,
memvalue
:
mem
.
toValue
(
vm
),
memvalue
:
mem
.
toValue
(
vm
),
stack
:
stack
,
stack
:
stack
,
...
@@ -265,16 +266,26 @@ func (jst *JavascriptTracer) callSafely(method string, argumentList ...interface
...
@@ -265,16 +266,26 @@ func (jst *JavascriptTracer) callSafely(method string, argumentList ...interface
return
ret
,
err
return
ret
,
err
}
}
func
wrapError
(
context
string
,
err
error
)
error
{
var
message
string
switch
err
:=
err
.
(
type
)
{
case
*
otto
.
Error
:
message
=
err
.
String
()
default
:
message
=
err
.
Error
()
}
return
fmt
.
Errorf
(
"%v in server-side tracer function '%v'"
,
message
,
context
)
}
// CaptureState implements the Tracer interface to trace a single step of VM execution
// CaptureState implements the Tracer interface to trace a single step of VM execution
func
(
jst
*
JavascriptTracer
)
CaptureState
(
env
vm
.
Environment
,
pc
uint64
,
op
vm
.
OpCode
,
gas
,
cost
*
big
.
Int
,
memory
*
vm
.
Memory
,
stack
*
vm
.
Stack
,
contract
*
vm
.
Contract
,
depth
int
,
err
error
)
{
func
(
jst
*
JavascriptTracer
)
CaptureState
(
env
vm
.
Environment
,
pc
uint64
,
op
vm
.
OpCode
,
gas
,
cost
*
big
.
Int
,
memory
*
vm
.
Memory
,
stack
*
vm
.
Stack
,
contract
*
vm
.
Contract
,
depth
int
,
err
error
)
{
if
jst
.
err
==
nil
{
if
jst
.
err
==
nil
{
jst
.
opcode
.
op
=
op
jst
.
memory
.
memory
=
memory
jst
.
memory
.
memory
=
memory
jst
.
stack
.
stack
=
stack
jst
.
stack
.
stack
=
stack
jst
.
db
.
db
=
env
.
Db
()
jst
.
db
.
db
=
env
.
Db
()
jst
.
log
[
"pc"
]
=
pc
jst
.
log
[
"pc"
]
=
pc
jst
.
log
[
"op"
]
=
jst
.
op
c
ode
value
jst
.
log
[
"op"
]
=
&
op
C
ode
Wrapper
{
op
}
jst
.
log
[
"gas"
]
=
gas
.
Int64
()
jst
.
log
[
"gas"
]
=
gas
.
Int64
()
jst
.
log
[
"gasPrice"
]
=
cost
.
Int64
()
jst
.
log
[
"gasPrice"
]
=
cost
.
Int64
()
jst
.
log
[
"memory"
]
=
jst
.
memvalue
jst
.
log
[
"memory"
]
=
jst
.
memvalue
...
@@ -285,7 +296,7 @@ func (jst *JavascriptTracer) CaptureState(env vm.Environment, pc uint64, op vm.O
...
@@ -285,7 +296,7 @@ func (jst *JavascriptTracer) CaptureState(env vm.Environment, pc uint64, op vm.O
_
,
err
:=
jst
.
callSafely
(
"step"
,
jst
.
logvalue
,
jst
.
dbvalue
)
_
,
err
:=
jst
.
callSafely
(
"step"
,
jst
.
logvalue
,
jst
.
dbvalue
)
if
err
!=
nil
{
if
err
!=
nil
{
jst
.
err
=
err
jst
.
err
=
wrapError
(
"step"
,
err
)
}
}
}
}
}
}
...
@@ -296,5 +307,9 @@ func (jst *JavascriptTracer) GetResult() (result interface{}, err error) {
...
@@ -296,5 +307,9 @@ func (jst *JavascriptTracer) GetResult() (result interface{}, err error) {
return
nil
,
jst
.
err
return
nil
,
jst
.
err
}
}
return
jst
.
callSafely
(
"result"
)
result
,
err
=
jst
.
callSafely
(
"result"
)
if
err
!=
nil
{
err
=
wrapError
(
"result"
,
err
)
}
return
}
}
This diff is collapsed.
Click to expand it.
internal/ethapi/tracer_test.go
+
2
−
2
View file @
d20238c2
...
@@ -161,7 +161,7 @@ func TestHalt(t *testing.T) {
...
@@ -161,7 +161,7 @@ func TestHalt(t *testing.T) {
tracer
.
Stop
(
timeout
)
tracer
.
Stop
(
timeout
)
}()
}()
if
_
,
err
=
runTrace
(
tracer
);
err
!=
timeout
{
if
_
,
err
=
runTrace
(
tracer
);
err
.
Error
()
!=
"stahp in server-side tracer function 'step'"
{
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
}
}
}
}
...
@@ -180,7 +180,7 @@ func TestHaltBetweenSteps(t *testing.T) {
...
@@ -180,7 +180,7 @@ func TestHaltBetweenSteps(t *testing.T) {
tracer
.
Stop
(
timeout
)
tracer
.
Stop
(
timeout
)
tracer
.
CaptureState
(
env
,
0
,
0
,
big
.
NewInt
(
0
),
big
.
NewInt
(
0
),
nil
,
nil
,
contract
,
0
,
nil
)
tracer
.
CaptureState
(
env
,
0
,
0
,
big
.
NewInt
(
0
),
big
.
NewInt
(
0
),
nil
,
nil
,
contract
,
0
,
nil
)
if
_
,
err
:=
tracer
.
GetResult
();
err
!=
timeout
{
if
_
,
err
:=
tracer
.
GetResult
();
err
.
Error
()
!=
"stahp in server-side tracer function 'step'"
{
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment