Skip to content

Commit

Permalink
Fix chaindatafetcher API
Browse files Browse the repository at this point in the history
Fix this error

```
panic: interface conversion: interface {} is json.RawMessage, not *vm.InternalTxTrace

goroutine 936 [running]:
github.com/klaytn/klaytn/datasync/chaindatafetcher.(*ChainDataFetcher).makeChainEvent(0xc08a357900, 0x4c4b401)
        /home/ec2-user/kaia/datasync/chaindatafetcher/chaindata_fetcher.go:323 +0xb30
github.com/klaytn/klaytn/datasync/chaindatafetcher.(*ChainDataFetcher).handleRequest(0xc08a357900)
        /home/ec2-user/kaia/datasync/chaindatafetcher/chaindata_fetcher.go:476 +0x1f4
created by github.com/klaytn/klaytn/datasync/chaindatafetcher.(*ChainDataFetcher).Start in goroutine 1
        /home/ec2-user/kaia/datasync/chaindatafetcher/chaindata_fetcher.go:174 +0x25
```
  • Loading branch information
ian0371 authored and blukat29 committed Jul 3, 2024
1 parent 81c1ac4 commit ee11904
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions blockchain/vm/call_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (f CallFrame) ToInternalTxTrace() *InternalTxTrace {
t.From = &f.From
t.To = f.To
if f.Value != nil {
t.Value = f.Value.Text(16)
t.Value = "0x" + f.Value.Text(16)
}

t.Gas = f.Gas
Expand Down Expand Up @@ -220,7 +220,16 @@ func (t *CallTracer) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost, ccL
func (t *CallTracer) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost, ccLeft, ccOpcode uint64, scope *ScopeContext, depth int, err error) {
}

func (t *CallTracer) GetResult() (json.RawMessage, error) {
func (t *CallTracer) GetResult() ([]CallFrame, error) {
if len(t.callstack) != 1 {
return nil, errors.New("incorrect number of top-level calls")
}

// Return with interrupt reason if any
return t.callstack, t.interruptReason
}

func (t *CallTracer) GetResultAsJson() (json.RawMessage, error) {
if len(t.callstack) != 1 {
return nil, errors.New("incorrect number of top-level calls")
}
Expand Down
6 changes: 5 additions & 1 deletion datasync/chaindatafetcher/chaindata_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ func (f *ChainDataFetcher) makeChainEvent(blockNumber uint64) (blockchain.ChainE
}
for _, r := range results {
if r.Result != nil {
internalTraces = append(internalTraces, r.Result.(*vm.InternalTxTrace))
switch r.Result.(type) {
case []vm.CallFrame:
cf := r.Result.([]vm.CallFrame)
internalTraces = append(internalTraces, cf[0].ToInternalTxTrace())
}
} else {
traceAPIErrorCounter.Inc(1)
logger.Error("the trace result is nil", "err", r.Error, "blockNumber", blockNumber)
Expand Down
2 changes: 1 addition & 1 deletion node/cn/tracers/tracers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func runTracer(t *testing.T, tc *tracerTestdata, tracer vm.Tracer) (*types.Trans
case *Tracer:
tracerResult, err = tracer.GetResult()
case *vm.CallTracer:
tracerResult, err = tracer.GetResult()
tracerResult, err = tracer.GetResultAsJson()
}
require.NoError(t, err)
assert.JSONEq(t, string(tc.Result), string(tracerResult))
Expand Down

0 comments on commit ee11904

Please sign in to comment.