-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// BlockStartHook is called before executing `block`. | ||
// `td` is the total difficulty prior to `block`. | ||
BlockStartHook = func(event BlockEvent) | ||
|
@@ -153,6 +156,7 @@ type Hooks struct { | |
OnGasChange GasChangeHook | ||
// Chain events | ||
OnBlockchainInit BlockchainInitHook | ||
OnClose CloseHook | ||
OnBlockStart BlockStartHook | ||
OnBlockEnd BlockEndHook | ||
OnSkippedBlock SkippedBlockHook | ||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 shouldClose
the tracer before we close the triedb, IMO.There was a problem hiding this comment.
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 fromtriedb
, it might feel safer to callOnClose
before.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracer has indirect access via statedb. However the lifetime of a statedb instance is that of a block.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by e881bf7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't compute for me... If the tracer opens before the triedb, then it should close after triedb.
Ideal order:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.