Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions core/types/rlp_payload.libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ func RegisterExtras[
// The [ExtraPayloads] that we returns is based on [HPtr,BPtr,SA], not
// [H,B,SA] so our constructors MUST match that. This guarantees that calls to
// the [HeaderHooks] and [BodyHooks] methods will never be performed on a nil pointer.
newHeader: pseudo.NewConstructor[H]().NewPointer, // i.e. non-nil HPtr
newBody: pseudo.NewConstructor[B]().NewPointer, // i.e. non-nil BPtr
newStateAccount: pseudo.NewConstructor[SA]().Zero,
cloneStateAccount: extra.cloneStateAccount,
hooks: extra,
newHeader: pseudo.NewConstructor[H]().NewPointer, // i.e. non-nil HPtr
newBody: pseudo.NewConstructor[B]().NewPointer, // i.e. non-nil BPtr
newStateAccount: pseudo.NewConstructor[SA]().Zero,
hooks: extra,
})
return extra
}
Expand All @@ -96,29 +95,17 @@ func TestOnlyClearRegisteredExtras() {
var registeredExtras register.AtMostOnce[*extraConstructors]

type extraConstructors struct {
stateAccountType string
newHeader func() *pseudo.Type
newBody func() *pseudo.Type
newStateAccount func() *pseudo.Type
cloneStateAccount func(*StateAccountExtra) *StateAccountExtra
hooks interface {
stateAccountType string
newHeader func() *pseudo.Type
newBody func() *pseudo.Type
newStateAccount func() *pseudo.Type
hooks interface {
hooksFromHeader(*Header) HeaderHooks
hooksFromBody(*Body) BodyHooks
cloneStateAccount(*StateAccountExtra) *StateAccountExtra
}
}

func (h *Header) extraPayload() *pseudo.Type {
return extraPayloadOrSetDefault(&h.extra, func(c *extraConstructors) *pseudo.Type {
return c.newHeader()
})
}

func (b *Body) extraPayload() *pseudo.Type {
return extraPayloadOrSetDefault(&b.extra, func(c *extraConstructors) *pseudo.Type {
return c.newBody()
})
}

func extraPayloadOrSetDefault(field **pseudo.Type, construct func(*extraConstructors) *pseudo.Type) *pseudo.Type {
r := registeredExtras
if !r.Registered() {
Expand All @@ -131,6 +118,18 @@ func extraPayloadOrSetDefault(field **pseudo.Type, construct func(*extraConstruc
return *field
}

func (h *Header) extraPayload() *pseudo.Type {
return extraPayloadOrSetDefault(&h.extra, func(c *extraConstructors) *pseudo.Type {
return c.newHeader()
})
}

func (b *Body) extraPayload() *pseudo.Type {
return extraPayloadOrSetDefault(&b.extra, func(c *extraConstructors) *pseudo.Type {
return c.newBody()
})
}

// hooks returns the [Header]'s registered [HeaderHooks], if any, otherwise a
// [NOOPHeaderHooks] suitable for running default behaviour.
func (h *Header) hooks() HeaderHooks {
Expand All @@ -154,7 +153,7 @@ func (e *StateAccountExtra) clone() *StateAccountExtra {
case !r.Registered(), e == nil:
return nil
default:
return r.Get().cloneStateAccount(e)
return r.Get().hooks.cloneStateAccount(e)
}
}

Expand Down