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

Support for different blob target and max values #14678

Merged
merged 4 commits into from
Dec 19, 2024

Conversation

terencechain
Copy link
Member

@terencechain terencechain commented Nov 27, 2024

This PR adds support for potential new blob target and max values (based on hard forks) in the configuration, with updates applied throughout the codebase. The detailed change list is provided below.

Notes This PR does not implement `EIP-7691: Blob throughput increase`; it is the first part of the PR, allowing a custom blob target and max count. The EIP will be included in the following PR, as we aim to keep each PR small and easy to review.

Config

  • Removed fieldparams package's MaxBlobsPerBlock for mainnet and minimal configurations.
  • Added DeprecatedMaxBlobsPerBlock to the config package which is mainly used for import through yaml
  • Introduced helpers MaxBlobsPerBlock and TargetBlobsPerBlock that determine the appropriate blob count for a given slot based on the active fork.

Proposer Requesting Header from Relayer

  • Updated ToProto() to ToProto(Slot) for the proposer getHeader response to the relayer endpoint. The proposer passes the slot, and ToProto ensures the builder's bid's KZG commitment does not exceed MaxBlobsPerBlock for the current slot.

Blockchain Package Checking DA

  • Added slot to missingIndices for calculating MaxBlobsPerBlock as a safety check ensuring KZG commitments in the beacon block body do not exceed the limit.
  • Updated forRoot in blobNotifierMap to use slot for constructing the correct number of channels (MaxBlobsPerBlock). This manages the NotifyIndex listener.

Sync Notify New Blob to Blockchain Package

  • Added slot to sendBlobEvent in notifyIndex to construct the correct size for the seen map and downstream notifier channel.

State Transition Process for New Payload

  • Added slot to verifyBlobCommitmentCount to ensure KZG commitments do not exceed the MaxBlobsPerBlock limit. This is part of the state transition check, using the state.slot before processing the payload to match the block slot.

DAS Cache

  • Removed safeCommitmentArray as it assumed a fixed MaxBlobsPerBlock.
  • Updated functions like filter, stash, and commitmentsToCheck:
    • commitmentsToCheck still ensures KZG commitments in the block do not exceed the max blob count.
    • stash now handles cases where e.scs is nil, which was previously unsupported.

Blob Storage

  • Added slot to indices for MaxBlobsPerBlock checks and for constructing the mask object.
  • Changed blobIndexMask to a slice instead of an array.
  • Updated hasIndex and AllAvailable to include additional checks ensuring indices do not exceed the length of the mask.
  • If v.mask is nil, a new blobIndexMask is constructed.

Beacon API RPC

  • Updated initial URL index checks to validate indices against MaxBlobsPerBlock based on Electra fork configurations.
  • Added a check to ensure indices do not exceed KZG commitments in beacon-chain/rpc/lookup/blocker.go.

Proposer

  • Ensured correct MaxBlobsPerBlock is used when fetching payload headers from the builder. This check is duplicated but not removed in this PR.

Initial Sync - Backfill

  • Changed blobVerifierMap to use a slice of BlobVerifier instead of a hardcoded length.

Sync - RPC

  • Added slot to constructPendingBlobsRequest for database index validation.
  • Added slot to blobBatchLimit for constructing the correct block batch limit.
  • Updated SendBlobSidecarByRoot to verify that the blob sidecars in the response do not exceed MaxBlobsPerBlock.

Sync - Subscribe

  • Added slot to all usages of database index changes.
  • Added a new validation rule ensuring the KZG commitment check is based on the blob's slot.

@terencechain terencechain force-pushed the custom-blob-count branch 6 times, most recently from 837eb16 to 68d9ce7 Compare December 9, 2024 20:18
@terencechain terencechain marked this pull request as ready for review December 9, 2024 20:18
@terencechain terencechain requested review from prestonvanloon and a team as code owners December 9, 2024 20:18
@terencechain terencechain force-pushed the custom-blob-count branch 6 times, most recently from 3d81330 to 4599ebd Compare December 11, 2024 00:08
@@ -1008,12 +1009,13 @@ func (ehr *ExecHeaderResponseDeneb) ToProto() (*eth.SignedBuilderBidDeneb, error
}

