Skip to content

Commit

Permalink
remove some expensive tracing only used on panic
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Dec 2, 2024
1 parent b5884d8 commit 02d9c24
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 55 deletions.
12 changes: 3 additions & 9 deletions pipeline/exec/baseexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ type BaseExecutor struct {
cachedInstance wasm.Instance

// Results
logs []string
logsTruncated bool
executionStack []string
logs []string
logsTruncated bool
}

func NewBaseExecutor(ctx context.Context, moduleName string, initialBlock uint64, wasmModule wasm.Module, cacheEnabled bool, wasmArguments []wasm.Argument, blockIndex *index.BlockIndex, entrypoint string, tracer ttrace.Tracer) *BaseExecutor {
Expand Down Expand Up @@ -104,7 +103,6 @@ func canSkipExecution(wasmArgumentValues map[string][]byte, hasSingleParams bool
func (e *BaseExecutor) wasmCall(outputGetter execout.ExecutionOutputGetter) (call *wasm.Call, err error) {
e.logs = nil
e.logsTruncated = false
e.executionStack = nil

argValues, hasSingleParams, err := getWasmArgumentValues(e.wasmArguments, outputGetter)
if err != nil {
Expand All @@ -126,7 +124,7 @@ func (e *BaseExecutor) wasmCall(outputGetter execout.ExecutionOutputGetter) (cal
if panicErr := call.Err(); panicErr != nil {
errExecutor := &ErrorExecutor{
message: panicErr.Error(),
stackTrace: call.ExecutionStack,
stackTrace: call.Logs,
}
return nil, fmt.Errorf("block %d: module %q: general wasm execution panicked: %w: %s", clock.Number, e.moduleName, ErrWasmDeterministicExec, errExecutor.Error())
}
Expand All @@ -148,7 +146,6 @@ func (e *BaseExecutor) wasmCall(outputGetter execout.ExecutionOutputGetter) (cal
}
e.logs = call.Logs
e.logsTruncated = call.ReachedLogsMaxByteCount()
e.executionStack = call.ExecutionStack
return
}

Expand All @@ -170,6 +167,3 @@ func (e *BaseExecutor) Close(ctx context.Context) error {
func (e *BaseExecutor) lastExecutionLogs() (logs []string, truncated bool) {
return e.logs, e.logsTruncated
}
func (e *BaseExecutor) lastExecutionStack() []string {
return e.executionStack
}
1 change: 0 additions & 1 deletion pipeline/exec/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ type ModuleExecutor interface {
RunsOnBlock(blockNum uint64) bool

lastExecutionLogs() (logs []string, truncated bool)
lastExecutionStack() []string
}
7 changes: 0 additions & 7 deletions pipeline/exec/module_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ func (t *MockModuleExecutor) lastExecutionLogs() (logs []string, truncated bool)
return nil, false
}

func (t *MockModuleExecutor) lastExecutionStack() []string {
if t.StackFunc != nil {
return t.StackFunc()
}
return nil
}

func TestModuleExecutorRunner_Run_HappyPath(t *testing.T) {
ctx := context.Background()

Expand Down
38 changes: 0 additions & 38 deletions wasm/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package wasm
import (
"fmt"
"math/big"
"os"
"time"

"github.com/dustin/go-humanize"
Expand All @@ -14,9 +13,6 @@ import (
"github.com/streamingfast/substreams/storage/store"
)

var TraceReads = os.Getenv("SUBSTREAMS_TRACE_READS") != "false"
var TraceWrites = os.Getenv("SUBSTREAMS_TRACE_WRITES") != "false"

type Call struct {
Clock *pbsubstreams.Clock // Used by WASM extensions
ModuleName string
Expand Down Expand Up @@ -100,7 +96,6 @@ func (c *Call) AppendLog(message string) {
c.LogsByteCount += uint64(len(message))
if !c.ReachedLogsMaxByteCount() {
c.Logs = append(c.Logs, message)
c.ExecutionStack = append(c.ExecutionStack, fmt.Sprintf("log: %s", message))
}
}

Expand Down Expand Up @@ -134,7 +129,6 @@ func (c *Call) DoAppend(ord uint64, key string, value []byte) {
}
func (c *Call) DoDeletePrefix(ord uint64, prefix string) {
now := time.Now()
c.traceStateWrites("delete_prefix", prefix)
c.outputStore.DeletePrefix(ord, prefix)
c.stats.RecordModuleWasmStoreDeletePrefix(c.ModuleName, c.outputStore.SizeBytes(), time.Since(now))
}
Expand Down Expand Up @@ -261,7 +255,6 @@ func (c *Call) DoGetAt(storeIndex int, ord uint64, key string) (value []byte, fo
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "get_at")
readStore := c.inputStores[storeIndex]
c.traceStateReads("get_at", storeIndex, found, key)
return readStore.GetAt(ord, key)
}

Expand All @@ -270,7 +263,6 @@ func (c *Call) DoHasAt(storeIndex int, ord uint64, key string) (found bool) {
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "has_at")
readStore := c.inputStores[storeIndex]
c.traceStateReads("has_at", storeIndex, found, key)
return readStore.HasAt(ord, key)
}

Expand All @@ -279,7 +271,6 @@ func (c *Call) DoGetFirst(storeIndex int, key string) (value []byte, found bool)
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "get_first")
readStore := c.inputStores[storeIndex]
c.traceStateReads("get_first", storeIndex, found, key)
return readStore.GetFirst(key)
}

Expand All @@ -288,7 +279,6 @@ func (c *Call) DoHasFirst(storeIndex int, key string) (found bool) {
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "has_first")
readStore := c.inputStores[storeIndex]
c.traceStateReads("has_first", storeIndex, found, key)
return readStore.HasFirst(key)
}

Expand All @@ -297,7 +287,6 @@ func (c *Call) DoGetLast(storeIndex int, key string) (value []byte, found bool)
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "get_last")
readStore := c.inputStores[storeIndex]
c.traceStateReads("get_last", storeIndex, found, key)
return readStore.GetLast(key)
}

