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

[Flow EVM] Run tracing hooks OnTxStart, OnTxEnd for DryRunTransaction #6491

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions fvm/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func (bl *BlockView) DryRunTransaction(
// we need to skip nonce check for dry run
msg.SkipAccountChecks = true

// call tracer
if proc.evm.Config.Tracer != nil && proc.evm.Config.Tracer.OnTxStart != nil {
proc.evm.Config.Tracer.OnTxStart(proc.evm.GetVMContext(), tx, msg.From)
}

// return without committing the state
txResult, err = proc.run(msg, tx.Hash(), tx.Type())
if txResult.Successful() {
Expand All @@ -306,6 +311,13 @@ func (bl *BlockView) DryRunTransaction(
txResult.GasConsumed += txResult.GasRefund
}

// call tracer on tx end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this should be before or after adjusting the txResult.GasConsumed with the various buffers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's correct the way it is now

if proc.evm.Config.Tracer != nil &&
proc.evm.Config.Tracer.OnTxEnd != nil &&
txResult != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txResult != nil this should always be true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that proc.run can return nil for txResult in some cases:

if err != nil {
	return nil, err
}

Besides, this is the exact same condition for both RunTransaction & BatchRunTransaction, so I wanted to be on the safe side.

proc.evm.Config.Tracer.OnTxEnd(txResult.Receipt(), txResult.ValidationError)
}

return txResult, err
}

Expand Down
Loading