// ToProto creates a BuilderBidDeneb Proto from BuilderBidDeneb.
func (bb *BuilderBidDeneb) ToProto() (*eth.BuilderBidDeneb, error) {
func (bb *BuilderBidDeneb) ToProto(s types.Slot) (*eth.BuilderBidDeneb, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not have this be the max blob count instead of the slot? That would be a better abstraction since this method doesn't actually care about the slot, it only needs it to derive the max blob count

Comment on lines 285 to 287
MaxBlobsPerBlock int `yaml:"MAX_BLOBS_PER_BLOCK" spec:"true"` // MaxBlobsPerBlock defines the max blobs could exist in a block.
MaxBlobsPerBlockElectra int `yaml:"MAX_BLOBS_PER_BLOCK_ELECTRA" spec:"true"` // MaxBlobsPerBlockElectra defines the max blobs could exist in a block post Electra hard fork.
TargetBlobsPerBlockElectra int `yaml:"TARGET_BLOBS_PER_BLOCK_ELECTRA" spec:"true"` // TargetBlobsPerBlockElectra defines the target number of blobs per block post Electra hard fork.
Copy link
Member

Choose a reason for hiding this comment

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

Why is it an int when everything else is uint64?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in the description :)
Tried both approaches and int is generally more friendly to work with, less conversion in most places
Screenshot 2024-12-17 at 6 48 07 AM

@@ -280,6 +280,11 @@ type BeaconChainConfig struct {
AttestationSubnetPrefixBits uint64 `yaml:"ATTESTATION_SUBNET_PREFIX_BITS" spec:"true"` // AttestationSubnetPrefixBits is defined as (ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS).
SubnetsPerNode uint64 `yaml:"SUBNETS_PER_NODE" spec:"true"` // SubnetsPerNode is the number of long-lived subnets a beacon node should be subscribed to.
NodeIdBits uint64 `yaml:"NODE_ID_BITS" spec:"true"` // NodeIdBits defines the bit length of a node id.

// Blobs Values
MaxBlobsPerBlock int `yaml:"MAX_BLOBS_PER_BLOCK" spec:"true"` // MaxBlobsPerBlock defines the max blobs could exist in a block.
Copy link
Member

Choose a reason for hiding this comment

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

I think having this as a public config value is going to be a potential footgun or lead to misuse. Is there a way that this can only be accessed via the helper method? If there is a single place in the production codepath that is using params.BeaconConfig().MaxBlobsPerBlock instead of params.BeaconConfig().MaxBlobCount(slot) then it's going to be a nasty bug at the fork.

@terencechain terencechain force-pushed the custom-blob-count branch 3 times, most recently from 8e83e77 to 8e2b3eb Compare December 19, 2024 00:57
prestonvanloon
prestonvanloon previously approved these changes Dec 19, 2024
CHANGELOG.md Outdated
@@ -78,6 +78,7 @@ Notable features:
- Save light client updates and bootstraps in DB.
- Added more comprehensive tests for `BlockToLightClientHeader`. [PR](https://github.com/prysmaticlabs/prysm/pull/14699)
- Added light client feature flag check to RPC handlers. [PR](https://github.com/prysmaticlabs/prysm/pull/14736)
- Added support to update target and max blob count to different values per hard fork config.
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong section

@@ -166,7 +171,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) {
ctx, cancel := context.WithCancel(ctx)
bn := &blobNotifierMap{
notifiers: make(map[[32]byte]chan uint64),
seenIndex: make(map[[32]byte][fieldparams.MaxBlobsPerBlock]bool),
seenIndex: make(map[[32]byte][]bool),
Copy link
Member

Choose a reason for hiding this comment

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

probably a micro optimization that can be in another PR, but a bitfield is cheaper on memory.

@terencechain terencechain added this pull request to the merge queue Dec 19, 2024
Merged via the queue into develop with commit bc69ab8 Dec 19, 2024
15 checks passed
@terencechain terencechain deleted the custom-blob-count branch December 19, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants