un-expose hooks copy

pull/30441/head
Sina Mahmoodi 2 months ago
parent de48d559ea
commit 9cae376df4
  1. 6
      core/tracing/hooks.go
  2. 2
      core/tracing/journal.go
  3. 2
      core/tracing/journal_test.go

@ -207,8 +207,10 @@ type Hooks struct {
OnBlockHashRead BlockHashReadHook OnBlockHashRead BlockHashReadHook
} }
// Copy creates a new Hooks instance with all implemented hooks copied from the original. // copy creates a new Hooks instance with all implemented hooks copied from the original.
func (h *Hooks) Copy() *Hooks { // 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{} copied := &Hooks{}
srcValue := reflect.ValueOf(h).Elem() srcValue := reflect.ValueOf(h).Elem()
dstValue := reflect.ValueOf(copied).Elem() dstValue := reflect.ValueOf(copied).Elem()

@ -62,7 +62,7 @@ func WrapWithJournal(hooks *Hooks) (*Hooks, error) {
} }
// Create a new Hooks instance and copy all hooks // Create a new Hooks instance and copy all hooks
wrapped := hooks.Copy() wrapped := hooks.copy()
// Create journal // Create journal
j := &journal{entries: make([]entry, 0), hooks: hooks} j := &journal{entries: make([]entry, 0), hooks: hooks}
// Scope hooks need to be re-implemented. // Scope hooks need to be re-implemented.

@ -179,7 +179,7 @@ func TestAllHooksCalled(t *testing.T) {
continue continue
} }
// Skip non-hooks, i.e. Copy // Skip non-hooks, i.e. Copy
if field.Name == "Copy" { if field.Name == "copy" {
continue continue
} }

Loading…
Cancel
Save