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

eth/tracers: add txHash field on txTraceResult #27183

Merged
merged 5 commits into from
May 5, 2023

Conversation

sjlee1125
Copy link
Contributor

This PR modifies the interface for the results of debug_traceBlock and debug_traceCall by adding the txHash, allowing users to identify which transaction's trace result corresponds to. This was previously discussed in issue #20629, but there has been no further discussion since then.

@sjlee1125 sjlee1125 requested a review from s1na as a code owner April 28, 2023 09:10
@holiman
Copy link
Contributor

holiman commented Apr 28, 2023

What @s1na wrote on that ticket was

result() has access to the transaction hash (ctx.txHash) now. I'm guessing that should be enough for the use-case.

Meaning, without putting the hash on the outer result-container, the inner tracer has access to the hash and can put it on the result, if desired. Is that not sufficient?

@@ -200,6 +200,7 @@ type StdTraceConfig struct {

// txTraceResult is the result of a single transaction trace.
type txTraceResult struct {
TxHash common.Hash `json:"txHash,omitempty"` // transaction hash
Copy link
Contributor

Choose a reason for hiding this comment

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

Does omitEmpty work as intended on the empty-hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I realized that common.Hash is of type [32]byte, so it cannot have an empty value in a byte array. I will modify that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed it!

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

In general, LGTM (if we want this feature)

@sjlee1125
Copy link
Contributor Author

What @s1na wrote on that ticket was

result() has access to the transaction hash (ctx.txHash) now. I'm guessing that should be enough for the use-case.

Meaning, without putting the hash on the outer result-container, the inner tracer has access to the hash and can put it on the result, if desired. Is that not sufficient?

How can the hash be inserted into the inner trace? It doesn't seem possible to retrieve the txHash when making a debug_traceBlock RPC call.

@holiman
Copy link
Contributor

holiman commented May 2, 2023

How can the hash be inserted into the inner trace?

So then it would be up to the tracer that is used -- and NewStructLogger is the default:

	// Default tracer is the struct logger
	tracer = logger.NewStructLogger(config.Config)
	if config.Tracer != nil {
		tracer, err = DefaultDirectory.New(*config.Tracer, txctx, config.TracerConfig)
		if err != nil {
			return nil, err
		}
	}

However, the TxHash is available through the txctx, which is passed to the non-default tracer constructor. It is not passed to the NewStructLogger constructor. If it were, it would have been possible for the structlogger to include it into the ExecutionResult:

type ExecutionResult struct {
	Gas         uint64         `json:"gas"`
	Failed      bool           `json:"failed"`
	ReturnValue string         `json:"returnValue"`
	StructLogs  []StructLogRes `json:"structLogs"`
}

As it is, we can either fix it "everywhere" with the way this PR does it, or we can fix it only for the structlogger by modifying the constructor.
I don't have any hard preference at this point. @s1na WDYT?

@s1na
Copy link
Contributor

s1na commented May 2, 2023

Tracers are used in multiple contexts:

  • traceCall which operates on a set of tx parameters. Here txHash would be nil.
  • traceTransaction which takes in a txHash as parameter, hence the user already knows the hash.
  • traceBlock and traceChain output the trace for multiple mined (or possibly pending) txes.

Because of this it might make sense to add this info directly to the result of traceBlock or traceChain. However the txHash of every trace is easily inferable via an eth_getBlockByNumber/Hash. Why aren't you using that?

@holiman
Copy link
Contributor

holiman commented May 2, 2023

I'm leaning towards accepting this PR as is, based on your comments above.

(However:)

However the txHash of every trace is easily inferable via an eth_getBlockByNumber/Hash.

Do you mean he should obtain the traces, then afterwards load the block body and correlate? Sounds clunky.

@s1na
Copy link
Contributor

s1na commented May 2, 2023

Can you please fix the failing tests?

@holiman holiman force-pushed the add-txHash-on-txTraceResult branch from ae94780 to 000dcdc Compare May 4, 2023 11:18
@holiman holiman changed the title Add a txhash field on txTraceResult eth/tracres: add txHash field on txTraceResult May 4, 2023
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman changed the title eth/tracres: add txHash field on txTraceResult eth/tracers: add txHash field on txTraceResult May 4, 2023
@holiman holiman added this to the 1.11.7 milestone May 4, 2023
@holiman holiman merged commit 604e215 into ethereum:master May 5, 2023
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
This PR modifies the interface for the results of `debug_traceBlock` and `debug_traceCall` by adding the `txHash`, allowing users to identify which transaction's trace result corresponds to. 

---------

Co-authored-by: Martin Holst Swende <[email protected]>
holiman pushed a commit that referenced this pull request Oct 23, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This PR modifies the interface for the results of `debug_traceBlock` and `debug_traceCall` by adding the `txHash`, allowing users to identify which transaction's trace result corresponds to. 

---------

Co-authored-by: Martin Holst Swende <[email protected]>
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants