2021-09-23 01:10:25 +00:00
|
|
|
package v2
|
|
|
|
|
2022-05-27 16:38:00 +00:00
|
|
|
import (
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
|
|
|
)
|
|
|
|
|
2021-09-23 01:10:25 +00:00
|
|
|
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
|
|
|
|
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-09-23 01:10:25 +00:00
|
|
|
}
|
|
|
|
if b.state.CurrentEpochParticipation == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.currentEpochParticipation(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PreviousEpochParticipation corresponding to participation bits on the beacon chain.
|
|
|
|
func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-09-23 01:10:25 +00:00
|
|
|
}
|
|
|
|
if b.state.PreviousEpochParticipation == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.previousEpochParticipation(), nil
|
|
|
|
}
|
|
|
|
|
2022-05-27 16:38:00 +00:00
|
|
|
// UnrealizedCheckpointBalances returns the total balances: active, target attested in
|
|
|
|
// current epoch and target attested in previous epoch. This function is used to
|
|
|
|
// compute the "unrealized justification" that a synced Beacon Block will have.
|
|
|
|
func (b *BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return 0, 0, 0, ErrNilInnerState
|
|
|
|
}
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
cp := b.state.CurrentEpochParticipation
|
|
|
|
pp := b.state.PreviousEpochParticipation
|
|
|
|
if cp == nil || pp == nil {
|
|
|
|
return 0, 0, 0, ErrNilParticipation
|
|
|
|
}
|
|
|
|
currentEpoch := time.CurrentEpoch(b)
|
|
|
|
return stateutil.UnrealizedCheckpointBalances(cp, pp, b.state.Validators, currentEpoch)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-23 01:10:25 +00:00
|
|
|
// currentEpochParticipation corresponding to participation bits on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) currentEpochParticipation() []byte {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
tmp := make([]byte, len(b.state.CurrentEpochParticipation))
|
|
|
|
copy(tmp, b.state.CurrentEpochParticipation)
|
|
|
|
return tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
// previousEpochParticipation corresponding to participation bits on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) previousEpochParticipation() []byte {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
tmp := make([]byte, len(b.state.PreviousEpochParticipation))
|
|
|
|
copy(tmp, b.state.PreviousEpochParticipation)
|
|
|
|
return tmp
|
|
|
|
}
|