prysm-pulse/beacon-chain/state/state-native/getters_misc.go
terencechain d17996f8b0
Update to V4 🚀 (#12134)
* Update V3 from V4

* Fix build v3 -> v4

* Update ssz

* Update beacon_chain.pb.go

* Fix formatter import

* Update update-mockgen.sh comment to v4

* Fix conflicts. Pass build and tests

* Fix test
2023-03-17 18:52:56 +00:00

113 lines
2.6 KiB
Go

package state_native
import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
// GenesisTime of the beacon state as a uint64.
func (b *BeaconState) GenesisTime() uint64 {
b.lock.RLock()
defer b.lock.RUnlock()
return b.genesisTime
}
// GenesisValidatorsRoot of the beacon state.
func (b *BeaconState) GenesisValidatorsRoot() []byte {
b.lock.RLock()
defer b.lock.RUnlock()
return b.genesisValidatorsRoot[:]
}
// Version of the beacon state. This method
// is strictly meant to be used without a lock
// internally.
func (b *BeaconState) Version() int {
return b.version
}
// Slot of the current beacon chain state.
func (b *BeaconState) Slot() primitives.Slot {
b.lock.RLock()
defer b.lock.RUnlock()
return b.slot
}
// Fork version of the beacon chain.
func (b *BeaconState) Fork() *ethpb.Fork {
if b.fork == nil {
return nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.forkVal()
}
// forkVal version of the beacon chain.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) forkVal() *ethpb.Fork {
if b.fork == nil {
return nil
}
prevVersion := make([]byte, len(b.fork.PreviousVersion))
copy(prevVersion, b.fork.PreviousVersion)
currVersion := make([]byte, len(b.fork.CurrentVersion))
copy(currVersion, b.fork.CurrentVersion)
return &ethpb.Fork{
PreviousVersion: prevVersion,
CurrentVersion: currVersion,
Epoch: b.fork.Epoch,
}
}
// HistoricalRoots based on epochs stored in the beacon state.
func (b *BeaconState) HistoricalRoots() ([][]byte, error) {
if b.historicalRoots == nil {
return nil, nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.historicalRoots.Slice(), nil
}
// balancesLength returns the length of the balances slice.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) balancesLength() int {
if b.balances == nil {
return 0
}
return len(b.balances)
}
// HistoricalSummaries of the beacon state.
func (b *BeaconState) HistoricalSummaries() ([]*ethpb.HistoricalSummary, error) {
if b.version < version.Capella {
return nil, errNotSupported("HistoricalSummaries", b.version)
}
if b.historicalSummaries == nil {
return nil, nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.historicalSummariesVal(), nil
}
// historicalSummariesVal of the beacon state.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) historicalSummariesVal() []*ethpb.HistoricalSummary {
return ethpb.CopyHistoricalSummaries(b.historicalSummaries)
}