diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 6b9b3e03e8..b70bd4cd50 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -207,8 +207,10 @@ type Hooks struct { OnBlockHashRead BlockHashReadHook } -// Copy creates a new Hooks instance with all implemented hooks copied from the original. -func (h *Hooks) Copy() *Hooks { +// copy creates a new Hooks instance with all implemented hooks copied from the original. +// Note: it is not a deep copy. If a hook has been implemented as a closure and acts on +// a mutable state, the copied hook will still act on the same state. +func (h *Hooks) copy() *Hooks { copied := &Hooks{} srcValue := reflect.ValueOf(h).Elem() dstValue := reflect.ValueOf(copied).Elem() diff --git a/core/tracing/journal.go b/core/tracing/journal.go index 7fab5a301b..6f386efda5 100644 --- a/core/tracing/journal.go +++ b/core/tracing/journal.go @@ -62,7 +62,7 @@ func WrapWithJournal(hooks *Hooks) (*Hooks, error) { } // Create a new Hooks instance and copy all hooks - wrapped := hooks.Copy() + wrapped := hooks.copy() // Create journal j := &journal{entries: make([]entry, 0), hooks: hooks} // Scope hooks need to be re-implemented. diff --git a/core/tracing/journal_test.go b/core/tracing/journal_test.go index e9a14e585e..7ea28bb75e 100644 --- a/core/tracing/journal_test.go +++ b/core/tracing/journal_test.go @@ -179,7 +179,7 @@ func TestAllHooksCalled(t *testing.T) { continue } // Skip non-hooks, i.e. Copy - if field.Name == "Copy" { + if field.Name == "copy" { continue }