Skip to content

Commit e29cd41

Browse files
committed
changes on beacon state
1 parent 677b63e commit e29cd41

40 files changed

+3071
-211
lines changed

cl/abstract/beacon_state.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type BeaconStateUpgradable interface {
4343
type BeaconStateExtension interface {
4444
SlashValidator(slashedInd uint64, whistleblowerInd *uint64) (uint64, error)
4545
InitiateValidatorExit(index uint64) error
46+
InitiateBuilderExit(builderIndex cltypes.BuilderIndex)
4647
GetActiveValidatorsIndices(epoch uint64) (indicies []uint64)
4748
GetTotalActiveBalance() uint64
4849
ComputeCommittee(indicies []uint64, slot uint64, index, count uint64) ([]uint64, error)
@@ -70,6 +71,15 @@ type BeaconStateExtension interface {
7071
ComputeExitEpochAndUpdateChurn(exitBalance uint64) uint64
7172
GetConsolidationBalanceToConsume() uint64
7273
GetProposerLookahead() solid.Uint64VectorSSZ
74+
GetBuilders() *solid.ListSSZ[*cltypes.Builder]
75+
GetLatestExecutionPayloadBid() *cltypes.ExecutionPayloadBid
76+
GetLatestBlockHash() common.Hash
77+
GetBuilderPendingWithdrawals() *solid.ListSSZ[*cltypes.BuilderPendingWithdrawal]
78+
GetBuilderPendingPayments() *solid.VectorSSZ[*cltypes.BuilderPendingPayment]
79+
GetBuilderPaymentQuorumThreshold() uint64
80+
GetNextWithdrawalBuilderIndex() cltypes.BuilderIndex
81+
GetPayloadExpectedWithdrawals() *solid.ListSSZ[*cltypes.Withdrawal]
82+
GetIndexedPayloadAttestation(payloadAttestation *cltypes.PayloadAttestation) (*cltypes.IndexedPayloadAttestation, error)
7383
}
7484

7585
type BeaconStateBasic interface {
@@ -143,6 +153,14 @@ type BeaconStateMutator interface {
143153
SetConsolidationBalanceToConsume(uint64)
144154
SetEarlistConsolidationEpoch(uint64)
145155
SetProposerLookahead(proposerLookahead solid.Uint64VectorSSZ)
156+
SetExecutionPayloadAvailability(slot uint64, available bool)
157+
SetBuilderPendingPayments(*solid.VectorSSZ[*cltypes.BuilderPendingPayment])
158+
SetBuilderPendingWithdrawals(withdrawals *solid.ListSSZ[*cltypes.BuilderPendingWithdrawal])
159+
SetPayloadExpectedWithdrawals(withdrawals *solid.ListSSZ[*cltypes.Withdrawal])
160+
SetLatestBlockHash(hash common.Hash)
161+
SetNextWithdrawalBuilderIndex(index cltypes.BuilderIndex)
162+
SetBuilders(builders *solid.ListSSZ[*cltypes.Builder])
163+
SetLatestExecutionPayloadBid(bid *cltypes.ExecutionPayloadBid)
146164

147165
AddEth1DataVote(vote *cltypes.Eth1Data)
148166
AddValidator(validator solid.Validator, balance uint64)

cl/beacon/handler/block_production.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ func (a *ApiHandler) produceBeaconBody(
610610
retryTime := 10 * time.Millisecond
611611
secsDiff := (targetSlot - baseBlock.Slot) * a.beaconChainCfg.SecondsPerSlot
612612
feeRecipient, _ := a.validatorParams.GetFeeRecipient(proposerIndex)
613-
clWithdrawals, _ := state.ExpectedWithdrawals(
613+
clWithdrawals := state.GetExpectedWithdrawals(
614614
baseState,
615615
targetSlot/a.beaconChainCfg.SlotsPerEpoch,
616616
)
617-
withdrawals := make([]*types.Withdrawal, 0, len(clWithdrawals))
618-
for _, w := range clWithdrawals {
617+
withdrawals := make([]*types.Withdrawal, 0, len(clWithdrawals.Withdrawals))
618+
for _, w := range clWithdrawals.Withdrawals {
619619
withdrawals = append(withdrawals, &types.Withdrawal{
620620
Index: w.Index,
621621
Amount: w.Amount,

cl/beacon/handler/builder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ func (a *ApiHandler) GetEth1V1BuilderStatesExpectedWithdrawals(w http.ResponseWr
6767
return nil, beaconhttp.NewEndpointError(http.StatusServiceUnavailable, errors.New("beacon node is syncing"))
6868
}
6969
if root == headRoot {
70-
var expectedWithdrawals []*cltypes.Withdrawal
71-
70+
var expectedWithdrawals *cltypes.ExpectedWithdrawals
7271
if err := a.syncedData.ViewHeadState(func(headState *state.CachingBeaconState) error {
73-
expectedWithdrawals, _ = state.ExpectedWithdrawals(headState, state.Epoch(headState))
72+
expectedWithdrawals = state.GetExpectedWithdrawals(headState, state.Epoch(headState))
7473
return nil
7574
}); err != nil {
7675
return nil, err
7776
}
78-
return newBeaconResponse(expectedWithdrawals).WithFinalized(false), nil
77+
return newBeaconResponse(expectedWithdrawals.Withdrawals).WithFinalized(false), nil
7978
}
8079
lookAhead := 1024
8180
for currSlot := *slot + 1; currSlot < *slot+uint64(lookAhead); currSlot++ {

cl/clparams/config.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ type BeaconChainConfig struct {
519519
DomainApplicationBuilder common.Bytes4 `json:"-"` // DomainApplicationBuilder defines the BLS signature domain for application builder.
520520
DomainBLSToExecutionChange common.Bytes4 `json:"-"` // DomainBLSToExecutionChange defines the BLS signature domain to change withdrawal addresses to ETH1 prefix
521521
DomainBlobSideCar common.Bytes4 `yaml:"DOMAIN_BLOB_SIDECAR" spec:"true" json:"DOMAIN_BLOB_SIDECAR"` // DomainBlobSideCar defines the BLS signature domain for blob sidecar verification
522+
DomainBeaconBuilder common.Bytes4 `json:"-"` // DomainBeaconBuilder defines the BLS signature domain for beacon builder.
523+
DomainPtcAttester common.Bytes4 `json:"-"` // DomainPtcAttester defines the BLS signature domain for proto-danksharding attestation verification.
524+
DomainProposerPreferences common.Bytes4 `json:"-"` // DomainProposerPreferences defines the BLS signature domain for proposer preferences.
522525

523526
// Slasher constants.
524527
PruneSlasherStoragePeriod uint64 `json:"-"` // PruneSlasherStoragePeriod defines the time period expressed in number of epochs were proof of stake network should prune attestation and block header store.
@@ -638,6 +641,14 @@ type BeaconChainConfig struct {
638641
// Fulu
639642
ValidatorCustodyRequirement uint64 `yaml:"VALIDATOR_CUSTODY_REQUIREMENT" spec:"true" json:"VALIDATOR_CUSTODY_REQUIREMENT,string"` // ValidatorCustodyRequirement defines the custody requirement for validators.
640643
BalancePerAdditionalCustodyGroup uint64 `yaml:"BALANCE_PER_ADDITIONAL_CUSTODY_GROUP" spec:"true" json:"BALANCE_PER_ADDITIONAL_CUSTODY_GROUP,string"` // BalancePerAdditionalCustodyGroup defines the balance required per additional custody group.
644+
645+
// Gloas
646+
BuilderWithdrawalPrefix ConfigByte `yaml:"-" json:"-"`
647+
MaxPayloadAttestations uint64 `yaml:"MAX_PAYLOAD_ATTESTATIONS" spec:"true" json:"MAX_PAYLOAD_ATTESTATIONS,string"` // MaxPayloadAttestations defines the maximum number of payload attestations in a block.
648+
BuilderRegistryLimit uint64 `yaml:"BUILDER_REGISTRY_LIMIT" spec:"true" json:"BUILDER_REGISTRY_LIMIT,string"` // BuilderRegistryLimit defines the upper bound of builders can participate in eth2.
649+
BuilderPendingWithdrawalsLimit uint64 `yaml:"BUILDER_PENDING_WITHDRAWALS_LIMIT" spec:"true" json:"BUILDER_PENDING_WITHDRAWALS_LIMIT,string"` // BuilderPendingWithdrawalsLimit defines the maximum number of pending withdrawals for builders.
650+
MaxBuildersPerWithdrawalsSweep uint64 `yaml:"MAX_BUILDERS_PER_WITHDRAWALS_SWEEP" spec:"true" json:"MAX_BUILDERS_PER_WITHDRAWALS_SWEEP,string"` // MaxBuildersPerWithdrawalsSweep bounds the size of the sweep searching for builder withdrawals per slot.
651+
MinBuilderWithdrawabilityDelay uint64 `yaml:"MIN_BUILDER_WITHDRAWABILITY_DELAY" spec:"true" json:"MIN_BUILDER_WITHDRAWABILITY_DELAY,string"` // MinBuilderWithdrawabilityDelay is the shortest amount of time a builder has to wait to withdraw.
641652
}
642653

643654
// GetBlobParameters returns the blob parameters at a given epoch
@@ -845,6 +856,9 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
845856
DomainApplicationMask: utils.Uint32ToBytes4(0x00000001),
846857
DomainApplicationBuilder: utils.Uint32ToBytes4(0x00000001),
847858
DomainBLSToExecutionChange: utils.Uint32ToBytes4(0x0A000000),
859+
DomainBeaconBuilder: utils.Uint32ToBytes4(0x0B000000),
860+
DomainPtcAttester: utils.Uint32ToBytes4(0x0C000000),
861+
DomainProposerPreferences: utils.Uint32ToBytes4(0x0D000000),
848862

849863
// Prysm constants.
850864
ConfigName: "mainnet",
@@ -963,6 +977,14 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
963977
{412672, 15},
964978
{419072, 21},
965979
},
980+
981+
// Gloas
982+
BuilderWithdrawalPrefix: 0x03,
983+
MaxPayloadAttestations: 4,
984+
BuilderRegistryLimit: 1 << 40,
985+
BuilderPendingWithdrawalsLimit: 1 << 20,
986+
MaxBuildersPerWithdrawalsSweep: 1 << 14,
987+
MinBuilderWithdrawabilityDelay: 64,
966988
}
967989

968990
func mainnetConfig() BeaconChainConfig {

cl/clparams/global.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package clparams
22

3+
import "math"
4+
5+
const (
6+
// non-configurable constants
7+
// For Gloas
8+
BuilderIndexFlag = uint64(1 << 40) // 2^40
9+
BuilderIndexSelfBuild = math.MaxUint64
10+
BuilderPaymentThresholdNumerator = uint64(6)
11+
BuilderPaymentThresholdDenominator = uint64(10)
12+
PtcSize = uint64(512)
13+
)
14+
315
var (
416
globalBeaconConfig *BeaconChainConfig
517
globalCaplinConfig *CaplinConfig

cl/cltypes/beacon_block.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,16 @@ type BeaconBody struct {
221221
// A summary of the current state of the beacon chain
222222
SyncAggregate *SyncAggregate `json:"sync_aggregate,omitempty"`
223223
// Data related to crosslink records and executing operations on the Ethereum 2.0 chain
224-
ExecutionPayload *Eth1Block `json:"execution_payload,omitempty"`
224+
ExecutionPayload *Eth1Block `json:"execution_payload,omitempty"` // will be removed after Gloas fork for EPBS
225225
// Withdrawals Diffs for Execution Layer
226226
ExecutionChanges *solid.ListSSZ[*SignedBLSToExecutionChange] `json:"bls_to_execution_changes,omitempty"`
227227
// The commitments for beacon chain blobs
228228
// With a max of 4 per block
229-
BlobKzgCommitments *solid.ListSSZ[*KZGCommitment] `json:"blob_kzg_commitments,omitempty"`
230-
ExecutionRequests *ExecutionRequests `json:"execution_requests,omitempty"`
229+
BlobKzgCommitments *solid.ListSSZ[*KZGCommitment] `json:"blob_kzg_commitments,omitempty"` // will be removed after Gloas fork for EPBS
230+
ExecutionRequests *ExecutionRequests `json:"execution_requests,omitempty"` // will be removed after Gloas fork for EPBS
231+
// Gloas
232+
SignedExecutionPayloadBid *SignedExecutionPayloadBid `json:"signed_execution_payload_bid,omitempty"`
233+
PayloadAttestations *solid.ListSSZ[*PayloadAttestation] `json:"payload_attestations,omitempty"`
231234

232235
// The version of the beacon chain
233236
Version clparams.StateVersion `json:"-"`
@@ -525,6 +528,14 @@ func (b *BeaconBody) GetExecutionRequests() *ExecutionRequests {
525528
return b.ExecutionRequests
526529
}
527530

531+
func (b *BeaconBody) GetSignedExecutionPayloadBid() *SignedExecutionPayloadBid {
532+
return b.SignedExecutionPayloadBid
533+
}
534+
535+
func (b *BeaconBody) GetPayloadAttestations() *solid.ListSSZ[*PayloadAttestation] {
536+
return b.PayloadAttestations
537+
}
538+
528539
func (b *BeaconBody) GetExecutionRequestsList() []hexutil.Bytes {
529540
return GetExecutionRequestsList(b.beaconCfg, b.ExecutionRequests)
530541
}

cl/cltypes/beacon_block_blinded.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131

3232
// make sure that the type implements the interface ssz2.ObjectSSZ
3333
var (
34-
_ ssz2.ObjectSSZ = (*BlindedBeaconBody)(nil)
35-
_ ssz2.ObjectSSZ = (*BlindedBeaconBlock)(nil)
36-
_ ssz2.ObjectSSZ = (*SignedBlindedBeaconBlock)(nil)
34+
_ ssz2.HashableSizedObjectSSZ = (*BlindedBeaconBody)(nil)
35+
_ ssz2.HashableSizedObjectSSZ = (*BlindedBeaconBlock)(nil)
36+
_ ssz.EncodableSSZ = (*SignedBlindedBeaconBlock)(nil)
3737

3838
_ GenericBeaconBlock = (*BlindedBeaconBlock)(nil)
3939
_ GenericBeaconBody = (*BlindedBeaconBody)(nil)
@@ -493,3 +493,11 @@ func (b *BlindedBeaconBody) GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExe
493493
func (b *BlindedBeaconBody) GetExecutionRequests() *ExecutionRequests {
494494
return b.ExecutionRequests
495495
}
496+
497+
func (b *BlindedBeaconBody) GetSignedExecutionPayloadBid() *SignedExecutionPayloadBid {
498+
return nil
499+
}
500+
501+
func (b *BlindedBeaconBody) GetPayloadAttestations() *solid.ListSSZ[*PayloadAttestation] {
502+
return nil
503+
}

cl/cltypes/beacon_block_interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ type GenericBeaconBody interface {
2929
GetBlobKzgCommitments() *solid.ListSSZ[*KZGCommitment]
3030
GetExecutionChanges() *solid.ListSSZ[*SignedBLSToExecutionChange]
3131
GetExecutionRequests() *ExecutionRequests
32+
GetSignedExecutionPayloadBid() *SignedExecutionPayloadBid
33+
GetPayloadAttestations() *solid.ListSSZ[*PayloadAttestation]
3234
}

cl/cltypes/column_sidecar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ var (
3333

3434
type DataColumnSidecar struct {
3535
BlockRoot common.Hash `json:"-"`
36-
Index uint64 `json:"index,string"` // index of the column
3736
Slot uint64 `json:"-"`
37+
Index uint64 `json:"index,string"` // index of the column
3838
Column *solid.ListSSZ[*Cell] `json:"column"`
3939
KzgCommitments *solid.ListSSZ[*KZGCommitment] `json:"kzg_commitments"`
4040
KzgProofs *solid.ListSSZ[*KZGProof] `json:"kzg_proofs"`

cl/cltypes/epbs_builder.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package cltypes
2+
3+
import (
4+
"github.com/erigontech/erigon/cl/merkle_tree"
5+
ssz2 "github.com/erigontech/erigon/cl/ssz"
6+
"github.com/erigontech/erigon/common"
7+
"github.com/erigontech/erigon/common/clonable"
8+
"github.com/erigontech/erigon/common/length"
9+
"github.com/erigontech/erigon/common/ssz"
10+
)
11+
12+
type BuilderIndex uint64
13+
14+
var (
15+
_ ssz.HashableSSZ = (*Builder)(nil)
16+
_ ssz.HashableSSZ = (*BuilderPendingWithdrawal)(nil)
17+
_ ssz.HashableSSZ = (*BuilderPendingPayment)(nil)
18+
19+
_ ssz2.SizedObjectSSZ = (*Builder)(nil)
20+
_ ssz2.SizedObjectSSZ = (*BuilderPendingWithdrawal)(nil)
21+
_ ssz2.SizedObjectSSZ = (*BuilderPendingPayment)(nil)
22+
)
23+
24+
// Builder represents a builder in the consensus layer.
25+
type Builder struct {
26+
Pubkey common.Bytes48 `json:"pubkey"`
27+
Version uint8 `json:"version"`
28+
ExecutionAddress common.Address `json:"execution_address"`
29+
Balance uint64 `json:"balance"`
30+
DepositEpoch uint64 `json:"deposit_epoch"`
31+
WithdrawableEpoch uint64 `json:"withdrawable_epoch"`
32+
}
33+
34+
func (b *Builder) EncodingSizeSSZ() int {
35+
return length.Bytes48 + 1 + length.Addr + 8 + 8 + 8
36+
}
37+
38+
func (b *Builder) Static() bool {
39+
return true
40+
}
41+
42+
func (b *Builder) EncodeSSZ(buf []byte) ([]byte, error) {
43+
return ssz2.MarshalSSZ(buf, b.Pubkey[:], b.Version, b.ExecutionAddress[:], b.Balance, b.DepositEpoch, b.WithdrawableEpoch)
44+
}
45+
46+
func (b *Builder) DecodeSSZ(buf []byte, version int) error {
47+
return ssz2.UnmarshalSSZ(buf, version, b.Pubkey[:], &b.Version, b.ExecutionAddress[:], &b.Balance, &b.DepositEpoch, &b.WithdrawableEpoch)
48+
}
49+
50+
func (b *Builder) Clone() clonable.Clonable {
51+
return &Builder{}
52+
}
53+
54+
func (b *Builder) HashSSZ() ([32]byte, error) {
55+
return merkle_tree.HashTreeRoot(b.Pubkey[:], uint64(b.Version), b.ExecutionAddress[:], b.Balance, b.DepositEpoch, b.WithdrawableEpoch)
56+
}
57+
58+
// BuilderPendingWithdrawal represents a pending withdrawal for a builder.
59+
type BuilderPendingWithdrawal struct {
60+
FeeRecipient common.Address `json:"fee_recipient"`
61+
Amount uint64 `json:"amount"`
62+
BuilderIndex BuilderIndex `json:"builder_index"`
63+
}
64+
65+
func (b *BuilderPendingWithdrawal) EncodingSizeSSZ() int {
66+
return length.Addr + 8 + 8
67+
}
68+
69+
func (b *BuilderPendingWithdrawal) Static() bool {
70+
return true
71+
}
72+
73+
func (b *BuilderPendingWithdrawal) EncodeSSZ(buf []byte) ([]byte, error) {
74+
return ssz2.MarshalSSZ(buf, b.FeeRecipient[:], b.Amount, b.BuilderIndex)
75+
}
76+
77+
func (b *BuilderPendingWithdrawal) DecodeSSZ(buf []byte, version int) error {
78+
return ssz2.UnmarshalSSZ(buf, version, b.FeeRecipient[:], &b.Amount, &b.BuilderIndex)
79+
}
80+
81+
func (b *BuilderPendingWithdrawal) Clone() clonable.Clonable {
82+
return &BuilderPendingWithdrawal{}
83+
}
84+
85+
func (b *BuilderPendingWithdrawal) HashSSZ() ([32]byte, error) {
86+
return merkle_tree.HashTreeRoot(b.FeeRecipient[:], b.Amount, b.BuilderIndex)
87+
}
88+
89+
// BuilderPendingPayment represents a pending payment for a builder.
90+
type BuilderPendingPayment struct {
91+
Weight uint64 `json:"weight"`
92+
Withdrawal *BuilderPendingWithdrawal `json:"withdrawal"`
93+
}
94+
95+
func (b *BuilderPendingPayment) HashSSZ() ([32]byte, error) {
96+
return merkle_tree.HashTreeRoot(&b.Weight, b.Withdrawal)
97+
}
98+
99+
func (b *BuilderPendingPayment) EncodingSizeSSZ() int {
100+
if b.Withdrawal == nil {
101+
return 8
102+
}
103+
return 8 + b.Withdrawal.EncodingSizeSSZ()
104+
}
105+
106+
func (b *BuilderPendingPayment) Static() bool {
107+
return true
108+
}
109+
110+
func (b *BuilderPendingPayment) EncodeSSZ(buf []byte) ([]byte, error) {
111+
return ssz2.MarshalSSZ(buf, b.Weight, b.Withdrawal)
112+
}
113+
114+
func (b *BuilderPendingPayment) DecodeSSZ(buf []byte, version int) error {
115+
b.Withdrawal = new(BuilderPendingWithdrawal)
116+
return ssz2.UnmarshalSSZ(buf, version, &b.Weight, b.Withdrawal)
117+
}
118+
119+
func (b *BuilderPendingPayment) Clone() clonable.Clonable {
120+
return &BuilderPendingPayment{
121+
Weight: b.Weight,
122+
Withdrawal: b.Withdrawal.Clone().(*BuilderPendingWithdrawal),
123+
}
124+
}

0 commit comments

Comments
 (0)