Skip to content
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

Stable Containers - EIP-7495 #8444

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

tbenr
Copy link
Contributor

@tbenr tbenr commented Jul 15, 2024

fixes #8428

Introduces new interfaces:

  • SszStableContainer
  • SszStableContainerSchema
  • SszProfile
  • SszProfileSchema

which are based on new SszStableContainerBase and SszStableContainerBaseSchema interfaces representing the common base functionalities.
Corresponding Abstract and Impl classes implement the logic.

Key points

  • these containers have a maxFieldCount (maximum future field count): the backing tree will always have that size despite the "actual" field count.
  • fields can be required, optional or disallowed (disallowed fields are the ones that are not specified as required nor as optional)
  • StableContainers have all fields as optional, Profile can have a mix of required and optional fields.
  • To represent which fields are active (required+optionals) an SszBitvector is used (sized as max future field count). It will be used in serialization as well as merkelization.
  • due to optionals and (and potentially disabled) fields, these containers are sparse, which means that size() = last_field_index + 1 does not hold anymore.
  • There is a difference between maxLength and maxChunks: the first is the possible maximum number of fields (required+optionals) the latter is related to the backing tree, so it is calculated based on maxFieldCount.
  • getOptional has been introduced to support optionality. Similarly we have createFromOptionalFieldValues on the schema side to handle optionality.
  • then getting fields values, the method can now throw NoSuchElementException along with existing IndexOutOfBoundsException. The general logic is:
    • NoSuchElementException is thrown whenever a field was allowed but (optional) but was not actually specified.
    • IndexOutOfBoundsException is thrown whenever a field was not allowed (nor optional nor required), which also covers the case the index is truly off.
      This allows to have nice implementation of the getOptional which simply delegate to get catching NoSuchElementException and returning Optional.empty.
  • merkelization works the same for both StableContainers and Profiles.
  • serialization are different. This polymorphism is achieved via abstract methods AbstractSszStableContainerBaseSchema.

High Level Usage:

to create a StableContainerSchema you need:

  • definedChildrenNamedSchemas: a list of NamedSchema representing the defined schemas.
  • maxFieldCount: theoretical future maximum field count.

to create a ProfileSchema you need:

  • stableContainerSchema: a SszStableContainer to create the profile schema against
  • requiredFieldIndices: a set of indices to indicate which fields are mandatory
  • optionalFieldIndices: a set of indices to indicate which fields are optional

AbstractSszStableContainerBaseSchemaTest showcases how to use them.

What is missing

  • Mutability is only implemented for Profiles with no optional fields. Optionality in mutation requires some additional works.
    • a new interface with optional-enabled set methods.
    • handling the expansion\contraction of the number of fields (and good handling of the "sparse" index set)
  • benchmarking?
  • allow to specify optional and required fields by name when creating Profiles?

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

@tbenr tbenr mentioned this pull request Jul 15, 2024
2 tasks
@tbenr tbenr changed the title Stable Containers - EIP - 7495 Stable Containers - EIP-7495 Jul 15, 2024
@tbenr tbenr requested a review from Nashatyrev July 15, 2024 18:07
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

  • Added new interfaces and classes for stable containers (SszStableContainer, SszProfile, SszStableContainerBase, etc.) in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/.
  • Modified existing classes to handle stable containers, including exception handling (NoSuchElementException) in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszComposite.java.
  • Updated serialization methods to handle extra data in backing trees in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszCollectionSchema.java.
  • Introduced methods to convert to stable container schemas and profile schemas in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/SszContainerSchema.java.
  • Enhanced schema handling for optional fields and active fields in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszStableContainerBaseSchema.java.

29 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of minor notes.
Many design question we discussed and agreed in our chat before.

abstract SszBitvector sszDeserializeActiveFieldsTree(final SszReader reader);

@Override
public TreeNode sszDeserializeTree(final SszReader reader) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It looks like sszSerialize/DeserializeTree() have a lot of common logic with AbstractSszContainerSchema. Maybe we could extract this logic to some util class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactor, checkout 5b13a1e

Copy link
Contributor Author

@tbenr tbenr Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to cut it at that point even I could have continued along that direction it even further.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

  • Introduced final variables for elementType and nodesCount in sszSerializeFixedVector method in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszCollectionSchema.java
  • Ensures variables are not reassigned, improving code safety and readability

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

  • Removed special handling for SszStableContainerBase in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java
  • Added calcNewSize method for size determination in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java
  • Introduced calcNewSize method for stable containers in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/SszMutableStableContainerBaseImpl.java
  • Simplified size calculation logic for better maintainability and readability
  • Ensure size consistency for profiles with no optional fields in stable containers

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

  • Refactored serialization/deserialization logic in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszContainerSchema.java
  • Updated /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszStableContainerBaseSchema.java to use ContainerSchemaUtil
  • Added new utility class /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/ContainerSchemaUtil.java for handling SSZ containers
  • Ensure new utility methods handle all edge cases and maintain functionality
  • Streamlined handling of fixed and variable children in SSZ containers

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

@tbenr tbenr force-pushed the stable-containers-eip7495 branch from 839dff5 to 5b13a1e Compare July 16, 2024 15:21
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

  • Refactored serialization/deserialization logic in /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszContainerSchema.java
  • Updated /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszStableContainerBaseSchema.java to use ContainerSchemaUtil
  • Added new utility class /infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/ContainerSchemaUtil.java for handling SSZ containers
  • Ensure new utility methods handle all edge cases and maintain functionality
  • Streamlined handling of fixed and variable children in SSZ containers

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

*
* @param index of the field set or updated
*/
protected int calcNewSize(final int index) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably just call this calculateNewSize rather than abbreviate...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problem is that in the ssz module seems like "calc" is the normal:
image

I wanted to maintain the style here. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i guess but i do hate abbreviations...

Copy link
Contributor

@rolfyone rolfyone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Introduced new interfaces and classes to support stable containers and profiles as per EIP-7495, with significant updates across multiple files to ensure compatibility and functionality.

  • New Interfaces: Added SszStableContainer, SszStableContainerSchema, SszProfile, and SszProfileSchema based on SszStableContainerBase and SszStableContainerBaseSchema.
  • Acceptance Tests: Updated acceptance-tests/src/acceptance-test/java/tech/pegasys/teku/test/acceptance/MergedGenesisAcceptanceTest.java to use genesisExecutionPayloadHeaderSource.
  • Validator API: Modified beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java to align with new getter methods for SyncCommitteeSubnetSubscription.
  • Sync Committee: Refactored data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSyncCommitteeSubscriptions.java to simplify request body type definition.
  • IPv6 Support: Enhanced networking/p2p/src/main/java/tech/pegasys/teku/networking/p2p/discovery/discv5/DiscV5Service.java and NodeRecordConverter.java to support IPv6 addresses.

46 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@tbenr tbenr enabled auto-merge (squash) July 23, 2024 07:40
@tbenr tbenr disabled auto-merge July 23, 2024 07:41
@lucassaldanha lucassaldanha added the DO NOT MERGE Not ready to merge label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE Not ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement general Stable Container support - EIP-7495
4 participants