feat: add ephemeral fields to Container#527
Draft
twoeths wants to merge 1 commit into
Draft
Conversation
Contributor
Performance Report✔️ no performance regression detected Full benchmark results
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ephemeralFieldsmap toContainerTypeandContainerNodeStructTypefor declaring application-only fields that are first-class on the value/View/ViewDU but strictly excluded from consensus: serialization, deserialization,hashTreeRoot, JSON, equality, and tree storage all ignore them.EphemeralFieldsdefaults toRecord<string, never>, so existing call sites compile unchanged.Motivation
ContainerType<Fields>currently requires every declared field to participate in consensus. Applications that want to attach derived/cached data on top of a container value have no first-class place to put it — they either fork the SSZ type, attach untyped sidebands, or wrap the type. This PR makes that pattern first-class.Concrete consumer: ChainSafe/lodestar#9341 — pending deposit requests are currently re-validated on every access. With this PR, lodestar can attach
{valid: BooleanType}as an ephemeral field onPendingDeposit, validate once, and cache the result on the container value/View/ViewDU without polluting the consensus type or its hash.API
ValueOfFields<F> & Partial<ValueOfFields<EF>>(consensus required, ephemerals optional).ephemeralValues); they never touch the merkle tree, \nodesChanged, orviewsChanged`.clone(value)deep-copies present ephemerals via each ephemeral type's ownclone.toView(value)/toViewDU(value)carry present ephemerals from the source value to the resulting view's ephemeral storage.getView(tree)/ `getViewDU(node)\ start with empty ephemerals (no value source).type,tree,node,cache,nodes, …) — they already exist on the view classes.Excluded from consensus (verified by tests)
serialize/deserialize— ephemerals never appear in bytes; deserialized values have no ephemeral keyshashTreeRoot— identical regardless of ephemeral valuesequals— compares consensus only; differing ephemerals are still equaltoJson/fromJson— ephemerals are not part of JSON encodingdefaultValue— emits no ephemeral keysmaxChunkCount/depth/fixedSize/serdeslayout — derived from consensus fields only🤖 Generated with Claude Code