Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
14df2d59
Commit
14df2d59
authored
Jan 19, 2022
by
Mark Tyneway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
l2geth: add markdown logger
parent
6d376644
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
logger.go
l2geth/core/vm/logger.go
+75
-0
No files found.
l2geth/core/vm/logger.go
View file @
14df2d59
...
@@ -21,12 +21,14 @@ import (
...
@@ -21,12 +21,14 @@ import (
"fmt"
"fmt"
"io"
"io"
"math/big"
"math/big"
"strings"
"time"
"time"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum-optimism/optimism/l2geth/common/hexutil"
"github.com/ethereum-optimism/optimism/l2geth/common/hexutil"
"github.com/ethereum-optimism/optimism/l2geth/common/math"
"github.com/ethereum-optimism/optimism/l2geth/common/math"
"github.com/ethereum-optimism/optimism/l2geth/core/types"
"github.com/ethereum-optimism/optimism/l2geth/core/types"
"github.com/ethereum-optimism/optimism/l2geth/params"
)
)
// Storage represents a contract's storage.
// Storage represents a contract's storage.
...
@@ -49,6 +51,8 @@ type LogConfig struct {
...
@@ -49,6 +51,8 @@ type LogConfig struct {
DisableStorage
bool
// disable storage capture
DisableStorage
bool
// disable storage capture
Debug
bool
// print output during capture end
Debug
bool
// print output during capture end
Limit
int
// maximum length of output, but zero means unlimited
Limit
int
// maximum length of output, but zero means unlimited
// Chain overrides, can be used to execute a trace using future fork rules
Overrides
*
params
.
ChainConfig
`json:"overrides,omitempty"`
}
}
//go:generate gencodec -type StructLog -field-override structLogMarshaling -out gen_structlog.go
//go:generate gencodec -type StructLog -field-override structLogMarshaling -out gen_structlog.go
...
@@ -254,3 +258,74 @@ func WriteLogs(writer io.Writer, logs []*types.Log) {
...
@@ -254,3 +258,74 @@ func WriteLogs(writer io.Writer, logs []*types.Log) {
fmt
.
Fprintln
(
writer
)
fmt
.
Fprintln
(
writer
)
}
}
}
}
type
mdLogger
struct
{
out
io
.
Writer
cfg
*
LogConfig
}
// NewMarkdownLogger creates a logger which outputs information in a format adapted
// for human readability, and is also a valid markdown table
func
NewMarkdownLogger
(
cfg
*
LogConfig
,
writer
io
.
Writer
)
*
mdLogger
{
l
:=
&
mdLogger
{
writer
,
cfg
}
if
l
.
cfg
==
nil
{
l
.
cfg
=
&
LogConfig
{}
}
return
l
}
func
(
t
*
mdLogger
)
CaptureStart
(
from
common
.
Address
,
to
common
.
Address
,
create
bool
,
input
[]
byte
,
gas
uint64
,
value
*
big
.
Int
)
error
{
if
!
create
{
fmt
.
Fprintf
(
t
.
out
,
"From: `%v`
\n
To: `%v`
\n
Data: `0x%x`
\n
Gas: `%d`
\n
Value `%v` wei
\n
"
,
from
.
String
(),
to
.
String
(),
input
,
gas
,
value
)
}
else
{
fmt
.
Fprintf
(
t
.
out
,
"From: `%v`
\n
Create at: `%v`
\n
Data: `0x%x`
\n
Gas: `%d`
\n
Value `%v` wei
\n
"
,
from
.
String
(),
to
.
String
(),
input
,
gas
,
value
)
}
fmt
.
Fprintf
(
t
.
out
,
`
| Pc | Op | Cost | Stack | RStack | Refund |
|-------|-------------|------|-----------|-----------|---------|
`
)
return
nil
}
func
(
t
*
mdLogger
)
CaptureState
(
env
*
EVM
,
pc
uint64
,
op
OpCode
,
gas
,
cost
uint64
,
memory
*
Memory
,
stack
*
Stack
,
contract
*
Contract
,
depth
int
,
err
error
)
error
{
fmt
.
Fprintf
(
t
.
out
,
"| %4d | %10v | %3d |"
,
pc
,
op
,
cost
)
if
!
t
.
cfg
.
DisableStack
{
// format stack
var
a
[]
string
for
_
,
elem
:=
range
stack
.
data
{
a
=
append
(
a
,
fmt
.
Sprintf
(
"%v"
,
elem
.
String
()))
}
b
:=
fmt
.
Sprintf
(
"[%v]"
,
strings
.
Join
(
a
,
","
))
fmt
.
Fprintf
(
t
.
out
,
"%10v |"
,
b
)
// format return stack
a
=
a
[
:
0
]
b
=
fmt
.
Sprintf
(
"[%v]"
,
strings
.
Join
(
a
,
","
))
fmt
.
Fprintf
(
t
.
out
,
"%10v |"
,
b
)
}
fmt
.
Fprintf
(
t
.
out
,
"%10v |"
,
env
.
StateDB
.
GetRefund
())
fmt
.
Fprintln
(
t
.
out
,
""
)
if
err
!=
nil
{
fmt
.
Fprintf
(
t
.
out
,
"Error: %v
\n
"
,
err
)
}
return
nil
}
func
(
t
*
mdLogger
)
CaptureFault
(
env
*
EVM
,
pc
uint64
,
op
OpCode
,
gas
,
cost
uint64
,
memory
*
Memory
,
stack
*
Stack
,
contract
*
Contract
,
depth
int
,
err
error
)
error
{
fmt
.
Fprintf
(
t
.
out
,
"
\n
Error: at pc=%d, op=%v: %v
\n
"
,
pc
,
op
,
err
)
return
nil
}
func
(
t
*
mdLogger
)
CaptureEnd
(
output
[]
byte
,
gasUsed
uint64
,
tm
time
.
Duration
,
err
error
)
error
{
fmt
.
Fprintf
(
t
.
out
,
"
\n
Output: `0x%x`
\n
Consumed gas: `%d`
\n
Error: `%v`
\n
"
,
output
,
gasUsed
,
err
)
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment