2021-12-14 09:18:27 +00:00
|
|
|
package execution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
2022-01-10 16:47:30 +00:00
|
|
|
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
|
2021-12-14 09:18:27 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2022-06-22 11:08:06 +00:00
|
|
|
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
2021-12-14 09:18:27 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
)
|
|
|
|
|
2022-01-26 07:24:47 +00:00
|
|
|
// UpgradeToBellatrix updates inputs a generic state to return the version Bellatrix state.
|
2021-12-14 09:18:27 +00:00
|
|
|
// It inserts an empty `ExecutionPayloadHeader` into the state.
|
2022-01-26 07:24:47 +00:00
|
|
|
func UpgradeToBellatrix(ctx context.Context, state state.BeaconState) (state.BeaconState, error) {
|
2021-12-14 09:18:27 +00:00
|
|
|
epoch := time.CurrentEpoch(state)
|
|
|
|
|
|
|
|
currentSyncCommittee, err := state.CurrentSyncCommittee()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nextSyncCommittee, err := state.NextSyncCommittee()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
prevEpochParticipation, err := state.PreviousEpochParticipation()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
currentEpochParticipation, err := state.CurrentEpochParticipation()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
inactivityScores, err := state.InactivityScores()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-01-10 16:47:30 +00:00
|
|
|
s := ðpb.BeaconStateBellatrix{
|
2021-12-14 09:18:27 +00:00
|
|
|
GenesisTime: state.GenesisTime(),
|
2022-02-14 13:34:38 +00:00
|
|
|
GenesisValidatorsRoot: state.GenesisValidatorsRoot(),
|
2021-12-14 09:18:27 +00:00
|
|
|
Slot: state.Slot(),
|
|
|
|
Fork: ðpb.Fork{
|
|
|
|
PreviousVersion: state.Fork().CurrentVersion,
|
2021-12-26 23:18:28 +00:00
|
|
|
CurrentVersion: params.BeaconConfig().BellatrixForkVersion,
|
2021-12-14 09:18:27 +00:00
|
|
|
Epoch: epoch,
|
|
|
|
},
|
|
|
|
LatestBlockHeader: state.LatestBlockHeader(),
|
|
|
|
BlockRoots: state.BlockRoots(),
|
|
|
|
StateRoots: state.StateRoots(),
|
|
|
|
HistoricalRoots: state.HistoricalRoots(),
|
|
|
|
Eth1Data: state.Eth1Data(),
|
|
|
|
Eth1DataVotes: state.Eth1DataVotes(),
|
|
|
|
Eth1DepositIndex: state.Eth1DepositIndex(),
|
|
|
|
Validators: state.Validators(),
|
|
|
|
Balances: state.Balances(),
|
|
|
|
RandaoMixes: state.RandaoMixes(),
|
|
|
|
Slashings: state.Slashings(),
|
|
|
|
PreviousEpochParticipation: prevEpochParticipation,
|
|
|
|
CurrentEpochParticipation: currentEpochParticipation,
|
|
|
|
JustificationBits: state.JustificationBits(),
|
|
|
|
PreviousJustifiedCheckpoint: state.PreviousJustifiedCheckpoint(),
|
|
|
|
CurrentJustifiedCheckpoint: state.CurrentJustifiedCheckpoint(),
|
|
|
|
FinalizedCheckpoint: state.FinalizedCheckpoint(),
|
|
|
|
InactivityScores: inactivityScores,
|
|
|
|
CurrentSyncCommittee: currentSyncCommittee,
|
|
|
|
NextSyncCommittee: nextSyncCommittee,
|
2022-06-22 11:08:06 +00:00
|
|
|
LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeader{
|
2021-12-14 09:18:27 +00:00
|
|
|
ParentHash: make([]byte, 32),
|
|
|
|
FeeRecipient: make([]byte, 20),
|
|
|
|
StateRoot: make([]byte, 32),
|
2022-04-16 13:18:07 +00:00
|
|
|
ReceiptsRoot: make([]byte, 32),
|
2021-12-14 09:18:27 +00:00
|
|
|
LogsBloom: make([]byte, 256),
|
2022-02-26 03:47:16 +00:00
|
|
|
PrevRandao: make([]byte, 32),
|
2021-12-14 09:18:27 +00:00
|
|
|
BlockNumber: 0,
|
|
|
|
GasLimit: 0,
|
|
|
|
GasUsed: 0,
|
|
|
|
Timestamp: 0,
|
|
|
|
BaseFeePerGas: make([]byte, 32),
|
|
|
|
BlockHash: make([]byte, 32),
|
|
|
|
TransactionsRoot: make([]byte, 32),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-01-20 06:54:21 +00:00
|
|
|
return v3.InitializeFromProtoUnsafe(s)
|
2021-12-14 09:18:27 +00:00
|
|
|
}
|