2021-06-30 15:06:19 +00:00
|
|
|
package v1
|
2019-12-04 19:20:33 +00:00
|
|
|
|
|
|
|
import (
|
2021-07-29 21:45:17 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2019-12-04 19:20:33 +00:00
|
|
|
)
|
|
|
|
|
2021-04-12 14:23:55 +00:00
|
|
|
// PreviousEpochAttestations corresponding to blocks on the beacon chain.
|
2021-07-29 21:45:17 +00:00
|
|
|
func (b *BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
2021-04-12 14:23:55 +00:00
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|
|
|
|
if b.state.PreviousEpochAttestations == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.previousEpochAttestations(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// previousEpochAttestations corresponding to blocks on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2021-07-29 21:45:17 +00:00
|
|
|
func (b *BeaconState) previousEpochAttestations() []*ethpb.PendingAttestation {
|
2021-04-12 14:23:55 +00:00
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-04 06:55:57 +00:00
|
|
|
return ethpb.CopyPendingAttestationSlice(b.state.PreviousEpochAttestations)
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentEpochAttestations corresponding to blocks on the beacon chain.
|
2021-07-29 21:45:17 +00:00
|
|
|
func (b *BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
2021-04-12 14:23:55 +00:00
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|
|
|
|
if b.state.CurrentEpochAttestations == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.currentEpochAttestations(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// currentEpochAttestations corresponding to blocks on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2021-07-29 21:45:17 +00:00
|
|
|
func (b *BeaconState) currentEpochAttestations() []*ethpb.PendingAttestation {
|
2021-04-12 14:23:55 +00:00
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-04 06:55:57 +00:00
|
|
|
return ethpb.CopyPendingAttestationSlice(b.state.CurrentEpochAttestations)
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|