prysm-pulse/beacon-chain/state/v2/getters_participation.go
Nishant Das 4f3762f1f7
Clean Up V2 BeaconState (#9648)
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-09-23 01:10:25 +00:00

54 lines
1.4 KiB
Go

package v2
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
if !b.hasInnerState() {
return nil, nil
}
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() {
return nil, nil
}
if b.state.PreviousEpochParticipation == nil {
return nil, nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.previousEpochParticipation(), nil
}
// 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
}