Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to disable structLogs for debug_trace* rpc methods. #1931

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions jsonrpc/debug_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ func NewDebug(store debugStore, requestsPerSecond uint64) *Debug {
}

type TraceConfig struct {
EnableMemory bool `json:"enableMemory"`
DisableStack bool `json:"disableStack"`
DisableStorage bool `json:"disableStorage"`
EnableReturnData bool `json:"enableReturnData"`
Timeout *string `json:"timeout"`
EnableMemory bool `json:"enableMemory"`
DisableStack bool `json:"disableStack"`
DisableStorage bool `json:"disableStorage"`
EnableReturnData bool `json:"enableReturnData"`
DisableStructLogs bool `json:"disableStructLogs"`
Timeout *string `json:"timeout"`
}

func (d *Debug) TraceBlockByNumber(
Expand Down Expand Up @@ -248,10 +249,11 @@ func newTracer(config *TraceConfig) (
}

tracer := structtracer.NewStructTracer(structtracer.Config{
EnableMemory: config.EnableMemory,
EnableStack: !config.DisableStack,
EnableStorage: !config.DisableStorage,
EnableMemory: config.EnableMemory && !config.DisableStructLogs,
EnableStack: !config.DisableStack && !config.DisableStructLogs,
EnableStorage: !config.DisableStorage && !config.DisableStructLogs,
EnableReturnData: config.EnableReturnData,
EnableStructLogs: !config.DisableStructLogs,
})

timeoutCtx, cancel := context.WithTimeout(context.Background(), timeout)
Expand Down
48 changes: 47 additions & 1 deletion jsonrpc/debug_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/state/runtime/tracer"
"github.com/0xPolygon/polygon-edge/state/runtime/tracer/structtracer"
"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/assert"
)

type debugEndpointMockStore struct {
Expand Down Expand Up @@ -154,6 +157,20 @@ func TestDebugTraceConfigDecode(t *testing.T) {
Timeout: &timeout15s,
},
},
{
input: `{
"disableStack": true,
"disableStorage": true,
"enableReturnData": true,
"disableStructLogs": true
}`,
expected: TraceConfig{
DisableStack: true,
DisableStorage: true,
EnableReturnData: true,
DisableStructLogs: true,
},
},
}

for _, test := range tests {
Expand Down Expand Up @@ -787,4 +804,33 @@ func Test_newTracer(t *testing.T) {
assert.NotNil(t, res)
assert.NoError(t, err)
})

t.Run("should disable everything if struct logs are disabled", func(t *testing.T) {
t.Parallel()

tracer, cancel, err := newTracer(&TraceConfig{
EnableMemory: true,
EnableReturnData: true,
DisableStack: false,
DisableStorage: false,
DisableStructLogs: true,
})

t.Cleanup(func() {
cancel()
})

assert.NoError(t, err)

st, ok := tracer.(*structtracer.StructTracer)
require.True(t, ok)

assert.Equal(t, structtracer.Config{
EnableMemory: false,
EnableStack: false,
EnableStorage: false,
EnableReturnData: true,
EnableStructLogs: false,
}, st.Config)
})
}
35 changes: 19 additions & 16 deletions state/runtime/tracer/structtracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Config struct {
EnableStack bool // enable stack capture
EnableStorage bool // enable storage capture
EnableReturnData bool // enable return data capture
EnableStructLogs bool // enable struct logs capture
}

type StructLog struct {
Expand Down Expand Up @@ -302,22 +303,24 @@ func (t *StructTracer) ExecuteState(
errStr = err.Error()
}

t.logs = append(
t.logs,
StructLog{
Pc: ip,
Op: opCode,
Gas: availableGas,
GasCost: cost,
Memory: memory,
Stack: stack,
ReturnData: returnData,
Storage: storage,
Depth: depth,
RefundCounter: host.GetRefund(),
Error: errStr,
},
)
if t.Config.EnableStructLogs {
t.logs = append(
t.logs,
StructLog{
Pc: ip,
Op: opCode,
Gas: availableGas,
GasCost: cost,
Memory: memory,
Stack: stack,
ReturnData: returnData,
Storage: storage,
Depth: depth,
RefundCounter: host.GetRefund(),
Error: errStr,
},
)
}
}

type StructTraceResult struct {
Expand Down
Loading
Loading