2022-01-13 11:23:53 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
2022-04-29 14:32:11 +00:00
|
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
2022-01-13 11:23:53 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GenesisTime of the beacon state as a uint64.
|
|
|
|
func (b *BeaconState) GenesisTime() uint64 {
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return b.genesisTime
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:34:38 +00:00
|
|
|
// GenesisValidatorsRoot of the beacon state.
|
|
|
|
func (b *BeaconState) GenesisValidatorsRoot() []byte {
|
2022-01-13 11:23:53 +00:00
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return b.genesisValidatorsRoot[:]
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Version of the beacon state. This method
|
|
|
|
// is strictly meant to be used without a lock
|
|
|
|
// internally.
|
|
|
|
func (_ *BeaconState) Version() int {
|
|
|
|
return version.Altair
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slot of the current beacon chain state.
|
|
|
|
func (b *BeaconState) Slot() types.Slot {
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return b.slot
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fork version of the beacon chain.
|
|
|
|
func (b *BeaconState) Fork() *ethpb.Fork {
|
2022-01-27 08:42:32 +00:00
|
|
|
if b.fork == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return b.forkVal()
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
// forkVal version of the beacon chain.
|
2022-01-13 11:23:53 +00:00
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-01-27 08:42:32 +00:00
|
|
|
func (b *BeaconState) forkVal() *ethpb.Fork {
|
|
|
|
if b.fork == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
prevVersion := make([]byte, len(b.fork.PreviousVersion))
|
|
|
|
copy(prevVersion, b.fork.PreviousVersion)
|
|
|
|
currVersion := make([]byte, len(b.fork.CurrentVersion))
|
|
|
|
copy(currVersion, b.fork.CurrentVersion)
|
2022-01-13 11:23:53 +00:00
|
|
|
return ðpb.Fork{
|
|
|
|
PreviousVersion: prevVersion,
|
|
|
|
CurrentVersion: currVersion,
|
2022-01-27 08:42:32 +00:00
|
|
|
Epoch: b.fork.Epoch,
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// HistoricalRoots based on epochs stored in the beacon state.
|
|
|
|
func (b *BeaconState) HistoricalRoots() [][]byte {
|
2022-01-27 08:42:32 +00:00
|
|
|
if b.historicalRoots == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return b.historicalRoots.Slice()
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// balancesLength returns the length of the balances slice.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) balancesLength() int {
|
2022-01-27 08:42:32 +00:00
|
|
|
if b.balances == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-01-27 08:42:32 +00:00
|
|
|
return len(b.balances)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|