Expand All @@ -306,7 +295,6 @@ func (c *Call) DoHasLast(storeIndex int, key string) (found bool) {
defer func() { c.stats.RecordModuleWasmStoreRead(c.ModuleName, time.Since(now)) }()
c.validateStoreIndex(storeIndex, "has_last")
readStore := c.inputStores[storeIndex]
c.traceStateReads("has_last", storeIndex, found, key)
return readStore.HasLast(key)
}

Expand All @@ -320,44 +308,18 @@ func (c *Call) validateSimple(stateFunc string, updatePolicy pbsubstreams.Module
if c.updatePolicy != updatePolicy {
c.returnInvalidPolicy(stateFunc, fmt.Sprintf(`updatePolicy == %q`, policyMap[updatePolicy]))
}
c.traceStateWrites(stateFunc, key)
}

func (c *Call) validateWithValueType(stateFunc string, updatePolicy pbsubstreams.Module_KindStore_UpdatePolicy, valueType string, key string) {
if c.updatePolicy != updatePolicy || c.valueType != valueType {
c.returnInvalidPolicy(stateFunc, fmt.Sprintf(`updatePolicy == %q and valueType == %q`, policyMap[updatePolicy], valueType))
}
c.traceStateWrites(stateFunc, key)
}

func (c *Call) validateWithTwoValueTypes(stateFunc string, updatePolicy pbsubstreams.Module_KindStore_UpdatePolicy, valueType1, valueType2 string, key string) {
if c.updatePolicy != updatePolicy || (c.valueType != valueType1 && c.valueType != valueType2) {
c.returnInvalidPolicy(stateFunc, fmt.Sprintf(`updatePolicy == %q and valueType == %q`, policyMap[updatePolicy], valueType1))
}
c.traceStateWrites(stateFunc, key)
}

func (c *Call) traceStateWrites(stateFunc, key string) {
if !TraceWrites {
return
}
store := c.outputStore
var line string
if store == nil {
line = fmt.Sprintf("%s key: %q", stateFunc, key)
} else {
line = fmt.Sprintf("%s::%s key: %q, store details: %s", store.Name(), stateFunc, key, store.String())
}
c.ExecutionStack = append(c.ExecutionStack, line)
}

func (c *Call) traceStateReads(stateFunc string, storeIndex int, found bool, key string) {
if !TraceReads {
return
}
store := c.inputStores[storeIndex]
line := fmt.Sprintf("%s::%s key: %q, found: %v, store details: %s", store.Name(), stateFunc, key, found, store.String())
c.ExecutionStack = append(c.ExecutionStack, line)
}

func (c *Call) returnInvalidPolicy(stateFunc, policy string) {
Expand Down

0 comments on commit 02d9c24

Please sign in to comment.