-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Gloas beacon state package #15611
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
Changes from all commits
c7f23a4
e7713f3
d221794
e4757ee
37f0b43
f84f3e8
963db2f
a179b7f
839cab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,14 @@ type BeaconState struct { | |
| pendingConsolidations []*ethpb.PendingConsolidation // pending_consolidations: List[PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT] | ||
| proposerLookahead []primitives.ValidatorIndex // proposer_look_ahead: List[uint64, (MIN_LOOKAHEAD + 1)*SLOTS_PER_EPOCH] | ||
|
|
||
| // Gloas fields | ||
| latestExecutionPayloadBid *ethpb.ExecutionPayloadBid | ||
| executionPayloadAvailability []byte | ||
| builderPendingPayments []*ethpb.BuilderPendingPayment | ||
| builderPendingWithdrawals []*ethpb.BuilderPendingWithdrawal | ||
| latestBlockHash []byte | ||
| latestWithdrawalsRoot []byte | ||
|
|
||
| id uint64 | ||
| lock sync.RWMutex | ||
| dirtyFields map[types.FieldIndex]bool | ||
|
|
@@ -125,6 +133,12 @@ type beaconStateMarshalable struct { | |
| PendingPartialWithdrawals []*ethpb.PendingPartialWithdrawal `json:"pending_partial_withdrawals" yaml:"pending_partial_withdrawals"` | ||
| PendingConsolidations []*ethpb.PendingConsolidation `json:"pending_consolidations" yaml:"pending_consolidations"` | ||
| ProposerLookahead []primitives.ValidatorIndex `json:"proposer_look_ahead" yaml:"proposer_look_ahead"` | ||
| LatestExecutionPayloadBid *ethpb.ExecutionPayloadBid `json:"latest_execution_payload_bid" yaml:"latest_execution_payload_bid"` | ||
| ExecutionPayloadAvailability []byte `json:"execution_payload_availability" yaml:"execution_payload_availability"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, justification bits is a Bitvector above. |
||
| BuilderPendingPayments []*ethpb.BuilderPendingPayment `json:"builder_pending_payments" yaml:"builder_pending_payments"` | ||
| BuilderPendingWithdrawals []*ethpb.BuilderPendingWithdrawal `json:"builder_pending_withdrawals" yaml:"builder_pending_withdrawals"` | ||
| LatestBlockHash []byte `json:"latest_block_hash" yaml:"latest_block_hash"` | ||
| LatestWithdrawalsRoot []byte `json:"latest_withdrawals_root" yaml:"latest_withdrawals_root"` | ||
| } | ||
|
|
||
| func (b *BeaconState) MarshalJSON() ([]byte, error) { | ||
|
|
@@ -179,6 +193,12 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) { | |
| PendingPartialWithdrawals: b.pendingPartialWithdrawals, | ||
| PendingConsolidations: b.pendingConsolidations, | ||
| ProposerLookahead: b.proposerLookahead, | ||
| LatestExecutionPayloadBid: b.latestExecutionPayloadBid, | ||
| ExecutionPayloadAvailability: b.executionPayloadAvailability, | ||
| BuilderPendingPayments: b.builderPendingPayments, | ||
| BuilderPendingWithdrawals: b.builderPendingWithdrawals, | ||
| LatestBlockHash: b.latestBlockHash, | ||
| LatestWithdrawalsRoot: b.latestWithdrawalsRoot, | ||
| } | ||
| return json.Marshal(marshalable) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package state_native | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having all Gloas logic in a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it better in the new fork specific file. |
||
|
|
||
| import ( | ||
| ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" | ||
| ) | ||
|
|
||
| // executionPayloadAvailabilityVal returns a copy of the execution payload availability. | ||
| // This assumes that a lock is already held on BeaconState. | ||
| func (b *BeaconState) executionPayloadAvailabilityVal() []byte { | ||
| if b.executionPayloadAvailability == nil { | ||
| return nil | ||
| } | ||
|
|
||
| availability := make([]byte, len(b.executionPayloadAvailability)) | ||
| copy(availability, b.executionPayloadAvailability) | ||
|
|
||
| return availability | ||
| } | ||
|
|
||
| // builderPendingPaymentsVal returns a copy of the builder pending payments. | ||
| // This assumes that a lock is already held on BeaconState. | ||
| func (b *BeaconState) builderPendingPaymentsVal() []*ethpb.BuilderPendingPayment { | ||
| if b.builderPendingPayments == nil { | ||
| return nil | ||
| } | ||
|
|
||
| payments := make([]*ethpb.BuilderPendingPayment, len(b.builderPendingPayments)) | ||
| for i, payment := range b.builderPendingPayments { | ||
| payments[i] = payment.Copy() | ||
| } | ||
|
|
||
| return payments | ||
| } | ||
|
|
||
| // builderPendingWithdrawalsVal returns a copy of the builder pending withdrawals. | ||
| // This assumes that a lock is already held on BeaconState. | ||
| func (b *BeaconState) builderPendingWithdrawalsVal() []*ethpb.BuilderPendingWithdrawal { | ||
| if b.builderPendingWithdrawals == nil { | ||
| return nil | ||
| } | ||
|
|
||
| withdrawals := make([]*ethpb.BuilderPendingWithdrawal, len(b.builderPendingWithdrawals)) | ||
| for i, withdrawal := range b.builderPendingWithdrawals { | ||
| withdrawals[i] = withdrawal.Copy() | ||
| } | ||
|
|
||
| return withdrawals | ||
| } | ||
|
|
||
| // latestBlockHashVal returns a copy of the latest block hash. | ||
| // This assumes that a lock is already held on BeaconState. | ||
| func (b *BeaconState) latestBlockHashVal() []byte { | ||
| if b.latestBlockHash == nil { | ||
| return nil | ||
| } | ||
|
|
||
| hash := make([]byte, len(b.latestBlockHash)) | ||
| copy(hash, b.latestBlockHash) | ||
|
|
||
| return hash | ||
| } | ||
|
|
||
| // latestWithdrawalsRootVal returns a copy of the latest withdrawals root. | ||
| // This assumes that a lock is already held on BeaconState. | ||
| func (b *BeaconState) latestWithdrawalsRootVal() []byte { | ||
| if b.latestWithdrawalsRoot == nil { | ||
| return nil | ||
| } | ||
|
|
||
| root := make([]byte, len(b.latestWithdrawalsRoot)) | ||
| copy(root, b.latestWithdrawalsRoot) | ||
|
|
||
| return root | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,8 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b | |
| fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateElectraFieldCount) | ||
| case version.Fulu: | ||
| fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateFuluFieldCount) | ||
| case version.Gloas: | ||
| fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateGloasFieldCount) | ||
| default: | ||
| return nil, fmt.Errorf("unknown state version %s", version.String(state.version)) | ||
| } | ||
|
|
@@ -245,7 +247,7 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b | |
| fieldRoots[types.LatestExecutionPayloadHeaderCapella.RealPosition()] = executionPayloadRoot[:] | ||
| } | ||
|
|
||
| if state.version >= version.Deneb { | ||
| if state.version >= version.Deneb && state.version < version.Gloas { | ||
| // Execution payload root. | ||
| executionPayloadRoot, err := state.latestExecutionPayloadHeaderDeneb.HashTreeRoot() | ||
| if err != nil { | ||
|
|
@@ -254,6 +256,16 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b | |
| fieldRoots[types.LatestExecutionPayloadHeaderDeneb.RealPosition()] = executionPayloadRoot[:] | ||
| } | ||
|
|
||
| if state.version >= version.Gloas { | ||
| // Execution payload bid root for Gloas. | ||
| bidRoot, err := state.latestExecutionPayloadBid.HashTreeRoot() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| fieldRoots[types.LatestExecutionPayloadBid.RealPosition()] = bidRoot[:] | ||
| } | ||
|
|
||
| if state.version >= version.Capella { | ||
| // Next withdrawal index root. | ||
| nextWithdrawalIndexRoot := make([]byte, 32) | ||
|
|
@@ -328,5 +340,34 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b | |
| } | ||
| fieldRoots[types.ProposerLookahead.RealPosition()] = proposerLookaheadRoot[:] | ||
| } | ||
|
|
||
| if state.version >= version.Gloas { | ||
| epaRoot, err := stateutil.ExecutionPayloadAvailabilityRoot(state.executionPayloadAvailability) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "could not compute execution payload availability merkleization") | ||
| } | ||
|
|
||
| fieldRoots[types.ExecutionPayloadAvailability.RealPosition()] = epaRoot[:] | ||
|
|
||
| bppRoot, err := stateutil.BuilderPendingPaymentsRoot(state.builderPendingPayments) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "could not compute builder pending payments merkleization") | ||
| } | ||
|
|
||
| fieldRoots[types.BuilderPendingPayments.RealPosition()] = bppRoot[:] | ||
|
|
||
| bpwRoot, err := stateutil.BuilderPendingWithdrawalsRoot(state.builderPendingWithdrawals) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "could not compute builder pending withdrawals merkleization") | ||
| } | ||
|
|
||
| fieldRoots[types.BuilderPendingWithdrawals.RealPosition()] = bpwRoot[:] | ||
|
|
||
| lbhRoot := bytesutil.ToBytes32(state.latestBlockHash) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need these copies? if there's any doubt I would rather keep these copies indeed. |
||
| fieldRoots[types.LatestBlockHash.RealPosition()] = lbhRoot[:] | ||
|
|
||
| lwrRoot := bytesutil.ToBytes32(state.latestWithdrawalsRoot) | ||
| fieldRoots[types.LatestWithdrawalsRoot.RealPosition()] = lwrRoot[:] | ||
| } | ||
| return fieldRoots, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustificationBits is a bitvector, why is
executionPayloadAvailabilityof type[]byte?