mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-02-05 02:25:08 -05:00
Compare commits
6 Commits
e2e-debugg
...
inStateUpg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90f59f7a49 | ||
|
|
976856c8a3 | ||
|
|
0fdbfd1c87 | ||
|
|
a9a9d7bf83 | ||
|
|
40769a7913 | ||
|
|
7f78df180a |
@@ -5,14 +5,7 @@ go_library(
|
|||||||
srcs = ["upgrade.go"],
|
srcs = ["upgrade.go"],
|
||||||
importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/capella",
|
importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/capella",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = ["//beacon-chain/state:go_default_library"],
|
||||||
"//beacon-chain/core/time:go_default_library",
|
|
||||||
"//beacon-chain/state:go_default_library",
|
|
||||||
"//beacon-chain/state/state-native:go_default_library",
|
|
||||||
"//config/params:go_default_library",
|
|
||||||
"//proto/engine/v1:go_default_library",
|
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
go_test(
|
go_test(
|
||||||
|
|||||||
@@ -1,101 +1,10 @@
|
|||||||
package capella
|
package capella
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time"
|
|
||||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
|
||||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
||||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
|
||||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpgradeToCapella updates a generic state to return the version Capella state.
|
// UpgradeToCapella updates a generic state to return the version Capella state.
|
||||||
func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) {
|
func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) {
|
||||||
epoch := time.CurrentEpoch(state)
|
return state.UpgradeToCapella()
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
payloadHeader, err := state.LatestExecutionPayloadHeader()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
txRoot, err := payloadHeader.TransactionsRoot()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
hrs, err := state.HistoricalRoots()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s := ðpb.BeaconStateCapella{
|
|
||||||
GenesisTime: state.GenesisTime(),
|
|
||||||
GenesisValidatorsRoot: state.GenesisValidatorsRoot(),
|
|
||||||
Slot: state.Slot(),
|
|
||||||
Fork: ðpb.Fork{
|
|
||||||
PreviousVersion: state.Fork().CurrentVersion,
|
|
||||||
CurrentVersion: params.BeaconConfig().CapellaForkVersion,
|
|
||||||
Epoch: epoch,
|
|
||||||
},
|
|
||||||
LatestBlockHeader: state.LatestBlockHeader(),
|
|
||||||
BlockRoots: state.BlockRoots(),
|
|
||||||
StateRoots: state.StateRoots(),
|
|
||||||
HistoricalRoots: hrs,
|
|
||||||
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,
|
|
||||||
LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderCapella{
|
|
||||||
ParentHash: payloadHeader.ParentHash(),
|
|
||||||
FeeRecipient: payloadHeader.FeeRecipient(),
|
|
||||||
StateRoot: payloadHeader.StateRoot(),
|
|
||||||
ReceiptsRoot: payloadHeader.ReceiptsRoot(),
|
|
||||||
LogsBloom: payloadHeader.LogsBloom(),
|
|
||||||
PrevRandao: payloadHeader.PrevRandao(),
|
|
||||||
BlockNumber: payloadHeader.BlockNumber(),
|
|
||||||
GasLimit: payloadHeader.GasLimit(),
|
|
||||||
GasUsed: payloadHeader.GasUsed(),
|
|
||||||
Timestamp: payloadHeader.Timestamp(),
|
|
||||||
ExtraData: payloadHeader.ExtraData(),
|
|
||||||
BaseFeePerGas: payloadHeader.BaseFeePerGas(),
|
|
||||||
BlockHash: payloadHeader.BlockHash(),
|
|
||||||
TransactionsRoot: txRoot,
|
|
||||||
WithdrawalsRoot: make([]byte, 32),
|
|
||||||
},
|
|
||||||
NextWithdrawalIndex: 0,
|
|
||||||
NextWithdrawalValidatorIndex: 0,
|
|
||||||
HistoricalSummaries: make([]*ethpb.HistoricalSummary, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
return state_native.InitializeFromProtoUnsafeCapella(s)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,10 @@ func (s *Service) broadcastBLSChanges(ctx context.Context, changes []*ethpb.Sign
|
|||||||
limit = len(changes)
|
limit = len(changes)
|
||||||
}
|
}
|
||||||
for _, ch := range changes[:limit] {
|
for _, ch := range changes[:limit] {
|
||||||
if err := s.Broadcast(ctx, ch); err != nil {
|
if ch != nil {
|
||||||
log.WithError(err).Error("could not broadcast BLS to execution changes.")
|
if err := s.Broadcast(ctx, ch); err != nil {
|
||||||
|
log.WithError(err).Error("could not broadcast BLS to execution changes.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changes = changes[limit:]
|
changes = changes[limit:]
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ type WriteOnlyBeaconState interface {
|
|||||||
WriteOnlyParticipation
|
WriteOnlyParticipation
|
||||||
WriteOnlyInactivity
|
WriteOnlyInactivity
|
||||||
WriteOnlySyncCommittee
|
WriteOnlySyncCommittee
|
||||||
|
WriteOnlyUpgrade
|
||||||
SetGenesisTime(val uint64) error
|
SetGenesisTime(val uint64) error
|
||||||
SetGenesisValidatorsRoot(val []byte) error
|
SetGenesisValidatorsRoot(val []byte) error
|
||||||
SetSlot(val primitives.Slot) error
|
SetSlot(val primitives.Slot) error
|
||||||
@@ -278,3 +279,8 @@ type WriteOnlySyncCommittee interface {
|
|||||||
SetCurrentSyncCommittee(val *ethpb.SyncCommittee) error
|
SetCurrentSyncCommittee(val *ethpb.SyncCommittee) error
|
||||||
SetNextSyncCommittee(val *ethpb.SyncCommittee) error
|
SetNextSyncCommittee(val *ethpb.SyncCommittee) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteOnlyUpgrade defines a struct that only has access to the fork upgrade methods.
|
||||||
|
type WriteOnlyUpgrade interface {
|
||||||
|
UpgradeToCapella() (BeaconState, error)
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ go_library(
|
|||||||
"setters_randao.go",
|
"setters_randao.go",
|
||||||
"setters_state.go",
|
"setters_state.go",
|
||||||
"setters_sync_committee.go",
|
"setters_sync_committee.go",
|
||||||
|
"setters_upgrade.go",
|
||||||
"setters_validator.go",
|
"setters_validator.go",
|
||||||
"setters_withdrawal.go",
|
"setters_withdrawal.go",
|
||||||
"spec_parameters.go",
|
"spec_parameters.go",
|
||||||
|
|||||||
149
beacon-chain/state/state-native/setters_upgrade.go
Normal file
149
beacon-chain/state/state-native/setters_upgrade.go
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
package state_native
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
||||||
|
nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||||
|
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||||
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||||
|
"github.com/prysmaticlabs/prysm/v3/time/slots"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UpgradeToCapella upgrades the beacon state to capella.
|
||||||
|
func (b *BeaconState) UpgradeToCapella() (state.BeaconState, error) {
|
||||||
|
if b.version != version.Bellatrix {
|
||||||
|
return nil, errNotSupported("UpgradeToCapella", b.version)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.lock.RLock()
|
||||||
|
defer b.lock.RUnlock()
|
||||||
|
|
||||||
|
fieldCount := params.BeaconConfig().BeaconStateCapellaFieldCount
|
||||||
|
epoch := slots.ToEpoch(b.slot)
|
||||||
|
|
||||||
|
payloadHeader := b.latestExecutionPayloadHeaderVal()
|
||||||
|
dst := &BeaconState{
|
||||||
|
version: version.Capella,
|
||||||
|
|
||||||
|
// Primitive nativetypes, safe to copy.
|
||||||
|
genesisTime: b.genesisTime,
|
||||||
|
slot: b.slot,
|
||||||
|
eth1DepositIndex: b.eth1DepositIndex,
|
||||||
|
nextWithdrawalIndex: 0,
|
||||||
|
nextWithdrawalValidatorIndex: 0,
|
||||||
|
|
||||||
|
// Large arrays, infrequently changed, constant size.
|
||||||
|
blockRoots: b.blockRoots,
|
||||||
|
stateRoots: b.stateRoots,
|
||||||
|
randaoMixes: b.randaoMixes,
|
||||||
|
previousEpochAttestations: b.previousEpochAttestations,
|
||||||
|
currentEpochAttestations: b.currentEpochAttestations,
|
||||||
|
eth1DataVotes: b.eth1DataVotes,
|
||||||
|
slashings: b.slashings,
|
||||||
|
|
||||||
|
// Large arrays, increases over time.
|
||||||
|
balances: b.balances,
|
||||||
|
historicalRoots: b.historicalRoots,
|
||||||
|
historicalSummaries: make([]*ethpb.HistoricalSummary, 0),
|
||||||
|
validators: b.validators,
|
||||||
|
previousEpochParticipation: b.previousEpochParticipation,
|
||||||
|
currentEpochParticipation: b.currentEpochParticipation,
|
||||||
|
inactivityScores: b.inactivityScores,
|
||||||
|
|
||||||
|
// Everything else, too small to be concerned about, constant size.
|
||||||
|
genesisValidatorsRoot: b.genesisValidatorsRoot,
|
||||||
|
justificationBits: b.justificationBitsVal(),
|
||||||
|
fork: ðpb.Fork{
|
||||||
|
PreviousVersion: b.fork.CurrentVersion,
|
||||||
|
CurrentVersion: params.BeaconConfig().CapellaForkVersion,
|
||||||
|
Epoch: epoch,
|
||||||
|
},
|
||||||
|
latestBlockHeader: b.latestBlockHeaderVal(),
|
||||||
|
eth1Data: b.eth1DataVal(),
|
||||||
|
previousJustifiedCheckpoint: b.previousJustifiedCheckpointVal(),
|
||||||
|
currentJustifiedCheckpoint: b.currentJustifiedCheckpointVal(),
|
||||||
|
finalizedCheckpoint: b.finalizedCheckpointVal(),
|
||||||
|
currentSyncCommittee: b.currentSyncCommitteeVal(),
|
||||||
|
nextSyncCommittee: b.nextSyncCommitteeVal(),
|
||||||
|
latestExecutionPayloadHeaderCapella: &enginev1.ExecutionPayloadHeaderCapella{
|
||||||
|
ParentHash: payloadHeader.ParentHash,
|
||||||
|
FeeRecipient: payloadHeader.FeeRecipient,
|
||||||
|
StateRoot: payloadHeader.StateRoot,
|
||||||
|
ReceiptsRoot: payloadHeader.ReceiptsRoot,
|
||||||
|
LogsBloom: payloadHeader.LogsBloom,
|
||||||
|
PrevRandao: payloadHeader.PrevRandao,
|
||||||
|
BlockNumber: payloadHeader.BlockNumber,
|
||||||
|
GasLimit: payloadHeader.GasLimit,
|
||||||
|
GasUsed: payloadHeader.GasUsed,
|
||||||
|
Timestamp: payloadHeader.Timestamp,
|
||||||
|
ExtraData: payloadHeader.ExtraData,
|
||||||
|
BaseFeePerGas: payloadHeader.BaseFeePerGas,
|
||||||
|
BlockHash: payloadHeader.BlockHash,
|
||||||
|
TransactionsRoot: payloadHeader.TransactionsRoot,
|
||||||
|
WithdrawalsRoot: make([]byte, 32),
|
||||||
|
},
|
||||||
|
|
||||||
|
dirtyFields: make(map[nativetypes.FieldIndex]bool, fieldCount),
|
||||||
|
dirtyIndices: make(map[nativetypes.FieldIndex][]uint64, fieldCount),
|
||||||
|
rebuildTrie: make(map[nativetypes.FieldIndex]bool, fieldCount),
|
||||||
|
stateFieldLeaves: make(map[nativetypes.FieldIndex]*fieldtrie.FieldTrie, fieldCount),
|
||||||
|
|
||||||
|
// Share the reference to validator index map.
|
||||||
|
valMapHandler: b.valMapHandler,
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.sharedFieldReferences = make(map[nativetypes.FieldIndex]*stateutil.Reference, capellaSharedFieldRefCount)
|
||||||
|
|
||||||
|
for field, ref := range b.sharedFieldReferences {
|
||||||
|
ref.AddRef()
|
||||||
|
dst.sharedFieldReferences[field] = ref
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment ref for validator map
|
||||||
|
b.valMapHandler.AddRef()
|
||||||
|
|
||||||
|
for i := range b.dirtyFields {
|
||||||
|
dst.dirtyFields[i] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range b.dirtyIndices {
|
||||||
|
indices := make([]uint64, len(b.dirtyIndices[i]))
|
||||||
|
copy(indices, b.dirtyIndices[i])
|
||||||
|
dst.dirtyIndices[i] = indices
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range b.rebuildTrie {
|
||||||
|
dst.rebuildTrie[i] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for fldIdx, fieldTrie := range b.stateFieldLeaves {
|
||||||
|
dst.stateFieldLeaves[fldIdx] = fieldTrie
|
||||||
|
if fieldTrie.FieldReference() != nil {
|
||||||
|
fieldTrie.Lock()
|
||||||
|
fieldTrie.FieldReference().AddRef()
|
||||||
|
fieldTrie.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range []types.FieldIndex{types.LatestExecutionPayloadHeaderCapella, types.HistoricalSummaries} {
|
||||||
|
b.dirtyFields[f] = true
|
||||||
|
b.rebuildTrie[f] = true
|
||||||
|
b.dirtyIndices[f] = []uint64{}
|
||||||
|
trie, err := fieldtrie.NewFieldTrie(f, types.BasicArray, nil, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b.stateFieldLeaves[f] = trie
|
||||||
|
}
|
||||||
|
|
||||||
|
state.StateCount.Inc()
|
||||||
|
// Finalizer runs when dst is being destroyed in garbage collection.
|
||||||
|
runtime.SetFinalizer(dst, finalizerCleanup)
|
||||||
|
return dst, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user