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

core/tracing: Add OnClose Trace Hook #29629

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

ziogaschr
Copy link
Contributor

The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.

@s1na s1na changed the title Add OnClose Trace Hook core/tracing: Add OnClose Trace Hook Apr 23, 2024
Copy link
Contributor

@s1na s1na left a comment

Choose a reason for hiding this comment

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

LGTM thx

@@ -107,6 +107,9 @@ type (
// BlockchainInitHook is called when the blockchain is initialized.
BlockchainInitHook = func(chainConfig *params.ChainConfig)

// CloseHook is called when the blockchain closes.
CloseHook = func()
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to allow returning an error? In general Go's Close() methods do so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.
The initial idea was to be used for allowing tracers to cleanup their stuff. I also checked the errors in Blockchain.Stop() and I am not sure if tracer will make any use of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

None of the other tracing methods return an error or any value for that matter. My 2c keep it as is.

// Allow tracers to clean-up and release resources.
if bc.logger != nil && bc.logger.OnClose != nil {
bc.logger.OnClose()
}
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, do we want to close the logger first or the triedb first? Any change the logger might have access to the trie and might want to do something with it? (Or any other live object really).

Copy link
Contributor

Choose a reason for hiding this comment

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

Closing should be reverse order to start. I assume triedb was opened before the tracer, so we should Close the tracer before we close the triedb, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tracer initiates before the triedb. On the other hand, and just in case a future tracer wants to finish reading something from triedb, it might feel safer to call OnClose before.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any change the logger might have access to the trie and might want to do something with it?

Tracer has indirect access via statedb. However the lifetime of a statedb instance is that of a block.

On the other hand, and just in case a future tracer wants to finish reading something from triedb

People really shouldn't keep a reference to statedb which they could use at OnClose. Because a new instance is created at every block.

@ziogaschr I think the reverse order martin mentioned makes sense. Can you please change it?

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 by e881bf7

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume triedb was opened before the tracer, so we should Close the tracer before [...] triedb

The tracer initiates before the triedb.

I think the reverse order martin mentioned makes sense. Can you please change it?

This doesn't compute for me... If the tracer opens before the triedb, then it should close after triedb.

Ideal order:

a.open
b.open
b.close
a.close

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, I don't particularly care if we do this way or another really, just pointing out that there seems to have been some misunderstanding

Copy link
Contributor

Choose a reason for hiding this comment

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

Well it depends what you mean by tracing open. Instance is created before triedb. But "OnBlockchainInit" is called after triedb is created.

@s1na s1na added this to the 1.14.0 milestone Apr 23, 2024
@holiman holiman merged commit fb08fd3 into ethereum:master Apr 24, 2024
1 of 2 checks passed
@ziogaschr ziogaschr deleted the feat/hook-onclose branch April 24, 2024 10:47
maoueh pushed a commit to streamingfast/go-ethereum that referenced this pull request Apr 24, 2024
The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
jorgemmsilva pushed a commit to iotaledger/go-ethereum that referenced this pull request Jun 17, 2024
The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
stwiname pushed a commit to subquery/data-node-go-ethereum that referenced this pull request Sep 9, 2024
The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
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.

4 participants