Skip to content

Commit

Permalink
Merge pull request onflow#6475 from onflow/ramtin/port-6467
Browse files Browse the repository at this point in the history
[EVM] port onflow#6467 - patch evm tracer
  • Loading branch information
ramtinms authored Sep 18, 2024
2 parents 11654a9 + f581a20 commit ae4ce43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
27 changes: 14 additions & 13 deletions fvm/evm/debug/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ func (t *CallTracer) GetResultByTxHash(txID gethCommon.Hash) json.RawMessage {
}

func (t *CallTracer) Collect(txID gethCommon.Hash) {
l := t.logger.With().
Str("tx-id", txID.String()).
Str("block-id", t.blockID.String()).
Logger()

// collect the trace result
res, found := t.resultsByTxID[txID]
if !found {
l.Error().Msg("trace result not found")
return
}
// remove the result
delete(t.resultsByTxID, txID)

// upload is concurrent and it doesn't produce any errors, as the
// client doesn't expect it, we don't want to break execution flow,
// in case there are errors we retry, and if we fail after retries
// we log them and continue.
go func() {
l := t.logger.With().
Str("tx-id", txID.String()).
Str("block-id", t.blockID.String()).
Logger()

defer func() {
if r := recover(); r != nil {
err, ok := r.(error)
Expand All @@ -98,20 +107,12 @@ func (t *CallTracer) Collect(txID gethCommon.Hash) {
Msg("failed to collect EVM traces")
}
}()

res, found := t.resultsByTxID[txID]
if !found {
l.Error().Msg("trace result not found")
return
}
if err := t.uploader.Upload(TraceID(txID, t.blockID), res); err != nil {
l.Error().Err(err).
Str("traces", string(res)).
Msg("failed to upload trace results, no more retries")
return
}
// remove the result
delete(t.resultsByTxID, txID)
l.Debug().Msg("evm traces uploaded successfully")
}()

Expand Down
17 changes: 9 additions & 8 deletions fvm/evm/emulator/emulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,8 @@ func TestCallingExtraPrecompiles(t *testing.T) {
AddressFunc: func() types.Address {
return addr
},
RequiredGasFunc: func(input []byte) uint64 {
RequiredGasFunc: func(inp []byte) uint64 {
require.Equal(t, input, inp)
return uint64(10)
},
RunFunc: func(inp []byte) ([]byte, error) {
Expand Down Expand Up @@ -1224,9 +1225,9 @@ func TestTransactionTracing(t *testing.T) {
require.NoError(t, res.ValidationError)
require.NoError(t, res.VMError)
txID = res.TxHash
tracer.Collect(txID)
trace = tracer.GetResultByTxHash(txID)
require.NotEmpty(t, trace)
tracer.Collect(txID)

testAccount.SetNonce(testAccount.Nonce() + 1)
require.Eventuallyf(t, func() bool {
Expand Down Expand Up @@ -1267,10 +1268,10 @@ func TestTransactionTracing(t *testing.T) {
)
requireSuccessfulExecution(t, err, res)
txID = res.TxHash
tracer.WithBlockID(blockID)
tracer.Collect(txID)
trace = tracer.GetResultByTxHash(txID)
require.NotEmpty(t, trace)
tracer.WithBlockID(blockID)
tracer.Collect(txID)

testAccount.SetNonce(testAccount.Nonce() + 1)
require.Eventuallyf(t, func() bool {
Expand Down Expand Up @@ -1311,10 +1312,10 @@ func TestTransactionTracing(t *testing.T) {
res, err := blk.RunTransaction(tx)
requireSuccessfulExecution(t, err, res)
txID = res.TxHash
tracer.WithBlockID(blockID)
tracer.Collect(txID)
trace = tracer.GetResultByTxHash(txID)
require.NotEmpty(t, trace)
tracer.WithBlockID(blockID)
tracer.Collect(txID)

testAccount.SetNonce(testAccount.Nonce() + 1)
require.Eventuallyf(t, func() bool {
Expand Down Expand Up @@ -1390,9 +1391,9 @@ func TestTransactionTracing(t *testing.T) {
requireSuccessfulExecution(t, err, res)
txID = res.TxHash
tracer.WithBlockID(blockID)
tracer.Collect(txID)
trace = tracer.GetResultByTxHash(txID)
require.NotEmpty(t, trace)
tracer.Collect(txID)

testAccount.SetNonce(testAccount.Nonce() + 1)
require.Eventuallyf(t, func() bool {
Expand Down Expand Up @@ -1482,9 +1483,9 @@ func TestTransactionTracing(t *testing.T) {
require.NoError(t, err)
require.Len(t, results, 1)
txID = results[0].TxHash
trace = tracer.GetResultByTxHash(txID)
tracer.WithBlockID(blockID)
tracer.Collect(txID)
trace = tracer.GetResultByTxHash(txID)

require.Eventuallyf(t, func() bool {
<-uploaded
Expand Down

0 comments on commit ae4ce43

Please sign in to comment.