diff --git a/fvm/evm/debug/tracer.go b/fvm/evm/debug/tracer.go index 0a047aed3df..52b4a7e5236 100644 --- a/fvm/evm/debug/tracer.go +++ b/fvm/evm/debug/tracer.go @@ -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) @@ -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") }() diff --git a/fvm/evm/emulator/emulator_test.go b/fvm/evm/emulator/emulator_test.go index 4e268a28902..a89ca945c1a 100644 --- a/fvm/evm/emulator/emulator_test.go +++ b/fvm/evm/emulator/emulator_test.go @@ -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) { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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