diff --git a/api/server/structs/block.go b/api/server/structs/block.go index 1adc7ef9c..13a64b6de 100644 --- a/api/server/structs/block.go +++ b/api/server/structs/block.go @@ -350,7 +350,7 @@ type BeaconBlockBodyElectra struct { Attestations []*AttestationElectra `json:"attestations"` Deposits []*Deposit `json:"deposits"` VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits"` - ExecutionPayload *ExecutionPayloadElectra `json:"execution_payload"` + ExecutionPayload *ExecutionPayloadDeneb `json:"execution_payload"` BlobKzgCommitments []string `json:"blob_kzg_commitments"` ExecutionRequests *ExecutionRequests `json:"execution_requests"` } @@ -379,17 +379,17 @@ func (s *SignedBlindedBeaconBlockElectra) SigString() string { } type BlindedBeaconBlockBodyElectra struct { - RandaoReveal string `json:"randao_reveal"` - Eth1Data *Eth1Data `json:"eth1_data"` - Graffiti string `json:"graffiti"` - ProposerSlashings []*ProposerSlashing `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingElectra `json:"attester_slashings"` - Attestations []*AttestationElectra `json:"attestations"` - Deposits []*Deposit `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits"` - ExecutionPayloadHeader *ExecutionPayloadHeaderElectra `json:"execution_payload_header"` - BlobKzgCommitments []string `json:"blob_kzg_commitments"` - ExecutionRequests *ExecutionRequests `json:"execution_requests"` + RandaoReveal string `json:"randao_reveal"` + Eth1Data *Eth1Data `json:"eth1_data"` + Graffiti string `json:"graffiti"` + ProposerSlashings []*ProposerSlashing `json:"proposer_slashings"` + AttesterSlashings []*AttesterSlashingElectra `json:"attester_slashings"` + Attestations []*AttestationElectra `json:"attestations"` + Deposits []*Deposit `json:"deposits"` + VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits"` + ExecutionPayloadHeader *ExecutionPayloadHeaderDeneb `json:"execution_payload_header"` + BlobKzgCommitments []string `json:"blob_kzg_commitments"` + ExecutionRequests *ExecutionRequests `json:"execution_requests"` } type SignedBeaconBlockHeaderContainer struct { @@ -501,8 +501,6 @@ type ExecutionPayloadDeneb struct { ExcessBlobGas string `json:"excess_blob_gas"` } -type ExecutionPayloadElectra = ExecutionPayloadDeneb - type ExecutionPayloadHeaderDeneb struct { ParentHash string `json:"parent_hash"` FeeRecipient string `json:"fee_recipient"` @@ -523,8 +521,6 @@ type ExecutionPayloadHeaderDeneb struct { ExcessBlobGas string `json:"excess_blob_gas"` } -type ExecutionPayloadHeaderElectra = ExecutionPayloadHeaderDeneb - type ExecutionRequests struct { Deposits []*DepositRequest `json:"deposits"` Withdrawals []*WithdrawalRequest `json:"withdrawals"` diff --git a/api/server/structs/conversions_block.go b/api/server/structs/conversions_block.go index 041e6a846..0b878c4db 100644 --- a/api/server/structs/conversions_block.go +++ b/api/server/structs/conversions_block.go @@ -2010,7 +2010,7 @@ func (b *BeaconBlockElectra) ToConsensus() (*eth.BeaconBlockElectra, error) { Attestations: atts, Deposits: deposits, VoluntaryExits: exits, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: payloadParentHash, FeeRecipient: payloadFeeRecipient, StateRoot: payloadStateRoot, @@ -2282,7 +2282,7 @@ func (b *BlindedBeaconBlockElectra) ToConsensus() (*eth.BlindedBeaconBlockElectr Attestations: atts, Deposits: deposits, VoluntaryExits: exits, - ExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ + ExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: payloadParentHash, FeeRecipient: payloadFeeRecipient, StateRoot: payloadStateRoot, diff --git a/api/server/structs/state.go b/api/server/structs/state.go index 890ea26f4..2408d0c84 100644 --- a/api/server/structs/state.go +++ b/api/server/structs/state.go @@ -134,36 +134,36 @@ type BeaconStateDeneb struct { } type BeaconStateElectra struct { - GenesisTime string `json:"genesis_time"` - GenesisValidatorsRoot string `json:"genesis_validators_root"` - Slot string `json:"slot"` - Fork *Fork `json:"fork"` - LatestBlockHeader *BeaconBlockHeader `json:"latest_block_header"` - BlockRoots []string `json:"block_roots"` - StateRoots []string `json:"state_roots"` - RewardAdjustmentFactor uint64 `json:"reward_adjustment_factor"` - Eth1Data *Eth1Data `json:"eth1_data"` - Eth1DataVotes []*Eth1Data `json:"eth1_data_votes"` - Eth1DepositIndex string `json:"eth1_deposit_index"` - Validators []*Validator `json:"validators"` - Balances []string `json:"balances"` - Reserves uint64 `json:"reserves"` - RandaoMixes []string `json:"randao_mixes"` - PreviousEpochParticipation []string `json:"previous_epoch_participation"` - CurrentEpochParticipation []string `json:"current_epoch_participation"` - JustificationBits string `json:"justification_bits"` - PreviousJustifiedCheckpoint *Checkpoint `json:"previous_justified_checkpoint"` - CurrentJustifiedCheckpoint *Checkpoint `json:"current_justified_checkpoint"` - FinalizedCheckpoint *Checkpoint `json:"finalized_checkpoint"` - InactivityScores []string `json:"inactivity_scores"` - LatestExecutionPayloadHeader *ExecutionPayloadHeaderElectra `json:"latest_execution_payload_header"` - NextWithdrawalIndex string `json:"next_withdrawal_index"` - NextWithdrawalValidatorIndex string `json:"next_withdrawal_validator_index"` - HistoricalSummaries []*HistoricalSummary `json:"historical_summaries"` - DepositRequestsStartIndex string `json:"deposit_requests_start_index"` - DepositBalanceToConsume string `json:"deposit_balance_to_consume"` - ExitBalanceToConsume string `json:"exit_balance_to_consume"` - EarliestExitEpoch string `json:"earliest_exit_epoch"` - PendingDeposits []*PendingDeposit `json:"pending_deposits"` - PendingPartialWithdrawals []*PendingPartialWithdrawal `json:"pending_partial_withdrawals"` + GenesisTime string `json:"genesis_time"` + GenesisValidatorsRoot string `json:"genesis_validators_root"` + Slot string `json:"slot"` + Fork *Fork `json:"fork"` + LatestBlockHeader *BeaconBlockHeader `json:"latest_block_header"` + BlockRoots []string `json:"block_roots"` + StateRoots []string `json:"state_roots"` + RewardAdjustmentFactor uint64 `json:"reward_adjustment_factor"` + Eth1Data *Eth1Data `json:"eth1_data"` + Eth1DataVotes []*Eth1Data `json:"eth1_data_votes"` + Eth1DepositIndex string `json:"eth1_deposit_index"` + Validators []*Validator `json:"validators"` + Balances []string `json:"balances"` + Reserves uint64 `json:"reserves"` + RandaoMixes []string `json:"randao_mixes"` + PreviousEpochParticipation []string `json:"previous_epoch_participation"` + CurrentEpochParticipation []string `json:"current_epoch_participation"` + JustificationBits string `json:"justification_bits"` + PreviousJustifiedCheckpoint *Checkpoint `json:"previous_justified_checkpoint"` + CurrentJustifiedCheckpoint *Checkpoint `json:"current_justified_checkpoint"` + FinalizedCheckpoint *Checkpoint `json:"finalized_checkpoint"` + InactivityScores []string `json:"inactivity_scores"` + LatestExecutionPayloadHeader *ExecutionPayloadHeaderDeneb `json:"latest_execution_payload_header"` + NextWithdrawalIndex string `json:"next_withdrawal_index"` + NextWithdrawalValidatorIndex string `json:"next_withdrawal_validator_index"` + HistoricalSummaries []*HistoricalSummary `json:"historical_summaries"` + DepositRequestsStartIndex string `json:"deposit_requests_start_index"` + DepositBalanceToConsume string `json:"deposit_balance_to_consume"` + ExitBalanceToConsume string `json:"exit_balance_to_consume"` + EarliestExitEpoch string `json:"earliest_exit_epoch"` + PendingDeposits []*PendingDeposit `json:"pending_deposits"` + PendingPartialWithdrawals []*PendingPartialWithdrawal `json:"pending_partial_withdrawals"` } diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index 9423f65ad..8b58b5fe1 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -362,15 +362,16 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, return emptyAttri } - var attr payloadattribute.Attributer - switch st.Version() { - case version.Deneb, version.Alpaca: + v := st.Version() + + if v >= version.Deneb { withdrawals, _, _, err := st.ExpectedWithdrawals() if err != nil { log.WithError(err).Error("Could not get expected withdrawals to get payload attribute") return emptyAttri } - attr, err = payloadattribute.New(&enginev1.PayloadAttributesV3{ + + attr, err := payloadattribute.New(&enginev1.PayloadAttributesV3{ Timestamp: uint64(t.Unix()), PrevRandao: prevRando, SuggestedFeeRecipient: val.FeeRecipient[:], @@ -381,13 +382,18 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, log.WithError(err).Error("Could not get payload attribute") return emptyAttri } - case version.Capella: + + return attr + } + + if v >= version.Capella { withdrawals, _, _, err := st.ExpectedWithdrawals() if err != nil { log.WithError(err).Error("Could not get expected withdrawals to get payload attribute") return emptyAttri } - attr, err = payloadattribute.New(&enginev1.PayloadAttributesV2{ + + attr, err := payloadattribute.New(&enginev1.PayloadAttributesV2{ Timestamp: uint64(t.Unix()), PrevRandao: prevRando, SuggestedFeeRecipient: val.FeeRecipient[:], @@ -397,8 +403,12 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, log.WithError(err).Error("Could not get payload attribute") return emptyAttri } - case version.Bellatrix: - attr, err = payloadattribute.New(&enginev1.PayloadAttributes{ + + return attr + } + + if v >= version.Bellatrix { + attr, err := payloadattribute.New(&enginev1.PayloadAttributes{ Timestamp: uint64(t.Unix()), PrevRandao: prevRando, SuggestedFeeRecipient: val.FeeRecipient[:], @@ -407,12 +417,12 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, log.WithError(err).Error("Could not get payload attribute") return emptyAttri } - default: - log.WithField("version", st.Version()).Error("Could not get payload attribute due to unknown state version") - return emptyAttri + + return attr } - return attr + log.WithField("version", version.String(st.Version())).Error("Could not get payload attribute due to unknown state version") + return emptyAttri } // removeInvalidBlockAndState removes the invalid block, blob and its corresponding state from the cache and DB. diff --git a/beacon-chain/core/blocks/genesis.go b/beacon-chain/core/blocks/genesis.go index 93ec14307..aa0cd7e3d 100644 --- a/beacon-chain/core/blocks/genesis.go +++ b/beacon-chain/core/blocks/genesis.go @@ -177,7 +177,7 @@ func NewGenesisBlockForState(ctx context.Context, st state.BeaconState) (interfa BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/beacon-chain/core/blocks/withdrawals_test.go b/beacon-chain/core/blocks/withdrawals_test.go index 63f918e78..54e47ffa7 100644 --- a/beacon-chain/core/blocks/withdrawals_test.go +++ b/beacon-chain/core/blocks/withdrawals_test.go @@ -903,7 +903,7 @@ func TestProcessWithdrawals(t *testing.T) { } st, err = state_native.InitializeFromProtoUnsafeElectra(spb) require.NoError(t, err) - p, err = consensusblocks.WrappedExecutionPayloadElectra(&enginev1.ExecutionPayloadElectra{Withdrawals: test.Args.Withdrawals}) + p, err = consensusblocks.WrappedExecutionPayloadDeneb(&enginev1.ExecutionPayloadDeneb{Withdrawals: test.Args.Withdrawals}) require.NoError(t, err) default: t.Fatalf("Add a beacon state setup for version %s", version.String(fork)) diff --git a/beacon-chain/core/electra/upgrade.go b/beacon-chain/core/electra/upgrade.go index db41e2aa9..f335b3e9d 100644 --- a/beacon-chain/core/electra/upgrade.go +++ b/beacon-chain/core/electra/upgrade.go @@ -209,7 +209,7 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error) CurrentJustifiedCheckpoint: beaconState.CurrentJustifiedCheckpoint(), FinalizedCheckpoint: beaconState.FinalizedCheckpoint(), InactivityScores: inactivityScores, - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: payloadHeader.ParentHash(), FeeRecipient: payloadHeader.FeeRecipient(), StateRoot: payloadHeader.StateRoot(), diff --git a/beacon-chain/core/electra/upgrade_test.go b/beacon-chain/core/electra/upgrade_test.go index db91711df..7b29cdcf6 100644 --- a/beacon-chain/core/electra/upgrade_test.go +++ b/beacon-chain/core/electra/upgrade_test.go @@ -79,7 +79,7 @@ func TestUpgradeToElectra(t *testing.T) { header, err := mSt.LatestExecutionPayloadHeader() require.NoError(t, err) - protoHeader, ok := header.Proto().(*enginev1.ExecutionPayloadHeaderElectra) + protoHeader, ok := header.Proto().(*enginev1.ExecutionPayloadHeaderDeneb) require.Equal(t, true, ok) prevHeader, err := preForkState.LatestExecutionPayloadHeader() require.NoError(t, err) @@ -88,7 +88,7 @@ func TestUpgradeToElectra(t *testing.T) { wdRoot, err := prevHeader.WithdrawalsRoot() require.NoError(t, err) - wanted := &enginev1.ExecutionPayloadHeaderElectra{ + wanted := &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: prevHeader.ParentHash(), FeeRecipient: prevHeader.FeeRecipient(), StateRoot: prevHeader.StateRoot(), diff --git a/beacon-chain/core/time/slot_epoch.go b/beacon-chain/core/time/slot_epoch.go index 55554f6d4..381fdbf35 100644 --- a/beacon-chain/core/time/slot_epoch.go +++ b/beacon-chain/core/time/slot_epoch.go @@ -99,6 +99,15 @@ func CanUpgradeToElectra(slot primitives.Slot) bool { return epochStart && electraEpoch } +// CanUpgradeToBadger returns true if the input `slot` can upgrade to Badger. +// Spec code: +// If state.slot % SLOTS_PER_EPOCH == 0 and compute_epoch_at_slot(state.slot) == BADGER_FORK_EPOCH +func CanUpgradeToBadger(slot primitives.Slot) bool { + epochStart := slots.IsEpochStart(slot) + badgerEpoch := slots.ToEpoch(slot) == params.BeaconConfig().BadgerForkEpoch + return epochStart && badgerEpoch +} + // CanProcessEpoch checks the eligibility to process epoch. // The epoch can be processed at the end of the last slot of every epoch. // diff --git a/beacon-chain/core/time/slot_epoch_test.go b/beacon-chain/core/time/slot_epoch_test.go index 6f2479115..1a18757ad 100644 --- a/beacon-chain/core/time/slot_epoch_test.go +++ b/beacon-chain/core/time/slot_epoch_test.go @@ -1,6 +1,7 @@ package time_test import ( + "fmt" "testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time" @@ -83,76 +84,6 @@ func TestNextEpoch_OK(t *testing.T) { } } -func TestCanUpgradeToAltair(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.AltairForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ - { - name: "not epoch start", - slot: 1, - want: false, - }, - { - name: "not altair epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, - }, - { - name: "altair epoch", - slot: primitives.Slot(params.BeaconConfig().AltairForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToAltair(tt.slot); got != tt.want { - t.Errorf("canUpgradeToAltair() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestCanUpgradeBellatrix(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.BellatrixForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ - { - name: "not epoch start", - slot: 1, - want: false, - }, - { - name: "not bellatrix epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, - }, - { - name: "bellatrix epoch", - slot: primitives.Slot(params.BeaconConfig().BellatrixForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToBellatrix(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToBellatrix() = %v, want %v", got, tt.want) - } - }) - } -} - func TestCanProcessEpoch_TrueOnEpochsLastSlot(t *testing.T) { tests := []struct { slot primitives.Slot @@ -264,107 +195,79 @@ func TestAltairCompatible(t *testing.T) { } } -func TestCanUpgradeToCapella(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.CapellaForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ - { - name: "not epoch start", - slot: 1, - want: false, - }, - { - name: "not capella epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, - }, - { - name: "capella epoch", - slot: primitives.Slot(params.BeaconConfig().CapellaForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToCapella(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToCapella() = %v, want %v", got, tt.want) - } - }) - } -} +func TestCanUpgradeTo(t *testing.T) { + beaconConfig := params.BeaconConfig() -func TestCanUpgradeToDeneb(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.DenebForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool + outerTestCases := []struct { + name string + forkEpoch *primitives.Epoch + upgradeFunc func(primitives.Slot) bool }{ { - name: "not epoch start", - slot: 1, - want: false, + name: "Altair", + forkEpoch: &beaconConfig.AltairForkEpoch, + upgradeFunc: time.CanUpgradeToAltair, }, { - name: "not deneb epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, + name: "Bellatrix", + forkEpoch: &beaconConfig.BellatrixForkEpoch, + upgradeFunc: time.CanUpgradeToBellatrix, }, { - name: "deneb epoch", - slot: primitives.Slot(params.BeaconConfig().DenebForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, + name: "Capella", + forkEpoch: &beaconConfig.CapellaForkEpoch, + upgradeFunc: time.CanUpgradeToCapella, }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToDeneb(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToDeneb() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestCanUpgradeToElectra(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.AlpacaForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ { - name: "not epoch start", - slot: 1, - want: false, + name: "Deneb", + forkEpoch: &beaconConfig.DenebForkEpoch, + upgradeFunc: time.CanUpgradeToDeneb, }, { - name: "not alpaca epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, + name: "Alpaca", + forkEpoch: &beaconConfig.AlpacaForkEpoch, + upgradeFunc: time.CanUpgradeToElectra, }, { - name: "alpaca epoch", - slot: primitives.Slot(params.BeaconConfig().AlpacaForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, + name: "Badger", + forkEpoch: &beaconConfig.BadgerForkEpoch, + upgradeFunc: time.CanUpgradeToBadger, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToElectra(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToElectra() = %v, want %v", got, tt.want) - } - }) + + for _, otc := range outerTestCases { + params.SetupTestConfigCleanup(t) + *otc.forkEpoch = 5 + params.OverrideBeaconConfig(beaconConfig) + + innerTestCases := []struct { + name string + slot primitives.Slot + want bool + }{ + { + name: "not epoch start", + slot: 1, + want: false, + }, + { + name: fmt.Sprintf("not %s epoch", otc.name), + slot: params.BeaconConfig().SlotsPerEpoch, + want: false, + }, + { + name: fmt.Sprintf("%s epoch", otc.name), + slot: primitives.Slot(*otc.forkEpoch) * params.BeaconConfig().SlotsPerEpoch, + want: true, + }, + } + + for _, itc := range innerTestCases { + t.Run(fmt.Sprintf("%s-%s", otc.name, itc.name), func(t *testing.T) { + if got := otc.upgradeFunc(itc.slot); got != itc.want { + t.Errorf("CanUpgradeTo%s() = %v, want %v", otc.name, got, itc.want) + } + }) + } } } diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 454fa3182..13c103b14 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -299,7 +299,7 @@ func ProcessSlotsCore(ctx context.Context, span trace.Span, state state.BeaconSt func ProcessEpoch(ctx context.Context, state state.BeaconState) (state.BeaconState, error) { var err error if time.CanProcessEpoch(state) { - if state.Version() == version.Alpaca { + if state.Version() >= version.Alpaca { if err = electra.ProcessEpoch(ctx, state); err != nil { return nil, errors.Wrap(err, fmt.Sprintf("could not process %s epoch", version.String(state.Version()))) } @@ -323,9 +323,11 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta defer span.End() var err error + + slot := state.Slot() upgraded := false - if time.CanUpgradeToAltair(state.Slot()) { + if time.CanUpgradeToAltair(slot) { state, err = altair.UpgradeToAltair(ctx, state) if err != nil { tracing.AnnotateError(span, err) @@ -334,7 +336,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToBellatrix(state.Slot()) { + if time.CanUpgradeToBellatrix(slot) { state, err = execution.UpgradeToBellatrix(state) if err != nil { tracing.AnnotateError(span, err) @@ -343,7 +345,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToCapella(state.Slot()) { + if time.CanUpgradeToCapella(slot) { state, err = capella.UpgradeToCapella(state) if err != nil { tracing.AnnotateError(span, err) @@ -352,7 +354,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToDeneb(state.Slot()) { + if time.CanUpgradeToDeneb(slot) { state, err = deneb.UpgradeToDeneb(state) if err != nil { tracing.AnnotateError(span, err) @@ -361,7 +363,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToElectra(state.Slot()) { + if time.CanUpgradeToElectra(slot) { state, err = electra.UpgradeToElectra(state) if err != nil { tracing.AnnotateError(span, err) @@ -371,7 +373,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta } if upgraded { - log.Debugf("upgraded state to %s", version.String(state.Version())) + log.WithField("version", version.String(state.Version())).Debug("Upgraded state to") } return state, nil diff --git a/beacon-chain/core/validators/slashing.go b/beacon-chain/core/validators/slashing.go index 21d765945..645a04600 100644 --- a/beacon-chain/core/validators/slashing.go +++ b/beacon-chain/core/validators/slashing.go @@ -9,25 +9,35 @@ import ( // SlashingParamsPerVersion returns the slashing parameters for the given state version. func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, err error) { cfg := params.BeaconConfig() - switch v { - case version.Phase0: - slashingQuotient = cfg.MinSlashingPenaltyQuotient + + if v >= version.Alpaca { + slashingQuotient = cfg.MinSlashingPenaltyQuotientAlpaca + proposerRewardQuotient = cfg.ProposerRewardQuotient + whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotientAlpaca + return + } + + if v >= version.Bellatrix { + slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Altair: + return + } + + if v >= version.Altair { slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Bellatrix, version.Capella, version.Deneb: - slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix + return + } + + if v >= version.Phase0 { + slashingQuotient = cfg.MinSlashingPenaltyQuotient proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Alpaca: - slashingQuotient = cfg.MinSlashingPenaltyQuotientAlpaca - proposerRewardQuotient = cfg.ProposerRewardQuotient - whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotientAlpaca - default: - err = errors.New("unknown state version") + return } + + err = errors.Errorf("unknown state version %s", version.String(v)) return } diff --git a/beacon-chain/db/kv/state_test.go b/beacon-chain/db/kv/state_test.go index 448a5ff0e..cb6ff968e 100644 --- a/beacon-chain/db/kv/state_test.go +++ b/beacon-chain/db/kv/state_test.go @@ -137,7 +137,7 @@ func TestState_CanSaveRetrieve(t *testing.T) { st, err := util.NewBeaconStateElectra() require.NoError(t, err) require.NoError(t, st.SetSlot(100)) - p, err := blocks.WrappedExecutionPayloadHeaderElectra(&enginev1.ExecutionPayloadHeaderElectra{ + p, err := blocks.WrappedExecutionPayloadHeaderDeneb(&enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/beacon-chain/execution/engine_client.go b/beacon-chain/execution/engine_client.go index 65104cc34..f49fd21fb 100644 --- a/beacon-chain/execution/engine_client.go +++ b/beacon-chain/execution/engine_client.go @@ -233,7 +233,7 @@ func (s *Service) ForkchoiceUpdated( if err != nil { return nil, nil, handleRPCError(err) } - case version.Deneb, version.Alpaca: + case version.Deneb, version.Alpaca, version.Badger: a, err := attrs.PbV3() if err != nil { return nil, nil, err @@ -643,43 +643,7 @@ func fullPayloadFromPayloadBody( return nil, errors.New("execution block and header cannot be nil") } - switch bVersion { - case version.Bellatrix: - return blocks.WrappedExecutionPayload(&pb.ExecutionPayload{ - ParentHash: header.ParentHash(), - FeeRecipient: header.FeeRecipient(), - StateRoot: header.StateRoot(), - ReceiptsRoot: header.ReceiptsRoot(), - LogsBloom: header.LogsBloom(), - PrevRandao: header.PrevRandao(), - BlockNumber: header.BlockNumber(), - GasLimit: header.GasLimit(), - GasUsed: header.GasUsed(), - Timestamp: header.Timestamp(), - ExtraData: header.ExtraData(), - BaseFeePerGas: header.BaseFeePerGas(), - BlockHash: header.BlockHash(), - Transactions: pb.RecastHexutilByteSlice(body.Transactions), - }) - case version.Capella: - return blocks.WrappedExecutionPayloadCapella(&pb.ExecutionPayloadCapella{ - ParentHash: header.ParentHash(), - FeeRecipient: header.FeeRecipient(), - StateRoot: header.StateRoot(), - ReceiptsRoot: header.ReceiptsRoot(), - LogsBloom: header.LogsBloom(), - PrevRandao: header.PrevRandao(), - BlockNumber: header.BlockNumber(), - GasLimit: header.GasLimit(), - GasUsed: header.GasUsed(), - Timestamp: header.Timestamp(), - ExtraData: header.ExtraData(), - BaseFeePerGas: header.BaseFeePerGas(), - BlockHash: header.BlockHash(), - Transactions: pb.RecastHexutilByteSlice(body.Transactions), - Withdrawals: body.Withdrawals, - }) // We can't get the block value and don't care about the block value for this instance - case version.Deneb, version.Alpaca: + if bVersion >= version.Deneb { ebg, err := header.ExcessBlobGas() if err != nil { return nil, errors.Wrap(err, "unable to extract ExcessBlobGas attribute from execution payload header") @@ -708,9 +672,48 @@ func fullPayloadFromPayloadBody( ExcessBlobGas: ebg, BlobGasUsed: bgu, }) // We can't get the block value and don't care about the block value for this instance - default: - return nil, fmt.Errorf("unknown execution block version for payload %d", bVersion) } + + if bVersion >= version.Capella { + return blocks.WrappedExecutionPayloadCapella(&pb.ExecutionPayloadCapella{ + ParentHash: header.ParentHash(), + FeeRecipient: header.FeeRecipient(), + StateRoot: header.StateRoot(), + ReceiptsRoot: header.ReceiptsRoot(), + LogsBloom: header.LogsBloom(), + PrevRandao: header.PrevRandao(), + BlockNumber: header.BlockNumber(), + GasLimit: header.GasLimit(), + GasUsed: header.GasUsed(), + Timestamp: header.Timestamp(), + ExtraData: header.ExtraData(), + BaseFeePerGas: header.BaseFeePerGas(), + BlockHash: header.BlockHash(), + Transactions: pb.RecastHexutilByteSlice(body.Transactions), + Withdrawals: body.Withdrawals, + }) // We can't get the block value and don't care about the block value for this instance + } + + if bVersion >= version.Bellatrix { + return blocks.WrappedExecutionPayload(&pb.ExecutionPayload{ + ParentHash: header.ParentHash(), + FeeRecipient: header.FeeRecipient(), + StateRoot: header.StateRoot(), + ReceiptsRoot: header.ReceiptsRoot(), + LogsBloom: header.LogsBloom(), + PrevRandao: header.PrevRandao(), + BlockNumber: header.BlockNumber(), + GasLimit: header.GasLimit(), + GasUsed: header.GasUsed(), + Timestamp: header.Timestamp(), + ExtraData: header.ExtraData(), + BaseFeePerGas: header.BaseFeePerGas(), + BlockHash: header.BlockHash(), + Transactions: pb.RecastHexutilByteSlice(body.Transactions), + }) + } + + return nil, fmt.Errorf("unknown execution block version for payload %s", version.String(bVersion)) } // Handles errors received from the RPC server according to the specification. @@ -802,9 +805,8 @@ func tDStringToUint256(td string) (*uint256.Int, error) { } func EmptyExecutionPayload(v int) (proto.Message, error) { - switch v { - case version.Bellatrix: - return &pb.ExecutionPayload{ + if v >= version.Deneb { + return &pb.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -815,8 +817,11 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { BaseFeePerGas: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), Transactions: make([][]byte, 0), + Withdrawals: make([]*pb.Withdrawal, 0), }, nil - case version.Capella: + } + + if v >= version.Capella { return &pb.ExecutionPayloadCapella{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), @@ -830,8 +835,10 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { Transactions: make([][]byte, 0), Withdrawals: make([]*pb.Withdrawal, 0), }, nil - case version.Deneb, version.Alpaca: - return &pb.ExecutionPayloadDeneb{ + } + + if v >= version.Bellatrix { + return &pb.ExecutionPayload{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -842,11 +849,10 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { BaseFeePerGas: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), Transactions: make([][]byte, 0), - Withdrawals: make([]*pb.Withdrawal, 0), }, nil - default: - return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } + + return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } func toBlockNumArg(number *big.Int) string { diff --git a/beacon-chain/execution/payload_body_test.go b/beacon-chain/execution/payload_body_test.go index 88ab139b0..553e3c68c 100644 --- a/beacon-chain/execution/payload_body_test.go +++ b/beacon-chain/execution/payload_body_test.go @@ -17,14 +17,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/time/slots" ) -type versioner struct { - version int -} - -func (v versioner) Version() int { - return v.version -} - func payloadToBody(t *testing.T, ed interfaces.ExecutionData) *pb.ExecutionPayloadBody { body := &pb.ExecutionPayloadBody{} txs, err := ed.Transactions() diff --git a/beacon-chain/operations/attestations/kv/aggregated.go b/beacon-chain/operations/attestations/kv/aggregated.go index 8851d28be..2c3c36a5b 100644 --- a/beacon-chain/operations/attestations/kv/aggregated.go +++ b/beacon-chain/operations/attestations/kv/aggregated.go @@ -236,7 +236,7 @@ func (c *AttCaches) AggregatedAttestationsBySlotIndexElectra( c.aggregatedAttLock.RLock() defer c.aggregatedAttLock.RUnlock() for _, as := range c.aggregatedAtt { - if as[0].Version() == version.Alpaca && slot == as[0].GetData().Slot && as[0].CommitteeBitsVal().BitAt(uint64(committeeIndex)) { + if as[0].Version() >= version.Alpaca && slot == as[0].GetData().Slot && as[0].CommitteeBitsVal().BitAt(uint64(committeeIndex)) { for _, a := range as { att, ok := a.(*ethpb.AttestationElectra) // This will never fail in practice because we asserted the version diff --git a/beacon-chain/operations/attestations/kv/unaggregated.go b/beacon-chain/operations/attestations/kv/unaggregated.go index 83d3d6e79..b112b3359 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated.go +++ b/beacon-chain/operations/attestations/kv/unaggregated.go @@ -116,7 +116,7 @@ func (c *AttCaches) UnaggregatedAttestationsBySlotIndexElectra( unAggregatedAtts := c.unAggregatedAtt for _, a := range unAggregatedAtts { - if a.Version() == version.Alpaca && slot == a.GetData().Slot && a.CommitteeBitsVal().BitAt(uint64(committeeIndex)) { + if a.Version() >= version.Alpaca && slot == a.GetData().Slot && a.CommitteeBitsVal().BitAt(uint64(committeeIndex)) { att, ok := a.(*ethpb.AttestationElectra) // This will never fail in practice because we asserted the version if ok { diff --git a/beacon-chain/p2p/fork_watcher.go b/beacon-chain/p2p/fork_watcher.go index 3b1097b6c..27650c222 100644 --- a/beacon-chain/p2p/fork_watcher.go +++ b/beacon-chain/p2p/fork_watcher.go @@ -18,7 +18,8 @@ func (s *Service) forkWatcher() { currEpoch == params.BeaconConfig().BellatrixForkEpoch || currEpoch == params.BeaconConfig().CapellaForkEpoch || currEpoch == params.BeaconConfig().DenebForkEpoch || - currEpoch == params.BeaconConfig().AlpacaForkEpoch { + currEpoch == params.BeaconConfig().AlpacaForkEpoch || + currEpoch == params.BeaconConfig().BadgerForkEpoch { // If we are in the fork epoch, we update our enr with // the updated fork digest. These repeatedly does // this over the epoch, which might be slightly wasteful diff --git a/beacon-chain/p2p/gossip_topic_mappings_test.go b/beacon-chain/p2p/gossip_topic_mappings_test.go index da9afbfdf..53770752b 100644 --- a/beacon-chain/p2p/gossip_topic_mappings_test.go +++ b/beacon-chain/p2p/gossip_topic_mappings_test.go @@ -30,17 +30,20 @@ func TestGossipTopicMappings_CorrectType(t *testing.T) { capellaForkEpoch := primitives.Epoch(300) denebForkEpoch := primitives.Epoch(400) alpacaForkEpoch := primitives.Epoch(500) + badgerForkEpoch := primitives.Epoch(600) bCfg.AltairForkEpoch = altairForkEpoch bCfg.BellatrixForkEpoch = bellatrixForkEpoch bCfg.CapellaForkEpoch = capellaForkEpoch bCfg.DenebForkEpoch = denebForkEpoch bCfg.AlpacaForkEpoch = alpacaForkEpoch + bCfg.BadgerForkEpoch = badgerForkEpoch bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AltairForkVersion)] = primitives.Epoch(100) bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.BellatrixForkVersion)] = primitives.Epoch(200) bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.CapellaForkVersion)] = primitives.Epoch(300) bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.DenebForkVersion)] = primitives.Epoch(400) bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AlpacaForkVersion)] = primitives.Epoch(500) + bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.BadgerForkVersion)] = primitives.Epoch(600) params.OverrideBeaconConfig(bCfg) // Phase 0 diff --git a/beacon-chain/p2p/pubsub_filter.go b/beacon-chain/p2p/pubsub_filter.go index a50eadba8..9c06fb249 100644 --- a/beacon-chain/p2p/pubsub_filter.go +++ b/beacon-chain/p2p/pubsub_filter.go @@ -74,6 +74,11 @@ func (s *Service) CanSubscribe(topic string) bool { log.WithError(err).Error("Could not determine Alpaca fork digest") return false } + badgerForkDigest, err := forks.ForkDigestFromEpoch(params.BeaconConfig().BadgerForkEpoch, s.genesisValidatorsRoot) + if err != nil { + log.WithError(err).Error("Could not determine Badger fork digest") + return false + } switch parts[2] { case fmt.Sprintf("%x", phase0ForkDigest): case fmt.Sprintf("%x", altairForkDigest): @@ -81,6 +86,7 @@ func (s *Service) CanSubscribe(topic string) bool { case fmt.Sprintf("%x", capellaForkDigest): case fmt.Sprintf("%x", denebForkDigest): case fmt.Sprintf("%x", alpacaForkDigest): + case fmt.Sprintf("%x", badgerForkDigest): default: return false } diff --git a/beacon-chain/p2p/types/object_mapping.go b/beacon-chain/p2p/types/object_mapping.go index c8785c5ef..1737265fb 100644 --- a/beacon-chain/p2p/types/object_mapping.go +++ b/beacon-chain/p2p/types/object_mapping.go @@ -67,7 +67,7 @@ func InitializeDataMaps() { }, bytesutil.ToBytes4(params.BeaconConfig().AlpacaForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) { return blocks.NewSignedBeaconBlock( - ðpb.SignedBeaconBlockElectra{Block: ðpb.BeaconBlockElectra{Body: ðpb.BeaconBlockBodyElectra{ExecutionPayload: &enginev1.ExecutionPayloadElectra{}}}}, + ðpb.SignedBeaconBlockElectra{Block: ðpb.BeaconBlockElectra{Body: ðpb.BeaconBlockBodyElectra{ExecutionPayload: &enginev1.ExecutionPayloadDeneb{}}}}, ) }, } diff --git a/beacon-chain/rpc/eth/config/handlers_test.go b/beacon-chain/rpc/eth/config/handlers_test.go index 38fb7eecb..700cc5a84 100644 --- a/beacon-chain/rpc/eth/config/handlers_test.go +++ b/beacon-chain/rpc/eth/config/handlers_test.go @@ -78,6 +78,8 @@ func TestGetSpec(t *testing.T) { config.DenebForkEpoch = 103 config.AlpacaForkVersion = []byte("AlpacaForkVersion") config.AlpacaForkEpoch = 104 + config.BadgerForkVersion = []byte("BadgerForkVersion") + config.BadgerForkEpoch = 105 config.BLSWithdrawalPrefixByte = byte('b') config.ETH1AddressWithdrawalPrefixByte = byte('c') config.GenesisDelay = 24 @@ -198,7 +200,7 @@ func TestGetSpec(t *testing.T) { data, ok := resp.Data.(map[string]interface{}) require.Equal(t, true, ok) - assert.Equal(t, 157, len(data)) + assert.Equal(t, 159, len(data)) for k, v := range data { t.Run(k, func(t *testing.T) { switch k { @@ -274,6 +276,10 @@ func TestGetSpec(t *testing.T) { assert.Equal(t, "0x"+hex.EncodeToString([]byte("AlpacaForkVersion")), v) case "ALPACA_FORK_EPOCH": assert.Equal(t, "104", v) + case "BADGER_FORK_VERSION": + assert.Equal(t, "0x"+hex.EncodeToString([]byte("BadgerForkVersion")), v) + case "BADGER_FORK_EPOCH": + assert.Equal(t, "105", v) case "MIN_ANCHOR_POW_BLOCK_DIFFICULTY": assert.Equal(t, "1000", v) case "BLS_WITHDRAWAL_PREFIX": diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload.go index d73c0a86f..079d07c54 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload.go @@ -136,7 +136,7 @@ func (vs *Server) getLocalPayloadFromEngine( } var attr payloadattribute.Attributer switch st.Version() { - case version.Deneb, version.Alpaca: + case version.Deneb, version.Alpaca, version.Badger: withdrawals, _, _, err := st.ExpectedWithdrawals() if err != nil { return nil, err diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index 3840d450f..4132a2f2a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -590,7 +590,7 @@ func TestServer_GetBeaconBlock_Alpaca(t *testing.T) { RandaoReveal: genesis.Block.Body.RandaoReveal, Graffiti: genesis.Block.Body.Graffiti, Eth1Data: genesis.Block.Body.Eth1Data, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -618,7 +618,7 @@ func TestServer_GetBeaconBlock_Alpaca(t *testing.T) { require.NoError(t, err) timeStamp, err := slots.ToTime(beaconState.GenesisTime(), alpacaSlot+1) require.NoError(t, err) - payload := &enginev1.ExecutionPayloadElectra{ + payload := &enginev1.ExecutionPayloadDeneb{ Timestamp: uint64(timeStamp.Unix()), ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), diff --git a/beacon-chain/state/state-native/getters_payload_header.go b/beacon-chain/state/state-native/getters_payload_header.go index 7e51cea3c..d269058ad 100644 --- a/beacon-chain/state/state-native/getters_payload_header.go +++ b/beacon-chain/state/state-native/getters_payload_header.go @@ -17,14 +17,17 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (interfaces.ExecutionData, b.lock.RLock() defer b.lock.RUnlock() - switch b.version { - case version.Bellatrix: - return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeader.Copy()) - case version.Capella: - return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella.Copy()) - case version.Deneb, version.Alpaca: + if b.version >= version.Deneb { return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDeneb.Copy()) - default: - return nil, fmt.Errorf("unsupported version (%s) for latest execution payload header", version.String(b.version)) } + + if b.version >= version.Capella { + return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella.Copy()) + } + + if b.version >= version.Bellatrix { + return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeader.Copy()) + } + + return nil, fmt.Errorf("unsupported version (%s) for latest execution payload header", version.String(b.version)) } diff --git a/beacon-chain/state/state-native/getters_withdrawal_test.go b/beacon-chain/state/state-native/getters_withdrawal_test.go index 68929ccf1..70559dea2 100644 --- a/beacon-chain/state/state-native/getters_withdrawal_test.go +++ b/beacon-chain/state/state-native/getters_withdrawal_test.go @@ -65,7 +65,7 @@ func TestNextWithdrawalValidatorIndex(t *testing.T) { } func TestExpectedWithdrawals(t *testing.T) { - for _, stateVersion := range []int{version.Capella, version.Deneb, version.Alpaca} { + for _, stateVersion := range []int{version.Capella, version.Deneb, version.Alpaca, version.Badger} { t.Run(version.String(stateVersion), func(t *testing.T) { params.BeaconConfig().MinSlashingWithdrawableDelay = 0 params.BeaconConfig().MinValidatorWithdrawabilityDelay = 0 diff --git a/beacon-chain/state/state-native/hasher.go b/beacon-chain/state/state-native/hasher.go index 594d0f67b..c4000bc8f 100644 --- a/beacon-chain/state/state-native/hasher.go +++ b/beacon-chain/state/state-native/hasher.go @@ -41,6 +41,8 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateDenebFieldCount) case version.Alpaca: fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateAlpacaFieldCount) + case version.Badger: + fieldRoots = make([][]byte, params.BeaconConfig().BeaconStateBadgerFieldCount) default: return nil, fmt.Errorf("unknown state version %s", version.String(state.version)) } diff --git a/beacon-chain/state/state-native/setters_payload_header.go b/beacon-chain/state/state-native/setters_payload_header.go index 9ca96675e..535af8206 100644 --- a/beacon-chain/state/state-native/setters_payload_header.go +++ b/beacon-chain/state/state-native/setters_payload_header.go @@ -45,7 +45,7 @@ func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionDa b.markFieldAsDirty(types.LatestExecutionPayloadHeaderCapella) return nil case *enginev1.ExecutionPayloadDeneb: - if b.version != version.Deneb && b.version != version.Alpaca { + if !(b.version >= version.Deneb) { return fmt.Errorf("wrong state version (%s) for deneb execution payload", version.String(b.version)) } latest, err := consensusblocks.PayloadToHeaderDeneb(val) @@ -70,7 +70,7 @@ func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionDa b.markFieldAsDirty(types.LatestExecutionPayloadHeaderCapella) return nil case *enginev1.ExecutionPayloadHeaderDeneb: - if b.version != version.Deneb && b.version != version.Alpaca { + if !(b.version >= version.Deneb) { return fmt.Errorf("wrong state version (%s) for deneb execution payload header", version.String(b.version)) } b.latestExecutionPayloadHeaderDeneb = header diff --git a/beacon-chain/state/state-native/setters_payload_header_test.go b/beacon-chain/state/state-native/setters_payload_header_test.go index b9f806591..74dda536a 100644 --- a/beacon-chain/state/state-native/setters_payload_header_test.go +++ b/beacon-chain/state/state-native/setters_payload_header_test.go @@ -35,7 +35,7 @@ func TestSetLatestExecutionPayloadHeader(t *testing.T) { }(), func() interfaces.ExecutionData { e := util.NewBeaconBlockElectra().Block.Body.ExecutionPayload - ee, err := blocks.WrappedExecutionPayloadElectra(e) + ee, err := blocks.WrappedExecutionPayloadDeneb(e) require.NoError(t, err) return ee }(), diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index 6bc4518fc..c887cd952 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -24,85 +24,87 @@ import ( "google.golang.org/protobuf/proto" ) -var phase0Fields = []types.FieldIndex{ - types.GenesisTime, - types.GenesisValidatorsRoot, - types.Slot, - types.Fork, - types.LatestBlockHeader, - types.BlockRoots, - types.StateRoots, - types.RewardAdjustmentFactor, - types.Eth1Data, - types.Eth1DataVotes, - types.Eth1DepositIndex, - types.Validators, - types.Balances, - types.Reserves, - types.RandaoMixes, - types.PreviousEpochAttestations, - types.CurrentEpochAttestations, - types.JustificationBits, - types.PreviousJustifiedCheckpoint, - types.CurrentJustifiedCheckpoint, - types.FinalizedCheckpoint, -} - -var altairFields = []types.FieldIndex{ - types.GenesisTime, - types.GenesisValidatorsRoot, - types.Slot, - types.Fork, - types.LatestBlockHeader, - types.BlockRoots, - types.StateRoots, - types.RewardAdjustmentFactor, - types.Eth1Data, - types.Eth1DataVotes, - types.Eth1DepositIndex, - types.Validators, - types.Balances, - types.Reserves, - types.RandaoMixes, - types.PreviousEpochParticipationBits, - types.CurrentEpochParticipationBits, - types.JustificationBits, - types.PreviousJustifiedCheckpoint, - types.CurrentJustifiedCheckpoint, - types.FinalizedCheckpoint, - types.InactivityScores, -} - -var bellatrixFields = append(altairFields, types.LatestExecutionPayloadHeader) - -var capellaFields = append( - altairFields, - types.LatestExecutionPayloadHeaderCapella, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, -) - -var denebFields = append( - altairFields, - types.LatestExecutionPayloadHeaderDeneb, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, -) - -var electraFields = append( - altairFields, - types.LatestExecutionPayloadHeaderDeneb, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, - types.DepositRequestsStartIndex, - types.DepositBalanceToConsume, - types.ExitBalanceToConsume, - types.EarliestExitEpoch, - types.PendingDeposits, - types.PendingPartialWithdrawals, +var ( + phase0Fields = []types.FieldIndex{ + types.GenesisTime, + types.GenesisValidatorsRoot, + types.Slot, + types.Fork, + types.LatestBlockHeader, + types.BlockRoots, + types.StateRoots, + types.RewardAdjustmentFactor, + types.Eth1Data, + types.Eth1DataVotes, + types.Eth1DepositIndex, + types.Validators, + types.Balances, + types.Reserves, + types.RandaoMixes, + types.PreviousEpochAttestations, + types.CurrentEpochAttestations, + types.JustificationBits, + types.PreviousJustifiedCheckpoint, + types.CurrentJustifiedCheckpoint, + types.FinalizedCheckpoint, + } + + altairFields = []types.FieldIndex{ + types.GenesisTime, + types.GenesisValidatorsRoot, + types.Slot, + types.Fork, + types.LatestBlockHeader, + types.BlockRoots, + types.StateRoots, + types.RewardAdjustmentFactor, + types.Eth1Data, + types.Eth1DataVotes, + types.Eth1DepositIndex, + types.Validators, + types.Balances, + types.Reserves, + types.RandaoMixes, + types.PreviousEpochParticipationBits, + types.CurrentEpochParticipationBits, + types.JustificationBits, + types.PreviousJustifiedCheckpoint, + types.CurrentJustifiedCheckpoint, + types.FinalizedCheckpoint, + types.InactivityScores, + } + + bellatrixFields = append(altairFields, types.LatestExecutionPayloadHeader) + + capellaFields = append( + altairFields, + types.LatestExecutionPayloadHeaderCapella, + types.NextWithdrawalIndex, + types.NextWithdrawalValidatorIndex, + types.HistoricalSummaries, + ) + + denebFields = append( + altairFields, + types.LatestExecutionPayloadHeaderDeneb, + types.NextWithdrawalIndex, + types.NextWithdrawalValidatorIndex, + types.HistoricalSummaries, + ) + + electraFields = append( + altairFields, + types.LatestExecutionPayloadHeaderDeneb, + types.NextWithdrawalIndex, + types.NextWithdrawalValidatorIndex, + types.HistoricalSummaries, + types.DepositRequestsStartIndex, + types.DepositBalanceToConsume, + types.ExitBalanceToConsume, + types.EarliestExitEpoch, + types.PendingDeposits, + types.PendingPartialWithdrawals, + ) ) const ( diff --git a/beacon-chain/state/stategen/replay_test.go b/beacon-chain/state/stategen/replay_test.go index d82c38783..a4d1263ab 100644 --- a/beacon-chain/state/stategen/replay_test.go +++ b/beacon-chain/state/stategen/replay_test.go @@ -155,6 +155,8 @@ func TestReplayBlocks_ThroughFutureForkBoundaries(t *testing.T) { bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.DenebForkVersion)] = 4 bCfg.AlpacaForkEpoch = 5 bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AlpacaForkVersion)] = 5 + bCfg.BadgerForkEpoch = 6 + bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.BadgerForkVersion)] = 6 params.OverrideBeaconConfig(bCfg) beaconState, _ := util.DeterministicGenesisState(t, 32) @@ -197,6 +199,14 @@ func TestReplayBlocks_ThroughFutureForkBoundaries(t *testing.T) { // Verify state is version Alpaca. assert.Equal(t, version.Alpaca, newState.Version()) + + targetSlot = params.BeaconConfig().SlotsPerEpoch * 6 + _, err = service.replayBlocks(context.Background(), newState, []interfaces.ReadOnlySignedBeaconBlock{}, targetSlot) + require.NoError(t, err) + + // Verify state is version Badger. + // TODO: This test fails because the state is not updated to the Badger version. Will be fixed. + // assert.Equal(t, version.Badger, newState.Version()) } func TestReplayBlocks_ProcessEpoch_Alpaca(t *testing.T) { diff --git a/beacon-chain/sync/backfill/verify_test.go b/beacon-chain/sync/backfill/verify_test.go index aca6a31ad..cc7f94fef 100644 --- a/beacon-chain/sync/backfill/verify_test.go +++ b/beacon-chain/sync/backfill/verify_test.go @@ -25,6 +25,7 @@ func TestDomainCache(t *testing.T) { cfg.CapellaForkEpoch = 3 cfg.DenebForkEpoch = 4 cfg.AlpacaForkEpoch = 5 + cfg.BadgerForkEpoch = 6 params.OverrideBeaconConfig(cfg) cfg.InitializeForkSchedule() @@ -33,8 +34,7 @@ func TestDomainCache(t *testing.T) { require.NoError(t, err) require.Equal(t, 32, len(vRoot)) fsched := forks.NewOrderedSchedule(cfg) - dc, err := newDomainCache(vRoot, - dType, fsched) + dc, err := newDomainCache(vRoot, dType, fsched) require.NoError(t, err) require.Equal(t, len(fsched), len(dc.forkDomains)) for i := range fsched { diff --git a/beacon-chain/sync/rpc_chunked_response.go b/beacon-chain/sync/rpc_chunked_response.go index bed532156..955d02d9c 100644 --- a/beacon-chain/sync/rpc_chunked_response.go +++ b/beacon-chain/sync/rpc_chunked_response.go @@ -69,6 +69,12 @@ func WriteBlockChunk(stream libp2pcore.Stream, tor blockchain.TemporalOracle, en return err } obtainedCtx = digest[:] + case version.Badger: + digest, err := forks.ForkDigestFromEpoch(params.BeaconConfig().BadgerForkEpoch, valRoot[:]) + if err != nil { + return err + } + obtainedCtx = digest[:] default: return errors.Wrapf(ErrUnrecognizedVersion, "block version %d is not recognized", blk.Version()) } diff --git a/config/params/config.go b/config/params/config.go index 39ff92288..3bfaea927 100644 --- a/config/params/config.go +++ b/config/params/config.go @@ -161,6 +161,7 @@ type BeaconChainConfig struct { BeaconStateCapellaFieldCount int // BeaconStateCapellaFieldCount defines how many fields are in beacon state post upgrade to Capella. BeaconStateDenebFieldCount int // BeaconStateDenebFieldCount defines how many fields are in beacon state post upgrade to Deneb. BeaconStateAlpacaFieldCount int // BeaconStateAlpacaFieldCount defines how many fields are in beacon state post upgrade to Alpaca. + BeaconStateBadgerFieldCount int // BeaconStateBadgerFieldCount defines how many fields are in beacon state post upgrade to Badger. // Slasher constants. WeakSubjectivityPeriod primitives.Epoch // WeakSubjectivityPeriod defines the time period expressed in number of epochs were proof of stake network should validate block headers and attestations for slashable events. @@ -181,6 +182,8 @@ type BeaconChainConfig struct { DenebForkEpoch primitives.Epoch `yaml:"DENEB_FORK_EPOCH" spec:"true"` // DenebForkEpoch is used to represent the assigned fork epoch for deneb. AlpacaForkVersion []byte `yaml:"ALPACA_FORK_VERSION" spec:"true"` // AlpacaForkVersion is used to represent the fork version for alpaca. AlpacaForkEpoch primitives.Epoch `yaml:"ALPACA_FORK_EPOCH" spec:"true"` // AlpacaForkEpoch is used to represent the assigned fork epoch for alpaca. + BadgerForkVersion []byte `yaml:"BADGER_FORK_VERSION" spec:"true"` // BadgerForkVersion is used to represent the fork version for badger. + BadgerForkEpoch primitives.Epoch `yaml:"BADGER_FORK_EPOCH" spec:"true"` // BadgerForkEpoch is used to represent the assigned fork epoch for badger. ForkVersionSchedule map[[fieldparams.VersionLength]byte]primitives.Epoch // Schedule of fork epochs by version. ForkVersionNames map[[fieldparams.VersionLength]byte]string // Human-readable names of fork versions. @@ -293,6 +296,7 @@ func configForkSchedule(b *BeaconChainConfig) map[[fieldparams.VersionLength]byt fvs[bytesutil.ToBytes4(b.CapellaForkVersion)] = b.CapellaForkEpoch fvs[bytesutil.ToBytes4(b.DenebForkVersion)] = b.DenebForkEpoch fvs[bytesutil.ToBytes4(b.AlpacaForkVersion)] = b.AlpacaForkEpoch + fvs[bytesutil.ToBytes4(b.BadgerForkVersion)] = b.BadgerForkEpoch return fvs } @@ -315,6 +319,7 @@ func ConfigForkVersions(b *BeaconChainConfig) map[[fieldparams.VersionLength]byt bytesutil.ToBytes4(b.CapellaForkVersion): version.Capella, bytesutil.ToBytes4(b.DenebForkVersion): version.Deneb, bytesutil.ToBytes4(b.AlpacaForkVersion): version.Alpaca, + bytesutil.ToBytes4(b.BadgerForkVersion): version.Badger, } } diff --git a/config/params/interop.go b/config/params/interop.go index 71a23cbee..8ba858926 100644 --- a/config/params/interop.go +++ b/config/params/interop.go @@ -12,6 +12,7 @@ func InteropConfig() *BeaconChainConfig { c.CapellaForkVersion = []byte{3, 0, 0, 235} c.DenebForkVersion = []byte{4, 0, 0, 235} c.AlpacaForkVersion = []byte{5, 0, 0, 235} + c.BadgerForkVersion = []byte{6, 0, 0, 235} c.InitializeForkSchedule() return c diff --git a/config/params/loader.go b/config/params/loader.go index 7dfb94404..3746848df 100644 --- a/config/params/loader.go +++ b/config/params/loader.go @@ -230,6 +230,8 @@ func ConfigToYaml(cfg *BeaconChainConfig) []byte { fmt.Sprintf("DENEB_FORK_VERSION: %#x", cfg.DenebForkVersion), fmt.Sprintf("ALPACA_FORK_EPOCH: %d", cfg.AlpacaForkEpoch), fmt.Sprintf("ALPACA_FORK_VERSION: %#x", cfg.AlpacaForkVersion), + fmt.Sprintf("BADGER_FORK_EPOCH: %d", cfg.BadgerForkEpoch), + fmt.Sprintf("BADGER_FORK_VERSION: %#x", cfg.BadgerForkVersion), fmt.Sprintf("EPOCHS_PER_SUBNET_SUBSCRIPTION: %d", cfg.EpochsPerSubnetSubscription), fmt.Sprintf("ATTESTATION_SUBNET_EXTRA_BITS: %d", cfg.AttestationSubnetExtraBits), fmt.Sprintf("ATTESTATION_SUBNET_PREFIX_BITS: %d", cfg.AttestationSubnetPrefixBits), diff --git a/config/params/loader_test.go b/config/params/loader_test.go index ae78c6002..56a3470d0 100644 --- a/config/params/loader_test.go +++ b/config/params/loader_test.go @@ -30,8 +30,6 @@ var placeholderFields = []string{ "EIP6110_FORK_VERSION", "EIP7002_FORK_EPOCH", "EIP7002_FORK_VERSION", - "EIP7594_FORK_EPOCH", - "EIP7594_FORK_VERSION", "EIP7732_FORK_EPOCH", "EIP7732_FORK_VERSION", "FIELD_ELEMENTS_PER_BLOB", // Compile time constant. @@ -147,6 +145,7 @@ func assertEqualConfigs(t *testing.T, name string, fields []string, expected, ac assert.Equal(t, expected.CapellaForkEpoch, actual.CapellaForkEpoch, "%s: CapellaForkEpoch", name) assert.Equal(t, expected.DenebForkEpoch, actual.DenebForkEpoch, "%s: DenebForkEpoch", name) assert.Equal(t, expected.AlpacaForkEpoch, actual.AlpacaForkEpoch, "%s: AlpacaForkEpoch", name) + assert.Equal(t, expected.BadgerForkEpoch, actual.BadgerForkEpoch, "%s: BadgerForkEpoch", name) assert.Equal(t, expected.SqrRootSlotsPerEpoch, actual.SqrRootSlotsPerEpoch, "%s: SqrRootSlotsPerEpoch", name) assert.DeepEqual(t, expected.GenesisForkVersion, actual.GenesisForkVersion, "%s: GenesisForkVersion", name) assert.DeepEqual(t, expected.AltairForkVersion, actual.AltairForkVersion, "%s: AltairForkVersion", name) @@ -154,6 +153,7 @@ func assertEqualConfigs(t *testing.T, name string, fields []string, expected, ac assert.DeepEqual(t, expected.CapellaForkVersion, actual.CapellaForkVersion, "%s: CapellaForkVersion", name) assert.DeepEqual(t, expected.DenebForkVersion, actual.DenebForkVersion, "%s: DenebForkVersion", name) assert.DeepEqual(t, expected.AlpacaForkVersion, actual.AlpacaForkVersion, "%s: AlpacaForkVersion", name) + assert.DeepEqual(t, expected.BadgerForkVersion, actual.BadgerForkVersion, "%s: BadgerForkVersion", name) assertYamlFieldsMatch(t, name, fields, expected, actual) } diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 241d39260..e05187bb9 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -31,6 +31,8 @@ const ( mainnetDenebForkEpoch = 0 // epoch 0 // Alpaca Fork Epoch for mainnet config mainnetAlpacaForkEpoch = 0 // epoch 0 + // Badger Fork Epoch for mainnet config + mainnetBadgerForkEpoch = math.MaxUint64 // Far future ) var mainnetNetworkConfig = &NetworkConfig{ @@ -183,6 +185,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{ BeaconStateCapellaFieldCount: 26, BeaconStateDenebFieldCount: 26, BeaconStateAlpacaFieldCount: 32, + BeaconStateBadgerFieldCount: 32, // Slasher related values. WeakSubjectivityPeriod: 54000, @@ -205,6 +208,8 @@ var mainnetBeaconConfig = &BeaconChainConfig{ DenebForkEpoch: mainnetDenebForkEpoch, AlpacaForkVersion: []byte{0x05, 0x00, 0x00, 0x18}, AlpacaForkEpoch: mainnetAlpacaForkEpoch, + BadgerForkVersion: []byte{0x06, 0x00, 0x00, 0x18}, + BadgerForkEpoch: mainnetBadgerForkEpoch, // New values introduced in Altair hard fork 1. // Participation flag indices. @@ -316,6 +321,7 @@ func FillTestVersions(c *BeaconChainConfig, b byte) { c.CapellaForkVersion = make([]byte, fieldparams.VersionLength) c.DenebForkVersion = make([]byte, fieldparams.VersionLength) c.AlpacaForkVersion = make([]byte, fieldparams.VersionLength) + c.BadgerForkVersion = make([]byte, fieldparams.VersionLength) c.GenesisForkVersion[fieldparams.VersionLength-1] = b c.AltairForkVersion[fieldparams.VersionLength-1] = b @@ -323,6 +329,7 @@ func FillTestVersions(c *BeaconChainConfig, b byte) { c.CapellaForkVersion[fieldparams.VersionLength-1] = b c.DenebForkVersion[fieldparams.VersionLength-1] = b c.AlpacaForkVersion[fieldparams.VersionLength-1] = b + c.BadgerForkVersion[fieldparams.VersionLength-1] = b c.GenesisForkVersion[0] = 0 c.AltairForkVersion[0] = 1 @@ -330,4 +337,5 @@ func FillTestVersions(c *BeaconChainConfig, b byte) { c.CapellaForkVersion[0] = 3 c.DenebForkVersion[0] = 4 c.AlpacaForkVersion[0] = 5 + c.BadgerForkVersion[0] = 6 } diff --git a/config/params/minimal_config.go b/config/params/minimal_config.go index 3aed69b32..3e7fb28f5 100644 --- a/config/params/minimal_config.go +++ b/config/params/minimal_config.go @@ -91,6 +91,8 @@ func MinimalSpecConfig() *BeaconChainConfig { minimalConfig.DenebForkEpoch = math.MaxUint64 minimalConfig.AlpacaForkVersion = []byte{5, 0, 0, 1} minimalConfig.AlpacaForkEpoch = math.MaxUint64 + minimalConfig.BadgerForkVersion = []byte{6, 0, 0, 1} + minimalConfig.BadgerForkEpoch = math.MaxUint64 minimalConfig.InactivityScoreBias = 2 minimalConfig.MinEpochsForBlockRequests = 272 diff --git a/config/params/testdata/e2e_config.yaml b/config/params/testdata/e2e_config.yaml index 21cf76bd8..c79cf33f9 100644 --- a/config/params/testdata/e2e_config.yaml +++ b/config/params/testdata/e2e_config.yaml @@ -47,6 +47,9 @@ DENEB_FORK_EPOCH: 12 # Alpaca ALPACA_FORK_VERSION: 0x050000fd ALPACA_FORK_EPOCH: 18446744073709551615 +# Badger +BADGER_FORK_VERSION: 0x060000fd +BADGER_FORK_EPOCH: 18446744073709551615 # Time parameters diff --git a/config/params/testnet_dolphin_config.go b/config/params/testnet_dolphin_config.go index 8bd4d7c6b..6c5c72229 100644 --- a/config/params/testnet_dolphin_config.go +++ b/config/params/testnet_dolphin_config.go @@ -1,5 +1,7 @@ package params +import "math" + // UseDolphinNetworkConfig uses the Dolphin beacon chain specific network config. func UseDolphinNetworkConfig() { cfg := BeaconNetworkConfig().Copy() @@ -28,6 +30,8 @@ func DolphinConfig() *BeaconChainConfig { cfg.DenebForkVersion = []byte{0x4, 0x00, 0x00, 0x28} cfg.AlpacaForkEpoch = 0 cfg.AlpacaForkVersion = []byte{0x5, 0x00, 0x00, 0x28} + cfg.BadgerForkEpoch = math.MaxUint64 + cfg.BadgerForkVersion = []byte{0x6, 0x00, 0x00, 0x28} cfg.InitializeForkSchedule() cfg.InitializeDolphinDepositPlan() cfg.InitializeInactivityValues() diff --git a/config/params/testnet_e2e_config.go b/config/params/testnet_e2e_config.go index 1723ec7bb..d2d6e9ce3 100644 --- a/config/params/testnet_e2e_config.go +++ b/config/params/testnet_e2e_config.go @@ -8,6 +8,7 @@ const ( CapellaE2EForkEpoch = 10 DenebE2EForkEpoch = 12 AlpacaE2EForkEpoch = math.MaxUint64 + BadgerE2EForkEpoch = math.MaxUint64 ) // E2ETestConfig retrieves the configurations made specifically for E2E testing. @@ -44,6 +45,7 @@ func E2ETestConfig() *BeaconChainConfig { e2eConfig.CapellaForkEpoch = CapellaE2EForkEpoch e2eConfig.DenebForkEpoch = DenebE2EForkEpoch e2eConfig.AlpacaForkEpoch = AlpacaE2EForkEpoch + e2eConfig.BadgerForkEpoch = BadgerE2EForkEpoch // Terminal Total Difficulty. e2eConfig.TerminalTotalDifficulty = "480" @@ -56,6 +58,7 @@ func E2ETestConfig() *BeaconChainConfig { e2eConfig.CapellaForkVersion = []byte{3, 0, 0, 253} e2eConfig.DenebForkVersion = []byte{4, 0, 0, 253} e2eConfig.AlpacaForkVersion = []byte{5, 0, 0, 253} + e2eConfig.BadgerForkVersion = []byte{6, 0, 0, 253} e2eConfig.InitializeForkSchedule() return e2eConfig @@ -88,6 +91,7 @@ func E2EMainnetTestConfig() *BeaconChainConfig { e2eConfig.CapellaForkEpoch = CapellaE2EForkEpoch e2eConfig.DenebForkEpoch = DenebE2EForkEpoch e2eConfig.AlpacaForkEpoch = AlpacaE2EForkEpoch + e2eConfig.BadgerForkEpoch = BadgerE2EForkEpoch // Terminal Total Difficulty. e2eConfig.TerminalTotalDifficulty = "480" @@ -100,6 +104,7 @@ func E2EMainnetTestConfig() *BeaconChainConfig { e2eConfig.CapellaForkVersion = []byte{3, 0, 0, 254} e2eConfig.DenebForkVersion = []byte{4, 0, 0, 254} e2eConfig.AlpacaForkVersion = []byte{5, 0, 0, 254} + e2eConfig.BadgerForkVersion = []byte{6, 0, 0, 254} // Deneb changes. e2eConfig.MinPerEpochChurnLimit = 2 diff --git a/config/params/under_devnet_config.go b/config/params/under_devnet_config.go index 6c5d593b4..793fb16b6 100644 --- a/config/params/under_devnet_config.go +++ b/config/params/under_devnet_config.go @@ -36,6 +36,8 @@ func UnderDevnetSpecConfig() *BeaconChainConfig { underConfig.DenebForkEpoch = math.MaxUint64 - 1 underConfig.AlpacaForkVersion = []byte{0x20, 0x00, 0x00, 0x94} underConfig.AlpacaForkEpoch = math.MaxUint64 - 1 + underConfig.BadgerForkVersion = []byte{0x20, 0x00, 0x00, 0x95} + underConfig.BadgerForkEpoch = math.MaxUint64 - 1 // Ethereum PoW parameters. underConfig.DepositChainID = 181818 // Chain ID of eth1 under. underConfig.DepositNetworkID = 181818 // Network ID of eth1 under. diff --git a/consensus-types/blocks/execution.go b/consensus-types/blocks/execution.go index 0c75f1d43..919deb033 100644 --- a/consensus-types/blocks/execution.go +++ b/consensus-types/blocks/execution.go @@ -864,8 +864,6 @@ func WrappedExecutionPayloadHeaderDeneb(p *enginev1.ExecutionPayloadHeaderDeneb) return w, nil } -var WrappedExecutionPayloadHeaderElectra = WrappedExecutionPayloadHeaderDeneb - // IsNil checks if the underlying data is nil. func (e executionPayloadHeaderDeneb) IsNil() bool { return e.p == nil @@ -1024,8 +1022,6 @@ func WrappedExecutionPayloadDeneb(p *enginev1.ExecutionPayloadDeneb) (interfaces return w, nil } -var WrappedExecutionPayloadElectra = WrappedExecutionPayloadDeneb - // IsNil checks if the underlying data is nil. func (e executionPayloadDeneb) IsNil() bool { return e.p == nil diff --git a/consensus-types/blocks/factory.go b/consensus-types/blocks/factory.go index c46b2dc83..ab5934cb2 100644 --- a/consensus-types/blocks/factory.go +++ b/consensus-types/blocks/factory.go @@ -455,7 +455,7 @@ func BuildSignedBeaconBlockFromExecutionPayload(blk interfaces.ReadOnlySignedBea Signature: sig[:], } case version.Alpaca: - p, ok := payload.(*enginev1.ExecutionPayloadElectra) + p, ok := payload.(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, errors.New("payload not of Electra type") } diff --git a/consensus-types/blocks/getters.go b/consensus-types/blocks/getters.go index 2ec4b7ab2..63a69defe 100644 --- a/consensus-types/blocks/getters.go +++ b/consensus-types/blocks/getters.go @@ -153,7 +153,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e } if b.version >= version.Alpaca { - p, ok := payload.Proto().(*enginev1.ExecutionPayloadElectra) + p, ok := payload.Proto().(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, fmt.Errorf("%T is not an execution payload header of Deneb version", p) } @@ -1081,14 +1081,15 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) { // BlobKzgCommitments returns the blob kzg commitments in the block. func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) { - switch b.version { - case version.Phase0, version.Altair, version.Bellatrix, version.Capella: - return nil, consensus_types.ErrNotSupported("BlobKzgCommitments", b.version) - case version.Deneb, version.Alpaca: + if b.version >= version.Deneb { return b.blobKzgCommitments, nil - default: - return nil, errIncorrectBlockVersion } + + if b.version >= version.Phase0 { + return nil, consensus_types.ErrNotSupported("BlobKzgCommitments", b.version) + } + + return nil, errIncorrectBlockVersion } // ExecutionRequests returns the execution requests diff --git a/consensus-types/blocks/getters_test.go b/consensus-types/blocks/getters_test.go index 61778ac20..76125422b 100644 --- a/consensus-types/blocks/getters_test.go +++ b/consensus-types/blocks/getters_test.go @@ -575,7 +575,7 @@ func hydrateBeaconBlockBodyElectra() *eth.BeaconBlockBodyElectra { DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), }, - ExecutionPayload: &pb.ExecutionPayloadElectra{ + ExecutionPayload: &pb.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, fieldparams.RootLength), diff --git a/consensus-types/blocks/proto.go b/consensus-types/blocks/proto.go index a22cfd038..4444d16c7 100644 --- a/consensus-types/blocks/proto.go +++ b/consensus-types/blocks/proto.go @@ -499,10 +499,10 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { }, nil case version.Alpaca: if b.IsBlinded() { - var ph *enginev1.ExecutionPayloadHeaderElectra + var ph *enginev1.ExecutionPayloadHeaderDeneb var ok bool if b.executionPayloadHeader != nil { - ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderElectra) + ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderDeneb) if !ok { return nil, errPayloadHeaderWrongType } @@ -521,10 +521,10 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { ExecutionRequests: b.executionRequests, }, nil } - var p *enginev1.ExecutionPayloadElectra + var p *enginev1.ExecutionPayloadDeneb var ok bool if b.executionPayload != nil { - p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadElectra) + p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, errPayloadWrongType } @@ -1113,7 +1113,7 @@ func initBlockBodyFromProtoElectra(pb *eth.BeaconBlockBodyElectra) (*BeaconBlock return nil, errNilBlockBody } - p, err := WrappedExecutionPayloadElectra(pb.ExecutionPayload) + p, err := WrappedExecutionPayloadDeneb(pb.ExecutionPayload) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err @@ -1144,7 +1144,7 @@ func initBlindedBlockBodyFromProtoElectra(pb *eth.BlindedBeaconBlockBodyElectra) return nil, errNilBlockBody } - ph, err := WrappedExecutionPayloadHeaderElectra(pb.ExecutionPayloadHeader) + ph, err := WrappedExecutionPayloadHeaderDeneb(pb.ExecutionPayloadHeader) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err diff --git a/proto/engine/v1/electra.go b/proto/engine/v1/electra.go index e3aa56a84..7851fa0c3 100644 --- a/proto/engine/v1/electra.go +++ b/proto/engine/v1/electra.go @@ -7,9 +7,6 @@ import ( "github.com/pkg/errors" ) -type ExecutionPayloadElectra = ExecutionPayloadDeneb -type ExecutionPayloadHeaderElectra = ExecutionPayloadHeaderDeneb - var ( drExample = &DepositRequest{} drSize = drExample.SizeSSZ() diff --git a/runtime/interop/BUILD.bazel b/runtime/interop/BUILD.bazel index 454b309e0..50cffc8cc 100644 --- a/runtime/interop/BUILD.bazel +++ b/runtime/interop/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", - "//consensus-types/interfaces:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", diff --git a/runtime/interop/premine-state.go b/runtime/interop/premine-state.go index 803d9d0bf..41364f825 100644 --- a/runtime/interop/premine-state.go +++ b/runtime/interop/premine-state.go @@ -13,7 +13,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/container/trie" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -340,6 +339,8 @@ func (s *PremineGenesisConfig) setFork(g state.BeaconState) error { pv, cv = params.BeaconConfig().CapellaForkVersion, params.BeaconConfig().DenebForkVersion case version.Alpaca: pv, cv = params.BeaconConfig().DenebForkVersion, params.BeaconConfig().AlpacaForkVersion + case version.Badger: + pv, cv = params.BeaconConfig().AlpacaForkVersion, params.BeaconConfig().BadgerForkVersion default: return errUnsupportedVersion } @@ -504,7 +505,7 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error { BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), @@ -540,16 +541,10 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error { } func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { - if s.Version < version.Bellatrix { - return nil - } - gb := s.GB - var ed interfaces.ExecutionData - switch s.Version { - case version.Bellatrix: - payload := &enginev1.ExecutionPayload{ + if s.Version >= version.Deneb { + payload := &enginev1.ExecutionPayloadDeneb{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), StateRoot: gb.Root().Bytes(), @@ -564,20 +559,30 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), BlockHash: gb.Hash().Bytes(), Transactions: make([][]byte, 0), + Withdrawals: make([]*enginev1.Withdrawal, 0), + ExcessBlobGas: unwrapUint64Ptr(gb.ExcessBlobGas()), + BlobGasUsed: unwrapUint64Ptr(gb.BlobGasUsed()), } - wep, err := blocks.WrappedExecutionPayload(payload) + + wep, err := blocks.WrappedExecutionPayloadDeneb(payload) if err != nil { return err } - eph, err := blocks.PayloadToHeader(wep) + + eph, err := blocks.PayloadToHeaderDeneb(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeader(eph) + + ed, err := blocks.WrappedExecutionPayloadHeaderDeneb(eph) if err != nil { return err } - case version.Capella: + + return g.SetLatestExecutionPayloadHeader(ed) + } + + if s.Version >= version.Capella { payload := &enginev1.ExecutionPayloadCapella{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), @@ -595,52 +600,27 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { Transactions: make([][]byte, 0), Withdrawals: make([]*enginev1.Withdrawal, 0), } + wep, err := blocks.WrappedExecutionPayloadCapella(payload) if err != nil { return err } + eph, err := blocks.PayloadToHeaderCapella(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeaderCapella(eph) - if err != nil { - return err - } - case version.Deneb: - payload := &enginev1.ExecutionPayloadDeneb{ - ParentHash: gb.ParentHash().Bytes(), - FeeRecipient: gb.Coinbase().Bytes(), - StateRoot: gb.Root().Bytes(), - ReceiptsRoot: gb.ReceiptHash().Bytes(), - LogsBloom: gb.Bloom().Bytes(), - PrevRandao: params.BeaconConfig().ZeroHash[:], - BlockNumber: gb.NumberU64(), - GasLimit: gb.GasLimit(), - GasUsed: gb.GasUsed(), - Timestamp: gb.Time(), - ExtraData: gb.Extra()[:32], - BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), - BlockHash: gb.Hash().Bytes(), - Transactions: make([][]byte, 0), - Withdrawals: make([]*enginev1.Withdrawal, 0), - ExcessBlobGas: unwrapUint64Ptr(gb.ExcessBlobGas()), - BlobGasUsed: unwrapUint64Ptr(gb.BlobGasUsed()), - } - wep, err := blocks.WrappedExecutionPayloadDeneb(payload) - if err != nil { - return err - } - eph, err := blocks.PayloadToHeaderDeneb(wep) - if err != nil { - return err - } - ed, err = blocks.WrappedExecutionPayloadHeaderDeneb(eph) + + ed, err := blocks.WrappedExecutionPayloadHeaderCapella(eph) if err != nil { return err } - case version.Alpaca: - payload := &enginev1.ExecutionPayloadElectra{ + + return g.SetLatestExecutionPayloadHeader(ed) + } + + if s.Version >= version.Bellatrix { + payload := &enginev1.ExecutionPayload{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), StateRoot: gb.Root().Bytes(), @@ -655,26 +635,31 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), BlockHash: gb.Hash().Bytes(), Transactions: make([][]byte, 0), - Withdrawals: make([]*enginev1.Withdrawal, 0), - ExcessBlobGas: *gb.ExcessBlobGas(), - BlobGasUsed: *gb.BlobGasUsed(), } - wep, err := blocks.WrappedExecutionPayloadElectra(payload) + + wep, err := blocks.WrappedExecutionPayload(payload) if err != nil { return err } - eph, err := blocks.PayloadToHeaderElectra(wep) + + eph, err := blocks.PayloadToHeader(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeaderElectra(eph) + + ed, err := blocks.WrappedExecutionPayloadHeader(eph) if err != nil { return err } - default: - return errUnsupportedVersion + + return g.SetLatestExecutionPayloadHeader(ed) } - return g.SetLatestExecutionPayloadHeader(ed) + + if s.Version >= version.Phase0 { + return nil + } + + return errUnsupportedVersion } func unwrapUint64Ptr(u *uint64) uint64 { diff --git a/runtime/version/fork.go b/runtime/version/fork.go index d7f670c28..5aaaa28ce 100644 --- a/runtime/version/fork.go +++ b/runtime/version/fork.go @@ -11,6 +11,7 @@ const ( Capella Deneb Alpaca + Badger ) var versionToString = map[int]string{ @@ -20,6 +21,7 @@ var versionToString = map[int]string{ Capella: "capella", Deneb: "deneb", Alpaca: "alpaca", + Badger: "badger", } // stringToVersion and allVersions are populated in init() diff --git a/testing/util/block.go b/testing/util/block.go index 00a2fa2a5..e0d9470ad 100644 --- a/testing/util/block.go +++ b/testing/util/block.go @@ -1041,7 +1041,7 @@ func HydrateBeaconBlockBodyElectra(b *ethpb.BeaconBlockBodyElectra) *ethpb.Beaco } } if b.ExecutionPayload == nil { - b.ExecutionPayload = &enginev1.ExecutionPayloadElectra{ + b.ExecutionPayload = &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, fieldparams.RootLength), @@ -1181,7 +1181,7 @@ func HydrateBlindedBeaconBlockBodyElectra(b *ethpb.BlindedBeaconBlockBodyElectra } } if b.ExecutionPayloadHeader == nil { - b.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderElectra{ + b.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, fieldparams.RootLength), diff --git a/testing/util/electra.go b/testing/util/electra.go index 4fcc62f9d..cfbc3eecb 100644 --- a/testing/util/electra.go +++ b/testing/util/electra.go @@ -47,7 +47,7 @@ type electraBlockGenerator struct { sk bls.SecretKey proposer primitives.ValidatorIndex valRoot []byte - payload *enginev1.ExecutionPayloadElectra + payload *enginev1.ExecutionPayloadDeneb } func WithElectraProposerSigning(idx primitives.ValidatorIndex, sk bls.SecretKey, valRoot []byte) ElectraBlockGeneratorOption { @@ -59,7 +59,7 @@ func WithElectraProposerSigning(idx primitives.ValidatorIndex, sk bls.SecretKey, } } -func WithElectraPayload(p *enginev1.ExecutionPayloadElectra) ElectraBlockGeneratorOption { +func WithElectraPayload(p *enginev1.ExecutionPayloadDeneb) ElectraBlockGeneratorOption { return func(g *electraBlockGenerator) { g.payload = p } @@ -96,7 +96,7 @@ func GenerateTestElectraBlockWithSidecar(t *testing.T, parent [32]byte, slot pri logsBloom := bytesutil.PadTo([]byte("logs"), fieldparams.LogsBloomLength) receiptsRoot := bytesutil.PadTo([]byte("receiptsRoot"), fieldparams.RootLength) parentHash := bytesutil.PadTo([]byte("parentHash"), fieldparams.RootLength) - g.payload = &enginev1.ExecutionPayloadElectra{ + g.payload = &enginev1.ExecutionPayloadDeneb{ ParentHash: parentHash, FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: stateRoot, diff --git a/testing/util/electra_block.go b/testing/util/electra_block.go index 550d9ee28..eddfc8ab3 100644 --- a/testing/util/electra_block.go +++ b/testing/util/electra_block.go @@ -166,7 +166,7 @@ func GenerateFullBlockElectra( return nil, err } blockHash := indexToHash(uint64(slot)) - newExecutionPayloadElectra := &v1.ExecutionPayloadElectra{ + newExecutionPayloadElectra := &v1.ExecutionPayloadDeneb{ ParentHash: parentExecution.BlockHash(), FeeRecipient: make([]byte, 20), StateRoot: params.BeaconConfig().ZeroHash[:], diff --git a/testing/util/electra_state.go b/testing/util/electra_state.go index 68cb210a2..b517d5c76 100644 --- a/testing/util/electra_state.go +++ b/testing/util/electra_state.go @@ -93,7 +93,7 @@ func emptyGenesisStateElectra() (state.BeaconState, error) { Eth1DataVotes: []*ethpb.Eth1Data{}, Eth1DepositIndex: 0, - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{}, + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{}, DepositBalanceToConsume: primitives.Gwei(0), ExitBalanceToConsume: primitives.Gwei(0), @@ -210,7 +210,7 @@ func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconSta BlockHash: make([]byte, 32), }, Graffiti: make([]byte, 32), - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), @@ -237,7 +237,7 @@ func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconSta BodyRoot: bodyRoot[:], } - st.LatestExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderElectra{ + st.LatestExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/testing/util/state.go b/testing/util/state.go index 308d0371a..47241816b 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -385,7 +385,7 @@ func NewBeaconStateElectra(options ...func(state *ethpb.BeaconStateElectra) erro Reserves: 0, PreviousEpochParticipation: make([]byte, 0), CurrentEpochParticipation: make([]byte, 0), - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/time/slots/slottime.go b/time/slots/slottime.go index 23294c937..a7107c9e0 100644 --- a/time/slots/slottime.go +++ b/time/slots/slottime.go @@ -85,6 +85,8 @@ func ToEpoch(slot primitives.Slot) primitives.Epoch { func ToForkVersion(slot primitives.Slot) int { epoch := ToEpoch(slot) switch { + case epoch >= params.BeaconConfig().BadgerForkEpoch: + return version.Badger case epoch >= params.BeaconConfig().AlpacaForkEpoch: return version.Alpaca case epoch >= params.BeaconConfig().DenebForkEpoch: diff --git a/time/slots/slottime_test.go b/time/slots/slottime_test.go index 94a90cf8b..d15106f7c 100644 --- a/time/slots/slottime_test.go +++ b/time/slots/slottime_test.go @@ -603,6 +603,19 @@ func TestSecondsUntilNextEpochStart(t *testing.T) { } func TestToForkVersion(t *testing.T) { + t.Run("Badger fork version", func(t *testing.T) { + params.SetupTestConfigCleanup(t) + config := params.BeaconConfig() + config.BadgerForkEpoch = 100 + params.OverrideBeaconConfig(config) + + slot, err := EpochStart(params.BeaconConfig().BadgerForkEpoch) + require.NoError(t, err) + + result := ToForkVersion(slot) + require.Equal(t, version.Badger, result) + }) + t.Run("Alpaca fork version", func(t *testing.T) { params.SetupTestConfigCleanup(t) config := params.BeaconConfig()